new spring properties tests - for external properties

This commit is contained in:
eugenp 2014-03-16 12:59:09 +02:00
parent cab8e4d830
commit a45c572d4b
4 changed files with 108 additions and 1 deletions

View File

@ -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);
}
//

View File

@ -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"));
}
}

View File

@ -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"));
}
}

View File

@ -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"));
}
}