I'm trying to add a test on a Play 2.0 w/Scala project:
"Application" should {
"return 404 on the index Action if web is disabled " in {
running(FakeApplication(additionalConfiguration = Map(("enable.webInterface" -> "false")) )) {
Config.IS_WEB_ENABLED must beFalse
val result = controllers.Application.index()(FakeRequest())
status(result) must equalTo(NOT_FOUND)
contentType(result) must beSome("text/html")
charset(result) must beSome("utf-8")
}
}
}
The value Config.IS_WEB_ENABLED
is defined as:
object Config {
lazy val IS_WEB_ENABLED = Play.configuration.getBoolean("enable.webInterface").getOrElse(false)
}
As you can see the test I try to override the configuration setting for enable.webInterface
to false as the application.conf
file has it set to true by default. But FakeApplication is not getting the new configuration value.
Any idea about what I'm missing there?
Use def
instead of lazy val
, maybe you used Config.IS_WEB_ENABLED before and it was initialized with true and returns only the same result because it's a val.
object Config {
def IS_WEB_ENABLED = Play.configuration.getBoolean("enable.webInterface").getOrElse(false)
}