Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typesafe Config: Load configuration from src/test/resources

This is a beginner question. So my app structure looks like

src/main/java/...
src/main/resources/application.conf

src/test/java/...
src/test/resources/module/test.module.conf

application.conf

location: mainLocation

test.module.conf

location: testLocation

In my test, I do

  @Test
  public void testLoadConfig() {
    final Config config = ConfigFactory.parseResources("test.module.conf");
    System.out.println(config);
  }

and what I see

Config(SimpleConfigObject({}))

Surely something is not right, but I can't spot it

UPDATE

When I do just

  @Test
  public void testActorForFailure() {
//    final Config config = ConfigFactory.load("test.module.conf");
    final Config config = ConfigFactory.load();
    System.out.println(config.getString("location"));

  }

I see

mainLocation

So overriding is not working, why?

like image 536
daydreamer Avatar asked Apr 29 '15 04:04

daydreamer


1 Answers

If you want to load that test config file try this:

ConfigFactory.load("modules/test.module")

The base ConfigFactory.load() method looks to load 'application.conf'. If you want it to load a different file you need to tell it what that different file is.

like image 118
cmbaxter Avatar answered Nov 12 '22 19:11

cmbaxter