I'm trying to do some acceptance/integration tests with websockets in my Application (play, akka, scalatest...) which will be consumed by a mobile app. I have done some unit test for every actor (in the future, i want that this "unit" refer to more than one actor). Now I want to test the whole system.
For non websocket endpoint like:
package controllers
import play.api.mvc.{Action, Controller}
class StatusController extends Controller {
def get() = Action { implicit request =>
Ok
}
}
I have the test:
package acceptance
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec}
import play.api.libs.ws.WS
import play.api.test.Helpers._
class StatusSpec extends PlaySpec with OneServerPerSuite {
"Server Status" should {
"work" in {
val response = await(WS.url(s"http://localhost:$port/status").get())
response.status mustBe OK
}
}
}
In this case everything looks fine and works :) the problem comes the controller which handles websockets:
@Singleton
class ChatController @Inject()(system: ActorSystem) extends Controller {
def socket() = WebSocket.tryAcceptWithActor[JsValue, JsValue] { implicit request =>
Future.successful(request.session.get("user") match {
case None => Left(Forbidden)
case Some(userId) => Right(TalkerSocket.props(userId))
})
}
}
I've looked for some manuals or tutorials for testing these things without luck. I've seen that it's possible to test this with Browser and Selenium ...
I want to open simulate two clients, open two websockets, send some messages from one of the clients and listen responses from another one. Do you think this approach is the correct one? Is it possible to do without browser?
Thanks
Aucun commentaire:
Enregistrer un commentaire