System property substitution in application.conf in test case

952 views
Skip to first unread message

Nils Weinander

unread,
Sep 18, 2013, 4:15:48 AM9/18/13
to play-fr...@googlegroups.com
Next test case question. In our application.conf we refer to a system property:


entitymachine
.baseDir=${se.altrusoft.entitymachine.path}


which works fine in both development and production mode with -Dse.altrusoft.entitymachine.path=... in the program start. When I try to run a test case from the Play console


$ test
-only test.api.ApiTest


the substitution doesn't work


10:03:46.622 [main] WARN  play - No application found at invoker init
[error] Test test.api.ApiTest.testApiList failed: java.lang.ExceptionInInitializerError: null
[error]     at play.libs.F$Promise.<clinit>(F.java:375)
[error]     at play.core.j.JavaAction$class.apply(JavaAction.scala:78)
[error]     at play.core.Router$HandlerInvoker$$anon$6$$anon$2.apply(Router.scala:185)
[error]     at play.test.Helpers.invokeHandler(Helpers.java:41)
[error]     at play.test.Helpers.callAction(Helpers.java:72)
[error]     at play.test.Helpers.callAction(Helpers.java:64)
[error]     at test.api.ApiTest.testApiList(ApiTest.java:23)
[error]     ...
[error] Caused by: com.typesafe.config.ConfigException$UnresolvedSubstitution: application.conf: 72: Could not resolve substitution to a value: ${se.altrusoft.entitymachine.path}
 

So, what can I do to get the system property recognized in test cases too?


Johan Andren

unread,
Sep 18, 2013, 12:43:12 PM9/18/13
to play-fr...@googlegroups.com
That is because the tests are run in a forked JVM, so it is not the same java process as the one you started with the play command.

You could set system properties for the forked test JVM with configuration in the build file as described in the sbt docs http://www.scala-sbt.org/release/docs/Detailed-Topics/Forking.html

I guess that will not solve your problem though, so I would take a look at using environment variables for substitution instead as they are inherited to child processes so the forked jvm should get those as well. The syntax in the config file is the same I think.

Nils Weinander

unread,
Sep 19, 2013, 4:41:56 AM9/19/13
to play-fr...@googlegroups.com
I see. I tried this in the build file:

javaOptions in test += "-Dse.altrusoft.entitymachine.path=" + System.getProperty("se.altrusoft.entitymachine.path")

but it did not work. Using an environment variable seems to work (I run into other problems, but that's another issue). Thanks!

Nils Weinander

unread,
Sep 23, 2013, 5:30:56 AM9/23/13
to play-fr...@googlegroups.com
Sigh, turns out using an environment variable doesn't go all the way, as we also set -Dconfig.file, which I need to pass on to the tests. I tried using

javaOptions in test += ...

but that doesn't seem to have any effect at all. So, any ideas what I am doing wrong? I have also tried passing -Xmx32G to get an error, but it seems that doesn't get passed on to test either.

Nils Weinander

unread,
Sep 24, 2013, 7:38:02 AM9/24/13
to play-fr...@googlegroups.com
OK, finally got it working (and got rid of the environment variable). With an extra ".settings()"

.settings(
  javaOptions
in test ++= Seq("-Dse.altrusoft.entitymachine.path=" + configPath, ...)
)

SBT is rather opaque...

Johan Andren

unread,
Sep 24, 2013, 9:42:37 AM9/24/13
to play-fr...@googlegroups.com
Out of curiosity, what do you mean with "an extra .settings()"? 

It did not work when you put it in Project().settings(..here...) but Project().settings().settings(...here...)?
Reply all
Reply to author
Forward
0 new messages