java - Test WebSocket in PlayFramework -
i have websocket in play application , want write test it, couldn't find example on how write such test. found discussion in play-framework google group there has been no activity recently.
so, there ideas on how test websocket's in java test?
you can retrieve underlying iteratee,enumerator , test them directly. way don't need use browser. need akka-testkit though, cope asynchronous nature of iteratees.
a scala example:
object websocket extends controller { def websocket = websocket.async[jsvalue] { request => future.successful(iteratee.ignore[jsvalue] -> enumerator.apply[jsvalue](json.obj("type" -> "error"))) } } class websocketspec extends playspecification { "websocket" should { "respond error packet" in new withapplication { val request = fakerequest() var message: jsvalue = null val iteratee = iteratee.foreach[jsvalue](chunk => message = chunk)(akka.system.dispatcher) controller.websocket().f(request)(enumerator.empty[jsvalue],iteratee) testkit.awaitcond(message == json.obj("type" -> "error"), 1 second) } } }
Comments
Post a Comment