moving unit tests from .testsuite -> .context.support
This commit is contained in:
@@ -20,8 +20,9 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.access.BeanFactoryLocator;
|
||||
import org.springframework.beans.factory.access.BeanFactoryReference;
|
||||
import org.springframework.beans.factory.access.SingletonBeanFactoryLocatorTests;
|
||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -33,9 +34,8 @@ public class ContextSingletonBeanFactoryLocatorTests extends SingletonBeanFactor
|
||||
public void testBaseBeanFactoryDefs() {
|
||||
// Just test the base BeanFactory/AppContext defs we are going to work
|
||||
// with in other tests.
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
new String[] {"/org/springframework/beans/factory/access/beans1.xml",
|
||||
"/org/springframework/beans/factory/access/beans2.xml"});
|
||||
new XmlBeanFactory(new ClassPathResource("/org/springframework/beans/factory/access/beans1.xml"));
|
||||
new XmlBeanFactory(new ClassPathResource("/org/springframework/beans/factory/access/beans2.xml"));
|
||||
}
|
||||
|
||||
public void testBasicFunctionality() {
|
||||
|
||||
@@ -1,97 +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.support;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class ApplicationContextLifecycleTests extends TestCase {
|
||||
|
||||
public void testBeansStart() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1");
|
||||
LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2");
|
||||
LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3");
|
||||
LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4");
|
||||
String error = "bean was not started";
|
||||
assertTrue(error, bean1.isRunning());
|
||||
assertTrue(error, bean2.isRunning());
|
||||
assertTrue(error, bean3.isRunning());
|
||||
assertTrue(error, bean4.isRunning());
|
||||
}
|
||||
|
||||
public void testBeansStop() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1");
|
||||
LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2");
|
||||
LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3");
|
||||
LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4");
|
||||
String startError = "bean was not started";
|
||||
assertTrue(startError, bean1.isRunning());
|
||||
assertTrue(startError, bean2.isRunning());
|
||||
assertTrue(startError, bean3.isRunning());
|
||||
assertTrue(startError, bean4.isRunning());
|
||||
context.stop();
|
||||
String stopError = "bean was not stopped";
|
||||
assertFalse(stopError, bean1.isRunning());
|
||||
assertFalse(stopError, bean2.isRunning());
|
||||
assertFalse(stopError, bean3.isRunning());
|
||||
assertFalse(stopError, bean4.isRunning());
|
||||
}
|
||||
|
||||
public void testStartOrder() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1");
|
||||
LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2");
|
||||
LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3");
|
||||
LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4");
|
||||
String notStartedError = "bean was not started";
|
||||
assertTrue(notStartedError, bean1.getStartOrder() > 0);
|
||||
assertTrue(notStartedError, bean2.getStartOrder() > 0);
|
||||
assertTrue(notStartedError, bean3.getStartOrder() > 0);
|
||||
assertTrue(notStartedError, bean4.getStartOrder() > 0);
|
||||
String orderError = "dependent bean must start after the bean it depends on";
|
||||
assertTrue(orderError, bean2.getStartOrder() > bean1.getStartOrder());
|
||||
assertTrue(orderError, bean3.getStartOrder() > bean2.getStartOrder());
|
||||
assertTrue(orderError, bean4.getStartOrder() > bean2.getStartOrder());
|
||||
}
|
||||
|
||||
public void testStopOrder() {
|
||||
AbstractApplicationContext context = new ClassPathXmlApplicationContext("lifecycleTests.xml", getClass());
|
||||
context.start();
|
||||
context.stop();
|
||||
LifecycleTestBean bean1 = (LifecycleTestBean) context.getBean("bean1");
|
||||
LifecycleTestBean bean2 = (LifecycleTestBean) context.getBean("bean2");
|
||||
LifecycleTestBean bean3 = (LifecycleTestBean) context.getBean("bean3");
|
||||
LifecycleTestBean bean4 = (LifecycleTestBean) context.getBean("bean4");
|
||||
String notStoppedError = "bean was not stopped";
|
||||
assertTrue(notStoppedError, bean1.getStopOrder() > 0);
|
||||
assertTrue(notStoppedError, bean2.getStopOrder() > 0);
|
||||
assertTrue(notStoppedError, bean3.getStopOrder() > 0);
|
||||
assertTrue(notStoppedError, bean4.getStopOrder() > 0);
|
||||
String orderError = "dependent bean must stop before the bean it depends on";
|
||||
assertTrue(orderError, bean2.getStopOrder() < bean1.getStopOrder());
|
||||
assertTrue(orderError, bean3.getStopOrder() < bean2.getStopOrder());
|
||||
assertTrue(orderError, bean4.getStopOrder() < bean2.getStopOrder());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +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.support;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class LifecycleTestBean implements Lifecycle {
|
||||
|
||||
private static int startCounter;
|
||||
|
||||
private static int stopCounter;
|
||||
|
||||
|
||||
private int startOrder;
|
||||
|
||||
private int stopOrder;
|
||||
|
||||
private boolean running;
|
||||
|
||||
|
||||
public int getStartOrder() {
|
||||
return startOrder;
|
||||
}
|
||||
|
||||
public int getStopOrder() {
|
||||
return stopOrder;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return this.running;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.startOrder = ++startCounter;
|
||||
this.running = true;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
this.stopOrder = ++stopCounter;
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<bean id="bean4" class="org.springframework.context.support.LifecycleTestBean" depends-on="bean2"/>
|
||||
|
||||
<bean id="bean3" class="org.springframework.context.support.LifecycleTestBean" depends-on="bean2"/>
|
||||
|
||||
<bean id="bean1" class="org.springframework.context.support.LifecycleTestBean"/>
|
||||
|
||||
<bean id="bean2" class="org.springframework.context.support.LifecycleTestBean" depends-on="bean1"/>
|
||||
|
||||
<bean id="bean2Proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="target" ref="bean2"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user