Skip to content

Commit fe41d5d

Browse files
committed
Fix grid converter test
1 parent 80a20d5 commit fe41d5d

File tree

1 file changed

+65
-68
lines changed

1 file changed

+65
-68
lines changed

src/test/scala/edu/ie3/simbench/convert/GridConverterSpec.scala

Lines changed: 65 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
package edu.ie3.simbench.convert
22

3+
import akka.actor.testkit.typed.scaladsl.ActorTestKit
4+
35
import java.nio.file.Paths
46
import java.util
57
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}
1010
import edu.ie3.simbench.convert.NodeConverter.AttributeOverride.JoinOverride
1111
import edu.ie3.simbench.io.SimbenchReader
1212
import edu.ie3.simbench.model.datamodel.{GridModel, Node, Switch}
1313
import edu.ie3.test.common.{SwitchTestingData, UnitSpec}
14-
import org.scalatest.Inside._
14+
import org.scalatest.BeforeAndAfterAll
1515

16+
import scala.concurrent.duration.{Duration, FiniteDuration}
1617
import scala.jdk.CollectionConverters._
1718

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+
1930
val simbenchReader: SimbenchReader = SimbenchReader(
2031
"1-LV-rural1--0-no_sw",
2132
Paths.get("src/test/resources/gridData/1-LV-rural1--0-no_sw")
@@ -140,69 +151,55 @@ class GridConverterSpec extends UnitSpec with SwitchTestingData {
140151

141152
"converting a full data set" should {
142153
"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+
}
192196
}
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+
*/
193203
}
194204
}
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
208205
}

0 commit comments

Comments
 (0)