Browse Source

[SPR-8387] Fixed logic error in DelegatingSmartContextLoader.processContextConfiguration().

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4709 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/merge
Sam Brannen 15 years ago
parent
commit
d123102495
  1. 6
      org.springframework.test/src/main/java/org/springframework/test/context/support/DelegatingSmartContextLoader.java
  2. 65
      org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java
  3. 3
      org.springframework.test/src/test/resources/log4j.xml

6
org.springframework.test/src/main/java/org/springframework/test/context/support/DelegatingSmartContextLoader.java

@ -64,7 +64,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { @@ -64,7 +64,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
*/
public void processContextConfiguration(ContextConfigurationAttributes configAttributes) {
final boolean hasResources = configAttributes.hasResources();
final boolean originallyHadResources = configAttributes.hasResources();
for (SmartContextLoader loader : candidates) {
if (logger.isDebugEnabled()) {
@ -75,7 +75,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { @@ -75,7 +75,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
// If the original locations and classes were not empty, there's no
// need to bother with default generation checks; just let each
// loader process the configuration.
if (hasResources) {
if (originallyHadResources) {
loader.processContextConfiguration(configAttributes);
}
// Otherwise, if the loader claims to generate defaults, let it
@ -91,7 +91,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader { @@ -91,7 +91,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
// If any loader claims to generate defaults but none actually did,
// throw an exception.
if (generatesDefaults() && !configAttributes.hasResources()) {
if (originallyHadResources && generatesDefaults() && !configAttributes.hasResources()) {
throw new IllegalStateException(String.format("None of the SmartContextLoader candidates %s "
+ "was able to generate defaults for context configuration [%s].", candidates, configAttributes));
}

65
org.springframework.test/src/test/java/org/springframework/test/context/expression/ExpressionUsageTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -13,40 +13,64 @@ @@ -13,40 +13,64 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.context.expression;
import static junit.framework.Assert.*;
import static junit.framework.Assert.assertEquals;
import java.util.Properties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Andy Clement
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests {
public class ExpressionUsageTests {
@Autowired
@Qualifier("derived")
private Properties props;
@Autowired
@Qualifier("andy2")
private Foo andy2;
@Autowired
@Qualifier("andy")
private Foo andy;
@Test
public void testSpr5906() throws Exception {
Properties props = (Properties)applicationContext.getBean("derived");
// verify the property values have been evaluated as expressions
assertEquals("Dave",props.getProperty("user.name"));
assertEquals("Andy",props.getProperty("username"));
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"));
assertEquals("exists", props.getProperty("Dave"));
assertEquals("exists also", props.getProperty("Andy"));
}
@Test
public void testSpr5847() throws Exception {
assertEquals("Andy", andy2.getName());
assertEquals("Andy", andy.getName());
}
public static class Foo {
private String name;
public String getName() {
return name;
}
@ -54,21 +78,6 @@ public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests { @@ -54,21 +78,6 @@ public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests {
public void setName(String name) {
this.name = name;
}
}
@Autowired
@Qualifier("andy2")
private Foo andy2;
@Autowired
@Qualifier("andy")
private Foo andy;
@Test
public void testSpr5847() throws Exception {
assertEquals("Andy", andy2.getName());
assertEquals("Andy", andy.getName());
}
}
}

3
org.springframework.test/src/test/resources/log4j.xml

@ -27,6 +27,9 @@ @@ -27,6 +27,9 @@
<logger name="org.springframework.test.context.support.AnnotationConfigContextLoader">
<level value="warn" />
</logger>
<logger name="org.springframework.test.context.support">
<level value="warn" />
</logger>
<!-- Root Logger -->
<root>

Loading…
Cancel
Save