CalculatingKraken
CalculatingKraken

Reputation: 781

Setting DATABASE_URL as an environmental variable using Play Framework 2.5.X on Eclipse

I am using PlayFramework 2.5.X

In my Application.conf file I have :

#local DB
db.default.driver=com.mysql.jdbc.Driver
db.default.url=${?DATABASE_URL}

I am also using eclipse. I am trying to edit the DATABASE_URL variable so I can test against my own db. I know I go to Run > Run configurations > [From here Set Environmental Variables]

But which tab should I be looking at, Eclipse Configurations or Java Application

Upvotes: 0

Views: 704

Answers (1)

asch
asch

Reputation: 1963

Play allows to use different configuration file for tests. In the test configuration file you can assign different value for any property, existing in application.conf. So, in tests configuration you can set different DB properties.

  1. Create file test.conf under the conf folder (any other name/location is OK).
  2. Put the test configuration file name into build.sbt: javaOptions in Test += "-Dconfig.file=conf/test.conf"
  3. Add content into the test.conf.

When you run sbt test, the sbt will take configuration file for tests. If ytou are running tests from eclipse, add to the test run configuration VM argument -Dconfig.file=conf/test.conf

Example of test.conf below inherits all the properties, which are defined in the application.conf. It redefines the default db connection properties: h2 db instead of mySql, defined in the application.conf.

    include "application.conf"
    db.default.driver=org.h2.Driver
    db.default.url="jdbc:h2:mem:play"
    db.default.jndiName=DefaultDS
    jpa.default=testPersistenceUnit

Upvotes: 2

Related Questions