|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2014 the original author or authors. |
|
|
|
|
* Copyright 2002-2015 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. |
|
|
|
|
@ -20,6 +20,7 @@ import java.util.Collections;
@@ -20,6 +20,7 @@ import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
import org.aspectj.lang.annotation.Aspect; |
|
|
|
|
import org.aspectj.lang.annotation.Before; |
|
|
|
|
|
|
|
|
|
import org.junit.Ignore; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
|
|
|
|
|
@ -28,7 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired;
@@ -28,7 +29,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; |
|
|
|
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; |
|
|
|
|
import org.springframework.context.ApplicationContext; |
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
|
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
|
@ -45,6 +45,7 @@ import static org.junit.Assert.*;
@@ -45,6 +45,7 @@ import static org.junit.Assert.*;
|
|
|
|
|
* |
|
|
|
|
* @author Chris Beams |
|
|
|
|
* @author Juergen Hoeller |
|
|
|
|
* @author Sam Brannen |
|
|
|
|
*/ |
|
|
|
|
public class ImportResourceTests { |
|
|
|
|
|
|
|
|
|
@ -55,6 +56,7 @@ public class ImportResourceTests {
@@ -55,6 +56,7 @@ public class ImportResourceTests {
|
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class); |
|
|
|
|
assertEquals("myName", tb.getName()); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Ignore // TODO: SPR-6310
|
|
|
|
|
@ -65,19 +67,23 @@ public class ImportResourceTests {
@@ -65,19 +67,23 @@ public class ImportResourceTests {
|
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class); |
|
|
|
|
assertEquals("myName", tb.getName()); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Ignore // TODO: SPR-6310
|
|
|
|
|
@Test |
|
|
|
|
public void testImportXmlByConvention() { |
|
|
|
|
ApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlByConventionConfig.class); |
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext( |
|
|
|
|
ImportXmlByConventionConfig.class); |
|
|
|
|
assertTrue("context does not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testImportXmlIsInheritedFromSuperclassDeclarations() { |
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class); |
|
|
|
|
assertTrue(ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -85,6 +91,7 @@ public class ImportResourceTests {
@@ -85,6 +91,7 @@ public class ImportResourceTests {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class); |
|
|
|
|
assertTrue("failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean")); |
|
|
|
|
assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -92,6 +99,7 @@ public class ImportResourceTests {
@@ -92,6 +99,7 @@ public class ImportResourceTests {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class); |
|
|
|
|
Object bean = ctx.getBean("proxiedXmlBean"); |
|
|
|
|
assertTrue(AopUtils.isAopProxy(bean)); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -101,6 +109,7 @@ public class ImportResourceTests {
@@ -101,6 +109,7 @@ public class ImportResourceTests {
|
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
TestBean tb = ctx.getBean("javaDeclaredBean", TestBean.class); |
|
|
|
|
assertEquals("myName", tb.getName()); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Ignore // TODO: SPR-6327
|
|
|
|
|
@ -109,6 +118,7 @@ public class ImportResourceTests {
@@ -109,6 +118,7 @@ public class ImportResourceTests {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SubResourceConfig.class); |
|
|
|
|
assertTrue(ctx.containsBean("propertiesDeclaredBean")); |
|
|
|
|
assertTrue(ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -120,6 +130,7 @@ public class ImportResourceTests {
@@ -120,6 +130,7 @@ public class ImportResourceTests {
|
|
|
|
|
ctx.register(ImportXmlConfig.class); |
|
|
|
|
ctx.refresh(); |
|
|
|
|
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -127,12 +138,14 @@ public class ImportResourceTests {
@@ -127,12 +138,14 @@ public class ImportResourceTests {
|
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class); |
|
|
|
|
String name = ctx.getBean("xmlBeanName", String.class); |
|
|
|
|
assertThat(name, equalTo("xml.declared")); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testImportNonXmlResource() { |
|
|
|
|
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class); |
|
|
|
|
assertTrue(ctx.containsBean("propertiesDeclaredBean")); |
|
|
|
|
ctx.close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -190,7 +203,7 @@ public class ImportResourceTests {
@@ -190,7 +203,7 @@ public class ImportResourceTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml") |
|
|
|
|
@ImportResource("classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml") |
|
|
|
|
static class ImportXmlAutowiredConfig { |
|
|
|
|
@Autowired TestBean xmlDeclaredBean; |
|
|
|
|
|
|
|
|
|
@ -200,14 +213,12 @@ public class ImportResourceTests {
@@ -200,14 +213,12 @@ public class ImportResourceTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportNonXmlResourceConfig-context.properties", |
|
|
|
|
reader=PropertiesBeanDefinitionReader.class) |
|
|
|
|
@ImportResource(locations = "classpath:org/springframework/context/annotation/configuration/ImportNonXmlResourceConfig-context.properties", reader = PropertiesBeanDefinitionReader.class) |
|
|
|
|
static class ImportNonXmlResourceConfig { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
@ImportResource(value="classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml", |
|
|
|
|
reader=XmlBeanDefinitionReader.class) |
|
|
|
|
@ImportResource(locations = "classpath:org/springframework/context/annotation/configuration/ImportXmlConfig-context.xml", reader = XmlBeanDefinitionReader.class) |
|
|
|
|
static class SubResourceConfig extends ImportNonXmlResourceConfig { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|