Skip to content

Commit

Permalink
tests for PrimaryServiceProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-bao committed Feb 21, 2024
1 parent 5765cdc commit ffaa520
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ case class PrimaryServiceProxy(
simulationStart: ZonedDateTime,
extSimulation: Option[ActorRef]
): Try[PrimaryServiceStateData] = {
var serviceStateData = PrimaryServiceStateData(Map.empty, Map.empty, simulationStart, primaryConfig, null)


createSources(primaryConfig).map {
case (mappingSource, metaInformationSource) =>
val modelToTimeSeries = mappingSource.getMapping.asScala.toMap
Expand Down Expand Up @@ -142,22 +143,26 @@ case class PrimaryServiceProxy(
}
}
.toMap
serviceStateData = PrimaryServiceStateData(
modelToTimeSeries,
timeSeriesToSourceRef,
simulationStart,
primaryConfig,
mappingSource
)
}
if (extSimulation.isDefined) {
// Ask ExtPrimaryDataService which UUIDs should be substituted
Success(serviceStateData.copy(
extSubscribers = getSubscribers,
extPrimaryDataService = extSimulation
))
} else {
Success(serviceStateData)
if (extSimulation.isDefined) {
// Ask ExtPrimaryDataService which UUIDs should be substituted
PrimaryServiceStateData(
modelToTimeSeries,
timeSeriesToSourceRef,
simulationStart,
primaryConfig,
mappingSource,
getSubscribers(),
extSimulation
)
} else {
PrimaryServiceStateData(
modelToTimeSeries,
timeSeriesToSourceRef,
simulationStart,
primaryConfig,
mappingSource
)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ class PrimaryServiceProxySpec

private val scheduler: TestProbe = TestProbe("scheduler")

val validExtPrimaryDataService = TestActorRef(
new ExtPrimaryDataService(
scheduler.ref
)
)

"Testing a primary service config" should {
"lead to complaining about too much source definitions" in {
val maliciousConfig = PrimaryConfig(
Expand Down Expand Up @@ -260,7 +266,8 @@ class PrimaryServiceProxySpec

proxy invokePrivate prepareStateData(
maliciousConfig,
simulationStart
simulationStart,
Option.empty
) match {
case Success(_) =>
fail("Building state data with missing config should fail")
Expand All @@ -280,7 +287,8 @@ class PrimaryServiceProxySpec

proxy invokePrivate prepareStateData(
maliciousConfig,
simulationStart
simulationStart,
Option.empty
) match {
case Success(_) =>
fail("Building state data with missing config should fail")
Expand All @@ -293,7 +301,8 @@ class PrimaryServiceProxySpec
"result in correct data" in {
proxy invokePrivate prepareStateData(
validPrimaryConfig,
simulationStart
simulationStart,
Option.empty
) match {
case Success(
PrimaryServiceStateData(
Expand Down Expand Up @@ -341,6 +350,29 @@ class PrimaryServiceProxySpec
)
}
}

"build proxy correctly when there is an external simulation" in {
proxy invokePrivate prepareStateData(
validPrimaryConfig,
simulationStart,
Some(validExtPrimaryDataService)
) match {
case Success(
PrimaryServiceStateData(
modelToTimeSeries,
timeSeriesToSourceRef,
simulationStart,
primaryConfig,
mappingSource,
extSubscribers,
extPrimaryDataService
)
) => extPrimaryDataService should contain (validExtPrimaryDataService)
extSubscribers shouldBe Iterable.empty
}
}


}

"Sending initialization information to an uninitialized actor" should {
Expand Down

0 comments on commit ffaa520

Please sign in to comment.