|
1 | 1 | package edu.ie3.simbench.convert |
2 | 2 |
|
| 3 | +import akka.actor.testkit.typed.scaladsl.ActorTestKit |
| 4 | + |
3 | 5 | import java.nio.file.Paths |
4 | 6 | import java.util |
5 | 7 | import edu.ie3.datamodel.models.UniqueEntity |
6 | | -import edu.ie3.datamodel.models.input.NodeInput |
7 | | -import edu.ie3.datamodel.models.input.connector.{LineInput, Transformer2WInput} |
8 | | -import edu.ie3.datamodel.models.input.system.{FixedFeedInInput, LoadInput} |
9 | | -import edu.ie3.simbench.actor.GridConverter |
| 8 | +import edu.ie3.simbench.actor.GridConverter.ConvertGridStructure |
| 9 | +import edu.ie3.simbench.actor.{Converter, GridConverter} |
10 | 10 | import edu.ie3.simbench.convert.NodeConverter.AttributeOverride.JoinOverride |
11 | 11 | import edu.ie3.simbench.io.SimbenchReader |
12 | 12 | import edu.ie3.simbench.model.datamodel.{GridModel, Node, Switch} |
13 | 13 | import edu.ie3.test.common.{SwitchTestingData, UnitSpec} |
14 | | -import org.scalatest.Inside._ |
| 14 | +import org.scalatest.BeforeAndAfterAll |
15 | 15 |
|
| 16 | +import scala.concurrent.duration.{Duration, FiniteDuration} |
16 | 17 | import scala.jdk.CollectionConverters._ |
17 | 18 |
|
18 | | -class GridConverterSpec extends UnitSpec with SwitchTestingData { |
| 19 | +class GridConverterSpec |
| 20 | + extends UnitSpec |
| 21 | + with BeforeAndAfterAll |
| 22 | + with SwitchTestingData { |
| 23 | + val akkaTestKit: ActorTestKit = ActorTestKit() |
| 24 | + |
| 25 | + override protected def afterAll(): Unit = { |
| 26 | + akkaTestKit.shutdownTestKit() |
| 27 | + super.afterAll() |
| 28 | + } |
| 29 | + |
19 | 30 | val simbenchReader: SimbenchReader = SimbenchReader( |
20 | 31 | "1-LV-rural1--0-no_sw", |
21 | 32 | Paths.get("src/test/resources/gridData/1-LV-rural1--0-no_sw") |
@@ -140,69 +151,55 @@ class GridConverterSpec extends UnitSpec with SwitchTestingData { |
140 | 151 |
|
141 | 152 | "converting a full data set" should { |
142 | 153 | "bring the correct amount of converted models" in { |
143 | | - // TODO: Fix test |
144 | | - succeed |
145 | | -// val actual = GridConverter.convert( |
146 | | -// "1-LV-rural1--0-no_sw", |
147 | | -// input, |
148 | | -// removeSwitches = false |
149 | | -// ) |
150 | | -// inside(actual) { |
151 | | -// case ( |
152 | | -// gridContainer, |
153 | | -// timeSeries, |
154 | | -// timeSeriesMapping, |
155 | | -// powerFlowResults |
156 | | -// ) => |
157 | | -// /* Evaluate the correctness of the container by counting the occurrence of models (the correct conversion is |
158 | | -// * tested in separate unit tests */ |
159 | | -// gridContainer.getGridName shouldBe "1-LV-rural1--0-no_sw" |
160 | | -// countClassOccurrences(gridContainer.getRawGrid.allEntitiesAsList()) shouldBe Map( |
161 | | -// classOf[NodeInput] -> 15, |
162 | | -// classOf[LineInput] -> 13, |
163 | | -// classOf[Transformer2WInput] -> 1 |
164 | | -// ) |
165 | | -// countClassOccurrences( |
166 | | -// gridContainer.getSystemParticipants.allEntitiesAsList() |
167 | | -// ) shouldBe Map( |
168 | | -// classOf[FixedFeedInInput] -> 4, |
169 | | -// classOf[LoadInput] -> 13 |
170 | | -// ) |
171 | | -// countClassOccurrences(gridContainer.getGraphics.allEntitiesAsList()) shouldBe Map |
172 | | -// .empty[Class[_ <: UniqueEntity], Int] |
173 | | -// |
174 | | -// /* Evaluate the correctness of the time series by counting the occurrence of models */ |
175 | | -// timeSeries.size shouldBe 17 |
176 | | -// |
177 | | -// /* Evaluate the existence of time series mappings for all participants */ |
178 | | -// timeSeriesMapping.size shouldBe 17 |
179 | | -// val participantUuids = gridContainer.getSystemParticipants |
180 | | -// .allEntitiesAsList() |
181 | | -// .asScala |
182 | | -// .map(_.getUuid) |
183 | | -// .toVector |
184 | | -// /* There is no participant uuid in mapping, that is not among participants */ |
185 | | -// timeSeriesMapping.exists( |
186 | | -// entry => !participantUuids.contains(entry.getParticipant) |
187 | | -// ) shouldBe false |
188 | | -// |
189 | | -// /* Evaluate the amount of converted power flow results */ |
190 | | -// powerFlowResults.size shouldBe 15 |
191 | | -// } |
| 154 | + /* Set up the actors */ |
| 155 | + val gridConverter = akkaTestKit.spawn(GridConverter(), "gridConverter") |
| 156 | + val converter = |
| 157 | + akkaTestKit.createTestProbe[Converter.ConverterMessage]("converter") |
| 158 | + |
| 159 | + /* Issue the conversion */ |
| 160 | + gridConverter ! ConvertGridStructure( |
| 161 | + "1-LV-rural1--0-no_sw", |
| 162 | + input.nodes, |
| 163 | + input.nodePFResults, |
| 164 | + input.externalNets, |
| 165 | + input.powerPlants, |
| 166 | + input.res, |
| 167 | + input.transformers2w, |
| 168 | + input.transformers3w, |
| 169 | + input.lines, |
| 170 | + input.switches, |
| 171 | + input.measurements, |
| 172 | + removeSwitches = false, |
| 173 | + converter.ref |
| 174 | + ) |
| 175 | + |
| 176 | + converter.expectMessageType[Converter.GridStructureConverted]( |
| 177 | + FiniteDuration(60, "s") |
| 178 | + ) match { |
| 179 | + case Converter.GridStructureConverted( |
| 180 | + nodeConversion, |
| 181 | + nodeResults, |
| 182 | + lines, |
| 183 | + transformers2w, |
| 184 | + transformers3w, |
| 185 | + switches, |
| 186 | + measurements |
| 187 | + ) => |
| 188 | + nodeConversion.size shouldBe 15 |
| 189 | + nodeResults.size shouldBe 15 |
| 190 | + lines.size shouldBe 13 |
| 191 | + transformers2w.size shouldBe 1 |
| 192 | + transformers3w.size shouldBe 0 |
| 193 | + switches.size shouldBe 0 |
| 194 | + measurements.size shouldBe 0 |
| 195 | + } |
192 | 196 | } |
| 197 | + /* TODO: Test amount of converted participants |
| 198 | + * 4 x FixedFeedInInput |
| 199 | + * 13 x LoadInput |
| 200 | + * 17 x Time Series and Mapping |
| 201 | + * All participants have a corresponding time series |
| 202 | + */ |
193 | 203 | } |
194 | 204 | } |
195 | | - |
196 | | - def countClassOccurrences( |
197 | | - entities: util.List[_ <: UniqueEntity] |
198 | | - ): Map[Class[_ <: UniqueEntity], Int] = |
199 | | - entities.asScala |
200 | | - .groupBy(_.getClass) |
201 | | - .map( |
202 | | - classToOccurrences => |
203 | | - classToOccurrences._1 -> classToOccurrences._2.size |
204 | | - ) |
205 | | - .toSeq |
206 | | - .sortBy(_._1.getName) |
207 | | - .toMap |
208 | 205 | } |
0 commit comments