[SPR-8387] Fixed logic error in DelegatingSmartContextLoader.processContextConfiguration().
This commit is contained in:
parent
b8624b470c
commit
e34fa6abb1
|
@ -64,7 +64,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
|
||||||
*/
|
*/
|
||||||
public void processContextConfiguration(ContextConfigurationAttributes configAttributes) {
|
public void processContextConfiguration(ContextConfigurationAttributes configAttributes) {
|
||||||
|
|
||||||
final boolean hasResources = configAttributes.hasResources();
|
final boolean originallyHadResources = configAttributes.hasResources();
|
||||||
|
|
||||||
for (SmartContextLoader loader : candidates) {
|
for (SmartContextLoader loader : candidates) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
@ -75,7 +75,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
|
||||||
// If the original locations and classes were not empty, there's no
|
// If the original locations and classes were not empty, there's no
|
||||||
// need to bother with default generation checks; just let each
|
// need to bother with default generation checks; just let each
|
||||||
// loader process the configuration.
|
// loader process the configuration.
|
||||||
if (hasResources) {
|
if (originallyHadResources) {
|
||||||
loader.processContextConfiguration(configAttributes);
|
loader.processContextConfiguration(configAttributes);
|
||||||
}
|
}
|
||||||
// Otherwise, if the loader claims to generate defaults, let it
|
// Otherwise, if the loader claims to generate defaults, let it
|
||||||
|
@ -91,7 +91,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
|
||||||
|
|
||||||
// If any loader claims to generate defaults but none actually did,
|
// If any loader claims to generate defaults but none actually did,
|
||||||
// throw an exception.
|
// throw an exception.
|
||||||
if (generatesDefaults() && !configAttributes.hasResources()) {
|
if (originallyHadResources && generatesDefaults() && !configAttributes.hasResources()) {
|
||||||
throw new IllegalStateException(String.format("None of the SmartContextLoader candidates %s "
|
throw new IllegalStateException(String.format("None of the SmartContextLoader candidates %s "
|
||||||
+ "was able to generate defaults for context configuration [%s].", candidates, configAttributes));
|
+ "was able to generate defaults for context configuration [%s].", candidates, configAttributes));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2006 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,49 +13,31 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.test.context.expression;
|
package org.springframework.test.context.expression;
|
||||||
|
|
||||||
import static junit.framework.Assert.*;
|
import static junit.framework.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
*/
|
*/
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests {
|
public class ExpressionUsageTests {
|
||||||
|
|
||||||
@Test
|
@Autowired
|
||||||
public void testSpr5906() throws Exception {
|
@Qualifier("derived")
|
||||||
Properties props = (Properties)applicationContext.getBean("derived");
|
private Properties props;
|
||||||
|
|
||||||
// verify the property values have been evaluated as expressions
|
|
||||||
assertEquals("Dave",props.getProperty("user.name"));
|
|
||||||
assertEquals("Andy",props.getProperty("username"));
|
|
||||||
|
|
||||||
// verify the property keys have been evaluated as expressions
|
|
||||||
assertEquals("exists",props.getProperty("Dave"));
|
|
||||||
assertEquals("exists also",props.getProperty("Andy"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Foo {
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("andy2")
|
@Qualifier("andy2")
|
||||||
|
@ -65,10 +47,37 @@ public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests {
|
||||||
@Qualifier("andy")
|
@Qualifier("andy")
|
||||||
private Foo andy;
|
private Foo andy;
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSpr5906() throws Exception {
|
||||||
|
// verify the property values have been evaluated as expressions
|
||||||
|
assertEquals("Dave", props.getProperty("user.name"));
|
||||||
|
assertEquals("Andy", props.getProperty("username"));
|
||||||
|
|
||||||
|
// verify the property keys have been evaluated as expressions
|
||||||
|
assertEquals("exists", props.getProperty("Dave"));
|
||||||
|
assertEquals("exists also", props.getProperty("Andy"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSpr5847() throws Exception {
|
public void testSpr5847() throws Exception {
|
||||||
assertEquals("Andy", andy2.getName());
|
assertEquals("Andy", andy2.getName());
|
||||||
assertEquals("Andy", andy.getName());
|
assertEquals("Andy", andy.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
public static class Foo {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
<logger name="org.springframework.test.context.support.AnnotationConfigContextLoader">
|
<logger name="org.springframework.test.context.support.AnnotationConfigContextLoader">
|
||||||
<level value="warn" />
|
<level value="warn" />
|
||||||
</logger>
|
</logger>
|
||||||
|
<logger name="org.springframework.test.context.support">
|
||||||
|
<level value="warn" />
|
||||||
|
</logger>
|
||||||
|
|
||||||
<!-- Root Logger -->
|
<!-- Root Logger -->
|
||||||
<root>
|
<root>
|
||||||
|
|
Loading…
Reference in New Issue