Introduce log4j 2 for Spring's test suite
This commit adds a test runtime dependency on log4j 2 for every project and migrates all log4j.properties files to log4j2-test.xml files. Issue: SPR-14431
This commit is contained in:
@@ -53,6 +53,7 @@ import static org.junit.Assert.*;
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class AutowiredConfigurationTests {
|
||||
|
||||
@@ -203,20 +204,23 @@ public class AutowiredConfigurationTests {
|
||||
|
||||
TestBean testBean = context.getBean("testBean", TestBean.class);
|
||||
assertThat(testBean.getName(), equalTo("localhost"));
|
||||
assertThat(testBean.getAge(), equalTo((int) new ClassPathResource("log4j.properties").contentLength()));
|
||||
assertThat(testBean.getAge(), equalTo(contentLength()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPropertiesWithGenericContext() throws IOException {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
// context.setResourceLoader(new FileSystemResourceLoader());
|
||||
new XmlBeanDefinitionReader(context).loadBeanDefinitions(
|
||||
new ClassPathResource("AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class));
|
||||
context.refresh();
|
||||
|
||||
TestBean testBean = context.getBean("testBean", TestBean.class);
|
||||
assertThat(testBean.getName(), equalTo("localhost"));
|
||||
assertThat(testBean.getAge(), equalTo((int) new ClassPathResource("log4j.properties").contentLength()));
|
||||
assertThat(testBean.getAge(), equalTo(contentLength()));
|
||||
}
|
||||
|
||||
private int contentLength() throws IOException {
|
||||
return (int) new ClassPathResource("do_not_delete_me.txt").contentLength();
|
||||
}
|
||||
|
||||
|
||||
@@ -477,7 +481,7 @@ public class AutowiredConfigurationTests {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
@Value("log4j.properties")
|
||||
@Value("do_not_delete_me.txt")
|
||||
public void setResource(Resource resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import java.util.Properties;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
@@ -61,6 +62,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ApplicationContextExpressionTests {
|
||||
@@ -326,11 +328,10 @@ public class ApplicationContextExpressionTests {
|
||||
|
||||
@Test
|
||||
public void resourceInjection() throws IOException {
|
||||
System.setProperty("logfile", "log4j.properties");
|
||||
try {
|
||||
AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ResourceInjectionBean.class);
|
||||
System.setProperty("logfile", "do_not_delete_me.txt");
|
||||
try (AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(ResourceInjectionBean.class)) {
|
||||
ResourceInjectionBean resourceInjectionBean = ac.getBean(ResourceInjectionBean.class);
|
||||
Resource resource = new ClassPathResource("log4j.properties");
|
||||
Resource resource = new ClassPathResource("do_not_delete_me.txt");
|
||||
assertEquals(resource, resourceInjectionBean.resource);
|
||||
assertEquals(resource.getURL(), resourceInjectionBean.url);
|
||||
assertEquals(resource.getURI(), resourceInjectionBean.uri);
|
||||
|
||||
Reference in New Issue
Block a user