moving unit tests from .testsuite -> .aop
This commit is contained in:
@@ -1,134 +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.aop.framework;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.aop.SpringProxy;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class AopProxyUtilsTests extends TestCase {
|
||||
|
||||
public void testCompleteProxiedInterfacesWorksWithNull() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(2, completedInterfaces.length);
|
||||
List ifaces = Arrays.asList(completedInterfaces);
|
||||
assertTrue(ifaces.contains(Advised.class));
|
||||
assertTrue(ifaces.contains(SpringProxy.class));
|
||||
}
|
||||
|
||||
public void testCompleteProxiedInterfacesWorksWithNullOpaque() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
as.setOpaque(true);
|
||||
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(1, completedInterfaces.length);
|
||||
}
|
||||
|
||||
public void testCompleteProxiedInterfacesAdvisedNotIncluded() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
as.addInterface(ITestBean.class);
|
||||
as.addInterface(Comparable.class);
|
||||
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(4, completedInterfaces.length);
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List l = Arrays.asList(completedInterfaces);
|
||||
assertTrue(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
public void testCompleteProxiedInterfacesAdvisedIncluded() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
as.addInterface(ITestBean.class);
|
||||
as.addInterface(Comparable.class);
|
||||
as.addInterface(Advised.class);
|
||||
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(4, completedInterfaces.length);
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List l = Arrays.asList(completedInterfaces);
|
||||
assertTrue(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
public void testCompleteProxiedInterfacesAdvisedNotIncludedOpaque() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
as.setOpaque(true);
|
||||
as.addInterface(ITestBean.class);
|
||||
as.addInterface(Comparable.class);
|
||||
Class[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertEquals(3, completedInterfaces.length);
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List l = Arrays.asList(completedInterfaces);
|
||||
assertFalse(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
public void testProxiedUserInterfacesWithSingleInterface() {
|
||||
ProxyFactory pf = new ProxyFactory();
|
||||
pf.setTarget(new TestBean());
|
||||
pf.addInterface(ITestBean.class);
|
||||
Object proxy = pf.getProxy();
|
||||
Class[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
|
||||
assertEquals(1, userInterfaces.length);
|
||||
assertEquals(ITestBean.class, userInterfaces[0]);
|
||||
}
|
||||
|
||||
public void testProxiedUserInterfacesWithMultipleInterfaces() {
|
||||
ProxyFactory pf = new ProxyFactory();
|
||||
pf.setTarget(new TestBean());
|
||||
pf.addInterface(ITestBean.class);
|
||||
pf.addInterface(Comparable.class);
|
||||
Object proxy = pf.getProxy();
|
||||
Class[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
|
||||
assertEquals(2, userInterfaces.length);
|
||||
assertEquals(ITestBean.class, userInterfaces[0]);
|
||||
assertEquals(Comparable.class, userInterfaces[1]);
|
||||
}
|
||||
|
||||
public void testProxiedUserInterfacesWithNoInterface() {
|
||||
Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0],
|
||||
new InvocationHandler() {
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
try {
|
||||
Class[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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.framework;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
* Benchmarks for introductions.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @since 2.0
|
||||
*/
|
||||
public class IntroductionBenchmarkTests extends TestCase {
|
||||
|
||||
private static final int EXPECTED_COMPARE = 13;
|
||||
|
||||
/** Increase this if you want meaningful results! */
|
||||
private static final int INVOCATIONS = 100000;
|
||||
|
||||
|
||||
public void testBenchmarks() {
|
||||
timeManyInvocations();
|
||||
}
|
||||
|
||||
public static class SimpleCounterIntroduction extends DelegatingIntroductionInterceptor implements Counter {
|
||||
|
||||
public int getCount() {
|
||||
return EXPECTED_COMPARE;
|
||||
}
|
||||
}
|
||||
|
||||
public static interface Counter {
|
||||
int getCount();
|
||||
}
|
||||
|
||||
protected long timeManyInvocations() {
|
||||
StopWatch sw = new StopWatch();
|
||||
|
||||
TestBean target = new TestBean();
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
pf.setProxyTargetClass(false);
|
||||
pf.addAdvice(new SimpleCounterIntroduction());
|
||||
ITestBean proxy = (ITestBean) pf.getProxy();
|
||||
|
||||
Counter counter = (Counter) proxy;
|
||||
|
||||
sw.start(INVOCATIONS + " invocations on proxy, not hitting introduction");
|
||||
for (int i = 0; i < INVOCATIONS; i++) {
|
||||
proxy.getAge();
|
||||
}
|
||||
sw.stop();
|
||||
|
||||
sw.start(INVOCATIONS + " invocations on proxy, hitting introduction");
|
||||
for (int i = 0; i < INVOCATIONS; i++) {
|
||||
counter.getCount();
|
||||
}
|
||||
sw.stop();
|
||||
|
||||
sw.start(INVOCATIONS + " invocations on target");
|
||||
for (int i = 0; i < INVOCATIONS; i++) {
|
||||
target.getAge();
|
||||
}
|
||||
sw.stop();
|
||||
|
||||
System.out.println(sw.prettyPrint());
|
||||
return sw.getLastTaskTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.CountingBeforeAdvice;
|
||||
import org.springframework.aop.framework.Lockable;
|
||||
@@ -41,8 +44,9 @@ import org.springframework.transaction.CallCountingTransactionManager;
|
||||
* Tests for auto proxy creation by advisor recognition.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
public class AdvisorAutoProxyCreatorTests {
|
||||
|
||||
private static final String ADVISOR_APC_BEAN_NAME = "aapc";
|
||||
|
||||
@@ -55,6 +59,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
return new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreator.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultExclusionPrefix() throws Exception {
|
||||
DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator) getBeanFactory().getBean(ADVISOR_APC_BEAN_NAME);
|
||||
assertEquals(ADVISOR_APC_BEAN_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR, aapc.getAdvisorBeanNamePrefix());
|
||||
@@ -64,18 +69,21 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
/**
|
||||
* If no pointcuts match (no attrs) there should be proxying.
|
||||
*/
|
||||
@Test
|
||||
public void testNoProxy() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
Object o = bf.getBean("noSetters");
|
||||
assertFalse(AopUtils.isAopProxy(o));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTxIsProxied() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
assertTrue(AopUtils.isAopProxy(test));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegexpApplied() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
@@ -90,6 +98,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
* appear in the chain before "specific" interceptors,
|
||||
* which are sourced from matching advisors
|
||||
*/
|
||||
@Test
|
||||
public void testCommonInterceptorAndAdvisor() throws Exception {
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/advisorAutoProxyCreatorWithCommonInterceptors.xml");
|
||||
ITestBean test1 = (ITestBean) bf.getBean("test1");
|
||||
@@ -119,6 +128,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
* We have custom TargetSourceCreators but there's no match, and
|
||||
* hence no proxying, for this bean
|
||||
*/
|
||||
@Test
|
||||
public void testCustomTargetSourceNoMatch() throws Exception {
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml");
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
@@ -127,6 +137,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
assertEquals("Kerry", test.getSpouse().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPrototypeTargetSource() throws Exception {
|
||||
CountingTestBean.count = 0;
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml");
|
||||
@@ -141,6 +152,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
CountingTestBean.count = 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLazyInitTargetSource() throws Exception {
|
||||
CountingTestBean.count = 0;
|
||||
BeanFactory bf = new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/customTargetSource.xml");
|
||||
@@ -155,6 +167,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
CountingTestBean.count = 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuickTargetSourceCreator() throws Exception {
|
||||
ClassPathXmlApplicationContext bf =
|
||||
new ClassPathXmlApplicationContext("/org/springframework/aop/framework/autoproxy/quickTargetSource.xml");
|
||||
@@ -200,6 +213,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testIntroductionIsProxied() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
Object modifiable = bf.getBean("modifiable1");
|
||||
@@ -209,6 +223,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testTransactionAttributeOnMethod() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
@@ -230,6 +245,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
/**
|
||||
* Should not roll back on servlet exception.
|
||||
*/
|
||||
@Test
|
||||
public void testRollbackRulesOnMethodCauseRollback() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
Rollback rb = (Rollback) bf.getBean("rollback");
|
||||
@@ -255,6 +271,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
assertEquals("Transaction counts match", 1, txMan.rollbacks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRollbackRulesOnMethodPreventRollback() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
Rollback rb = (Rollback) bf.getBean("rollback");
|
||||
@@ -272,6 +289,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
assertEquals("Transaction counts match", 1, txMan.commits);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProgrammaticRollback() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
|
||||
@@ -289,6 +307,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
assertEquals(1, txMan.rollbacks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithOptimizedProxy() throws Exception {
|
||||
BeanFactory beanFactory = new ClassPathXmlApplicationContext("org/springframework/aop/framework/autoproxy/optimizedAutoProxyCreator.xml");
|
||||
|
||||
@@ -311,6 +330,7 @@ public class AdvisorAutoProxyCreatorTests extends TestCase {
|
||||
* The Modifiable behaviour of each instance of TestBean should be distinct.
|
||||
*/
|
||||
/*
|
||||
@Test
|
||||
public void testIntroductionViaPrototype() throws Exception {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
@@ -38,10 +40,12 @@ import org.springframework.context.support.StaticMessageSource;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 09.12.2003
|
||||
*/
|
||||
public class AutoProxyCreatorTests extends TestCase {
|
||||
public class AutoProxyCreatorTests {
|
||||
|
||||
@Test
|
||||
public void testBeanNameAutoProxyCreator() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testInterceptor", TestInterceptor.class);
|
||||
@@ -90,6 +94,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
assertEquals(7, ti.nrOfInvocations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanNameAutoProxyCreatorWithFactoryBeanProxy() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testInterceptor", TestInterceptor.class);
|
||||
@@ -114,7 +119,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
singletonToBeProxied.getName();
|
||||
assertEquals(1, ti.nrOfInvocations);
|
||||
|
||||
FactoryBean factory = (FactoryBean) sac.getBean("&singletonFactoryToBeProxied");
|
||||
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
|
||||
assertTrue(Proxy.isProxyClass(factory.getClass()));
|
||||
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
|
||||
assertFalse(AopUtils.isAopProxy(tb));
|
||||
@@ -123,6 +128,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
assertEquals(3, ti.nrOfInvocations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomAutoProxyCreator() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
|
||||
@@ -150,6 +156,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoProxyCreatorWithFactoryBean() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
|
||||
@@ -159,7 +166,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean factory = (FactoryBean) sac.getBean("&singletonFactoryToBeProxied");
|
||||
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
|
||||
assertTrue(AopUtils.isCglibProxy(factory));
|
||||
|
||||
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
|
||||
@@ -169,6 +176,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
assertEquals(3, tapc.testInterceptor.nrOfInvocations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoProxyCreatorWithFactoryBeanAndPrototype() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class);
|
||||
@@ -182,7 +190,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean prototypeFactory = (FactoryBean) sac.getBean("&prototypeFactoryToBeProxied");
|
||||
FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
|
||||
assertTrue(AopUtils.isCglibProxy(prototypeFactory));
|
||||
TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied");
|
||||
assertTrue(AopUtils.isCglibProxy(tb));
|
||||
@@ -192,6 +200,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
assertEquals(3, tapc.testInterceptor.nrOfInvocations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoProxyCreatorWithFactoryBeanAndProxyObjectOnly() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
|
||||
@@ -206,7 +215,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean factory = (FactoryBean) sac.getBean("&singletonFactoryToBeProxied");
|
||||
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
|
||||
assertFalse(AopUtils.isAopProxy(factory));
|
||||
|
||||
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
|
||||
@@ -222,6 +231,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoProxyCreatorWithFactoryBeanAndProxyFactoryBeanOnly() {
|
||||
StaticApplicationContext sac = new StaticApplicationContext();
|
||||
|
||||
@@ -238,7 +248,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
|
||||
tapc.testInterceptor.nrOfInvocations = 0;
|
||||
|
||||
FactoryBean prototypeFactory = (FactoryBean) sac.getBean("&prototypeFactoryToBeProxied");
|
||||
FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
|
||||
assertTrue(AopUtils.isCglibProxy(prototypeFactory));
|
||||
TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied");
|
||||
assertFalse(AopUtils.isCglibProxy(tb));
|
||||
@@ -249,6 +259,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class TestAutoProxyCreator extends AbstractAutoProxyCreator {
|
||||
|
||||
private boolean proxyFactoryBean = true;
|
||||
@@ -270,7 +281,7 @@ public class AutoProxyCreatorTests extends TestCase {
|
||||
this.proxyObject = proxyObject;
|
||||
}
|
||||
|
||||
protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String name, TargetSource customTargetSource) {
|
||||
protected Object[] getAdvicesAndAdvisorsForBean(Class<?> beanClass, String name, TargetSource customTargetSource) {
|
||||
if (StaticMessageSource.class.equals(beanClass)) {
|
||||
return DO_NOT_PROXY;
|
||||
}
|
||||
|
||||
@@ -16,30 +16,27 @@
|
||||
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class BeanNameAutoProxyCreatorInitTests extends TestCase {
|
||||
public class BeanNameAutoProxyCreatorInitTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testIgnoreAdvisorThatIsCurrentlyCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext("beanNameAutoProxyCreatorInitTests.xml", getClass());
|
||||
TestBean bean = (TestBean) ctx.getBean("bean");
|
||||
bean.setName("foo");
|
||||
assertEquals("foo", bean.getName());
|
||||
try {
|
||||
bean.setName(null);
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
bean.setName(null); // should throw
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.CountingBeforeAdvice;
|
||||
import org.springframework.aop.framework.Lockable;
|
||||
@@ -35,35 +37,41 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class BeanNameAutoProxyCreatorTests extends TestCase {
|
||||
public class BeanNameAutoProxyCreatorTests {
|
||||
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
protected void setUp() throws IOException {
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
// Note that we need an ApplicationContext, not just a BeanFactory,
|
||||
// for post-processing and hence auto-proxying to work.
|
||||
this.beanFactory = new ClassPathXmlApplicationContext("beanNameAutoProxyCreatorTests.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoProxy() {
|
||||
TestBean tb = (TestBean) beanFactory.getBean("noproxy");
|
||||
assertFalse(AopUtils.isAopProxy(tb));
|
||||
assertEquals("noproxy", tb.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdkProxyWithExactNameMatch() {
|
||||
ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk");
|
||||
jdkAssertions(tb, 1);
|
||||
assertEquals("onlyJdk", tb.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdkProxyWithDoubleProxying() {
|
||||
ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk");
|
||||
jdkAssertions(tb, 2);
|
||||
assertEquals("doubleJdk", tb.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdkIntroduction() {
|
||||
ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
|
||||
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
|
||||
@@ -102,6 +110,7 @@ public class BeanNameAutoProxyCreatorTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
|
||||
ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
|
||||
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
|
||||
@@ -139,18 +148,21 @@ public class BeanNameAutoProxyCreatorTests extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdkProxyWithWildcardMatch() {
|
||||
ITestBean tb = (ITestBean) beanFactory.getBean("jdk1");
|
||||
jdkAssertions(tb, 1);
|
||||
assertEquals("jdk1", tb.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCglibProxyWithWildcardMatch() {
|
||||
TestBean tb = (TestBean) beanFactory.getBean("cglib1");
|
||||
cglibAssertions(tb);
|
||||
assertEquals("cglib1", tb.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithFrozenProxy() {
|
||||
ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
|
||||
assertTrue(((Advised)testBean).isFrozen());
|
||||
|
||||
Reference in New Issue
Block a user