BAEL-2719: Fixed the changes to load external file
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.properties;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringBootTest(classes = ExternalPropertyFileLoader.class)
|
||||
public class ExternalPropertyFileLoaderIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
ConfProperties props;
|
||||
|
||||
@Test
|
||||
public void whenExternalisedPropertiesLoaded_thenReadValues() throws IOException {
|
||||
assertEquals("jdbc:postgresql://localhost:5432/", props.getUrl());
|
||||
assertEquals("admin", props.getUsername());
|
||||
assertEquals("root", props.getPassword());
|
||||
}
|
||||
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.properties;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class ExternalPropertyFileLoaderUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenExternalisedPropertiesLoaded_thenReadValues() {
|
||||
ConfigurableApplicationContext applicationContext = new SpringApplicationBuilder(ExternalPropertyFileLoader.class).properties("spring.config.name:conf", "spring.config.location:file:src/main/resources/external/")
|
||||
.build()
|
||||
.run();
|
||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
||||
Assert.assertEquals(environment.getProperty("url"), "jdbc:postgresql://localhost:5432/");
|
||||
Assert.assertEquals(environment.getProperty("username"), "admin");
|
||||
Assert.assertEquals(environment.getProperty("password"), "root");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
url=jdbc:postgresql://localhost:5432/
|
||||
username=admin
|
||||
password=root
|
||||
Reference in New Issue
Block a user