Reputation: 9144
I have a Play 2.3 project with a sub-project inside. Following this tutorial, I am writing a test for sub-project's controller with route
method:
"Get Action" in new WithApplication {
val Some(result) = route(FakeRequest(GET, "/sub/bob/11"))
status(result) mustEqual OK
}
Assumed in routes.conf, the sub-project routes is configured like this:
-> /sub sub.Routes
And in sub.Routes, it contains:
GET /bob/:id controllers.sub.BobController.get(id: Int)
However the route()
method always returns None
. Using route(FakeRequest(GET, "/bob/11"))
doesn't work too.
Currently I can only solve the problem by direct call to the Controller's method:
val result = BobController.get(11)(FakeRequest(GET, "/bob/11"))
In this case, the "11" parameter in the "/bob/11" become useless as it's unused.
So anyone know how to make the route() works for sub-project?
Upvotes: 0
Views: 145
Reputation: 410
Try setting application.router of FakeApplication to submodule's route file.
For example:
class SubModuleRouteSpec extends PlaySpecification with After {
lazy val app = FakeApplication(additionalConfiguration = Map("application.router" -> "sub.Routes"))
"SubModule route" should {
"Get Action" in new WithApplication(app) {
val result = route(FakeRequest(GET, "/bob/11")).get
println(contentAsString(result))
result must not beNull
}
}
override def after: Any = Play.stop()
}
Upvotes: 1