BAEL 3234 - Add missing code snippets (#9285)
This commit is contained in:
+2
-12
@@ -14,17 +14,13 @@ import com.baeldung.properties.AdditionalProperties;
|
||||
import com.baeldung.properties.ConfigPropertiesDemoApplication;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {ConfigPropertiesDemoApplication.class, DatabaseConfigPropertiesApp.class})
|
||||
@TestPropertySource(locations = {"classpath:configprops-test.properties", "classpath:database-test.properties"})
|
||||
@SpringBootTest(classes = {ConfigPropertiesDemoApplication.class})
|
||||
@TestPropertySource(locations = {"classpath:configprops-test.properties"})
|
||||
public class ConfigPropertiesIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ConfigProperties properties;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dataSource")
|
||||
private Database databaseProperties;
|
||||
|
||||
@Autowired
|
||||
private AdditionalProperties additionalProperties;
|
||||
|
||||
@@ -59,10 +55,4 @@ public class ConfigPropertiesIntegrationTest {
|
||||
Assert.assertTrue(additionalProperties.getMax() == 100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDatabasePropertyQueriedthenReturnsProperty() {
|
||||
Assert.assertTrue(databaseProperties.getUrl().equals("jdbc:postgresql:/localhost:5432"));
|
||||
Assert.assertTrue(databaseProperties.getUsername().equals("foo"));
|
||||
Assert.assertTrue(databaseProperties.getPassword().equals("bar"));
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -4,26 +4,28 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.properties.ConfigPropertiesDemoApplication;
|
||||
import com.baeldung.properties.Database;
|
||||
import com.baeldung.configurationproperties.Database;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConfigPropertiesDemoApplication.class)
|
||||
@TestPropertySource("classpath:application.properties")
|
||||
@SpringBootTest(classes = DatabaseConfigPropertiesApp.class)
|
||||
@TestPropertySource("classpath:database-test.properties")
|
||||
public class DatabasePropertiesIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dataSource")
|
||||
private Database database;
|
||||
|
||||
@Test
|
||||
public void testDatabaseProperties() {
|
||||
Assert.assertNotNull(database);
|
||||
Assert.assertEquals("jdbc:postgresql:/localhost:5432/instance", database.getUrl());
|
||||
Assert.assertEquals("jdbc:postgresql:/localhost:5432", database.getUrl());
|
||||
Assert.assertEquals("foo", database.getUsername());
|
||||
Assert.assertEquals("bar", database.getPassword());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user