moving unit tests from .testsuite -> .aop
This commit is contained in:
parent
bd33eb7715
commit
2b7bc1ea58
|
|
@ -0,0 +1,35 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package example.aspects;
|
||||||
|
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.springframework.core.Ordered;
|
||||||
|
|
||||||
|
@Aspect("pertarget(execution(* *.getSpouse()))")
|
||||||
|
public class PerTargetAspect implements Ordered {
|
||||||
|
|
||||||
|
public int count;
|
||||||
|
|
||||||
|
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||||
|
|
||||||
|
@Around("execution(int *.getAge())")
|
||||||
|
public int returnCountAsAge() {
|
||||||
|
return count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before("execution(void *.set*(int))")
|
||||||
|
public void countSetter() {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrder() {
|
||||||
|
return this.order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(int order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.aop.aspectj.autoproxy;
|
package example.aspects;
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package example.aspects;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
|
||||||
|
@Aspect
|
||||||
|
public class TwoAdviceAspect {
|
||||||
|
private int totalCalls;
|
||||||
|
|
||||||
|
@Around("execution(* getAge())")
|
||||||
|
public int returnCallCount(ProceedingJoinPoint pjp) throws Exception {
|
||||||
|
return totalCalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before("execution(* setAge(int)) && args(newAge)")
|
||||||
|
public void countSet(int newAge) throws Exception {
|
||||||
|
++totalCalls;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -49,6 +49,9 @@ import org.springframework.core.OrderComparator;
|
||||||
import org.springframework.core.Ordered;
|
import org.springframework.core.Ordered;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
|
|
||||||
|
import example.aspects.PerTargetAspect;
|
||||||
|
import example.aspects.TwoAdviceAspect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract tests for AspectJAdvisorFactory.
|
* Abstract tests for AspectJAdvisorFactory.
|
||||||
* See subclasses for tests of concrete factories.
|
* See subclasses for tests of concrete factories.
|
||||||
|
|
@ -593,33 +596,6 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Aspect("pertarget(execution(* *.getSpouse()))")
|
|
||||||
public static class PerTargetAspect implements Ordered {
|
|
||||||
|
|
||||||
public int count;
|
|
||||||
|
|
||||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
|
||||||
|
|
||||||
@Around("execution(int *.getAge())")
|
|
||||||
public int returnCountAsAge() {
|
|
||||||
return count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before("execution(void *.set*(int))")
|
|
||||||
public void countSetter() {
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getOrder() {
|
|
||||||
return this.order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrder(int order) {
|
|
||||||
this.order = order;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Aspect("pertarget(execution(* *.getSpouse()))")
|
@Aspect("pertarget(execution(* *.getSpouse()))")
|
||||||
@Order(10)
|
@Order(10)
|
||||||
public static class PerTargetAspectWithOrderAnnotation10 {
|
public static class PerTargetAspectWithOrderAnnotation10 {
|
||||||
|
|
@ -656,28 +632,6 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Aspect("perthis(execution(* *.getSpouse()))")
|
|
||||||
public static class PerThisAspect {
|
|
||||||
|
|
||||||
public int count;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Just to check that this doesn't cause problems with introduction processing
|
|
||||||
*/
|
|
||||||
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
|
|
||||||
|
|
||||||
@Around("execution(int *.getAge())")
|
|
||||||
public int returnCountAsAge() {
|
|
||||||
return count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before("execution(void *.set*(int))")
|
|
||||||
public void countSetter() {
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Aspect("pertypewithin(org.springframework.beans.IOther+)")
|
@Aspect("pertypewithin(org.springframework.beans.IOther+)")
|
||||||
public static class PerTypeWithinAspect {
|
public static class PerTypeWithinAspect {
|
||||||
|
|
||||||
|
|
@ -833,22 +787,6 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Aspect
|
|
||||||
public static class TwoAdviceAspect {
|
|
||||||
private int totalCalls;
|
|
||||||
|
|
||||||
@Around("execution(* getAge())")
|
|
||||||
public int returnCallCount(ProceedingJoinPoint pjp) throws Exception {
|
|
||||||
return totalCalls;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before("execution(* setAge(int)) && args(newAge)")
|
|
||||||
public void countSet(int newAge) throws Exception {
|
|
||||||
++totalCalls;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class Echo {
|
public static class Echo {
|
||||||
|
|
||||||
public Object echo(Object o) throws Exception {
|
public Object echo(Object o) throws Exception {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ import org.springframework.aop.aspectj.AspectJExpressionPointcutTests;
|
||||||
import org.springframework.aop.framework.AopConfigException;
|
import org.springframework.aop.framework.AopConfigException;
|
||||||
import org.springframework.beans.TestBean;
|
import org.springframework.beans.TestBean;
|
||||||
|
|
||||||
|
import example.aspects.PerTargetAspect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rod Johnson
|
* @author Rod Johnson
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
|
@ -51,7 +53,7 @@ public class AspectJPointcutAdvisorTests {
|
||||||
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
ajexp.setExpression(AspectJExpressionPointcutTests.MATCH_ALL_METHODS);
|
||||||
|
|
||||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(af, ajexp,
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.PerTargetAspect(),"someBean"), null, 1, "someBean");
|
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(),"someBean"), null, 1, "someBean");
|
||||||
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
||||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
|
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
|
||||||
assertTrue(ajpa.isPerInstance());
|
assertTrue(ajpa.isPerInstance());
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@ import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionAspect;
|
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionAspect;
|
||||||
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.PerTargetAspect;
|
|
||||||
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.PerThisAspect;
|
import example.aspects.PerTargetAspect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.autoproxy.MultiplyReturnValue;
|
import org.springframework.aop.aspectj.autoproxy.MultiplyReturnValue;
|
||||||
import org.springframework.aop.aspectj.autoproxy.PerThisAspect;
|
|
||||||
|
import example.aspects.PerThisAspect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.springframework.aop.aspectj.annotation;
|
||||||
|
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.springframework.beans.ITestBean;
|
||||||
|
import org.springframework.beans.TestBean;
|
||||||
|
|
||||||
|
@Aspect("perthis(execution(* *.getSpouse()))")
|
||||||
|
public class PerThisAspect {
|
||||||
|
|
||||||
|
public int count;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just to check that this doesn't cause problems with introduction processing
|
||||||
|
*/
|
||||||
|
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
|
||||||
|
|
||||||
|
@Around("execution(int *.getAge())")
|
||||||
|
public int returnCountAsAge() {
|
||||||
|
return count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before("execution(void *.set*(int))")
|
||||||
|
public void countSetter() {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue