Add missing code snippets (#9228)
This commit is contained in:
+5
@@ -15,6 +15,11 @@ class PropertyBeanInjectionUnitTest {
|
||||
@Autowired
|
||||
private PropertyBeanInjection propertyBeanInjection;
|
||||
|
||||
@Test
|
||||
void checkThatJdbcPropertiesHaveTheCorrectValueFromPropertiesFile() {
|
||||
Assertions.assertEquals("jdbc:postgresql:/localhost:5432", propertyBeanInjection.getJdbcUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkThatCustomPropertiesHaveTheCorrectValueFromPropertiesFile() {
|
||||
Assertions.assertEquals("www.abc.test.com", propertyBeanInjection.getUrl());
|
||||
|
||||
+14
-2
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -13,13 +14,17 @@ import com.baeldung.properties.AdditionalProperties;
|
||||
import com.baeldung.properties.ConfigPropertiesDemoApplication;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ConfigPropertiesDemoApplication.class)
|
||||
@TestPropertySource("classpath:configprops-test.properties")
|
||||
@SpringBootTest(classes = {ConfigPropertiesDemoApplication.class, DatabaseConfigPropertiesApp.class})
|
||||
@TestPropertySource(locations = {"classpath:configprops-test.properties", "classpath:database-test.properties"})
|
||||
public class ConfigPropertiesIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private ConfigProperties properties;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dataSource")
|
||||
private Database databaseProperties;
|
||||
|
||||
@Autowired
|
||||
private AdditionalProperties additionalProperties;
|
||||
|
||||
@@ -53,4 +58,11 @@ public class ConfigPropertiesIntegrationTest {
|
||||
Assert.assertTrue(additionalProperties.getUnit().equals("km"));
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.properties.multiple;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import com.baeldung.properties.spring.PropertyPlaceholderConfig;
|
||||
import com.baeldung.properties.spring.PropertySourcesPlaceholderConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringJUnitConfig({PropertyPlaceholderConfig.class, PropertySourcesPlaceholderConfig.class})
|
||||
public class MultiplePlaceholdersJavaConfigIntegrationTest {
|
||||
|
||||
@Value("${key.something}")
|
||||
private String something;
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadInjectedValues_thenGetCorrectValues() {
|
||||
assertThat(something).isEqualTo("val");
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.properties.multiple;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@SpringJUnitConfig(locations = "classpath:configForPropertyPlaceholderBeans.xml")
|
||||
public class MultiplePlaceholdersXmlConfigIntegrationTest {
|
||||
|
||||
@Value("${foo}")
|
||||
private String something;
|
||||
|
||||
@Value("${key.something}")
|
||||
private String something2;
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReadInjectedValues_thenGetCorrectValues() {
|
||||
assertThat(something).isEqualTo("bar");
|
||||
assertThat(something2).isEqualTo("val");
|
||||
}
|
||||
}
|
||||
+3
@@ -13,9 +13,12 @@ public class MultiplePropertiesXmlConfigIntegrationTest {
|
||||
|
||||
@Value("${key.something2}") private String something2;
|
||||
|
||||
@Value("${jdbc.url}") private String jdbcUrl;
|
||||
|
||||
@Test
|
||||
public void whenReadInjectedValues_thenGetCorrectValues() {
|
||||
assertThat(something).isEqualTo("val");
|
||||
assertThat(something2).isEqualTo("val2");
|
||||
assertThat(jdbcUrl).isEqualTo("jdbc:postgresql:/localhost:5432");
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -10,6 +10,8 @@ import com.baeldung.properties.basic.PropertiesWithXmlIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithJavaIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithMultipleXmlsIntegrationTest;
|
||||
import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest;
|
||||
import com.baeldung.properties.multiple.MultiplePropertiesXmlConfigIntegrationTest;
|
||||
import com.baeldung.properties.multiple.MultiplePlaceholdersXmlConfigIntegrationTest;
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@SuiteClasses({ //@formatter:off
|
||||
@@ -17,8 +19,8 @@ import com.baeldung.properties.external.ExternalPropertiesWithXmlManualTest;
|
||||
ExternalPropertiesWithJavaIntegrationTest.class,
|
||||
ExternalPropertiesWithMultipleXmlsIntegrationTest.class,
|
||||
ExternalPropertiesWithXmlManualTest.class,
|
||||
ExtendedPropertiesWithJavaIntegrationTest.class,
|
||||
PropertiesWithMultipleXmlsIntegrationTest.class,
|
||||
ExtendedPropertiesWithJavaIntegrationTest.class, MultiplePropertiesXmlConfigIntegrationTest.class,
|
||||
PropertiesWithMultipleXmlsIntegrationTest.class, MultiplePlaceholdersXmlConfigIntegrationTest.class
|
||||
})// @formatter:on
|
||||
public final class IntegrationTestSuite {
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user