moving unit tests from .testsuite -> .aop
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@397 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
parent
559d321b50
commit
1867815ac5
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
* 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.aop.interceptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean that changes state on a business invocation, so that
|
||||||
|
* we can check whether it's been invoked
|
||||||
|
* @author Rod Johnson
|
||||||
|
*/
|
||||||
|
public class SideEffectBean {
|
||||||
|
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doWork() {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -16,20 +16,23 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
|
||||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|
||||||
import org.springframework.beans.ITestBean;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
import org.springframework.beans.ITestBean;
|
||||||
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
|
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Chris Beams
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class CommonsPoolTargetSourceProxyTests extends TestCase {
|
public class CommonsPoolTargetSourceProxyTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testProxy() throws Exception {
|
public void testProxy() throws Exception {
|
||||||
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
|
||||||
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
|
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
|
||||||
|
|
@ -16,8 +16,11 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
import org.springframework.aop.interceptor.SerializableNopInterceptor;
|
import org.springframework.aop.interceptor.SerializableNopInterceptor;
|
||||||
|
|
@ -31,22 +34,25 @@ import org.springframework.util.SerializationTestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class HotSwappableTargetSourceTests extends TestCase {
|
public class HotSwappableTargetSourceTests {
|
||||||
|
|
||||||
/** Initial count value set in bean factory XML */
|
/** Initial count value set in bean factory XML */
|
||||||
private static final int INITIAL_COUNT = 10;
|
private static final int INITIAL_COUNT = 10;
|
||||||
|
|
||||||
private XmlBeanFactory beanFactory;
|
private XmlBeanFactory beanFactory;
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
this.beanFactory = new XmlBeanFactory(new ClassPathResource("hotSwapTests.xml", getClass()));
|
this.beanFactory = new XmlBeanFactory(new ClassPathResource("hotSwapTests.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We must simulate container shutdown, which should clear threads.
|
* We must simulate container shutdown, which should clear threads.
|
||||||
*/
|
*/
|
||||||
protected void tearDown() {
|
@After
|
||||||
|
public void tearDown() {
|
||||||
// Will call pool.close()
|
// Will call pool.close()
|
||||||
this.beanFactory.destroySingletons();
|
this.beanFactory.destroySingletons();
|
||||||
}
|
}
|
||||||
|
|
@ -55,8 +61,8 @@ public class HotSwappableTargetSourceTests extends TestCase {
|
||||||
* Check it works like a normal invoker
|
* Check it works like a normal invoker
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testBasicFunctionality() {
|
public void testBasicFunctionality() {
|
||||||
SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
|
|
||||||
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||||
assertEquals(INITIAL_COUNT, proxied.getCount() );
|
assertEquals(INITIAL_COUNT, proxied.getCount() );
|
||||||
proxied.doWork();
|
proxied.doWork();
|
||||||
|
|
@ -67,12 +73,12 @@ public class HotSwappableTargetSourceTests extends TestCase {
|
||||||
assertEquals(INITIAL_COUNT + 2, proxied.getCount() );
|
assertEquals(INITIAL_COUNT + 2, proxied.getCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testValidSwaps() {
|
public void testValidSwaps() {
|
||||||
SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
|
SideEffectBean target1 = (SideEffectBean) beanFactory.getBean("target1");
|
||||||
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
|
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
|
||||||
|
|
||||||
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||||
// assertEquals(target1, ((Advised) proxied).getTarget());
|
|
||||||
assertEquals(target1.getCount(), proxied.getCount() );
|
assertEquals(target1.getCount(), proxied.getCount() );
|
||||||
proxied.doWork();
|
proxied.doWork();
|
||||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount() );
|
assertEquals(INITIAL_COUNT + 1, proxied.getCount() );
|
||||||
|
|
@ -117,6 +123,7 @@ public class HotSwappableTargetSourceTests extends TestCase {
|
||||||
return aopex;
|
return aopex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRejectsSwapToNull() {
|
public void testRejectsSwapToNull() {
|
||||||
IllegalArgumentException ex = testRejectsSwapToInvalidValue(null);
|
IllegalArgumentException ex = testRejectsSwapToInvalidValue(null);
|
||||||
assertTrue(ex.getMessage().indexOf("null") != -1);
|
assertTrue(ex.getMessage().indexOf("null") != -1);
|
||||||
|
|
@ -126,6 +133,7 @@ public class HotSwappableTargetSourceTests extends TestCase {
|
||||||
// how to decide what's valid?
|
// how to decide what's valid?
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerialization() throws Exception {
|
public void testSerialization() throws Exception {
|
||||||
SerializablePerson sp1 = new SerializablePerson();
|
SerializablePerson sp1 = new SerializablePerson();
|
||||||
sp1.setName("Tony");
|
sp1.setName("Tony");
|
||||||
|
|
@ -16,23 +16,26 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.TargetSource;
|
import org.springframework.aop.TargetSource;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class LazyCreationTargetSourceTests extends TestCase {
|
public class LazyCreationTargetSourceTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCreateLazy() {
|
public void testCreateLazy() {
|
||||||
TargetSource targetSource = new AbstractLazyCreationTargetSource() {
|
TargetSource targetSource = new AbstractLazyCreationTargetSource() {
|
||||||
protected Object createObject() {
|
protected Object createObject() {
|
||||||
return new InitCountingBean();
|
return new InitCountingBean();
|
||||||
}
|
}
|
||||||
public Class getTargetClass() {
|
public Class<?> getTargetClass() {
|
||||||
return InitCountingBean.class;
|
return InitCountingBean.class;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -16,10 +16,11 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
@ -27,10 +28,12 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Chris Beams
|
||||||
* @since 07.01.2005
|
* @since 07.01.2005
|
||||||
*/
|
*/
|
||||||
public class LazyInitTargetSourceTests extends TestCase {
|
public class LazyInitTargetSourceTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLazyInitSingletonTargetSource() {
|
public void testLazyInitSingletonTargetSource() {
|
||||||
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("lazyInitSingletonTests.xml", getClass()));
|
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("lazyInitSingletonTests.xml", getClass()));
|
||||||
bf.preInstantiateSingletons();
|
bf.preInstantiateSingletons();
|
||||||
|
|
@ -41,6 +44,7 @@ public class LazyInitTargetSourceTests extends TestCase {
|
||||||
assertTrue(bf.containsSingleton("target"));
|
assertTrue(bf.containsSingleton("target"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testCustomLazyInitSingletonTargetSource() {
|
public void testCustomLazyInitSingletonTargetSource() {
|
||||||
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("customLazyInitTarget.xml", getClass()));
|
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("customLazyInitTarget.xml", getClass()));
|
||||||
bf.preInstantiateSingletons();
|
bf.preInstantiateSingletons();
|
||||||
|
|
@ -51,16 +55,17 @@ public class LazyInitTargetSourceTests extends TestCase {
|
||||||
assertTrue(bf.containsSingleton("target"));
|
assertTrue(bf.containsSingleton("target"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testLazyInitFactoryBeanTargetSource() {
|
public void testLazyInitFactoryBeanTargetSource() {
|
||||||
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("lazyInitFactoryBean.xml", getClass()));
|
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("lazyInitFactoryBean.xml", getClass()));
|
||||||
bf.preInstantiateSingletons();
|
bf.preInstantiateSingletons();
|
||||||
|
|
||||||
Set set1 = (Set) bf.getBean("proxy1");
|
Set<?> set1 = (Set<?>) bf.getBean("proxy1");
|
||||||
assertFalse(bf.containsSingleton("target1"));
|
assertFalse(bf.containsSingleton("target1"));
|
||||||
assertTrue(set1.contains("10"));
|
assertTrue(set1.contains("10"));
|
||||||
assertTrue(bf.containsSingleton("target1"));
|
assertTrue(bf.containsSingleton("target1"));
|
||||||
|
|
||||||
Set set2 = (Set) bf.getBean("proxy2");
|
Set<?> set2 = (Set<?>) bf.getBean("proxy2");
|
||||||
assertFalse(bf.containsSingleton("target2"));
|
assertFalse(bf.containsSingleton("target2"));
|
||||||
assertTrue(set2.contains("20"));
|
assertTrue(set2.contains("20"));
|
||||||
assertTrue(bf.containsSingleton("target2"));
|
assertTrue(bf.containsSingleton("target2"));
|
||||||
|
|
@ -16,8 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.TargetSource;
|
import org.springframework.aop.TargetSource;
|
||||||
import org.springframework.beans.MutablePropertyValues;
|
import org.springframework.beans.MutablePropertyValues;
|
||||||
import org.springframework.beans.SerializablePerson;
|
import org.springframework.beans.SerializablePerson;
|
||||||
|
|
@ -31,9 +32,11 @@ import org.springframework.util.SerializationTestUtils;
|
||||||
* and not subclasses.
|
* and not subclasses.
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class PrototypeBasedTargetSourceTests extends TestCase {
|
public class PrototypeBasedTargetSourceTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSerializability() throws Exception {
|
public void testSerializability() throws Exception {
|
||||||
MutablePropertyValues tsPvs = new MutablePropertyValues();
|
MutablePropertyValues tsPvs = new MutablePropertyValues();
|
||||||
tsPvs.addPropertyValue("targetBeanName", "person");
|
tsPvs.addPropertyValue("targetBeanName", "person");
|
||||||
|
|
@ -16,8 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.interceptor.SideEffectBean;
|
import org.springframework.aop.interceptor.SideEffectBean;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
|
|
@ -25,15 +27,17 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class PrototypeTargetSourceTests extends TestCase {
|
public class PrototypeTargetSourceTests {
|
||||||
|
|
||||||
/** Initial count value set in bean factory XML */
|
/** Initial count value set in bean factory XML */
|
||||||
private static final int INITIAL_COUNT = 10;
|
private static final int INITIAL_COUNT = 10;
|
||||||
|
|
||||||
private BeanFactory beanFactory;
|
private BeanFactory beanFactory;
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
this.beanFactory = new XmlBeanFactory(new ClassPathResource("prototypeTests.xml", getClass()));
|
this.beanFactory = new XmlBeanFactory(new ClassPathResource("prototypeTests.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,6 +46,7 @@ public class PrototypeTargetSourceTests extends TestCase {
|
||||||
* in no change to visible state, as a new instance is used.
|
* in no change to visible state, as a new instance is used.
|
||||||
* With the singleton, there will be change.
|
* With the singleton, there will be change.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testPrototypeAndSingletonBehaveDifferently() {
|
public void testPrototypeAndSingletonBehaveDifferently() {
|
||||||
SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
|
SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
|
||||||
assertEquals(INITIAL_COUNT, singleton.getCount() );
|
assertEquals(INITIAL_COUNT, singleton.getCount() );
|
||||||
|
|
@ -16,8 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.interceptor.SideEffectBean;
|
import org.springframework.aop.interceptor.SideEffectBean;
|
||||||
import org.springframework.beans.ITestBean;
|
import org.springframework.beans.ITestBean;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
|
|
@ -25,15 +27,17 @@ import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class ThreadLocalTargetSourceTests extends TestCase {
|
public class ThreadLocalTargetSourceTests {
|
||||||
|
|
||||||
/** Initial count value set in bean factory XML */
|
/** Initial count value set in bean factory XML */
|
||||||
private static final int INITIAL_COUNT = 10;
|
private static final int INITIAL_COUNT = 10;
|
||||||
|
|
||||||
private XmlBeanFactory beanFactory;
|
private XmlBeanFactory beanFactory;
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
this.beanFactory = new XmlBeanFactory(new ClassPathResource("threadLocalTests.xml", getClass()));
|
this.beanFactory = new XmlBeanFactory(new ClassPathResource("threadLocalTests.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,6 +53,7 @@ public class ThreadLocalTargetSourceTests extends TestCase {
|
||||||
* managing objects of different types without them interfering
|
* managing objects of different types without them interfering
|
||||||
* with one another.
|
* with one another.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testUseDifferentManagedInstancesInSameThread() {
|
public void testUseDifferentManagedInstancesInSameThread() {
|
||||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||||
|
|
@ -60,6 +65,7 @@ public class ThreadLocalTargetSourceTests extends TestCase {
|
||||||
assertEquals("Kerry", test.getSpouse().getName());
|
assertEquals("Kerry", test.getSpouse().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReuseInSameThread() {
|
public void testReuseInSameThread() {
|
||||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||||
|
|
@ -73,6 +79,7 @@ public class ThreadLocalTargetSourceTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Relies on introduction.
|
* Relies on introduction.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testCanGetStatsViaMixin() {
|
public void testCanGetStatsViaMixin() {
|
||||||
ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment");
|
ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment");
|
||||||
// +1 because creating target for stats call counts
|
// +1 because creating target for stats call counts
|
||||||
|
|
@ -90,6 +97,7 @@ public class ThreadLocalTargetSourceTests extends TestCase {
|
||||||
assertEquals(1, stats.getObjectCount());
|
assertEquals(1, stats.getObjectCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNewThreadHasOwnInstance() throws InterruptedException {
|
public void testNewThreadHasOwnInstance() throws InterruptedException {
|
||||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||||
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
assertEquals(INITIAL_COUNT, apartment.getCount() );
|
||||||
|
|
@ -128,11 +136,12 @@ public class ThreadLocalTargetSourceTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE
|
* Test for SPR-1442. Destroyed target should re-associated with thread and not throw NPE
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testReuseDestroyedTarget() {
|
public void testReuseDestroyedTarget() {
|
||||||
ThreadLocalTargetSource source = (ThreadLocalTargetSource)this.beanFactory.getBean("threadLocalTs");
|
ThreadLocalTargetSource source = (ThreadLocalTargetSource)this.beanFactory.getBean("threadLocalTs");
|
||||||
|
|
||||||
// try first time
|
// try first time
|
||||||
Object o = source.getTarget();
|
source.getTarget();
|
||||||
source.destroy();
|
source.destroy();
|
||||||
|
|
||||||
// try second time
|
// try second time
|
||||||
|
|
@ -16,16 +16,20 @@
|
||||||
|
|
||||||
package org.springframework.aop.target.dynamic;
|
package org.springframework.aop.target.dynamic;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class RefreshableTargetSourceTests extends TestCase {
|
public class RefreshableTargetSourceTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test what happens when checking for refresh but not refreshing object.
|
* Test what happens when checking for refresh but not refreshing object.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testRefreshCheckWithNonRefresh() throws Exception {
|
public void testRefreshCheckWithNonRefresh() throws Exception {
|
||||||
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource();
|
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource();
|
||||||
ts.setRefreshCheckDelay(0);
|
ts.setRefreshCheckDelay(0);
|
||||||
|
|
@ -41,6 +45,7 @@ public class RefreshableTargetSourceTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Test what happens when checking for refresh and refresh occurs.
|
* Test what happens when checking for refresh and refresh occurs.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testRefreshCheckWithRefresh() throws Exception {
|
public void testRefreshCheckWithRefresh() throws Exception {
|
||||||
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
|
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
|
||||||
ts.setRefreshCheckDelay(0);
|
ts.setRefreshCheckDelay(0);
|
||||||
|
|
@ -56,6 +61,7 @@ public class RefreshableTargetSourceTests extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Test what happens when no refresh occurs.
|
* Test what happens when no refresh occurs.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testWithNoRefreshCheck() throws Exception {
|
public void testWithNoRefreshCheck() throws Exception {
|
||||||
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
|
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
|
||||||
ts.setRefreshCheckDelay(-1);
|
ts.setRefreshCheckDelay(-1);
|
||||||
|
|
@ -67,6 +73,7 @@ public class RefreshableTargetSourceTests extends TestCase {
|
||||||
assertSame("Objects should be the same - refresh check delay not elapsed", a, b);
|
assertSame("Objects should be the same - refresh check delay not elapsed", a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testRefreshOverTime() throws Exception {
|
public void testRefreshOverTime() throws Exception {
|
||||||
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
|
CountingRefreshableTargetSource ts = new CountingRefreshableTargetSource(true);
|
||||||
ts.setRefreshCheckDelay(100);
|
ts.setRefreshCheckDelay(100);
|
||||||
|
|
@ -16,11 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.interceptor.SideEffectBean;
|
import org.springframework.aop.interceptor.SideEffectBean;
|
||||||
import org.springframework.beans.Person;
|
import org.springframework.beans.Person;
|
||||||
|
|
@ -37,8 +40,9 @@ import org.springframework.util.SerializationTestUtils;
|
||||||
*
|
*
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Chris Beams
|
||||||
*/
|
*/
|
||||||
public class CommonsPoolTargetSourceTests extends TestCase {
|
public class CommonsPoolTargetSourceTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initial count value set in bean factory XML
|
* Initial count value set in bean factory XML
|
||||||
|
|
@ -47,14 +51,16 @@ public class CommonsPoolTargetSourceTests extends TestCase {
|
||||||
|
|
||||||
private XmlBeanFactory beanFactory;
|
private XmlBeanFactory beanFactory;
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
this.beanFactory = new XmlBeanFactory(new ClassPathResource("commonsPoolTests.xml", getClass()));
|
this.beanFactory = new XmlBeanFactory(new ClassPathResource("commonsPoolTests.xml", getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We must simulate container shutdown, which should clear threads.
|
* We must simulate container shutdown, which should clear threads.
|
||||||
*/
|
*/
|
||||||
protected void tearDown() {
|
@After
|
||||||
|
public void tearDown() {
|
||||||
// Will call pool.close()
|
// Will call pool.close()
|
||||||
this.beanFactory.destroySingletons();
|
this.beanFactory.destroySingletons();
|
||||||
}
|
}
|
||||||
|
|
@ -72,14 +78,17 @@ public class CommonsPoolTargetSourceTests extends TestCase {
|
||||||
//assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
//assertEquals(INITIAL_COUNT + 1, apartment.getCount() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFunctionality() {
|
public void testFunctionality() {
|
||||||
testFunctionality("pooled");
|
testFunctionality("pooled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFunctionalityWithNoInterceptors() {
|
public void testFunctionalityWithNoInterceptors() {
|
||||||
testFunctionality("pooledNoInterceptors");
|
testFunctionality("pooledNoInterceptors");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testConfigMixin() {
|
public void testConfigMixin() {
|
||||||
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean("pooledWithMixin");
|
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean("pooledWithMixin");
|
||||||
assertEquals(INITIAL_COUNT, pooled.getCount());
|
assertEquals(INITIAL_COUNT, pooled.getCount());
|
||||||
|
|
@ -94,6 +103,7 @@ public class CommonsPoolTargetSourceTests extends TestCase {
|
||||||
assertEquals(25, conf.getMaxSize());
|
assertEquals(25, conf.getMaxSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetSourceSerializableWithoutConfigMixin() throws Exception {
|
public void testTargetSourceSerializableWithoutConfigMixin() throws Exception {
|
||||||
CommonsPoolTargetSource cpts = (CommonsPoolTargetSource) beanFactory.getBean("personPoolTargetSource");
|
CommonsPoolTargetSource cpts = (CommonsPoolTargetSource) beanFactory.getBean("personPoolTargetSource");
|
||||||
|
|
||||||
|
|
@ -102,6 +112,7 @@ public class CommonsPoolTargetSourceTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testProxySerializableWithoutConfigMixin() throws Exception {
|
public void testProxySerializableWithoutConfigMixin() throws Exception {
|
||||||
Person pooled = (Person) beanFactory.getBean("pooledPerson");
|
Person pooled = (Person) beanFactory.getBean("pooledPerson");
|
||||||
|
|
||||||
|
|
@ -115,6 +126,7 @@ public class CommonsPoolTargetSourceTests extends TestCase {
|
||||||
assertEquals(25, serialized.getAge());
|
assertEquals(25, serialized.getAge());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHitMaxSize() throws Exception {
|
public void testHitMaxSize() throws Exception {
|
||||||
int maxSize = 10;
|
int maxSize = 10;
|
||||||
|
|
||||||
|
|
@ -150,6 +162,7 @@ public class CommonsPoolTargetSourceTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHitMaxSizeLoadedFromContext() throws Exception {
|
public void testHitMaxSizeLoadedFromContext() throws Exception {
|
||||||
Advised person = (Advised) beanFactory.getBean("maxSizePooledPerson");
|
Advised person = (Advised) beanFactory.getBean("maxSizePooledPerson");
|
||||||
CommonsPoolTargetSource targetSource = (CommonsPoolTargetSource) person.getTargetSource();
|
CommonsPoolTargetSource targetSource = (CommonsPoolTargetSource) person.getTargetSource();
|
||||||
|
|
@ -182,6 +195,7 @@ public class CommonsPoolTargetSourceTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetWhenExhaustedAction() {
|
public void testSetWhenExhaustedAction() {
|
||||||
CommonsPoolTargetSource targetSource = new CommonsPoolTargetSource();
|
CommonsPoolTargetSource targetSource = new CommonsPoolTargetSource();
|
||||||
targetSource.setWhenExhaustedActionName("WHEN_EXHAUSTED_BLOCK");
|
targetSource.setWhenExhaustedActionName("WHEN_EXHAUSTED_BLOCK");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue