+ refactoring .testsuite .aop.aspectj tests in preparation for migration to .context
+ updated all ivy.xml files to depend on AspectJ 1.6.2
This commit is contained in:
parent
5b9da399c6
commit
d7a9d7c8e6
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
<dependencies>
|
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="optional, aspectj->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.2.RELEASE" conf="optional, aspectj->compile"/>
|
||||
<dependency org="org.springframework" name="org.springframework.beans" rev="latest.integration" conf="compile->compile"/>
|
||||
<dependency org="org.springframework" name="org.springframework.transaction" rev="latest.integration" conf="optional, tx->compile"/>
|
||||
</dependencies>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
package org.springframework.aop.aspectj;
|
||||
/*
|
||||
* Copyright 2002-2006 the original author or authors.
|
||||
*
|
||||
|
|
@ -15,6 +14,8 @@ package org.springframework.aop.aspectj;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.aop.aspectj;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.collections" rev="3.2.0" conf="optional, commons-collections->compile"/>
|
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile->compile"/>
|
||||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="optional, log4j->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="optional, aspectj->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.2.RELEASE" conf="optional, aspectj->compile"/>
|
||||
<!-- These should be replaced with the internal repackaging of ASM -->
|
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm" rev="2.2.3" conf="optional->compile"/>
|
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="2.2.3" conf="optional->compile"/>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.dbcp" rev="1.2.2.osgi" conf="compile->runtime"/>
|
||||
<dependency org="org.apache.log4j" name="com.springsource.org.apache.log4j" rev="1.2.15" conf="compile->runtime"/>
|
||||
<dependency org="org.apache.taglibs" name="com.springsource.org.apache.taglibs.standard" rev="1.1.2" conf="compile->runtime"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="compile->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.2.RELEASE" conf="compile->compile"/>
|
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm" rev="2.2.3" conf="compile->compile" />
|
||||
<dependency org="org.objectweb.asm" name="com.springsource.org.objectweb.asm.commons" rev="2.2.3" conf="compile->compile" />
|
||||
<dependency org="org.springframework" name="org.springframework.orm" rev="latest.integration" conf="compile->compile"/>
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
<dependency org="org.junit" name="com.springsource.org.junit" rev="4.5.0" conf="optional->compile"/>
|
||||
<dependency org="org.apache.commons" name="com.springsource.org.apache.commons.logging" rev="1.1.1" conf="compile->compile"/>
|
||||
<dependency org="org.apache.taglibs" name="com.springsource.org.apache.taglibs.standard" rev="1.1.2" conf="optional->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="optional->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.2.RELEASE" conf="optional->compile"/>
|
||||
<dependency org="org.testng" name="com.springsource.org.testng" rev="5.8.0" conf="optional->compile"/>
|
||||
<dependency org="org.springframework" name="org.springframework.beans" rev="latest.integration" conf="optional->compile"/>
|
||||
<dependency org="org.springframework" name="org.springframework.context" rev="latest.integration" conf="optional->compile"/>
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
<dependency org="org.apache.tiles" name="com.springsource.org.apache.tiles.jsp" rev="2.0.5" conf="test->compile"/>
|
||||
<dependency org="org.apache.velocity" name="com.springsource.org.apache.velocity" rev="1.5.0" conf="test->compile"/>
|
||||
<dependency org="org.apache.velocity" name="com.springsource.org.apache.velocity.tools.view" rev="1.4.0" conf="test->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.5.4" conf="test->compile"/>
|
||||
<dependency org="org.aspectj" name="com.springsource.org.aspectj.weaver" rev="1.6.2.RELEASE" conf="test->compile"/>
|
||||
<dependency org="org.codehaus.groovy" name="com.springsource.org.codehaus.groovy" rev="1.5.1" conf="test->compile"/>
|
||||
<dependency org="org.dom4j" name="com.springsource.org.dom4j" rev="1.6.1" conf="test->compile"/>
|
||||
<dependency org="org.easymock" name="com.springsource.org.easymock" rev="2.3.0" conf="test->compile"/>
|
||||
|
|
|
|||
|
|
@ -1,41 +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.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
@Aspect
|
||||
public class AdviceUsingThisJoinPoint {
|
||||
|
||||
private String lastEntry = "";
|
||||
|
||||
public String getLastMethodEntered() {
|
||||
return this.lastEntry;
|
||||
}
|
||||
|
||||
@Pointcut("execution(* *(..))")
|
||||
public void methodExecution() {}
|
||||
|
||||
@Before("methodExecution()")
|
||||
public void entryTrace(JoinPoint jp) {
|
||||
this.lastEntry = jp.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +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.aop.aspectj.autoproxy;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface AnnotatedTestBean {
|
||||
|
||||
String doThis();
|
||||
|
||||
String doThat();
|
||||
|
||||
String doTheOther();
|
||||
|
||||
String[] doArray();
|
||||
|
||||
}
|
||||
|
|
@ -1,48 +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.aop.aspectj.autoproxy;
|
||||
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @since 2.0
|
||||
*/
|
||||
@Transactional
|
||||
public class AnnotatedTestBeanImpl implements AnnotatedTestBean {
|
||||
|
||||
@TestAnnotation("this value")
|
||||
public String doThis() {
|
||||
return "doThis";
|
||||
}
|
||||
|
||||
@TestAnnotation("that value")
|
||||
public String doThat() {
|
||||
return "doThat";
|
||||
}
|
||||
|
||||
@TestAnnotation("array value")
|
||||
public String[] doArray() {
|
||||
return new String[] {"doThis", "doThat"};
|
||||
}
|
||||
|
||||
// not annotated
|
||||
public String doTheOther() {
|
||||
return "doTheOther";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,30 +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.aop.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
*/
|
||||
public class AnnotationBindingTestAspect {
|
||||
|
||||
public String doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnnotation) throws Throwable {
|
||||
return testAnnotation.value();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,29 +16,35 @@
|
|||
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AnnotationBindingTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public final class AnnotationBindingTests {
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "around-advice-tests.xml";
|
||||
}
|
||||
|
||||
public void setTestBean(AnnotatedTestBean testBean) {
|
||||
this.testBean = testBean;
|
||||
@Before
|
||||
public void setUp() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
assertEquals("this value", testBean.doThis());
|
||||
assertEquals("that value", testBean.doThat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMatchingWithoutAnnotationPresent() {
|
||||
assertEquals("doTheOther", testBean.doTheOther());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<aop:advisor advice-ref="testInterceptor" pointcut-ref="myPointcut"/>
|
||||
</aop:config>
|
||||
|
||||
<bean id="testInterceptor" class="org.springframework.aop.aspectj.autoproxy.AnnotationPointcutTests$TestMethodInterceptor"/>
|
||||
<bean id="testInterceptor" class="org.springframework.aop.aspectj.autoproxy.TestMethodInterceptor"/>
|
||||
|
||||
<bean id="myPointcut" class="org.springframework.aop.support.annotation.AnnotationMatchingPointcut" factory-method="forMethodAnnotation">
|
||||
<constructor-arg value="org.springframework.aop.aspectj.autoproxy.TestAnnotation"/>
|
||||
|
|
@ -16,41 +16,47 @@
|
|||
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AnnotationPointcutTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public final class AnnotationPointcutTests {
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "annotationPointcut.xml";
|
||||
}
|
||||
|
||||
public void setTestBean(AnnotatedTestBean testBean) {
|
||||
this.testBean = testBean;
|
||||
@Before
|
||||
public void setUp() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
assertEquals("this value", testBean.doThis());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMatchingWithoutAnnotationPresent() {
|
||||
assertEquals("doTheOther", testBean.doTheOther());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class TestMethodInterceptor implements MethodInterceptor {
|
||||
|
||||
class TestMethodInterceptor implements MethodInterceptor {
|
||||
|
||||
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
|
||||
return "this value";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,5 +16,5 @@
|
|||
<bean id="testBean" class="org.springframework.beans.TestBean" />
|
||||
|
||||
<bean id="interfaceExtendingAspect"
|
||||
class="org.springframework.aop.aspectj.autoproxy.AspectImplementingInterfaceTests$InterfaceExtendingAspect"/>
|
||||
class="org.springframework.aop.aspectj.autoproxy.InterfaceExtendingAspect"/>
|
||||
</beans>
|
||||
|
|
@ -16,47 +16,47 @@
|
|||
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Test for ensuring the aspects aren't advised. See SPR-3893 for more details.
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectImplementingInterfaceTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
protected ITestBean testBean;
|
||||
protected AnInterface interfaceExtendingAspect;
|
||||
|
||||
public AspectImplementingInterfaceTests() {
|
||||
setPopulateProtectedVariables(true);
|
||||
}
|
||||
|
||||
protected String getConfigPath() {
|
||||
return "aspect-implementing-interface-tests.xml";
|
||||
}
|
||||
|
||||
protected void onSetUp() throws Exception {
|
||||
super.onSetUp();
|
||||
}
|
||||
public final class AspectImplementingInterfaceTests {
|
||||
|
||||
@Test
|
||||
public void testProxyCreation() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
ITestBean testBean = (ITestBean) ctx.getBean("testBean");
|
||||
AnInterface interfaceExtendingAspect = (AnInterface) ctx.getBean("interfaceExtendingAspect");
|
||||
|
||||
assertTrue(testBean instanceof Advised);
|
||||
assertFalse(interfaceExtendingAspect instanceof Advised);
|
||||
}
|
||||
|
||||
public static interface AnInterface {
|
||||
public void interfaceMethod();
|
||||
}
|
||||
}
|
||||
|
||||
public static class InterfaceExtendingAspect implements AnInterface {
|
||||
|
||||
interface AnInterface {
|
||||
public void interfaceMethod();
|
||||
}
|
||||
|
||||
|
||||
class InterfaceExtendingAspect implements AnInterface {
|
||||
public void increment(ProceedingJoinPoint pjp) throws Throwable {
|
||||
pjp.proceed();
|
||||
}
|
||||
|
||||
public void interfaceMethod() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,26 +16,26 @@
|
|||
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
|
||||
public AspectJAutoProxyCreatorAndLazyInitTargetSourceTests() {
|
||||
setAutowireMode(AUTOWIRE_BY_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "lazy.xml";
|
||||
}
|
||||
public final class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
|
||||
|
||||
@Test
|
||||
public void testAdrian() {
|
||||
ITestBean adrian = (ITestBean) applicationContext.getBean("adrian");
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
ITestBean adrian = (ITestBean) ctx.getBean("adrian");
|
||||
assertEquals(0, LazyTestBean.instantiations);
|
||||
assertNotNull(adrian);
|
||||
adrian.getAge();
|
||||
|
|
@ -44,3 +44,14 @@ public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests extends Abstrac
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class LazyTestBean extends TestBean {
|
||||
|
||||
public static int instantiations;
|
||||
|
||||
public LazyTestBean() {
|
||||
++instantiations;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,27 +15,36 @@
|
|||
*/
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
|
||||
import org.springframework.aop.aspectj.annotation.AspectMetadata;
|
||||
import org.springframework.aop.config.AopConfigUtils;
|
||||
import org.springframework.aop.framework.ProxyConfig;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
|
||||
import org.springframework.beans.INestedTestBean;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.NestedTestBean;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
|
|
@ -43,7 +52,10 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
|||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
/**
|
||||
|
|
@ -54,14 +66,13 @@ import org.springframework.util.StopWatch;
|
|||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AspectJAutoProxyCreatorTests {
|
||||
public final class AspectJAutoProxyCreatorTests {
|
||||
|
||||
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
|
||||
|
||||
@Test
|
||||
public void testAspectsAreApplied() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspects.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("aspects.xml");
|
||||
ITestBean tb = (ITestBean) bf.getBean("adrian");
|
||||
assertEquals(68, tb.getAge());
|
||||
MethodInvokingFactoryBean factoryBean = (MethodInvokingFactoryBean) bf.getBean("&factoryBean");
|
||||
|
|
@ -71,8 +82,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testMultipleAspectsWithParameterApplied() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspects.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("aspects.xml");
|
||||
ITestBean tb = (ITestBean) bf.getBean("adrian");
|
||||
tb.setAge(10);
|
||||
assertEquals(20, tb.getAge());
|
||||
|
|
@ -80,18 +90,16 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testAspectsAreAppliedInDefinedOrder() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsWithOrdering.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("aspectsWithOrdering.xml");
|
||||
ITestBean tb = (ITestBean) bf.getBean("adrian");
|
||||
assertEquals(71, tb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAspectsAndAdvisorAreApplied() {
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml");
|
||||
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
|
||||
ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian");
|
||||
testAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
|
||||
doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -100,14 +108,13 @@ public class AspectJAutoProxyCreatorTests {
|
|||
// Skip this test: Trace logging blows the time limit.
|
||||
return;
|
||||
}
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml");
|
||||
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start("prototype");
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2");
|
||||
if (i < 10) {
|
||||
testAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
|
||||
doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
|
||||
}
|
||||
}
|
||||
sw.stop();
|
||||
|
|
@ -121,8 +128,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
// Skip this test: Trace logging blows the time limit.
|
||||
return;
|
||||
}
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml");
|
||||
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start("prototype");
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
|
|
@ -144,7 +150,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
}
|
||||
GenericApplicationContext ac = new GenericApplicationContext();
|
||||
new XmlBeanDefinitionReader(ac).loadBeanDefinitions(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml");
|
||||
new ClassPathResource(qName("aspectsPlusAdvisor.xml"), getClass()));
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
ac.registerBeanDefinition("singleton" + i, new RootBeanDefinition(NestedTestBean.class));
|
||||
}
|
||||
|
|
@ -158,8 +164,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testAspectsAndAdvisorAreAppliedEvenIfComingFromParentFactory() {
|
||||
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsPlusAdvisor.xml");
|
||||
ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
|
||||
GenericApplicationContext childAc = new GenericApplicationContext(ac);
|
||||
// Create a child factory with a bean that should be weaved
|
||||
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
|
||||
|
|
@ -173,10 +178,10 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
ITestBean beanFromChildContextThatShouldBeWeaved = (ITestBean) childAc.getBean("adrian2");
|
||||
//testAspectsAndAdvisorAreApplied(childAc, (ITestBean) ac.getBean("adrian"));
|
||||
testAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved);
|
||||
doTestAspectsAndAdvisorAreApplied(childAc, beanFromChildContextThatShouldBeWeaved);
|
||||
}
|
||||
|
||||
protected void testAspectsAndAdvisorAreApplied(ApplicationContext ac, ITestBean shouldBeWeaved) {
|
||||
protected void doTestAspectsAndAdvisorAreApplied(ApplicationContext ac, ITestBean shouldBeWeaved) {
|
||||
TestBeanAdvisor tba = (TestBeanAdvisor) ac.getBean("advisor");
|
||||
|
||||
MultiplyReturnValue mrv = (MultiplyReturnValue) ac.getBean("aspect");
|
||||
|
|
@ -195,8 +200,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testPerThisAspect() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/perthis.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("perthis.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
assertTrue(AopUtils.isAopProxy(adrian1));
|
||||
|
|
@ -216,8 +220,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testPerTargetAspect() throws SecurityException, NoSuchMethodException {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/pertarget.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("pertarget.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
assertTrue(AopUtils.isAopProxy(adrian1));
|
||||
|
|
@ -262,8 +265,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
}
|
||||
|
||||
private void doTestTwoAdviceAspectWith(String location) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/" + location);
|
||||
ClassPathXmlApplicationContext bf = newContext(location);
|
||||
|
||||
boolean aspectSingleton = bf.isSingleton("aspect");
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
|
|
@ -275,8 +277,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testAdviceUsingJoinPoint() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/usesJoinPointAspect.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("usesJoinPointAspect.xml");
|
||||
|
||||
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
|
||||
adrian1.getAge();
|
||||
|
|
@ -288,8 +289,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testIncludeMechanism() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/usesInclude.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("usesInclude.xml");
|
||||
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
assertTrue(AopUtils.isAopProxy(adrian));
|
||||
|
|
@ -310,8 +310,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testForceProxyTargetClass() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsWithCGLIB.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("aspectsWithCGLIB.xml");
|
||||
|
||||
ProxyConfig pc = (ProxyConfig) bf.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
assertTrue("should be proxying classes", pc.isProxyTargetClass());
|
||||
|
|
@ -319,8 +318,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testWithAbstractFactoryBeanAreApplied() {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/aspectsWithAbstractBean.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("aspectsWithAbstractBean.xml");
|
||||
|
||||
ITestBean adrian = (ITestBean) bf.getBean("adrian");
|
||||
assertTrue(AopUtils.isAopProxy(adrian));
|
||||
|
|
@ -329,8 +327,7 @@ public class AspectJAutoProxyCreatorTests {
|
|||
|
||||
@Test
|
||||
public void testRetryAspect() throws Exception {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(
|
||||
"/org/springframework/aop/aspectj/autoproxy/retryAspect.xml");
|
||||
ClassPathXmlApplicationContext bf = newContext("retryAspect.xml");
|
||||
UnreliableBean bean = (UnreliableBean) bf.getBean("unreliableBean");
|
||||
RetryAspect aspect = (RetryAspect) bf.getBean("retryAspect");
|
||||
int attempts = bean.unreliable();
|
||||
|
|
@ -340,6 +337,22 @@ public class AspectJAutoProxyCreatorTests {
|
|||
assertEquals(1, aspect.getCommitCalls());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@link ClassPathXmlApplicationContext} for the file ending in <var>fileSuffix</var>.
|
||||
*/
|
||||
private ClassPathXmlApplicationContext newContext(String fileSuffix) {
|
||||
return new ClassPathXmlApplicationContext(qName(fileSuffix), getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relatively qualified name for <var>fileSuffix</var>.
|
||||
* e.g. for a fileSuffix='foo.xml', this method will return
|
||||
* 'AspectJAutoProxyCreatorTests-foo.xml'
|
||||
*/
|
||||
private String qName(String fileSuffix) {
|
||||
return format("%s-%s", getClass().getSimpleName(), fileSuffix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -369,3 +382,203 @@ class PerTargetAspect implements Ordered {
|
|||
}
|
||||
}
|
||||
|
||||
@Aspect
|
||||
class AdviceUsingThisJoinPoint {
|
||||
|
||||
private String lastEntry = "";
|
||||
|
||||
public String getLastMethodEntered() {
|
||||
return this.lastEntry;
|
||||
}
|
||||
|
||||
@Pointcut("execution(* *(..))")
|
||||
public void methodExecution() {}
|
||||
|
||||
@Before("methodExecution()")
|
||||
public void entryTrace(JoinPoint jp) {
|
||||
this.lastEntry = jp.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class DummyAspect {
|
||||
|
||||
@Around("execution(* setAge(int))")
|
||||
public Object test(ProceedingJoinPoint pjp) throws Throwable {
|
||||
return pjp.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class DummyAspectWithParameter {
|
||||
|
||||
@Around("execution(* setAge(int)) && args(age)")
|
||||
public Object test(ProceedingJoinPoint pjp, int age) throws Throwable {
|
||||
return pjp.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class DummyFactoryBean implements FactoryBean<Object> {
|
||||
|
||||
public Object getObject() throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Class<?> getObjectType() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
@Order(10)
|
||||
class IncreaseReturnValue {
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable {
|
||||
int result = (Integer) pjp.proceed();
|
||||
return result + 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class MultiplyReturnValue {
|
||||
|
||||
private int multiple = 2;
|
||||
|
||||
public int invocations;
|
||||
|
||||
public void setMultiple(int multiple) {
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
public int getMultiple() {
|
||||
return this.multiple;
|
||||
}
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable {
|
||||
++this.invocations;
|
||||
int result = (Integer) pjp.proceed();
|
||||
return result * this.multiple;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class RetryAspect {
|
||||
|
||||
private int beginCalls;
|
||||
|
||||
private int commitCalls;
|
||||
|
||||
private int rollbackCalls;
|
||||
|
||||
|
||||
@Pointcut("execution(public * UnreliableBean.*(..))")
|
||||
public void execOfPublicMethod() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry Advice
|
||||
*/
|
||||
@Around("execOfPublicMethod()")
|
||||
public Object retry(ProceedingJoinPoint jp) throws Throwable {
|
||||
boolean retry = true;
|
||||
Object o = null;
|
||||
while (retry) {
|
||||
try {
|
||||
retry = false;
|
||||
this.beginCalls++;
|
||||
try {
|
||||
o = jp.proceed();
|
||||
this.commitCalls++;
|
||||
}
|
||||
catch (RetryableException e) {
|
||||
this.rollbackCalls++;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch (RetryableException re) {
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
public int getBeginCalls() {
|
||||
return this.beginCalls;
|
||||
}
|
||||
|
||||
public int getCommitCalls() {
|
||||
return this.commitCalls;
|
||||
}
|
||||
|
||||
public int getRollbackCalls() {
|
||||
return this.rollbackCalls;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class RetryableException extends NestedRuntimeException {
|
||||
|
||||
public RetryableException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public RetryableException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class UnreliableBean {
|
||||
|
||||
private int calls;
|
||||
|
||||
public int unreliable() {
|
||||
this.calls++;
|
||||
if (this.calls % 2 != 0) {
|
||||
throw new RetryableException("foo");
|
||||
}
|
||||
return this.calls;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
class TestBeanAdvisor extends StaticMethodMatcherPointcutAdvisor {
|
||||
|
||||
public int count;
|
||||
|
||||
public TestBeanAdvisor() {
|
||||
setAdvice(new MethodBeforeAdvice() {
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable {
|
||||
++count;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean matches(Method method, Class<?> targetClass) {
|
||||
return ITestBean.class.isAssignableFrom(targetClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ package org.springframework.aop.aspectj.autoproxy;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
|
|
@ -27,16 +29,18 @@ import java.io.IOException;
|
|||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
* @since 2.0
|
||||
*/
|
||||
public class AtAspectJAfterThrowingTests {
|
||||
public final class AtAspectJAfterThrowingTests {
|
||||
|
||||
@Test
|
||||
public void testAccessThrowable() throws Exception {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("afterThrowingAdviceTests.xml", getClass());
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
ITestBean bean = (ITestBean) context.getBean("testBean");
|
||||
ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) context.getBean("aspect");
|
||||
ITestBean bean = (ITestBean) ctx.getBean("testBean");
|
||||
ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) ctx.getBean("aspect");
|
||||
|
||||
assertTrue(AopUtils.isAopProxy(bean));
|
||||
try {
|
||||
|
|
@ -50,3 +54,19 @@ public class AtAspectJAfterThrowingTests {
|
|||
assertNotNull(aspect.lastException);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class ExceptionHandlingAspect {
|
||||
|
||||
public int handled;
|
||||
|
||||
public IOException lastException;
|
||||
|
||||
@AfterThrowing(pointcut = "within(org.springframework.beans.ITestBean+)", throwing = "ex")
|
||||
public void handleIOException(IOException ex) {
|
||||
handled++;
|
||||
lastException = ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +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.aop.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Aspect
|
||||
public class AtAspectJAnnotationBindingTestAspect {
|
||||
|
||||
@Around("execution(* *(..)) && @annotation(testAnn)")
|
||||
public Object doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnn)
|
||||
throws Throwable {
|
||||
String annValue = testAnn.value();
|
||||
Object result = pjp.proceed();
|
||||
return (result instanceof String ? annValue + " " + result : result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,39 +16,84 @@
|
|||
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AtAspectJAnnotationBindingTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public final class AtAspectJAnnotationBindingTests {
|
||||
|
||||
private AnnotatedTestBean testBean;
|
||||
private ClassPathXmlApplicationContext ctx;
|
||||
|
||||
|
||||
public void setTestBean(AnnotatedTestBean testBean) {
|
||||
this.testBean = testBean;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "ataspectj-around-advice-tests.xml";
|
||||
@Before
|
||||
public void setUp() {
|
||||
ctx = new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
testBean = (AnnotatedTestBean) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAnnotationBindingInAroundAdvice() {
|
||||
assertEquals("this value doThis", testBean.doThis());
|
||||
assertEquals("that value doThat", testBean.doThat());
|
||||
assertEquals(2, testBean.doArray().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMatchingWithoutAnnotationPresent() {
|
||||
assertEquals("doTheOther", testBean.doTheOther());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPointcutEvaulatedAgainstArray() {
|
||||
applicationContext.getBean("arrayFactoryBean");
|
||||
ctx.getBean("arrayFactoryBean");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class AtAspectJAnnotationBindingTestAspect {
|
||||
|
||||
@Around("execution(* *(..)) && @annotation(testAnn)")
|
||||
public Object doWithAnnotation(ProceedingJoinPoint pjp, TestAnnotation testAnn)
|
||||
throws Throwable {
|
||||
String annValue = testAnn.value();
|
||||
Object result = pjp.proceed();
|
||||
return (result instanceof String ? annValue + " " + result : result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ResourceArrayFactoryBean implements FactoryBean<Object> {
|
||||
|
||||
@TestAnnotation("some value")
|
||||
public Object getObject() throws Exception {
|
||||
return new Resource[0];
|
||||
}
|
||||
|
||||
@TestAnnotation("some value")
|
||||
public Class<?> getObjectType() {
|
||||
return Resource[].class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +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.aop.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Aspect
|
||||
public class DummyAspect {
|
||||
|
||||
@Around("execution(* setAge(int))")
|
||||
public Object test(ProceedingJoinPoint pjp) throws Throwable {
|
||||
return pjp.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +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.aop.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Aspect
|
||||
public class DummyAspectWithParameter {
|
||||
|
||||
@Around("execution(* setAge(int)) && args(age)")
|
||||
public Object test(ProceedingJoinPoint pjp, int age) throws Throwable {
|
||||
return pjp.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,38 +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.aspectj.autoproxy;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public class DummyFactoryBean implements FactoryBean {
|
||||
|
||||
public Object getObject() throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Class getObjectType() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +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.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @since 2.0
|
||||
*/
|
||||
@Aspect
|
||||
public class ExceptionHandlingAspect {
|
||||
|
||||
public int handled;
|
||||
|
||||
public IOException lastException;
|
||||
|
||||
@AfterThrowing(pointcut = "within(org.springframework.beans.ITestBean+)", throwing = "ex")
|
||||
public void handleIOException(IOException ex) {
|
||||
handled++;
|
||||
lastException = ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,38 +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.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Aspect
|
||||
@Order(10)
|
||||
public class IncreaseReturnValue {
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable {
|
||||
int result = (Integer) pjp.proceed();
|
||||
return result + 3;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,36 +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.aspectj.autoproxy;
|
||||
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @since 2.0
|
||||
*/
|
||||
public class LazyTestBean extends TestBean {
|
||||
|
||||
public static int instantiations;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public LazyTestBean() {
|
||||
++instantiations;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,48 +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.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@Aspect
|
||||
public class MultiplyReturnValue {
|
||||
|
||||
private int multiple = 2;
|
||||
|
||||
public int invocations;
|
||||
|
||||
public void setMultiple(int multiple) {
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
public int getMultiple() {
|
||||
return this.multiple;
|
||||
}
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable {
|
||||
++this.invocations;
|
||||
int result = (Integer) pjp.proceed();
|
||||
return result * this.multiple;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,41 +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.aop.aspectj.autoproxy;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ResourceArrayFactoryBean implements FactoryBean {
|
||||
|
||||
@TestAnnotation("some value")
|
||||
public Object getObject() throws Exception {
|
||||
return new Resource[0];
|
||||
}
|
||||
|
||||
@TestAnnotation("some value")
|
||||
public Class getObjectType() {
|
||||
return Resource[].class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,83 +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.aop.aspectj.autoproxy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
@Aspect
|
||||
public class RetryAspect {
|
||||
|
||||
private int beginCalls;
|
||||
|
||||
private int commitCalls;
|
||||
|
||||
private int rollbackCalls;
|
||||
|
||||
|
||||
@Pointcut("execution(public * UnreliableBean.*(..))")
|
||||
public void execOfPublicMethod() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry Advice
|
||||
*/
|
||||
@Around("execOfPublicMethod()")
|
||||
public Object retry(ProceedingJoinPoint jp) throws Throwable {
|
||||
boolean retry = true;
|
||||
Object o = null;
|
||||
while (retry) {
|
||||
try {
|
||||
retry = false;
|
||||
this.beginCalls++;
|
||||
try {
|
||||
o = jp.proceed();
|
||||
this.commitCalls++;
|
||||
}
|
||||
catch (RetryableException e) {
|
||||
this.rollbackCalls++;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
catch (RetryableException re) {
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
public int getBeginCalls() {
|
||||
return this.beginCalls;
|
||||
}
|
||||
|
||||
public int getCommitCalls() {
|
||||
return this.commitCalls;
|
||||
}
|
||||
|
||||
public int getRollbackCalls() {
|
||||
return this.rollbackCalls;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,34 +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.aspectj.autoproxy;
|
||||
|
||||
import org.springframework.core.NestedRuntimeException;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @since 2.0
|
||||
*/
|
||||
public class RetryableException extends NestedRuntimeException {
|
||||
|
||||
public RetryableException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public RetryableException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +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.
|
||||
*
|
||||
* Created on 6 Oct 2006 by Adrian Colyer
|
||||
*/
|
||||
package org.springframework.aop.aspectj.autoproxy;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @since 2.0
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TestAnnotation {
|
||||
String value() ;
|
||||
}
|
||||
|
|
@ -1,41 +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.aspectj.autoproxy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
|
||||
import org.springframework.beans.ITestBean;
|
||||
|
||||
public class TestBeanAdvisor extends StaticMethodMatcherPointcutAdvisor {
|
||||
|
||||
public int count;
|
||||
|
||||
public TestBeanAdvisor() {
|
||||
setAdvice(new MethodBeforeAdvice() {
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable {
|
||||
++count;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean matches(Method method, Class targetClass) {
|
||||
return ITestBean.class.isAssignableFrom(targetClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,34 +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.aop.aspectj.autoproxy;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public class UnreliableBean {
|
||||
|
||||
private int calls;
|
||||
|
||||
public int unreliable() {
|
||||
this.calls++;
|
||||
if (this.calls % 2 != 0) {
|
||||
throw new RetryableException("foo");
|
||||
}
|
||||
return this.calls;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,9 +18,21 @@ package org.springframework.aop.aspectj.autoproxy.benchmark;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.AfterReturningAdvice;
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcut;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
|
@ -32,18 +44,13 @@ import org.springframework.util.StopWatch;
|
|||
* @author Rod Johnson
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class BenchmarkTests {
|
||||
public final class BenchmarkTests {
|
||||
|
||||
private static final String ASPECTJ_CONTEXT = "/org/springframework/aop/aspectj/autoproxy/benchmark/aspectj.xml";
|
||||
private static final Class<?> CLASS = BenchmarkTests.class;
|
||||
|
||||
private static final String SPRING_AOP_CONTEXT = "/org/springframework/aop/aspectj/autoproxy/benchmark/springAop.xml";
|
||||
private static final String ASPECTJ_CONTEXT = CLASS.getSimpleName() + "-aspectj.xml";
|
||||
|
||||
/**
|
||||
* Change the return number to a higher number to make this test useful.
|
||||
*/
|
||||
protected int getCount() {
|
||||
return 10;
|
||||
}
|
||||
private static final String SPRING_AOP_CONTEXT = CLASS.getSimpleName() + "-springAop.xml";
|
||||
|
||||
@Test
|
||||
public void testRepeatedAroundAdviceInvocationsWithAspectJ() {
|
||||
|
|
@ -85,8 +92,15 @@ public class BenchmarkTests {
|
|||
testMix(SPRING_AOP_CONTEXT, getCount(), "Spring AOP");
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the return number to a higher number to make this test useful.
|
||||
*/
|
||||
protected int getCount() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated around advice invocations with " + technology);
|
||||
|
|
@ -105,7 +119,7 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated before advice invocations with " + technology);
|
||||
|
|
@ -126,7 +140,7 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated after returning advice invocations with " + technology);
|
||||
|
|
@ -148,7 +162,7 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
private long testMix(String file, int howmany, String technology) {
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file);
|
||||
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
sw.start(howmany + " repeated mixed invocations with " + technology);
|
||||
|
|
@ -176,3 +190,89 @@ public class BenchmarkTests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class MultiplyReturnValueInterceptor implements MethodInterceptor {
|
||||
|
||||
private int multiple = 2;
|
||||
|
||||
public int invocations;
|
||||
|
||||
public void setMultiple(int multiple) {
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
public int getMultiple() {
|
||||
return this.multiple;
|
||||
}
|
||||
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
++invocations;
|
||||
int result = (Integer) mi.proceed();
|
||||
return result * this.multiple;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class TraceAfterReturningAdvice implements AfterReturningAdvice {
|
||||
|
||||
public int afterTakesInt;
|
||||
|
||||
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
|
||||
++afterTakesInt;
|
||||
}
|
||||
|
||||
public static Advisor advisor() {
|
||||
return new DefaultPointcutAdvisor(
|
||||
new StaticMethodMatcherPointcut() {
|
||||
public boolean matches(Method method, Class<?> targetClass) {
|
||||
return method.getParameterTypes().length == 1 &&
|
||||
method.getParameterTypes()[0].equals(Integer.class);
|
||||
}
|
||||
},
|
||||
new TraceAfterReturningAdvice());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class TraceAspect {
|
||||
|
||||
public int beforeStringReturn;
|
||||
|
||||
public int afterTakesInt;
|
||||
|
||||
@Before("execution(String *.*(..))")
|
||||
public void traceWithoutJoinPoint() {
|
||||
++beforeStringReturn;
|
||||
}
|
||||
|
||||
@AfterReturning("execution(void *.*(int))")
|
||||
public void traceWithoutJoinPoint2() {
|
||||
++afterTakesInt;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class TraceBeforeAdvice implements MethodBeforeAdvice {
|
||||
|
||||
public int beforeStringReturn;
|
||||
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable {
|
||||
++beforeStringReturn;
|
||||
}
|
||||
|
||||
public static Advisor advisor() {
|
||||
return new DefaultPointcutAdvisor(
|
||||
new StaticMethodMatcherPointcut() {
|
||||
public boolean matches(Method method, Class<?> targetClass) {
|
||||
return method.getReturnType().equals(String.class);
|
||||
}
|
||||
},
|
||||
new TraceBeforeAdvice());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +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.aspectj.autoproxy.benchmark;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
public class MultiplyReturnValueInterceptor implements MethodInterceptor {
|
||||
|
||||
private int multiple = 2;
|
||||
|
||||
public int invocations;
|
||||
|
||||
public void setMultiple(int multiple) {
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
public int getMultiple() {
|
||||
return this.multiple;
|
||||
}
|
||||
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
++invocations;
|
||||
int result = (Integer) mi.proceed();
|
||||
return result * this.multiple;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +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.aspectj.autoproxy.benchmark;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.AfterReturningAdvice;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcut;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*
|
||||
*/
|
||||
public class TraceAfterReturningAdvice implements AfterReturningAdvice {
|
||||
|
||||
public int afterTakesInt;
|
||||
|
||||
public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
|
||||
++afterTakesInt;
|
||||
}
|
||||
|
||||
public static Advisor advisor() {
|
||||
return new DefaultPointcutAdvisor(
|
||||
new StaticMethodMatcherPointcut() {
|
||||
public boolean matches(Method method, Class targetClass) {
|
||||
return method.getParameterTypes().length == 1 &&
|
||||
method.getParameterTypes()[0].equals(Integer.class);
|
||||
}
|
||||
},
|
||||
new TraceAfterReturningAdvice());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,40 +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.aspectj.autoproxy.benchmark;
|
||||
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
|
||||
@Aspect
|
||||
public class TraceAspect {
|
||||
|
||||
public int beforeStringReturn;
|
||||
|
||||
public int afterTakesInt;
|
||||
|
||||
@Before("execution(String *.*(..))")
|
||||
public void traceWithoutJoinPoint() {
|
||||
++beforeStringReturn;
|
||||
}
|
||||
|
||||
@AfterReturning("execution(void *.*(int))")
|
||||
public void traceWithoutJoinPoint2() {
|
||||
++afterTakesInt;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,44 +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.aspectj.autoproxy.benchmark;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.aop.support.StaticMethodMatcherPointcut;
|
||||
|
||||
public class TraceBeforeAdvice implements MethodBeforeAdvice {
|
||||
|
||||
public int beforeStringReturn;
|
||||
|
||||
public void before(Method method, Object[] args, Object target) throws Throwable {
|
||||
++beforeStringReturn;
|
||||
}
|
||||
|
||||
public static Advisor advisor() {
|
||||
return new DefaultPointcutAdvisor(
|
||||
new StaticMethodMatcherPointcut() {
|
||||
public boolean matches(Method method, Class targetClass) {
|
||||
return method.getReturnType().equals(String.class);
|
||||
}
|
||||
},
|
||||
new TraceBeforeAdvice());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,26 +15,33 @@
|
|||
*/
|
||||
package org.springframework.aop.aspectj.autoproxy.spr3064;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
|
||||
/**
|
||||
* @author acolyer
|
||||
*
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class SPR3064Tests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public final class SPR3064Tests {
|
||||
|
||||
private Service service;
|
||||
|
||||
@Override
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] {"org/springframework/aop/aspectj/autoproxy/spr3064/annotationbinding-spr3064.xml"};
|
||||
}
|
||||
|
||||
public void setService(Service service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServiceIsAdvised() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
|
||||
|
||||
service = (Service) ctx.getBean("service");
|
||||
|
||||
try {
|
||||
this.service.serveMe();
|
||||
fail("service operation has not been advised by transaction interceptor");
|
||||
|
|
@ -45,3 +52,37 @@ public class SPR3064Tests extends AbstractDependencyInjectionSpringContextTests
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Transaction {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
class TransactionInterceptor {
|
||||
|
||||
@Around(value="execution(* *..Service.*(..)) && @annotation(transaction)")
|
||||
public Object around(ProceedingJoinPoint pjp, Transaction transaction) throws Throwable {
|
||||
throw new RuntimeException("advice invoked");
|
||||
//return pjp.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
interface Service {
|
||||
|
||||
void serveMe();
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ServiceImpl implements Service {
|
||||
|
||||
@Transaction
|
||||
public void serveMe() {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
<bean id="annotatedBean" class="org.springframework.aop.aspectj.autoproxy.spr3064.ServiceImpl"/>
|
||||
<bean id="service" class="org.springframework.aop.aspectj.autoproxy.spr3064.ServiceImpl"/>
|
||||
|
||||
<bean id="transactionInterceptor" class="org.springframework.aop.aspectj.autoproxy.spr3064.TransactionInterceptor"/>
|
||||
|
||||
|
|
@ -1,26 +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.aop.aspectj.autoproxy.spr3064;
|
||||
|
||||
/**
|
||||
* @author acolyer
|
||||
*
|
||||
*/
|
||||
public interface Service {
|
||||
|
||||
void serveMe();
|
||||
|
||||
}
|
||||
|
|
@ -1,32 +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.aop.aspectj.autoproxy.spr3064;
|
||||
|
||||
/**
|
||||
* @author acolyer
|
||||
*
|
||||
*/
|
||||
public class ServiceImpl implements Service {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.aop.aspectj.autoproxy.spr3064.Service#serveMe()
|
||||
*/
|
||||
@Transaction
|
||||
public void serveMe() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,28 +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.aop.aspectj.autoproxy.spr3064;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* @author acolyer
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Transaction {
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +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.aop.aspectj.autoproxy.spr3064;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
/**
|
||||
* @author acolyer
|
||||
*
|
||||
*/
|
||||
@Aspect
|
||||
public class TransactionInterceptor {
|
||||
|
||||
@Around(value="execution(* *..Service.*(..)) && @annotation(transaction)")
|
||||
public Object around(ProceedingJoinPoint pjp, Transaction transaction) throws Throwable {
|
||||
throw new RuntimeException("advice invoked");
|
||||
//return pjp.proceed();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.AfterReturningGenericTypeMatchingTests$CounterAspect"/>
|
||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.CounterAspect"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.aop.aspectj.generic.AfterReturningGenericTypeMatchingTests$GenericReturnTypeVariationClass"/>
|
||||
<bean id="testBean" class="org.springframework.aop.aspectj.generic.GenericReturnTypeVariationClass"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -16,16 +16,19 @@
|
|||
|
||||
package org.springframework.aop.aspectj.generic;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.aspectj.lang.annotation.AfterReturning;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.Employee;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests ensuring that after-returning advice for generic parameters bound to
|
||||
|
|
@ -34,29 +37,27 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
|||
* <p>See SPR-3628 for more details.
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public final class AfterReturningGenericTypeMatchingTests {
|
||||
|
||||
protected GenericReturnTypeVariationClass testBean;
|
||||
private GenericReturnTypeVariationClass testBean;
|
||||
|
||||
protected CounterAspect counterAspect;
|
||||
private CounterAspect counterAspect;
|
||||
|
||||
|
||||
public AfterReturningGenericTypeMatchingTests() {
|
||||
setPopulateProtectedVariables(true);
|
||||
}
|
||||
@Before
|
||||
public void setUp() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "afterReturningGenericTypeMatchingTests-context.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetUp() throws Exception {
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect.reset();
|
||||
super.onSetUp();
|
||||
|
||||
testBean = (GenericReturnTypeVariationClass) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeExactMatching() {
|
||||
testBean.getStrings();
|
||||
assertEquals(1, counterAspect.getStringsInvocationsCount);
|
||||
|
|
@ -69,6 +70,7 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn
|
|||
assertEquals(1, counterAspect.getIntegersInvocationsCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeRawMatching() {
|
||||
testBean.getStrings();
|
||||
assertEquals(1, counterAspect.getRawsInvocationsCount);
|
||||
|
|
@ -79,11 +81,13 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn
|
|||
assertEquals(1, counterAspect.getRawsInvocationsCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeUpperBoundMatching() {
|
||||
testBean.getIntegers();
|
||||
assertEquals(1, counterAspect.getNumbersInvocationsCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnTypeLowerBoundMatching() {
|
||||
testBean.getTestBeans();
|
||||
assertEquals(1, counterAspect.getTestBeanInvocationsCount);
|
||||
|
|
@ -94,8 +98,10 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn
|
|||
assertEquals(0, counterAspect.getTestBeanInvocationsCount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GenericReturnTypeVariationClass {
|
||||
|
||||
class GenericReturnTypeVariationClass {
|
||||
|
||||
public Collection<String> getStrings() {
|
||||
return new ArrayList<String>();
|
||||
|
|
@ -112,28 +118,28 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn
|
|||
public Collection<Employee> getEmployees() {
|
||||
return new ArrayList<Employee>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Aspect
|
||||
public static class CounterAspect {
|
||||
@Aspect
|
||||
class CounterAspect {
|
||||
|
||||
private int getRawsInvocationsCount;
|
||||
int getRawsInvocationsCount;
|
||||
|
||||
private int getStringsInvocationsCount;
|
||||
int getStringsInvocationsCount;
|
||||
|
||||
private int getIntegersInvocationsCount;
|
||||
int getIntegersInvocationsCount;
|
||||
|
||||
private int getNumbersInvocationsCount;
|
||||
int getNumbersInvocationsCount;
|
||||
|
||||
private int getTestBeanInvocationsCount;
|
||||
int getTestBeanInvocationsCount;
|
||||
|
||||
@Pointcut("execution(* org.springframework.aop.aspectj.generic.AfterReturningGenericTypeMatchingTests.GenericReturnTypeVariationClass.*(..))")
|
||||
@Pointcut("execution(* org.springframework.aop.aspectj.generic.GenericReturnTypeVariationClass.*(..))")
|
||||
public void anyTestMethod() {
|
||||
}
|
||||
|
||||
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
|
||||
public void incrementGetRawsInvocationsCount(Collection ret) {
|
||||
public void incrementGetRawsInvocationsCount(Collection<?> ret) {
|
||||
getRawsInvocationsCount++;
|
||||
}
|
||||
|
||||
|
|
@ -164,6 +170,5 @@ public class AfterReturningGenericTypeMatchingTests extends AbstractDependencyIn
|
|||
getNumbersInvocationsCount = 0;
|
||||
getTestBeanInvocationsCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
<aop:aspectj-autoproxy proxy-target-class="true"/>
|
||||
|
||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$CounterAspect"/>
|
||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericCounterAspect"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$DerivedStringParameterizedClass"/>
|
||||
<bean id="testBean" class="org.springframework.aop.aspectj.generic.DerivedStringParameterizedClass"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -16,6 +16,10 @@
|
|||
|
||||
package org.springframework.aop.aspectj.generic;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Tests for AspectJ pointcut expression matching when working with bridge methods.
|
||||
*
|
||||
|
|
@ -24,19 +28,17 @@ package org.springframework.aop.aspectj.generic;
|
|||
* <p>See GenericBridgeMethodMatchingTests for more details.
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests {
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "genericBridgeMethodMatchingTests-classProxy-context.xml";
|
||||
}
|
||||
public final class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMethodMatchingTests {
|
||||
|
||||
@Test
|
||||
public void testGenericDerivedInterfaceMethodThroughClass() {
|
||||
((DerivedStringParameterizedClass) testBean).genericDerivedInterfaceMethod("");
|
||||
assertEquals(1, counterAspect.count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericBaseInterfaceMethodThroughClass() {
|
||||
((DerivedStringParameterizedClass) testBean).genericBaseInterfaceMethod("");
|
||||
assertEquals(1, counterAspect.count);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
<aop:aspectj-autoproxy proxy-target-class="false"/>
|
||||
|
||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$CounterAspect"/>
|
||||
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericCounterAspect"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$DerivedStringParameterizedClass"/>
|
||||
<bean id="testBean" class="org.springframework.aop.aspectj.generic.DerivedStringParameterizedClass"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -16,9 +16,12 @@
|
|||
|
||||
package org.springframework.aop.aspectj.generic;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests for AspectJ pointcut expression matching when working with bridge methods.
|
||||
|
|
@ -33,63 +36,66 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
|||
* See SPR-3556 for more details.
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericBridgeMethodMatchingTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public class GenericBridgeMethodMatchingTests {
|
||||
|
||||
protected DerivedInterface<String> testBean;
|
||||
|
||||
protected CounterAspect counterAspect;
|
||||
protected GenericCounterAspect counterAspect;
|
||||
|
||||
|
||||
public GenericBridgeMethodMatchingTests() {
|
||||
setPopulateProtectedVariables(true);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@org.junit.Before
|
||||
public void setUp() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "genericBridgeMethodMatchingTests-context.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetUp() throws Exception {
|
||||
counterAspect = (GenericCounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect.count = 0;
|
||||
super.onSetUp();
|
||||
|
||||
testBean = (DerivedInterface<String>) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenericDerivedInterfaceMethodThroughInterface() {
|
||||
testBean.genericDerivedInterfaceMethod("");
|
||||
assertEquals(1, counterAspect.count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericBaseInterfaceMethodThroughInterface() {
|
||||
testBean.genericBaseInterfaceMethod("");
|
||||
assertEquals(1, counterAspect.count);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public interface BaseInterface<T> {
|
||||
|
||||
interface BaseInterface<T> {
|
||||
|
||||
void genericBaseInterfaceMethod(T t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public interface DerivedInterface<T> extends BaseInterface<T> {
|
||||
interface DerivedInterface<T> extends BaseInterface<T> {
|
||||
|
||||
public void genericDerivedInterfaceMethod(T t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class DerivedStringParameterizedClass implements DerivedInterface<String> {
|
||||
class DerivedStringParameterizedClass implements DerivedInterface<String> {
|
||||
|
||||
public void genericDerivedInterfaceMethod(String t) {
|
||||
}
|
||||
|
||||
public void genericBaseInterfaceMethod(String t) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Aspect
|
||||
public static class CounterAspect {
|
||||
@Aspect
|
||||
class GenericCounterAspect {
|
||||
|
||||
public int count;
|
||||
|
||||
|
|
@ -98,6 +104,5 @@ public class GenericBridgeMethodMatchingTests extends AbstractDependencyInjectio
|
|||
count++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,54 +16,56 @@
|
|||
|
||||
package org.springframework.aop.aspectj.generic;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* Tests that poitncut matching is correct with generic method parameter.
|
||||
* See SPR-3904 for more details.
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class GenericParameterMatchingTests extends AbstractDependencyInjectionSpringContextTests {
|
||||
public final class GenericParameterMatchingTests {
|
||||
|
||||
protected CounterAspect counterAspect;
|
||||
private CounterAspect counterAspect;
|
||||
|
||||
protected GenericInterface<String> testBean;
|
||||
private GenericInterface<String> testBean;
|
||||
|
||||
|
||||
public GenericParameterMatchingTests() {
|
||||
setPopulateProtectedVariables(true);
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@org.junit.Before
|
||||
public void setUp() {
|
||||
ClassPathXmlApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
|
||||
@Override
|
||||
protected String getConfigPath() {
|
||||
return "genericParameterMatchingTests-context.xml";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetUp() throws Exception {
|
||||
counterAspect = (CounterAspect) ctx.getBean("counterAspect");
|
||||
counterAspect.reset();
|
||||
super.onSetUp();
|
||||
|
||||
testBean = (GenericInterface<String>) ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGenericInterfaceGenericArgExecution() {
|
||||
testBean.save("");
|
||||
assertEquals(1, counterAspect.genericInterfaceGenericArgExecutionCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericInterfaceGenericCollectionArgExecution() {
|
||||
testBean.saveAll(null);
|
||||
// TODO: uncomment once we officially update to AspectJ 1.6.0
|
||||
//assertEquals(1, counterAspect.genericInterfaceGenericCollectionArgExecutionCount);
|
||||
assertEquals(1, counterAspect.genericInterfaceGenericCollectionArgExecutionCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericInterfaceSubtypeGenericCollectionArgExecution() {
|
||||
testBean.saveAll(null);
|
||||
assertEquals(1, counterAspect.genericInterfaceSubtypeGenericCollectionArgExecutionCount);
|
||||
|
|
@ -89,7 +91,7 @@ public class GenericParameterMatchingTests extends AbstractDependencyInjectionSp
|
|||
|
||||
|
||||
@Aspect
|
||||
public static class CounterAspect {
|
||||
static class CounterAspect {
|
||||
|
||||
int genericInterfaceGenericArgExecutionCount;
|
||||
int genericInterfaceGenericCollectionArgExecutionCount;
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@
|
|||
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -16,9 +16,9 @@
|
|||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -19,36 +19,25 @@ package org.springframework.aop.config;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AopNamespaceAdviceTypeTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
protected String getOKConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerAdviceTypeOKTests.xml";
|
||||
}
|
||||
|
||||
protected String getErrorConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerAdviceTypeErrorTests.xml";
|
||||
}
|
||||
public final class AopNamespaceHandlerAdviceTypeTests {
|
||||
|
||||
@Test
|
||||
public void testParsingOfAdviceTypes() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingOfAdviceTypesWithError() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass());
|
||||
fail("Expected BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
|
|
@ -56,8 +45,4 @@ public class AopNamespaceAdviceTypeTests {
|
|||
}
|
||||
}
|
||||
|
||||
protected ITestBean getTestBean() {
|
||||
return (ITestBean) this.context.getBean("testBean");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,9 +12,9 @@
|
|||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -12,9 +12,9 @@
|
|||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -19,35 +19,24 @@ package org.springframework.aop.config;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AopNamespaceHandlerArgNamesTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
protected String getOKConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerArgNamesOKTests.xml";
|
||||
}
|
||||
|
||||
protected String getErrorConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerArgNamesErrorTests.xml";
|
||||
}
|
||||
public final class AopNamespaceHandlerArgNamesTests {
|
||||
|
||||
@Test
|
||||
public void testArgNamesOK() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgNamesError() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass());
|
||||
fail("Expected BeanCreationException");
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
|
|
@ -55,8 +44,4 @@ public class AopNamespaceHandlerArgNamesTests {
|
|||
}
|
||||
}
|
||||
|
||||
protected ITestBean getTestBean() {
|
||||
return (ITestBean) this.context.getBean("testBean");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -24,8 +24,9 @@ import org.springframework.beans.ITestBean;
|
|||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandlerTests {
|
||||
public final class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandlerTests {
|
||||
|
||||
@Test
|
||||
public void testIsClassProxy() {
|
||||
|
|
@ -33,8 +34,4 @@ public class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandle
|
|||
assertTrue("Should be a CGLIB proxy", AopUtils.isCglibProxy(bean));
|
||||
}
|
||||
|
||||
protected String getConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerProxyTargetClassTests.xml";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -11,9 +11,9 @@
|
|||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -19,36 +19,25 @@ package org.springframework.aop.config;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AopNamespaceHandlerReturningTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
protected String getOKConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerReturningOKTests.xml";
|
||||
}
|
||||
|
||||
protected String getErrorConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerReturningErrorTests.xml";
|
||||
}
|
||||
public final class AopNamespaceHandlerReturningTests {
|
||||
|
||||
@Test
|
||||
public void testReturningOnReturningAdvice() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseReturningOnOtherAdviceType() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass());
|
||||
fail("Expected BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
|
|
@ -56,8 +45,4 @@ public class AopNamespaceHandlerReturningTests {
|
|||
}
|
||||
}
|
||||
|
||||
protected ITestBean getTestBean() {
|
||||
return (ITestBean) this.context.getBean("testBean");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,15 +34,16 @@ import org.springframework.web.context.support.XmlWebApplicationContext;
|
|||
/**
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AopNamespaceHandlerScopeTests {
|
||||
public final class AopNamespaceHandlerScopeTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
||||
wac.setConfigLocations(new String[] {"classpath:org/springframework/aop/config/aopNamespaceHandlerScopeTests.xml"});
|
||||
wac.setConfigLocations(new String[] {"classpath:org/springframework/aop/config/AopNamespaceHandlerScopeTests-context.xml"});
|
||||
wac.refresh();
|
||||
this.context = wac;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -18,16 +18,18 @@ package org.springframework.aop.config;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.framework.Advised;
|
||||
import org.springframework.aop.framework.CountingBeforeAdvice;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import test.advice.CountingBeforeAdvice;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
|
|
@ -35,13 +37,11 @@ public class AopNamespaceHandlerTests {
|
|||
|
||||
private ApplicationContext context;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.context = new ClassPathXmlApplicationContext(getConfigLocation());
|
||||
}
|
||||
|
||||
protected String getConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerTests.xml";
|
||||
this.context =
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -103,3 +103,51 @@ public class AopNamespaceHandlerTests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class CountingAspectJAdvice {
|
||||
|
||||
private int beforeCount;
|
||||
|
||||
private int afterCount;
|
||||
|
||||
private int aroundCount;
|
||||
|
||||
public void myBeforeAdvice() throws Throwable {
|
||||
this.beforeCount++;
|
||||
}
|
||||
|
||||
public void myAfterAdvice() throws Throwable {
|
||||
this.afterCount++;
|
||||
}
|
||||
|
||||
public void myAroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
|
||||
this.aroundCount++;
|
||||
pjp.proceed();
|
||||
}
|
||||
|
||||
public void myAfterReturningAdvice(int age) {
|
||||
this.afterCount++;
|
||||
}
|
||||
|
||||
public void myAfterThrowingAdvice(RuntimeException ex) {
|
||||
this.afterCount++;
|
||||
}
|
||||
|
||||
public void mySetAgeAdvice(int newAge, ITestBean bean) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
public int getBeforeCount() {
|
||||
return this.beforeCount;
|
||||
}
|
||||
|
||||
public int getAfterCount() {
|
||||
return this.afterCount;
|
||||
}
|
||||
|
||||
public int getAroundCount() {
|
||||
return this.aroundCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -11,9 +11,9 @@
|
|||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="test.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.TestBean"/>
|
||||
|
||||
|
|
@ -19,36 +19,25 @@ package org.springframework.aop.config;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ITestBean;
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.xml.sax.SAXParseException;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class AopNamespaceHandlerThrowingTests {
|
||||
|
||||
private ApplicationContext context;
|
||||
|
||||
protected String getOKConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerThrowingOKTests.xml";
|
||||
}
|
||||
|
||||
protected String getErrorConfigLocation() {
|
||||
return "org/springframework/aop/config/aopNamespaceHandlerThrowingErrorTests.xml";
|
||||
}
|
||||
public final class AopNamespaceHandlerThrowingTests {
|
||||
|
||||
@Test
|
||||
public void testThrowingOnThrowingAdvice() {
|
||||
this.context = new ClassPathXmlApplicationContext(getOKConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-ok.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseThrowingOnOtherAdviceType() {
|
||||
try {
|
||||
this.context = new ClassPathXmlApplicationContext(getErrorConfigLocation());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-error.xml", getClass());
|
||||
fail("Expected BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
|
|
@ -56,8 +45,4 @@ public class AopNamespaceHandlerThrowingTests {
|
|||
}
|
||||
}
|
||||
|
||||
protected ITestBean getTestBean() {
|
||||
return (ITestBean) this.context.getBean("testBean");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,69 +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.config;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.springframework.beans.ITestBean;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public class CountingAspectJAdvice {
|
||||
|
||||
private int beforeCount;
|
||||
|
||||
private int afterCount;
|
||||
|
||||
private int aroundCount;
|
||||
|
||||
public void myBeforeAdvice() throws Throwable {
|
||||
this.beforeCount++;
|
||||
}
|
||||
|
||||
public void myAfterAdvice() throws Throwable {
|
||||
this.afterCount++;
|
||||
}
|
||||
|
||||
public void myAroundAdvice(ProceedingJoinPoint pjp) throws Throwable {
|
||||
this.aroundCount++;
|
||||
pjp.proceed();
|
||||
}
|
||||
|
||||
public void myAfterReturningAdvice(int age) {
|
||||
this.afterCount++;
|
||||
}
|
||||
|
||||
public void myAfterThrowingAdvice(RuntimeException ex) {
|
||||
this.afterCount++;
|
||||
}
|
||||
|
||||
public void mySetAgeAdvice(int newAge, ITestBean bean) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
public int getBeforeCount() {
|
||||
return this.beforeCount;
|
||||
}
|
||||
|
||||
public int getAfterCount() {
|
||||
return this.afterCount;
|
||||
}
|
||||
|
||||
public int getAroundCount() {
|
||||
return this.aroundCount;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,128 +16,100 @@
|
|||
|
||||
package org.springframework.aop.config;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.mock.easymock.AbstractScalarMockTemplate;
|
||||
import org.springframework.test.AssertThrows;
|
||||
|
||||
/**
|
||||
* @author Rick Evans
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public final class MethodLocatingFactoryBeanTests {
|
||||
|
||||
private static final String BEAN_NAME = "string";
|
||||
private MethodLocatingFactoryBean factory;
|
||||
private BeanFactory beanFactory;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
factory = new MethodLocatingFactoryBean();
|
||||
|
||||
// methods must set up expectations and call replay() manually for this mock
|
||||
beanFactory = createMock(BeanFactory.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
verify(beanFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsSingleton() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
public void testIsSingleton() {
|
||||
replay(beanFactory);
|
||||
assertTrue(factory.isSingleton());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetObjectType() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
public void testGetObjectType() {
|
||||
replay(beanFactory);
|
||||
assertEquals(Method.class, factory.getObjectType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNullTargetBeanName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithNullTargetBeanName() {
|
||||
replay(beanFactory);
|
||||
|
||||
factory.setMethodName("toString()");
|
||||
factory.setBeanFactory(beanFactory);
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithEmptyTargetBeanName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithEmptyTargetBeanName() {
|
||||
replay(beanFactory);
|
||||
|
||||
factory.setTargetBeanName("");
|
||||
factory.setMethodName("toString()");
|
||||
factory.setBeanFactory(beanFactory);
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithNullTargetMethodName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithNullTargetMethodName() {
|
||||
replay(beanFactory);
|
||||
|
||||
factory.setTargetBeanName(BEAN_NAME);
|
||||
factory.setBeanFactory(beanFactory);
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithEmptyTargetMethodName() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
public void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithEmptyTargetMethodName() {
|
||||
replay(beanFactory);
|
||||
|
||||
factory.setTargetBeanName(BEAN_NAME);
|
||||
factory.setMethodName("");
|
||||
factory.setBeanFactory(beanFactory);
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhenTargetBeanClassCannotBeResolved() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception {
|
||||
beanFactory.getType(BEAN_NAME);
|
||||
mockControl.setReturnValue(null);
|
||||
}
|
||||
protected void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWhenTargetBeanClassCannotBeResolved() {
|
||||
expect(beanFactory.getType(BEAN_NAME)).andReturn(null);
|
||||
replay(beanFactory);
|
||||
|
||||
factory.setTargetBeanName(BEAN_NAME);
|
||||
factory.setMethodName("toString()");
|
||||
factory.setBeanFactory(beanFactory);
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunnyDayPath() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception {
|
||||
beanFactory.getType(BEAN_NAME);
|
||||
mockControl.setReturnValue(String.class);
|
||||
}
|
||||
protected void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
expect(beanFactory.getType(BEAN_NAME)).andReturn(String.class);
|
||||
replay(beanFactory);
|
||||
|
||||
factory.setTargetBeanName(BEAN_NAME);
|
||||
factory.setMethodName("toString()");
|
||||
factory.setBeanFactory(beanFactory);
|
||||
|
|
@ -147,48 +119,15 @@ public final class MethodLocatingFactoryBeanTests {
|
|||
Method method = (Method) result;
|
||||
assertEquals("Bingo", method.invoke("Bingo", new Object[]{}));
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereMethodCannotBeResolved() throws Exception {
|
||||
new BeanFactoryScalarMockTemplate() {
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception {
|
||||
beanFactory.getType(BEAN_NAME);
|
||||
mockControl.setReturnValue(String.class);
|
||||
}
|
||||
protected void doTestInternal(final BeanFactory beanFactory) throws Exception {
|
||||
new AssertThrows(IllegalArgumentException.class) {
|
||||
public void test() throws Exception {
|
||||
MethodLocatingFactoryBean factory = new MethodLocatingFactoryBean();
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWhereMethodCannotBeResolved() {
|
||||
expect(beanFactory.getType(BEAN_NAME)).andReturn(String.class);
|
||||
replay(beanFactory);
|
||||
|
||||
factory.setTargetBeanName(BEAN_NAME);
|
||||
factory.setMethodName("loadOfOld()");
|
||||
factory.setBeanFactory(beanFactory);
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
}.test();
|
||||
}
|
||||
|
||||
|
||||
private static abstract class BeanFactoryScalarMockTemplate extends AbstractScalarMockTemplate {
|
||||
|
||||
public BeanFactoryScalarMockTemplate() {
|
||||
super(BeanFactory.class);
|
||||
}
|
||||
|
||||
public void setupExpectations(MockControl mockControl, Object mockObject) throws Exception {
|
||||
setupBeanFactoryExpectations(mockControl, (BeanFactory) mockObject);
|
||||
}
|
||||
|
||||
public void doTest(Object mockObject) throws Exception {
|
||||
doTestInternal((BeanFactory) mockObject);
|
||||
}
|
||||
|
||||
protected void setupBeanFactoryExpectations(MockControl mockControl, BeanFactory beanFactory) throws Exception {
|
||||
}
|
||||
|
||||
protected abstract void doTestInternal(final BeanFactory beanFactory) throws Exception;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,12 +21,13 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class PrototypeProxyTests {
|
||||
public final class PrototypeProxyTests {
|
||||
|
||||
@Test
|
||||
public void testInjectionBeforeWrappingCheckDoesNotKickInForPrototypeProxy() {
|
||||
new ClassPathXmlApplicationContext("prototypeProxy.xml", getClass());
|
||||
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import java.util.Map;
|
|||
import javax.servlet.ServletException;
|
||||
import javax.transaction.TransactionRequiredException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.aopalliance.aop.Advice;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
|
@ -42,10 +44,9 @@ import org.springframework.aop.AfterReturningAdvice;
|
|||
import org.springframework.aop.DynamicIntroductionAdvice;
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.ThrowsAdvice;
|
||||
import org.springframework.aop.interceptor.DebugInterceptor;
|
||||
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
|
||||
import org.springframework.aop.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.interceptor.SerializableNopInterceptor;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.DefaultIntroductionAdvisor;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
|
|
@ -61,10 +62,24 @@ import org.springframework.beans.ITestBean;
|
|||
import org.springframework.beans.Person;
|
||||
import org.springframework.beans.SerializablePerson;
|
||||
import org.springframework.beans.TestBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import test.advice.CountingAfterReturningAdvice;
|
||||
import test.advice.CountingBeforeAdvice;
|
||||
import test.advice.MethodCounter;
|
||||
import test.advice.MyThrowsHandler;
|
||||
import test.interceptor.NopInterceptor;
|
||||
import test.interceptor.SerializableNopInterceptor;
|
||||
import test.interceptor.TimestampIntroductionInterceptor;
|
||||
import test.mixin.LockMixin;
|
||||
import test.mixin.LockMixinAdvisor;
|
||||
import test.mixin.Lockable;
|
||||
import test.mixin.LockedException;
|
||||
import test.util.TimeStamped;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
|
|
@ -804,7 +819,7 @@ public abstract class AbstractAopProxyTests {
|
|||
@SuppressWarnings("serial")
|
||||
class MyDi extends DelegatingIntroductionInterceptor implements TimeStamped {
|
||||
/**
|
||||
* @see org.springframework.aop.framework.TimeStamped#getTimeStamp()
|
||||
* @see test.util.TimeStamped#getTimeStamp()
|
||||
*/
|
||||
public long getTimeStamp() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
@ -1904,4 +1919,130 @@ public abstract class AbstractAopProxyTests {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class CountingMultiAdvice extends MethodCounter implements MethodBeforeAdvice,
|
||||
AfterReturningAdvice, ThrowsAdvice {
|
||||
|
||||
public void before(Method m, Object[] args, Object target) throws Throwable {
|
||||
count(m);
|
||||
}
|
||||
|
||||
public void afterReturning(Object o, Method m, Object[] args, Object target)
|
||||
throws Throwable {
|
||||
count(m);
|
||||
}
|
||||
|
||||
public void afterThrowing(ServletException sex) throws Throwable {
|
||||
count(ServletException.class.getName());
|
||||
}
|
||||
|
||||
public void afterThrowing(DataAccessException ex) throws Throwable {
|
||||
count(DataAccessException.class.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class CountingThrowsAdvice extends MethodCounter implements ThrowsAdvice {
|
||||
|
||||
public void afterThrowing(ServletException sex) throws Throwable {
|
||||
count(ServletException.class.getName());
|
||||
}
|
||||
|
||||
public void afterThrowing(DataAccessException ex) throws Throwable {
|
||||
count(DataAccessException.class.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class MockTargetSource implements TargetSource {
|
||||
|
||||
private Object target;
|
||||
|
||||
public int gets;
|
||||
|
||||
public int releases;
|
||||
|
||||
public void reset() {
|
||||
this.target = null;
|
||||
gets = releases = 0;
|
||||
}
|
||||
|
||||
public void setTarget(Object target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.aop.TargetSource#getTargetClass()
|
||||
*/
|
||||
public Class<?> getTargetClass() {
|
||||
return target.getClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.aop.TargetSource#getTarget()
|
||||
*/
|
||||
public Object getTarget() throws Exception {
|
||||
++gets;
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.aop.TargetSource#releaseTarget(java.lang.Object)
|
||||
*/
|
||||
public void releaseTarget(Object pTarget) throws Exception {
|
||||
if (pTarget != this.target)
|
||||
throw new RuntimeException("Released wrong target");
|
||||
++releases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that gets and releases match
|
||||
*
|
||||
*/
|
||||
public void verify() {
|
||||
if (gets != releases)
|
||||
throw new RuntimeException("Expectation failed: " + gets + " gets and " + releases + " releases");
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.springframework.aop.TargetSource#isStatic()
|
||||
*/
|
||||
public boolean isStatic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static abstract class ExposedInvocationTestBean extends TestBean {
|
||||
|
||||
public String getName() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
public void absquatulate() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
super.absquatulate();
|
||||
}
|
||||
|
||||
protected abstract void assertions(MethodInvocation invocation);
|
||||
}
|
||||
|
||||
|
||||
static class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean {
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
TestCase.assertTrue(invocation.getThis() == this);
|
||||
TestCase.assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
|
||||
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ import java.io.Serializable;
|
|||
|
||||
import net.sf.cglib.core.CodeGenerationException;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.aop.interceptor.NopInterceptor;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.beans.ITestBean;
|
||||
|
|
@ -37,6 +37,10 @@ import org.springframework.context.ApplicationContext;
|
|||
import org.springframework.context.ApplicationContextException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import test.advice.CountingBeforeAdvice;
|
||||
import test.interceptor.NopInterceptor;
|
||||
import test.mixin.LockMixinAdvisor;
|
||||
|
||||
/**
|
||||
* Additional and overridden tests for the CGLIB proxy.
|
||||
*
|
||||
|
|
@ -46,7 +50,11 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|||
* @author Ramnivas Laddad
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public class CglibProxyTests extends AbstractAopProxyTests {
|
||||
@SuppressWarnings("serial")
|
||||
public final class CglibProxyTests extends AbstractAopProxyTests implements Serializable {
|
||||
|
||||
private static final String DEPENDENCY_CHECK_CONTEXT = CglibProxyTests.class.getSimpleName() + "-with-dependency-checking.xml";
|
||||
|
||||
|
||||
protected Object createProxy(ProxyCreatorSupport as) {
|
||||
as.setProxyTargetClass(true);
|
||||
|
|
@ -330,7 +338,7 @@ public class CglibProxyTests extends AbstractAopProxyTests {
|
|||
@Test
|
||||
public void testWithDependencyChecking() {
|
||||
ApplicationContext ctx =
|
||||
new ClassPathXmlApplicationContext("org/springframework/aop/framework/withDependencyChecking.xml");
|
||||
new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
|
||||
ctx.getBean("testBean");
|
||||
}
|
||||
|
||||
|
|
@ -429,3 +437,61 @@ public class CglibProxyTests extends AbstractAopProxyTests {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class CglibTestBean {
|
||||
|
||||
private String name;
|
||||
|
||||
public CglibTestBean() {
|
||||
setName("Some Default");
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NoArgCtorTestBean {
|
||||
|
||||
private boolean called = false;
|
||||
|
||||
public NoArgCtorTestBean(String x, int y) {
|
||||
called = true;
|
||||
}
|
||||
|
||||
public boolean wasCalled() {
|
||||
return called;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
called = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ProtectedMethodTestBean {
|
||||
|
||||
protected String getString() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class UnsupportedInterceptor implements MethodInterceptor {
|
||||
|
||||
/**
|
||||
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
|
||||
*/
|
||||
public Object invoke(MethodInvocation mi) throws Throwable {
|
||||
throw new UnsupportedOperationException(mi.getMethod().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +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;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
*/
|
||||
public class CglibTestBean {
|
||||
|
||||
private String name;
|
||||
|
||||
public CglibTestBean() {
|
||||
setName("Some Default");
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +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 java.lang.reflect.Method;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.springframework.aop.AfterReturningAdvice;
|
||||
import org.springframework.aop.MethodBeforeAdvice;
|
||||
import org.springframework.aop.ThrowsAdvice;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
/**
|
||||
* Advice object that implements <i>multiple</i> Advice interfaces.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 19.05.2005
|
||||
*/
|
||||
public class CountingMultiAdvice extends MethodCounter
|
||||
implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice {
|
||||
|
||||
public void before(Method m, Object[] args, Object target) throws Throwable {
|
||||
count(m);
|
||||
}
|
||||
|
||||
public void afterReturning(Object o, Method m, Object[] args, Object target) throws Throwable {
|
||||
count(m);
|
||||
}
|
||||
|
||||
public void afterThrowing(ServletException sex) throws Throwable {
|
||||
count(ServletException.class.getName());
|
||||
}
|
||||
|
||||
public void afterThrowing(DataAccessException ex) throws Throwable {
|
||||
count(DataAccessException.class.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,37 +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 javax.servlet.ServletException;
|
||||
|
||||
import org.springframework.aop.ThrowsAdvice;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public class CountingThrowsAdvice extends MethodCounter implements ThrowsAdvice {
|
||||
|
||||
public void afterThrowing(ServletException sex) throws Throwable {
|
||||
count(ServletException.class.getName());
|
||||
}
|
||||
|
||||
public void afterThrowing(DataAccessException ex) throws Throwable {
|
||||
count(DataAccessException.class.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.aop.framework;
|
||||
|
||||
class Echo implements IEcho {
|
||||
private int a;
|
||||
|
||||
public int echoException(int i, Throwable t) throws Throwable {
|
||||
if (t != null)
|
||||
throw t;
|
||||
return i;
|
||||
}
|
||||
public void setA(int a) {
|
||||
this.a = a;
|
||||
}
|
||||
public int getA() {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +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 org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
|
||||
import org.springframework.beans.TestBean;
|
||||
|
||||
|
||||
/**
|
||||
* Used to test ExposeInvocationInterceptor.
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
public abstract class ExposedInvocationTestBean extends TestBean {
|
||||
|
||||
public String getName() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
return super.getName();
|
||||
}
|
||||
|
||||
public void absquatulate() {
|
||||
MethodInvocation invocation = ExposeInvocationInterceptor.currentInvocation();
|
||||
assertions(invocation);
|
||||
super.absquatulate();
|
||||
}
|
||||
|
||||
protected abstract void assertions(MethodInvocation invocation);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue