0

I just read a post discussing loading properties in a Junit

( Loading Properties File In JUnit @BeforeClass )

The properties load seems to work but I am not sure how to reference the specific property in my unit test ...any ideas - I am trying to load the value of the testinput entry in my properties file ?

============================================================ Property file users.properties content :

testinput=D/somefolder/somefile

public class OrderRouterTest2 extends CamelSpringTestSupport {

  @Override
    protected AbstractXmlApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("META-INF/spring/camel- context.xml");
    }

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        final Properties props = new Properties();
        final InputStream fileIn = OrderRouterTest2.class.getResourceAsStream("/**users.properties**");
        **props.load(fileIn)**;
    }

    @Test
    public void testSendToWebService() throws Exception { 

          // These don't work
          String value1 = context.resolvePropertyPlaceholders("{{testinput}}");
          String value2 = "I see ${testinput}";
          String value3 = "I see {{testinput}}";
}
Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59
R M
  • 133
  • 10

2 Answers2

1

You should use useOverridePropertiesWithPropertiesComponent from CamelTestSupport, see: https://camel.apache.org/camel-test.html

Luca Burgazzoli
  • 1,216
  • 7
  • 9
  • Also, use the file you may already have in your classpath: [Load Property File from Classpath](https://stackoverflow.com/a/16184488/922457) – Edenshaw Dec 28 '22 at 20:09
0

Ok ...I tried the obvious ...defining the Property object outside of the before class and that worked ...seems like there must another way though to reference that properties object that was loaded in the before class.

R M
  • 133
  • 10