Skip to content

Commit a45c572

Browse files
author
eugenp
committed
new spring properties tests - for external properties
1 parent cab8e4d commit a45c572

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ComponentInXmlUsingProperties implements InitializingBean {
1616
public ComponentInXmlUsingProperties(final String propertyValue) {
1717
super();
1818

19-
System.out.println("Constructor Injection - Property Value resolted to: " + propertyValue);
19+
System.out.println("Constructor Injection - Property Value resolved to: " + propertyValue);
2020
}
2121

2222
//
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.baeldung.properties.core;
2+
3+
import org.baeldung.properties.spring.PropertiesWithJavaConfig;
4+
import org.baeldung.properties.spring.PropertiesWithJavaConfigOther;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.core.env.Environment;
10+
import org.springframework.test.context.ContextConfiguration;
11+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
13+
14+
@RunWith(SpringJUnit4ClassRunner.class)
15+
@ContextConfiguration(classes = { PropertiesWithJavaConfig.class, PropertiesWithJavaConfigOther.class }, loader = AnnotationConfigContextLoader.class)
16+
public class ExternalPropertiesWithJavaIntegrationTest {
17+
18+
@Autowired
19+
private Environment env;
20+
21+
@Value("${key.something}")
22+
private String injectedProperty;
23+
24+
@Value("${external.something}")
25+
private String injectedExternalProperty;
26+
27+
@Test
28+
public final void givenContextIsInitialized_thenNoException() {
29+
System.out.println("in test via @Value: " + injectedProperty);
30+
System.out.println("in test Environment: " + env.getProperty("key.something"));
31+
32+
System.out.println("in test via @Value - external: " + injectedExternalProperty);
33+
System.out.println("in test Environment - external: " + env.getProperty("external.something"));
34+
}
35+
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package org.baeldung.properties.core;
2+
3+
import org.baeldung.properties.spring.PropertiesWithXmlConfigOne;
4+
import org.baeldung.properties.spring.PropertiesWithXmlConfigTwo;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.core.env.Environment;
10+
import org.springframework.test.context.ContextConfiguration;
11+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
13+
14+
@RunWith(SpringJUnit4ClassRunner.class)
15+
@ContextConfiguration(classes = { PropertiesWithXmlConfigOne.class, PropertiesWithXmlConfigTwo.class }, loader = AnnotationConfigContextLoader.class)
16+
public class ExternalPropertiesWithMultipleXmlsIntegrationTest {
17+
18+
@Autowired
19+
private Environment env;
20+
21+
@Value("${key.something}")
22+
private String injectedProperty;
23+
24+
@Value("${external.something}")
25+
private String injectedExternalProperty;
26+
27+
@Test
28+
public final void givenContextIsInitialized_thenNoException() {
29+
System.out.println("in test via @Value: " + injectedProperty);
30+
System.out.println("in test Environment: " + env.getProperty("key.something"));
31+
32+
System.out.println("in test via @Value - external: " + injectedExternalProperty);
33+
System.out.println("in test Environment - external: " + env.getProperty("external.something"));
34+
}
35+
36+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.baeldung.properties.core;
2+
3+
import org.baeldung.properties.spring.PropertiesWithXmlConfig;
4+
import org.junit.Test;
5+
import org.junit.runner.RunWith;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.core.env.Environment;
9+
import org.springframework.test.context.ContextConfiguration;
10+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11+
import org.springframework.test.context.support.AnnotationConfigContextLoader;
12+
13+
@RunWith(SpringJUnit4ClassRunner.class)
14+
@ContextConfiguration(classes = { PropertiesWithXmlConfig.class }, loader = AnnotationConfigContextLoader.class)
15+
public class ExternalPropertiesWithXmlIntegrationTest {
16+
17+
@Autowired
18+
private Environment env;
19+
20+
@Value("${key.something}")
21+
private String injectedProperty;
22+
23+
@Value("${external.something}")
24+
private String injectedExternalProperty;
25+
26+
@Test
27+
public final void givenContextIsInitialized_thenNoException() {
28+
System.out.println("in test via @Value: " + injectedProperty);
29+
System.out.println("in test Environment: " + env.getProperty("key.something"));
30+
31+
System.out.println("in test via @Value - external: " + injectedExternalProperty);
32+
System.out.println("in test Environment - external: " + env.getProperty("external.something"));
33+
}
34+
35+
}

0 commit comments

Comments
 (0)