Polishing
This commit is contained in:
parent
6a34ca24ce
commit
a6885c7235
|
|
@ -46,7 +46,6 @@ import test.aop.PerTargetAspect;
|
||||||
import test.aop.TwoAdviceAspect;
|
import test.aop.TwoAdviceAspect;
|
||||||
|
|
||||||
import org.springframework.aop.Advisor;
|
import org.springframework.aop.Advisor;
|
||||||
import org.springframework.aop.aspectj.annotation.ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor;
|
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.framework.AopConfigException;
|
import org.springframework.aop.framework.AopConfigException;
|
||||||
import org.springframework.aop.framework.ProxyFactory;
|
import org.springframework.aop.framework.ProxyFactory;
|
||||||
|
|
@ -114,7 +113,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||||
|
|
||||||
Advised advised = (Advised) itb;
|
Advised advised = (Advised) itb;
|
||||||
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||||
|
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
|
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
|
||||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||||
|
|
@ -201,7 +201,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
Advised advised = (Advised) itb;
|
Advised advised = (Advised) itb;
|
||||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||||
assertEquals(4, advised.getAdvisors().length);
|
assertEquals(4, advised.getAdvisors().length);
|
||||||
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||||
|
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
||||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||||
|
|
@ -236,7 +237,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
Advised advised = (Advised) itb;
|
Advised advised = (Advised) itb;
|
||||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||||
assertEquals(4, advised.getAdvisors().length);
|
assertEquals(4, advised.getAdvisors().length);
|
||||||
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||||
|
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
||||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||||
|
|
@ -369,9 +371,9 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
@Test
|
@Test
|
||||||
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() {
|
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() {
|
||||||
assertTrue(AopUtils.findAdvisorsThatCanApply(
|
assertTrue(AopUtils.findAdvisorsThatCanApply(
|
||||||
getFixture().getAdvisors(
|
getFixture().getAdvisors(
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||||
CannotBeUnlocked.class).isEmpty());
|
CannotBeUnlocked.class).isEmpty());
|
||||||
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(
|
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size());
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size());
|
||||||
}
|
}
|
||||||
|
|
@ -699,6 +701,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
public static class NamedPointcutAspectWithoutFQN {
|
public static class NamedPointcutAspectWithoutFQN {
|
||||||
|
|
||||||
@Pointcut("execution(* getAge())")
|
@Pointcut("execution(* getAge())")
|
||||||
public void getAge() {
|
public void getAge() {
|
||||||
}
|
}
|
||||||
|
|
@ -755,7 +758,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
@Around(value="setAge(age)",argNames="age")
|
@Around(value="setAge(age)",argNames="age")
|
||||||
// @ArgNames({"age"}) // AMC needs more work here? ignoring pjp arg... ok??
|
// @ArgNames({"age"}) // AMC needs more work here? ignoring pjp arg... ok??
|
||||||
// argNames should be suported in Around as it is in Pointcut
|
// argNames should be suported in Around as it is in Pointcut
|
||||||
public void changeReturnType(ProceedingJoinPoint pjp, int age) throws Throwable {
|
public void changeReturnType(ProceedingJoinPoint pjp, int age) throws Throwable {
|
||||||
pjp.proceed(new Object[] {age*2});
|
pjp.proceed(new Object[] {age*2});
|
||||||
}
|
}
|
||||||
|
|
@ -764,12 +767,12 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
public static class ManyValuedArgs {
|
public static class ManyValuedArgs {
|
||||||
|
|
||||||
public String mungeArgs(String a, int b, int c, String d, StringBuffer e) {
|
public String mungeArgs(String a, int b, int c, String d, StringBuffer e) {
|
||||||
return a + b + c + d + e;
|
return a + b + c + d + e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)",
|
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
|
||||||
argNames="b,c,d,e,a")
|
|
||||||
public String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
|
public String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
|
||||||
assertEquals(a + b+ c+ d+ e, pjp.proceed());
|
assertEquals(a + b+ c+ d+ e, pjp.proceed());
|
||||||
return a + b + c + d + e;
|
return a + b + c + d + e;
|
||||||
|
|
@ -779,6 +782,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
public static class ExceptionAspect {
|
public static class ExceptionAspect {
|
||||||
|
|
||||||
private final Exception ex;
|
private final Exception ex;
|
||||||
|
|
||||||
public ExceptionAspect(Exception ex) {
|
public ExceptionAspect(Exception ex) {
|
||||||
|
|
@ -805,8 +809,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
public static class ExceptionHandling {
|
public static class ExceptionHandling {
|
||||||
|
|
||||||
public int successCount;
|
public int successCount;
|
||||||
|
|
||||||
public int failureCount;
|
public int failureCount;
|
||||||
|
|
||||||
public int afterCount;
|
public int afterCount;
|
||||||
|
|
||||||
@AfterReturning("execution(* echo(*))")
|
@AfterReturning("execution(* echo(*))")
|
||||||
|
|
@ -878,10 +885,12 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
abstract class AbstractMakeModifiable {
|
abstract class AbstractMakeModifiable {
|
||||||
|
|
||||||
public interface MutableModifable extends Modifiable {
|
public interface MutableModifable extends Modifiable {
|
||||||
|
|
||||||
void markDirty();
|
void markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ModifiableImpl implements MutableModifable {
|
public static class ModifiableImpl implements MutableModifable {
|
||||||
|
|
||||||
private boolean modified;
|
private boolean modified;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -900,10 +909,9 @@ abstract class AbstractMakeModifiable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before(value="execution(void set*(*)) && this(modifiable) && args(newValue)",
|
@Before(value="execution(void set*(*)) && this(modifiable) && args(newValue)", argNames="modifiable,newValue")
|
||||||
argNames="modifiable,newValue")
|
public void recordModificationIfSetterArgumentDiffersFromOldValue(
|
||||||
public void recordModificationIfSetterArgumentDiffersFromOldValue(JoinPoint jp,
|
JoinPoint jp, MutableModifable mixin, Object newValue) {
|
||||||
MutableModifable mixin, Object newValue) {
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We use the mixin to check and, if necessary, change,
|
* We use the mixin to check and, if necessary, change,
|
||||||
|
|
@ -968,6 +976,7 @@ class MakeITestBeanModifiable extends AbstractMakeModifiable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a declare parents pointcut - spr5307
|
* Adds a declare parents pointcut - spr5307
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
|
|
@ -977,8 +986,7 @@ class MakeITestBeanModifiable extends AbstractMakeModifiable {
|
||||||
class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable {
|
class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable {
|
||||||
|
|
||||||
@DeclareParents(value = "(@org.springframework.aop.aspectj.annotation.Measured *)",
|
@DeclareParents(value = "(@org.springframework.aop.aspectj.annotation.Measured *)",
|
||||||
// @DeclareParents(value = "(@Measured *)", // this would be a nice alternative...
|
defaultImpl = DefaultLockable.class)
|
||||||
defaultImpl=DefaultLockable.class)
|
|
||||||
public static Lockable mixin;
|
public static Lockable mixin;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -990,8 +998,7 @@ class MakeAnnotatedTypeModifiable extends AbstractMakeModifiable {
|
||||||
@Aspect
|
@Aspect
|
||||||
class MakeLockable {
|
class MakeLockable {
|
||||||
|
|
||||||
@DeclareParents(value = "org.springframework..*",
|
@DeclareParents(value = "org.springframework..*", defaultImpl = DefaultLockable.class)
|
||||||
defaultImpl=DefaultLockable.class)
|
|
||||||
public static Lockable mixin;
|
public static Lockable mixin;
|
||||||
|
|
||||||
@Before(value="execution(void set*(*)) && this(mixin)", argNames="mixin")
|
@Before(value="execution(void set*(*)) && this(mixin)", argNames="mixin")
|
||||||
|
|
@ -1043,6 +1050,7 @@ interface Modifiable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used as a target.
|
* Used as a target.
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
|
|
@ -1050,11 +1058,12 @@ interface Modifiable {
|
||||||
interface AnnotatedTarget {
|
interface AnnotatedTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Measured
|
@Measured
|
||||||
class AnnotatedTargetImpl implements AnnotatedTarget {
|
class AnnotatedTargetImpl implements AnnotatedTarget {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@interface Measured {}
|
@interface Measured {}
|
||||||
|
|
||||||
|
|
@ -1078,9 +1087,7 @@ class PerThisAspect {
|
||||||
|
|
||||||
public int count;
|
public int count;
|
||||||
|
|
||||||
/**
|
// Just to check that this doesn't cause problems with introduction processing
|
||||||
* Just to check that this doesn't cause problems with introduction processing
|
|
||||||
*/
|
|
||||||
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
|
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
|
||||||
|
|
||||||
@Around("execution(int *.getAge())")
|
@Around("execution(int *.getAge())")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue