Browse Source

Refactor BeanConfigurerTests

In preparation for the introduction of @EnableSpringConfigured

Issue: SPR-7888
pull/7/head
Chris Beams 13 years ago
parent
commit
4318ccd9d5
  1. 25
      org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/AbstractBeanConfigurerTests.java
  2. 38
      org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/XmlBeanConfigurerTests.java
  3. 64
      org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/beanConfigurerTests-beans.xml
  4. 56
      org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/beanConfigurerTests.xml

25
org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/BeanConfigurerTests.java → org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/AbstractBeanConfigurerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007 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.
@ -24,16 +24,16 @@ import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.TestBean; import org.springframework.beans.TestBean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.UnsatisfiedDependencyException; import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.beans.factory.annotation.Autowire; import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable; import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.mail.MailSender; import org.springframework.mail.MailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
@ -42,24 +42,20 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
* @author Rod Johnson * @author Rod Johnson
* @author Ramnivas Laddad * @author Ramnivas Laddad
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams
*/ */
public class BeanConfigurerTests extends TestCase { public abstract class AbstractBeanConfigurerTests extends TestCase {
private ClassPathXmlApplicationContext context; protected ConfigurableApplicationContext context;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
this.context = this.context = createContext();
new ClassPathXmlApplicationContext("org/springframework/beans/factory/aspectj/beanConfigurerTests.xml");
} }
public void testConfigurableWithExplicitBeanName() { protected abstract ConfigurableApplicationContext createContext();
ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring();
assertEquals("Rod", myObject.getName());
}
public void testInjectionAfterRefresh() { public void testConfigurableWithExplicitBeanName() {
context.refresh();
ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring(); ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring();
assertEquals("Rod", myObject.getName()); assertEquals("Rod", myObject.getName());
} }
@ -252,7 +248,7 @@ public class BeanConfigurerTests extends TestCase {
@Configurable("beanOne") @Configurable("beanOne")
private static class ShouldBeConfiguredBySpring implements Serializable { protected static class ShouldBeConfiguredBySpring implements Serializable {
private String name; private String name;
@ -287,7 +283,6 @@ public class BeanConfigurerTests extends TestCase {
} }
} }
// Won't work until we use hasmethod() experimental pointcut in AspectJ. // Won't work until we use hasmethod() experimental pointcut in AspectJ.
// @Configurable("beanOne") // @Configurable("beanOne")
// private static class ShouldBeConfiguredBySpringContainsPrivateReadResolve implements Serializable { // private static class ShouldBeConfiguredBySpringContainsPrivateReadResolve implements Serializable {

38
org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/XmlBeanConfigurerTests.java

@ -0,0 +1,38 @@
/*
* 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.
* 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.aspectj;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Chris Beams
*/
public class XmlBeanConfigurerTests extends AbstractBeanConfigurerTests {
@Override
protected ConfigurableApplicationContext createContext() {
return new ClassPathXmlApplicationContext("org/springframework/beans/factory/aspectj/beanConfigurerTests.xml");
}
public void testInjectionAfterRefresh() {
context.refresh();
ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring();
assertEquals("Rod", myObject.getName());
}
}

64
org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/beanConfigurerTests-beans.xml

@ -0,0 +1,64 @@
<?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.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$WireArbitraryExistingPojo"
factory-method="aspectOf"/>
<bean id="beanOne" class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$ShouldBeConfiguredBySpring"
lazy-init="true">
<property name="name" value="Rod"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$ShouldBeConfiguredBySpringUsingTypeNameAsBeanName"
lazy-init="true">
<property name="name" value="Rob"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$SubBean"
lazy-init="true">
<property name="name" value="Ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$SubBeanPreConstruction"
lazy-init="true">
<property name="name" value="Ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$SubSerializableBean"
lazy-init="true">
<property name="name" value="Ramnivas"/>
</bean>
<bean id="circular" class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$CircularFactoryBean"
autowire-candidate="false"/>
<!-- Used as a target for autowiring by type -->
<bean id="ramnivas" class="org.springframework.beans.TestBean" depends-on="circular">
<property name="name" value="Ramnivas"/>
<property name="spouse" ref="circular"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$ArbitraryExistingPojo">
<property name="friend" ref="ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$PreConstructionConfiguredBean">
<property name="name" value="ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$PostConstructionConfiguredBean">
<property name="name" value="ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$GenericParameterConfigurableBean" scope="prototype">
<property name="testService" ref="testService"/>
</bean>
<bean id="testService" class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$TestService"/>
<bean id="paymentService" class="org.springframework.beans.factory.aspectj.AbstractBeanConfigurerTests$PaymentService"/>
</beans>

56
org.springframework.aspects/src/test/java/org/springframework/beans/factory/aspectj/beanConfigurerTests.xml

@ -9,60 +9,6 @@
<context:annotation-config/> <context:annotation-config/>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$WireArbitraryExistingPojo" <import resource="beanConfigurerTests-beans.xml"/>
factory-method="aspectOf"/>
<bean id="beanOne" class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$ShouldBeConfiguredBySpring"
lazy-init="true">
<property name="name" value="Rod"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$ShouldBeConfiguredBySpringUsingTypeNameAsBeanName"
lazy-init="true">
<property name="name" value="Rob"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$SubBean"
lazy-init="true">
<property name="name" value="Ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$SubBeanPreConstruction"
lazy-init="true">
<property name="name" value="Ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$SubSerializableBean"
lazy-init="true">
<property name="name" value="Ramnivas"/>
</bean>
<bean id="circular" class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$CircularFactoryBean"
autowire-candidate="false"/>
<!-- Used as a target for autowiring by type -->
<bean id="ramnivas" class="org.springframework.beans.TestBean" depends-on="circular">
<property name="name" value="Ramnivas"/>
<property name="spouse" ref="circular"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$ArbitraryExistingPojo">
<property name="friend" ref="ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$PreConstructionConfiguredBean">
<property name="name" value="ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$PostConstructionConfiguredBean">
<property name="name" value="ramnivas"/>
</bean>
<bean class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$GenericParameterConfigurableBean" scope="prototype">
<property name="testService" ref="testService"/>
</bean>
<bean id="testService" class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$TestService"/>
<bean id="paymentService" class="org.springframework.beans.factory.aspectj.BeanConfigurerTests$PaymentService"/>
</beans> </beans>

Loading…
Cancel
Save