moved ApplicationContext-dependent .beans.factory.xml.* tests from .testsuite -> .context

This commit is contained in:
Chris Beams
2008-12-19 22:33:26 +00:00
parent be53a80657
commit 7a0d9c7533
12 changed files with 143 additions and 294 deletions

View File

@@ -1,148 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beansProjectDescription>
<version>1</version>
<pluginVersion><![CDATA[2.2.0.v200809261800]]></pluginVersion>
<configSuffixes>
<configSuffix><![CDATA[xml]]></configSuffix>
</configSuffixes>
<enableImports><![CDATA[true]]></enableImports>
<configs>
<config>src/test/java/org/springframework/aop/aspectj/advice-precedence-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/after-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/afterReturning-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/afterThrowing-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/ambiguous-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/args-mismatch.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/around-advice-circular-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/around-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/aspectj.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/bean-name-pointcut-atAspect-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/bean-name-pointcut-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/before-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/declare-parents-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/implicit-jp-argument-matching-atAspectJ-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/implicit-jp-argument-matching-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/overloaded-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/proceedTests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/property-dependent-aspect-property-after-aspect-test.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/property-dependent-aspect-property-before-aspect-test.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/property-dependent-atAspectJ-aspect-property-after-aspect-test.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/property-dependent-atAspectJ-aspect-property-before-aspect-test.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/targetPointcutSelectionTests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/this-and-target-selectionOnly-pointcuts-atAspectJ-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/this-and-target-selectionOnly-pointcuts-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/topsy-turvy-aspect.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/afterThrowingAdviceTests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/annotationPointcut.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/around-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/aspect-implementing-interface-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/aspects.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithAbstractBean.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithCGLIB.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/aspectsWithOrdering.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/ataspectj-around-advice-tests.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/lazy.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/pertarget.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/perthis.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/retryAspect.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/twoAdviceAspect.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/twoAdviceAspectPrototype.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/usesInclude.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/usesJoinPointAspect.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/aspectj.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/benchmark/springAop.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/autoproxy/spr3064/annotationbinding-spr3064.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/generic/afterReturningGenericTypeMatchingTests-context.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-classProxy-context.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/generic/genericBridgeMethodMatchingTests-context.xml</config>
<config>src/test/java/org/springframework/aop/aspectj/generic/genericParameterMatchingTests-context.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerAdviceTypeOKTests.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerArgNamesOKTests.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerProxyTargetClassTests.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerReturningOKTests.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerScopeTests.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerTests.xml</config>
<config>src/test/java/org/springframework/aop/config/aopNamespaceHandlerThrowingOKTests.xml</config>
<config>src/test/java/org/springframework/aop/config/prototypeProxy.xml</config>
<config>src/test/java/org/springframework/aop/framework/frozenProxyFactoryBean.xml</config>
<config>src/test/java/org/springframework/aop/framework/innerBeanTarget.xml</config>
<config>src/test/java/org/springframework/aop/framework/invalidProxyFactory.xml</config>
<config>src/test/java/org/springframework/aop/framework/prototypeTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/proxyFactoryBeanAutowiringTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/proxyFactoryDoubleTargetSourceTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/proxyFactoryTargetSourceNotLastTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/proxyFactoryTargetSourceTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/proxyFactoryTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/serializationTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/throwsAdvice.xml</config>
<config>src/test/java/org/springframework/aop/framework/withDependencyChecking.xml</config>
<config>src/test/java/org/springframework/aop/framework/adapter/withBPPContext.xml</config>
<config>src/test/java/org/springframework/aop/framework/adapter/withoutBPPContext.xml</config>
<config>src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml</config>
<config>src/test/java/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml</config>
<config>src/test/java/org/springframework/aop/framework/autoproxy/beanNameAutoProxyCreatorInitTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/autoproxy/beanNameAutoProxyCreatorTests.xml</config>
<config>src/test/java/org/springframework/aop/framework/autoproxy/customTargetSource.xml</config>
<config>src/test/java/org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml</config>
<config>src/test/java/org/springframework/aop/scope/scopedList.xml</config>
<config>src/test/java/org/springframework/aop/scope/scopedMap.xml</config>
<config>src/test/java/org/springframework/aop/scope/scopedOverride.xml</config>
<config>src/test/java/org/springframework/aop/scope/scopedTestBean.xml</config>
<config>src/test/java/org/springframework/aop/target/commonsPoolTests.xml</config>
<config>src/test/java/org/springframework/beans/factory/config/test-properties.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/autowire-constructor-with-exclusion.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/beanEvents.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/beanEventsImported.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/beanNameGeneration.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/child.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/classNotFound.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/collectionMerging.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/collectionsWithDefaultTypes.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/complexFactoryCircle.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/constructorOverrides.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/default-autowire.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/default-lazy-init.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/defaultLifecycleMethods.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/delegationOverrides.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-carg-autowire.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-carg-inner.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-carg.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-dependsOn-inner.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-dependsOn.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-prop-autowireByName.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-prop-autowireByType.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-prop-inner.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-prop-inTheMiddle.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependencies-prop.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/dependenciesMaterializeThis.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/factoryCircle.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/ignoreDefaultLifecycleMethods.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/invalid-factory.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/local-collections-using-XSD.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/no-such-factory-method.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/overloadOverrides.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/overrides.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/parent.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/qualifierAnnotationTests.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/recursiveImport.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/reftypes.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/resource.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/resourceImport.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/satisfiedAllDependencyCheck.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/satisfiedObjectDependencyCheck.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/satisfiedSimpleDependencyCheck.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/schemaValidated.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/shortcutTests.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/test.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/unsatisfiedAllDependencyCheckMissingObjects.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/unsatisfiedObjectDependencyCheck.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/unsatisfiedSimpleDependencyCheck.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/validateWithDtd.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/validateWithXsd.xml</config>
<config>src/test/java/org/springframework/beans/factory/xml/withMeta.xml</config>
</configs>
<configSets>
</configSets>
</beansProjectDescription>

View File

@@ -1,87 +0,0 @@
/*
* Copyright 2002-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.factory.xml;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.beans.ITestBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Tests lookup methods wrapped by a CGLIB proxy (see SPR-391).
*
* @author Rod Johnson
* @author Juergen Hoeller
* @author Chris Beams
*/
public class LookupMethodWrappedByCglibProxyTests {
private ApplicationContext applicationContext;
@Before
public void setUp() {
this.applicationContext = new ClassPathXmlApplicationContext("overloadOverrides.xml", getClass());
resetInterceptor();
}
@Test
public void testAutoProxiedLookup() {
OverloadLookup olup = (OverloadLookup) applicationContext.getBean("autoProxiedOverload");
ITestBean jenny = olup.newTestBean();
assertEquals("Jenny", jenny.getName());
assertEquals("foo", olup.testMethod());
assertInterceptorCount(2);
}
@Test
public void testRegularlyProxiedLookup() {
OverloadLookup olup = (OverloadLookup) applicationContext.getBean("regularlyProxiedOverload");
ITestBean jenny = olup.newTestBean();
assertEquals("Jenny", jenny.getName());
assertEquals("foo", olup.testMethod());
assertInterceptorCount(2);
}
private void assertInterceptorCount(int count) {
DebugInterceptor interceptor = getInterceptor();
assertEquals("Interceptor count is incorrect", count, interceptor.getCount());
}
private void resetInterceptor() {
DebugInterceptor interceptor = getInterceptor();
interceptor.resetCount();
}
private DebugInterceptor getInterceptor() {
return (DebugInterceptor) applicationContext.getBean("interceptor");
}
public static abstract class OverloadLookup {
public abstract ITestBean newTestBean();
public String testMethod() {
return "foo";
}
}
}

View File

@@ -1,298 +0,0 @@
/*
* Copyright 2002-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.factory.xml;
import static org.junit.Assert.*;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.context.support.StaticApplicationContext;
/**
* @author Mark Fisher
* @author Juergen Hoeller
* @author Chris Beams
*/
public class QualifierAnnotationTests {
private static final String CONFIG_LOCATION =
"classpath:org/springframework/beans/factory/xml/qualifierAnnotationTests.xml";
@Test
public void testNonQualifiedFieldFails() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", NonQualifiedTestBean.class);
try {
context.refresh();
fail("Should have thrown a BeanCreationException");
}
catch (BeanCreationException e) {
assertTrue(e.getMessage().contains("found 6"));
}
}
@Test
public void testQualifiedByValue() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", QualifiedByValueTestBean.class);
context.refresh();
QualifiedByValueTestBean testBean = (QualifiedByValueTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("Larry", person.getName());
}
@Test
public void testQualifiedByBeanName() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", QualifiedByBeanNameTestBean.class);
context.refresh();
QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarryBean", person.getName());
}
@Test
public void testQualifiedByAlias() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", QualifiedByAliasTestBean.class);
context.refresh();
QualifiedByAliasTestBean testBean = (QualifiedByAliasTestBean) context.getBean("testBean");
Person person = testBean.getStooge();
assertEquals("LarryBean", person.getName());
}
@Test
public void testQualifiedByAnnotation() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", QualifiedByAnnotationTestBean.class);
context.refresh();
QualifiedByAnnotationTestBean testBean = (QualifiedByAnnotationTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarrySpecial", person.getName());
}
@Test
public void testQualifiedByCustomValue() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", QualifiedByCustomValueTestBean.class);
context.refresh();
QualifiedByCustomValueTestBean testBean = (QualifiedByCustomValueTestBean) context.getBean("testBean");
Person person = testBean.getCurly();
assertEquals("Curly", person.getName());
}
@Test
public void testQualifiedByAnnotationValue() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", QualifiedByAnnotationValueTestBean.class);
context.refresh();
QualifiedByAnnotationValueTestBean testBean = (QualifiedByAnnotationValueTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarrySpecial", person.getName());
}
@Test
public void testQualifiedByAttributesFailsWithoutCustomQualifierRegistered() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
context.registerSingleton("testBean", QualifiedByAttributesTestBean.class);
try {
context.refresh();
fail("should have thrown a BeanCreationException");
}
catch (BeanCreationException e) {
assertTrue(e.getMessage().contains("found 6"));
}
}
@Test
public void testQualifiedByAttributesWithCustomQualifierRegistered() {
StaticApplicationContext context = new StaticApplicationContext();
BeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(CONFIG_LOCATION);
QualifierAnnotationAutowireCandidateResolver resolver = (QualifierAnnotationAutowireCandidateResolver)
context.getDefaultListableBeanFactory().getAutowireCandidateResolver();
resolver.addQualifierType(MultipleAttributeQualifier.class);
context.registerSingleton("testBean", QualifiedByAttributesTestBean.class);
context.refresh();
QualifiedByAttributesTestBean testBean = (QualifiedByAttributesTestBean) context.getBean("testBean");
Person moeSenior = testBean.getMoeSenior();
Person moeJunior = testBean.getMoeJunior();
assertEquals("Moe Sr.", moeSenior.getName());
assertEquals("Moe Jr.", moeJunior.getName());
}
private static class NonQualifiedTestBean {
@Autowired
private Person anonymous;
public Person getAnonymous() {
return anonymous;
}
}
private static class QualifiedByValueTestBean {
@Autowired @Qualifier("larry")
private Person larry;
public Person getLarry() {
return larry;
}
}
private static class QualifiedByBeanNameTestBean {
@Autowired @Qualifier("larryBean")
private Person larry;
public Person getLarry() {
return larry;
}
}
private static class QualifiedByAliasTestBean {
@Autowired @Qualifier("stooge")
private Person stooge;
public Person getStooge() {
return stooge;
}
}
private static class QualifiedByAnnotationTestBean {
@Autowired @Qualifier("special")
private Person larry;
public Person getLarry() {
return larry;
}
}
private static class QualifiedByCustomValueTestBean {
@Autowired @SimpleValueQualifier("curly")
private Person curly;
public Person getCurly() {
return curly;
}
}
private static class QualifiedByAnnotationValueTestBean {
@Autowired @SimpleValueQualifier("special")
private Person larry;
public Person getLarry() {
return larry;
}
}
private static class QualifiedByAttributesTestBean {
@Autowired @MultipleAttributeQualifier(name="moe", age=42)
private Person moeSenior;
@Autowired @MultipleAttributeQualifier(name="moe", age=15)
private Person moeJunior;
public Person getMoeSenior() {
return moeSenior;
}
public Person getMoeJunior() {
return moeJunior;
}
}
private static class Person {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Qualifier("special")
@SimpleValueQualifier("special")
private static class SpecialPerson extends Person {
}
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface SimpleValueQualifier {
String value() default "";
}
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MultipleAttributeQualifier {
String name();
int age();
}
}

View File

@@ -1,39 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!--
Not yet in use: illustration of possible approach.
-->
<bean id="autoProxiedOverload" lazy-init="true"
class="org.springframework.beans.factory.xml.LookupMethodWrappedByCglibProxyTests$OverloadLookup">
<lookup-method name="newTestBean" bean="jenny"/>
</bean>
<bean id="regularlyProxiedOverloadTarget" scope="prototype"
class="org.springframework.beans.factory.xml.LookupMethodWrappedByCglibProxyTests$OverloadLookup">
<lookup-method name="newTestBean" bean="jenny"/>
</bean>
<bean id="regularlyProxiedOverload" lazy-init="true" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target"><ref local="regularlyProxiedOverloadTarget"/></property>
<property name="proxyTargetClass"><value>true</value></property>
<property name="interceptorNames"><value>interceptor</value></property>
</bean>
<bean id="jenny" class="org.springframework.beans.TestBean" scope="prototype">
<property name="name"><value>Jenny</value></property>
<property name="age"><value>30</value></property>
</bean>
<!-- Add autoproxy -->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames"><value>autoProxiedOverload</value></property>
<property name="proxyTargetClass"><value>true</value></property>
<property name="interceptorNames"><value>interceptor</value></property>
</bean>
<bean id="interceptor" class="org.springframework.aop.interceptor.DebugInterceptor"/>
</beans>

View File

@@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:annotation-config/>
<bean id="larryBean" class="org.springframework.beans.factory.xml.QualifierAnnotationTests$Person">
<property name="name" value="LarryBean"/>
</bean>
<alias name="larryBean" alias="stooge"/>
<bean class="org.springframework.beans.factory.xml.QualifierAnnotationTests$Person">
<property name="name" value="Larry"/>
<qualifier value="larry"/>
</bean>
<bean class="org.springframework.beans.factory.xml.QualifierAnnotationTests$SpecialPerson">
<property name="name" value="LarrySpecial"/>
</bean>
<bean class="org.springframework.beans.factory.xml.QualifierAnnotationTests$Person">
<property name="name" value="Curly"/>
<qualifier type="QualifierAnnotationTests.SimpleValueQualifier" value="curly"/>
</bean>
<bean class="org.springframework.beans.factory.xml.QualifierAnnotationTests$Person">
<meta key="name" value="moe"/>
<meta key="age" value="42"/>
<property name="name" value="Moe Sr."/>
</bean>
<bean class="org.springframework.beans.factory.xml.QualifierAnnotationTests$Person">
<property name="name" value="Moe Jr."/>
<qualifier type="QualifierAnnotationTests.MultipleAttributeQualifier">
<attribute key="name" value="moe"/>
<attribute key="age" value="15"/>
</qualifier>
</bean>
</beans>

View File

@@ -1,168 +0,0 @@
/*
* Copyright 2002-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.factory.xml.support;
import static org.junit.Assert.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.aop.Advisor;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.aop.support.AopUtils;
import org.springframework.beans.ITestBean;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver;
import org.springframework.beans.factory.xml.NamespaceHandlerResolver;
import org.springframework.beans.factory.xml.PluggableSchemaResolver;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.xml.sax.InputSource;
import test.interceptor.NopInterceptor;
/**
* @author Rob Harrop
* @author Rick Evans
* @author Chris Beams
*/
public final class CustomNamespaceHandlerTests {
private DefaultListableBeanFactory beanFactory;
@Before
public void setUp() throws Exception {
String location = "org/springframework/beans/factory/xml/support/customNamespace.properties";
NamespaceHandlerResolver resolver = new DefaultNamespaceHandlerResolver(getClass().getClassLoader(), location);
this.beanFactory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(this.beanFactory);
reader.setNamespaceHandlerResolver(resolver);
reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD);
reader.setEntityResolver(new DummySchemaResolver());
reader.loadBeanDefinitions(getResource());
}
@Test
public void testSimpleParser() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("testBean");
assetTestBean(bean);
}
@Test
public void testSimpleDecorator() throws Exception {
TestBean bean = (TestBean) this.beanFactory.getBean("customisedTestBean");
assetTestBean(bean);
}
@Test
public void testProxyingDecorator() throws Exception {
ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
assetTestBean(bean);
assertTrue(AopUtils.isAopProxy(bean));
Advisor[] advisors = ((Advised) bean).getAdvisors();
assertEquals("Incorrect number of advisors", 1, advisors.length);
assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass());
}
@Test
public void testChainedDecorators() throws Exception {
ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
assetTestBean(bean);
assertTrue(AopUtils.isAopProxy(bean));
Advisor[] advisors = ((Advised) bean).getAdvisors();
assertEquals("Incorrect number of advisors", 2, advisors.length);
assertEquals("Incorrect advice class.", DebugInterceptor.class, advisors[0].getAdvice().getClass());
assertEquals("Incorrect advice class.", NopInterceptor.class, advisors[1].getAdvice().getClass());
}
@Test
public void testDecorationViaAttribute() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition("decorateWithAttribute");
assertEquals("foo", beanDefinition.getAttribute("objectName"));
}
/**
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
*/
@Test
public void testCustomElementNestedWithinUtilList() throws Exception {
List<?> things = (List<?>) this.beanFactory.getBean("list.of.things");
assertNotNull(things);
assertEquals(2, things.size());
}
/**
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
*/
@Test
public void testCustomElementNestedWithinUtilSet() throws Exception {
Set<?> things = (Set<?>) this.beanFactory.getBean("set.of.things");
assertNotNull(things);
assertEquals(2, things.size());
}
/**
* http://opensource.atlassian.com/projects/spring/browse/SPR-2728
*/
@Test
public void testCustomElementNestedWithinUtilMap() throws Exception {
Map<?, ?> things = (Map<?, ?>) this.beanFactory.getBean("map.of.things");
assertNotNull(things);
assertEquals(2, things.size());
}
private void assetTestBean(ITestBean bean) {
assertEquals("Invalid name", "Rob Harrop", bean.getName());
assertEquals("Invalid age", 23, bean.getAge());
}
private Resource getResource() {
return new ClassPathResource("customNamespace.xml", getClass());
}
private final class DummySchemaResolver extends PluggableSchemaResolver {
public DummySchemaResolver() {
super(CustomNamespaceHandlerTests.this.getClass().getClassLoader());
}
public InputSource resolveEntity(String publicId, String systemId) throws IOException {
InputSource source = super.resolveEntity(publicId, systemId);
if (source == null) {
Resource resource = new ClassPathResource("org/springframework/beans/factory/xml/support/spring-test.xsd");
source = new InputSource(resource.getInputStream());
source.setPublicId(publicId);
source.setSystemId(systemId);
}
return source;
}
}
}

View File

@@ -1,120 +0,0 @@
/*
* Copyright 2002-2006 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.beans.factory.xml.support;
import org.springframework.aop.config.AbstractInterceptorDrivenBeanDefinitionDecorator;
import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.TestBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import test.interceptor.NopInterceptor;
/**
* @author Rob Harrop
*/
public class TestNamespaceHandler extends NamespaceHandlerSupport {
public void init() {
registerBeanDefinitionParser("testBean", new TestBeanDefinitionParser());
registerBeanDefinitionParser("person", new PersonDefinitionParser());
registerBeanDefinitionDecorator("set", new PropertyModifyingBeanDefinitionDecorator());
registerBeanDefinitionDecorator("debug", new DebugBeanDefinitionDecorator());
registerBeanDefinitionDecorator("nop", new NopInterceptorBeanDefinitionDecorator());
registerBeanDefinitionDecoratorForAttribute("object-name", new ObjectNameBeanDefinitionDecorator());
}
private static class TestBeanDefinitionParser implements BeanDefinitionParser {
public BeanDefinition parse(Element element, ParserContext parserContext) {
RootBeanDefinition definition = new RootBeanDefinition();
definition.setBeanClass(TestBean.class);
MutablePropertyValues mpvs = new MutablePropertyValues();
mpvs.addPropertyValue("name", element.getAttribute("name"));
mpvs.addPropertyValue("age", element.getAttribute("age"));
definition.setPropertyValues(mpvs);
parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), definition);
return null;
}
}
private static final class PersonDefinitionParser extends AbstractSingleBeanDefinitionParser {
protected Class getBeanClass(Element element) {
return TestBean.class;
}
protected void doParse(Element element, BeanDefinitionBuilder builder) {
builder.addPropertyValue("name", element.getAttribute("name"));
builder.addPropertyValue("age", element.getAttribute("age"));
}
}
private static class PropertyModifyingBeanDefinitionDecorator implements BeanDefinitionDecorator {
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
Element element = (Element) node;
BeanDefinition def = definition.getBeanDefinition();
MutablePropertyValues mpvs = (def.getPropertyValues() == null) ? new MutablePropertyValues() : def.getPropertyValues();
mpvs.addPropertyValue("name", element.getAttribute("name"));
mpvs.addPropertyValue("age", element.getAttribute("age"));
((AbstractBeanDefinition) def).setPropertyValues(mpvs);
return definition;
}
}
private static class DebugBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator {
protected BeanDefinition createInterceptorDefinition(Node node) {
return new RootBeanDefinition(DebugInterceptor.class);
}
}
private static class NopInterceptorBeanDefinitionDecorator extends AbstractInterceptorDrivenBeanDefinitionDecorator {
protected BeanDefinition createInterceptorDefinition(Node node) {
return new RootBeanDefinition(NopInterceptor.class);
}
}
private static class ObjectNameBeanDefinitionDecorator implements BeanDefinitionDecorator {
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
Attr objectNameAttribute = (Attr) node;
definition.getBeanDefinition().setAttribute("objectName", objectNameAttribute.getValue());
return definition;
}
}
}

View File

@@ -1,2 +0,0 @@
http\://www.springframework.org/schema/beans/test=org.springframework.beans.factory.xml.support.TestNamespaceHandler
http\://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler

View File

@@ -1,50 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:test="http://www.springframework.org/schema/beans/test"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://www.springframework.org/schema/beans/test http://www.springframework.org/schema/beans/factory/xml/support/spring-test.xsd">
<test:testBean id="testBean" name="Rob Harrop" age="23"/>
<bean id="customisedTestBean" class="org.springframework.beans.TestBean">
<test:set name="Rob Harrop" age="23"/>
</bean>
<bean id="debuggingTestBean" class="org.springframework.beans.TestBean">
<test:debug/>
<property name="name" value="Rob Harrop"/>
<property name="age" value="23"/>
</bean>
<bean id="chainedTestBean" class="org.springframework.beans.TestBean">
<test:debug/>
<test:nop/>
<property name="name" value="Rob Harrop"/>
<property name="age" value="23"/>
</bean>
<bean id="decorateWithAttribute" class="org.springframework.beans.TestBean" test:object-name="foo"/>
<util:list id="list.of.things">
<test:person name="Fiona Apple" age="20"/>
<test:person name="Harriet Wheeler" age="30"/>
</util:list>
<util:set id="set.of.things">
<test:person name="Fiona Apple" age="20"/>
<test:person name="Harriet Wheeler" age="30"/>
</util:set>
<util:map id="map.of.things">
<entry key="fiona.apple">
<test:person name="Fiona Apple" age="20"/>
</entry>
<entry key="harriet.wheeler">
<test:person name="Harriet Wheeler" age="30"/>
</entry>
</util:map>
</beans>

View File

@@ -1 +0,0 @@
http\://www.springframework.org/schema/test=java.lang.String

View File

@@ -1 +0,0 @@
http\://www.springframework.org/schema/test=com.myapp.Foo

View File

@@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://www.springframework.org/schema/beans/test"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/schema/beans/test"
elementFormDefault="qualified">
<xsd:element name="person">
<xsd:complexType>
<xsd:attribute name="id" type="xsd:string" use="optional" form="unqualified"/>
<xsd:attribute name="name" type="xsd:string" use="required" form="unqualified"/>
<xsd:attribute name="age" type="xsd:integer" use="required" form="unqualified"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="testBean">
<xsd:complexType>
<xsd:attribute name="id" type="xsd:string" use="required" form="unqualified"/>
<xsd:attribute name="name" type="xsd:string" use="required" form="unqualified"/>
<xsd:attribute name="age" type="xsd:integer" use="required" form="unqualified"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="set">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" use="required" form="unqualified"/>
<xsd:attribute name="age" type="xsd:integer" use="required" form="unqualified"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="debug"/>
<xsd:element name="nop"/>
<xsd:attribute name="object-name" type="xsd:string"/>
</xsd:schema>