Skip to content

Instantly share code, notes, and snippets.

@dat-vikash
Last active August 29, 2015 14:18
Show Gist options
  • Save dat-vikash/2beaf89e541f481f441c to your computer and use it in GitHub Desktop.
Save dat-vikash/2beaf89e541f481f441c to your computer and use it in GitHub Desktop.
Play 2.2.x WSClientVisitorSpec
class WSClientVisitorSpec extends TestKit(_system = Akka.system(FakeApplication())) with WordSpecLike with Matchers with ImplicitSender
{
//instantiate test constants
val actorRef = TestActorRef(new WSClientVisitor("TEST") with MockWebSocketChannel, name= "test")
// get a test reference to our actor
val actor = actorRef.underlyingActor
"Web Socket Client For Visitor" should {
"register a new socket" in new WithApplication(app = FakeApplication(additionalConfiguration =Map("akka.event-handlers" -> List("akka.testkit.TestEventListener")),
withGlobal = Some(new GlobalSettings() {
override def onStart(app: api.Application) {
Logger.info("Akka system up")
}
}))) {
// clear our channel
actor.mockWebSocketChannelQueue = List.empty
// send the RegisterSocket message and verify the data on the chaneel
actor.receive(RegisterSocket)
actor.mockWebSocketChannelQueue(0) \ "type" should equal(JsString(“event”))
actor.mockWebSocketChannelQueue(0) \ "data" should equal(JsString(“connection_on”)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment