moving unit tests from .testsuite -> .context

This commit is contained in:
Chris Beams 2008-12-14 19:47:56 +00:00
parent 69d80518f3
commit 87de85ef19
57 changed files with 231 additions and 171 deletions

View File

@ -1,36 +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.context;
/**
* @author Juergen Hoeller
*/
public class BeanThatBroadcasts implements ApplicationContextAware {
public ApplicationContext applicationContext;
public int receivedCount;
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
if (applicationContext.getDisplayName().indexOf("listener") != -1) {
applicationContext.getBean("listener");
}
}
}

View File

@ -1,61 +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.context;
import java.util.Map;
/**
* A stub {@link ApplicationListener}.
*
* @author Thomas Risberg
* @author Juergen Hoeller
*/
public class BeanThatListens implements ApplicationListener {
private BeanThatBroadcasts beanThatBroadcasts;
private int eventCount;
public BeanThatListens() {
}
public BeanThatListens(BeanThatBroadcasts beanThatBroadcasts) {
this.beanThatBroadcasts = beanThatBroadcasts;
Map beans = beanThatBroadcasts.applicationContext.getBeansOfType(BeanThatListens.class);
if (!beans.isEmpty()) {
throw new IllegalStateException("Shouldn't have found any BeanThatListens instances");
}
}
public void onApplicationEvent(ApplicationEvent event) {
eventCount++;
if (beanThatBroadcasts != null) {
beanThatBroadcasts.receivedCount++;
}
}
public int getEventCount() {
return eventCount;
}
public void zero() {
eventCount = 0;
}
}

View File

@ -1,28 +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>
<bean name="assemblerOne" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="target"><ref parent="assemblerOne"/></property>
<property name="proxyTargetClass"><value>true</value></property>
<property name="transactionAttributes">
<props>
<prop key="test">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean name="assemblerTwo" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="target"><ref parent="assemblerTwo"/></property>
<property name="proxyTargetClass"><value>true</value></property>
<property name="transactionAttributes">
<props>
<prop key="test">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<import resource="resourceImport.xml"/>
<bean id="resource2" class="org.springframework.beans.ResourceTestBean">
<constructor-arg index="0">
<value>classpath:org/springframework/beans/factory/xml/test.properties</value>
</constructor-arg>
<constructor-arg index="1">
<value>classpath:org/springframework/beans/factory/xml/test.properties</value>
</constructor-arg>
</bean>
</beans>

View File

@ -0,0 +1,15 @@
<?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>
<bean id="resource1" class="org.springframework.beans.ResourceTestBean">
<property name="resource">
<value>classpath:org/springframework/beans/factory/xml/test.properties</value>
</property>
<property name="inputStream">
<value>classpath:org/springframework/beans/factory/xml/test.properties</value>
</property>
</bean>
</beans>

View File

@ -0,0 +1,127 @@
<?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>
<bean id="validEmptyWithDescription" class="org.springframework.beans.TestBean">
<description>
I have no properties and I'm happy without them.
</description>
</bean>
<!--
Check automatic creation of alias, to allow for names that are illegal as XML ids.
-->
<bean id="aliased" class=" org.springframework.beans.TestBean " name="myalias">
<property name="name"><value>aliased</value></property>
</bean>
<alias name="aliased" alias="youralias"/>
<alias name="multiAliased" alias="alias3"/>
<bean id="multiAliased" class="org.springframework.beans.TestBean" name="alias1,alias2">
<property name="name"><value>aliased</value></property>
</bean>
<alias name="multiAliased" alias="alias4"/>
<bean class="org.springframework.beans.TestBean" name="aliasWithoutId1,aliasWithoutId2,aliasWithoutId3">
<property name="name"><value>aliased</value></property>
</bean>
<bean class="org.springframework.beans.TestBean">
<property name="name"><null/></property>
</bean>
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
<bean class="org.springframework.beans.factory.xml.DummyReferencer"/>
<bean id="rod" class="org.springframework.beans.TestBean">
<property name="name"><value><!-- a comment -->Rod</value></property>
<property name="age"><value>31</value></property>
<property name="spouse"><ref bean="father"/></property>
<property name="touchy"><value/></property>
</bean>
<bean id="roderick" parent="rod">
<property name="name"><value>Roderick<!-- a comment --></value></property>
<!-- Should inherit age -->
</bean>
<bean id="kerry" class="org.springframework.beans.TestBean">
<property name="name"><value>Ker<!-- a comment -->ry</value></property>
<property name="age"><value>34</value></property>
<property name="spouse"><ref local="rod"/></property>
<property name="touchy"><value></value></property>
</bean>
<bean id="kathy" class="org.springframework.beans.TestBean" scope="prototype">
<property name="name"><value>Kathy</value></property>
<property name="age"><value>28</value></property>
<property name="spouse"><ref bean="father"/></property>
</bean>
<bean id="typeMismatch" class="org.springframework.beans.TestBean" scope="prototype">
<property name="name"><value>typeMismatch</value></property>
<property name="age"><value>34x</value></property>
<property name="spouse"><ref local="rod"/></property>
</bean>
<!-- Test of lifecycle callbacks -->
<bean id="mustBeInitialized" class="org.springframework.beans.factory.MustBeInitialized"/>
<bean id="lifecycle" class="org.springframework.beans.factory.LifecycleBean"
init-method="declaredInitMethod">
<property name="initMethodDeclared"><value>true</value></property>
</bean>
<bean id="protectedLifecycle" class="org.springframework.beans.factory.xml.ProtectedLifecycleBean"
init-method="declaredInitMethod">
<property name="initMethodDeclared"><value>true</value></property>
</bean>
<!-- Factory beans are automatically treated differently -->
<bean id="singletonFactory" class="org.springframework.beans.factory.DummyFactory">
</bean>
<bean id="prototypeFactory" class="org.springframework.beans.factory.DummyFactory">
<property name="singleton"><value>false</value></property>
</bean>
<!-- Check that the circular reference resolution mechanism doesn't break
repeated references to the same FactoryBean -->
<bean id="factoryReferencer" class="org.springframework.beans.factory.xml.DummyReferencer">
<property name="testBean1"><ref bean="singletonFactory"/></property>
<property name="testBean2"><ref local="singletonFactory"/></property>
<property name="dummyFactory"><ref bean="&amp;singletonFactory"/></property>
</bean>
<bean id="factoryReferencerWithConstructor" class="org.springframework.beans.factory.xml.DummyReferencer">
<constructor-arg><ref bean="&amp;singletonFactory"/></constructor-arg>
<property name="testBean1"><ref bean="singletonFactory"/></property>
<property name="testBean2"><ref local="singletonFactory"/></property>
</bean>
<!-- Check that the circular reference resolution mechanism doesn't break
prototype instantiation -->
<bean id="prototypeReferencer" class="org.springframework.beans.factory.xml.DummyReferencer" scope="prototype">
<property name="testBean1"><ref local="kathy"/></property>
<property name="testBean2"><ref bean="kathy"/></property>
</bean>
<bean id="listenerVeto" class="org.springframework.beans.TestBean">
<property name="name"><value>listenerVeto</value></property>
<property name="age"><value>66</value></property>
</bean>
<bean id="validEmpty" class="org.springframework.beans.TestBean"/>
<bean id="commentsInValue" class="org.springframework.beans.TestBean">
<property name="name"><value>this is<!-- don't mind me --> a <![CDATA[<!--comment-->]]></value></property>
</bean>
</beans>

View File

@ -33,4 +33,4 @@ public class BeanThatBroadcasts implements ApplicationContextAware {
}
}
}
}

View File

@ -19,7 +19,7 @@ package org.springframework.context;
import java.util.Map;
/**
* A stub {@link org.springframework.context.ApplicationListener}.
* A stub {@link ApplicationListener}.
*
* @author Thomas Risberg
* @author Juergen Hoeller
@ -58,4 +58,4 @@ public class BeanThatListens implements ApplicationListener {
eventCount = 0;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2005 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.
@ -14,28 +14,19 @@
* limitations under the License.
*/
package org.springframework.context;
package org.springframework.context.support;
import org.springframework.aop.ThrowsAdvice;
/**
* Listener that maintains a global count of events.
* Advice object that implements <i>multiple</i> Advice interfaces.
*
* @author Rod Johnson
* @since January 21, 2001
* @author Chris Beams
*/
public class TestListener implements ApplicationListener {
public class NoOpAdvice implements ThrowsAdvice {
private int eventCount;
public int getEventCount() {
return eventCount;
}
public void zeroCounter() {
eventCount = 0;
}
public void onApplicationEvent(ApplicationEvent e) {
++eventCount;
public void afterThrowing(Exception ex) throws Throwable {
// no-op
}
}

View File

@ -0,0 +1,37 @@
/*
* 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.context.support;
import org.springframework.aop.framework.AbstractSingletonProxyFactoryBean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.FactoryBean;
@SuppressWarnings("serial")
public class TestProxyFactoryBean extends AbstractSingletonProxyFactoryBean
implements FactoryBean, BeanFactoryAware {
@Override
protected Object createMainInterceptor() {
return new NoOpAdvice();
}
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
}
}

View File

@ -0,0 +1,14 @@
<?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>
<bean name="assemblerOne" class="org.springframework.context.support.TestProxyFactoryBean">
<property name="target"><ref parent="assemblerOne"/></property>
</bean>
<bean name="assemblerTwo" class="org.springframework.context.support.TestProxyFactoryBean">
<property name="target"><ref parent="assemblerTwo"/></property>
</bean>
</beans>

View File

@ -9,7 +9,7 @@
<import resource="classpath:org/springframework/context/support/test/*/import2.xml"/>
<context:property-override location="org/springframework/context/support/override.properties"/>
<context:property-override location="org/springframework/context/support/override.properties"/>
<bean id="messageSource" class="org.springframework.context.support.StaticMessageSource"/>
@ -17,38 +17,22 @@
<bean name="service" class="org.springframework.context.support.Service" dependency-check="objects">
<property name="resources" value="/org/springframework/context/support/test/context*.xml"/>
</bean>
</bean>
<bean name="service2" class="org.springframework.context.support.Service" autowire="byName" depends-on="service">
<property name="resources" value="/org/springframework/context/support/test/context*.xml"/>
</bean>
</bean>
<bean name="autowiredService" class="org.springframework.context.support.AutowiredService" autowire="byName"/>
<bean name="autowiredService2" class="org.springframework.context.support.AutowiredService" autowire="byType"/>
<bean name="transactionManager" class="org.springframework.transaction.CallCountingTransactionManager"/>
<bean name="wrappedAssemblerOne" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<bean name="wrappedAssemblerOne" class="org.springframework.context.support.TestProxyFactoryBean">
<property name="target" ref="assemblerOne"/>
<property name="proxyTargetClass" value="xxx"/>
<property name="transactionAttributes">
<props>
<prop key="test">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean name="wrappedAssemblerTwo" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="target" ref="assemblerTwo"/>
<property name="proxyTargetClass" value="yyy"/>
<property name="transactionAttributes">
<props>
<prop key="test">PROPAGATION_REQUIRED</prop>
</props>
</property>
<bean name="wrappedAssemblerTwo" class="org.springframework.context.support.TestProxyFactoryBean">
<property name="target" ref="assemblerTwo"/>
</bean>
</beans>

View File

@ -40,7 +40,7 @@ public class CauchoRemotingTests extends TestCase {
// expected
}
factory.setServiceInterface(ITestBean.class);
factory.setServiceUrl("http://localhosta/testbean");
factory.setServiceUrl("http://localhost/testbean");
factory.afterPropertiesSet();
assertTrue("Correct singleton value", factory.isSingleton());
@ -66,7 +66,7 @@ public class CauchoRemotingTests extends TestCase {
// expected
}
factory.setServiceInterface(ITestBean.class);
factory.setServiceUrl("http://localhosta/testbean");
factory.setServiceUrl("http://localhost/testbean");
factory.setUsername("test");
factory.setPassword("bean");
factory.setOverloadEnabled(true);
@ -89,7 +89,7 @@ public class CauchoRemotingTests extends TestCase {
TestHessianProxyFactory proxyFactory = new TestHessianProxyFactory();
HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
factory.setServiceInterface(ITestBean.class);
factory.setServiceUrl("http://localhosta/testbean");
factory.setServiceUrl("http://localhost/testbean");
factory.setProxyFactory(proxyFactory);
factory.setUsername("test");
factory.setPassword("bean");