0

I recently updated to ActiveJDBC 2.1 in order to use activejdbc.properties for the purpose of externalizing out the database property so we didn't have to check in the database username/password into SVN.

Putting the "activejdbc.property" file in src/main/resources for the main code works perfect. Now the goal is to replace the "database.property" file in the test directory src/test/resources with an "activejdbc.property" so it can point to the same database config file out on the file system.

After making this change in the test directory, we receive an error when performing the gradle build (gradle clean build). This is the exception we see:

`"org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)"

Any ideas why this works for main directory but not for the tests?

Stacktrace: es/main/com/brookdale/model/UnitOfMeasure.class **************************** END INSTRUMENTATION **************************** ... :assemble :compileTestJava :processTestResources :testClasses :test

      com.brookdale.model.ActualChargeTest > unitQuantityMustBeGreaterThanZero FAILED
        org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)
        Caused by:
        java.io.FileNotFoundException: \database.properties (The system cannot find the file specified)
       ... more tests ...
      com.brookdale.service.RelationshipServiceTest > updateContactRel_GivenValidInfo_
       RecordIsInserted FAILED
        org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \datab
    ase.properties (The system cannot find the file specified)
        Caused by:
        java.io.FileNotFoundException: \database.properties (The system cannot f
       ind the file specified)
       49 tests completed, 25 failed, 7 skipped
       :test FAILED
       FAILURE: Build failed with an exception.
       * What went wrong:
       Execution failed for task ':test'.
       BUILD FAILED`
Jeff Moreau
  • 29
  • 1
  • 7

1 Answers1

0

It seems you did not name the file correctly: the name of the file is not activejdbc.property, it is activejdbc.properties.

Additionally, Java class loaders do not guarantee which file they will load first if it finds multiples on the classpath. If you want different JDBC properties in your test environment, please follow docs here: http://javalite.io/database_connection_management#multiple-environments-property-file-method

Here is a sample project with this implementation: https://github.com/javalite/simple-example/

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • Sorry, that was a typo in my description. I do have the name as "activejdbc.properties". Also, I actually prefer to use only one reference to the JDBC database property. So I tried to remove the one from /src/test/resources so it picks up the one from /src/main/resources but I get the same stacktrace – Jeff Moreau Mar 01 '18 at 21:23
  • Have you had a chance to look at the example I provided? – ipolevoy Mar 01 '18 at 21:31
  • I removed the activejdbc.properties from src/test/resources. Now I only have one activejdbc.properties in src/main/resources. I get the same error: org.javalite.activejdbc.InitException: java.io.FileNotFoundException: \datab ase.properties (The system cannot find the file specified) Caused by: java.io.FileNotFoundException: \database.properties (The system cannot f ind the file specified) – Jeff Moreau Mar 01 '18 at 21:31
  • Looking at example now. – Jeff Moreau Mar 01 '18 at 21:32
  • I reviewed but this is if I needed multiple environments. Basically what I'm getting at is I would like to connect to the same database regardless if it's the main code or test classes. I need it externalized, so I need to use activejdbc.properties. When I try to build with tests it fails on the tests because it can't find the database property that I specified in the activejdbc.properties file. If I run without tests, then I can build and it works fine when I deployed. But because we want to use tests, I need to figure out why it fails. – Jeff Moreau Mar 01 '18 at 21:37
  • @JeffMoreau, this bug was fixed: https://github.com/javalite/activejdbc/issues/681. You can find a doc here: http://javalite.io/database_connection_management#using-system-property – ipolevoy Mar 07 '18 at 18:16