From a45c572d4b5a75d91383815368a2c6817c693406 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 16 Mar 2014 12:59:09 +0200 Subject: [PATCH] new spring properties tests - for external properties --- .../core/ComponentInXmlUsingProperties.java | 2 +- ...rnalPropertiesWithJavaIntegrationTest.java | 36 +++++++++++++++++++ ...ertiesWithMultipleXmlsIntegrationTest.java | 36 +++++++++++++++++++ ...ernalPropertiesWithXmlIntegrationTest.java | 35 ++++++++++++++++++ 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithJavaIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithMultipleXmlsIntegrationTest.java create mode 100644 spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithXmlIntegrationTest.java diff --git a/spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java b/spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java index f695326cd6..dbdcebcb36 100644 --- a/spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java +++ b/spring-all/src/main/java/org/baeldung/properties/core/ComponentInXmlUsingProperties.java @@ -16,7 +16,7 @@ public class ComponentInXmlUsingProperties implements InitializingBean { public ComponentInXmlUsingProperties(final String propertyValue) { super(); - System.out.println("Constructor Injection - Property Value resolted to: " + propertyValue); + System.out.println("Constructor Injection - Property Value resolved to: " + propertyValue); } // diff --git a/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithJavaIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithJavaIntegrationTest.java new file mode 100644 index 0000000000..bfc2f52579 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithJavaIntegrationTest.java @@ -0,0 +1,36 @@ +package org.baeldung.properties.core; + +import org.baeldung.properties.spring.PropertiesWithJavaConfig; +import org.baeldung.properties.spring.PropertiesWithJavaConfigOther; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PropertiesWithJavaConfig.class, PropertiesWithJavaConfigOther.class }, loader = AnnotationConfigContextLoader.class) +public class ExternalPropertiesWithJavaIntegrationTest { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + @Value("${external.something}") + private String injectedExternalProperty; + + @Test + public final void givenContextIsInitialized_thenNoException() { + System.out.println("in test via @Value: " + injectedProperty); + System.out.println("in test Environment: " + env.getProperty("key.something")); + + System.out.println("in test via @Value - external: " + injectedExternalProperty); + System.out.println("in test Environment - external: " + env.getProperty("external.something")); + } + +} diff --git a/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithMultipleXmlsIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithMultipleXmlsIntegrationTest.java new file mode 100644 index 0000000000..6391b8d655 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithMultipleXmlsIntegrationTest.java @@ -0,0 +1,36 @@ +package org.baeldung.properties.core; + +import org.baeldung.properties.spring.PropertiesWithXmlConfigOne; +import org.baeldung.properties.spring.PropertiesWithXmlConfigTwo; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PropertiesWithXmlConfigOne.class, PropertiesWithXmlConfigTwo.class }, loader = AnnotationConfigContextLoader.class) +public class ExternalPropertiesWithMultipleXmlsIntegrationTest { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + @Value("${external.something}") + private String injectedExternalProperty; + + @Test + public final void givenContextIsInitialized_thenNoException() { + System.out.println("in test via @Value: " + injectedProperty); + System.out.println("in test Environment: " + env.getProperty("key.something")); + + System.out.println("in test via @Value - external: " + injectedExternalProperty); + System.out.println("in test Environment - external: " + env.getProperty("external.something")); + } + +} diff --git a/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithXmlIntegrationTest.java b/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithXmlIntegrationTest.java new file mode 100644 index 0000000000..0d437842e6 --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/properties/core/ExternalPropertiesWithXmlIntegrationTest.java @@ -0,0 +1,35 @@ +package org.baeldung.properties.core; + +import org.baeldung.properties.spring.PropertiesWithXmlConfig; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PropertiesWithXmlConfig.class }, loader = AnnotationConfigContextLoader.class) +public class ExternalPropertiesWithXmlIntegrationTest { + + @Autowired + private Environment env; + + @Value("${key.something}") + private String injectedProperty; + + @Value("${external.something}") + private String injectedExternalProperty; + + @Test + public final void givenContextIsInitialized_thenNoException() { + System.out.println("in test via @Value: " + injectedProperty); + System.out.println("in test Environment: " + env.getProperty("key.something")); + + System.out.println("in test via @Value - external: " + injectedExternalProperty); + System.out.println("in test Environment - external: " + env.getProperty("external.something")); + } + +}