0

After reading a value from application.conf, I'd like to create a java.io.File with that path.

val filePath= ConfigFactory.load().getString("filePath")
val file = application.getExistingFile(filePath).get

When running tests that run the above code, I get the following run-time error on the second line.

java.lang.RuntimeException: There is no started application

How can I retrieve a file in Play with a relative path both during application run-time & testing?

1 Answer 1

1

You will need to run it inside a FakeApplication to be able to do stuff that depend on having a running app. See the docs for more details: http://www.playframework.com/documentation/2.2.x/ScalaFunctionalTest

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks. Do I need to specify which application.conf will be used by the FakeApplication?
It will use the default application.conf, you can make it use another one or just provide specific settings through the constructor parameters of FakeApplication
If I read this answer correctly, then he says it's not possible to point to another application.conf - stackoverflow.com/a/14116805/409976
Yeah, I jumped to conclusions about the path argument, you could probably subclass FakeApplication and override Application.configuration to provide a totally separate config though.
is it legitimate to use a fakeApplication if the application cannot be resolved? In other words, if application can't be read, then play is definitely not running? It seems hacky for me to put a fakeApplication in my non-test code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.