Skip to content

Commit

Permalink
Add test in GraphSpec for no valid messages
Browse files Browse the repository at this point in the history
  • Loading branch information
simoexpo committed Feb 19, 2020
1 parent 5b3106d commit 704c440
Showing 1 changed file with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import it.bitrock.dvs.producer.aviationedge.model.{ErrorMessageJson, MessageJson
import it.bitrock.dvs.producer.aviationedge.services.Graphs._
import it.bitrock.testcommons.Suite
import net.manub.embeddedkafka.schemaregistry._
import org.scalatest.{BeforeAndAfterAll, OptionValues}
import org.scalatest.concurrent.PatienceConfiguration.Timeout
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.wordspec.AnyWordSpecLike
import org.scalatest.{BeforeAndAfterAll, OptionValues}

import scala.concurrent.Future
import scala.concurrent.duration._
Expand Down Expand Up @@ -55,7 +55,7 @@ class GraphsSpec
}
}

"produce monitoring messages to monitoring sink" in {
"produce monitoring messages to monitoring sink when there are valid messages" in {
val source = Source.single(
List(
Right(FlightMessage),
Expand Down Expand Up @@ -84,5 +84,28 @@ class GraphsSpec
m.head.total shouldBe 6
}
}

"produce monitoring messages to monitoring sink when there are no valid messages" in {
val source = Source.single(
List(
Left(ErrorMessage.copy(errorSource = "/v2/public/flights"))
)
)
val monitoringSink: Sink[MonitoringMessageJson, Future[List[MonitoringMessageJson]]] =
Sink.fold[List[MonitoringMessageJson], MonitoringMessageJson](Nil)(_ :+ _)

val futureMonitoring = source.viaMat(monitoringGraph(monitoringSink))(Keep.right).to(Sink.ignore).run()

whenReady(futureMonitoring, timeout) { m =>
m.size shouldBe 1
m.head.minUpdated shouldBe empty
m.head.maxUpdated shouldBe empty
m.head.averageUpdated shouldBe empty
m.head.numErrors shouldBe 1
m.head.numValid shouldBe 0
m.head.numInvalid shouldBe 0
m.head.total shouldBe 1
}
}
}
}

0 comments on commit 704c440

Please sign in to comment.