|
|
|
@ -76,7 +76,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
* @return the fixture |
|
|
|
* @return the fixture |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected abstract AspectJAdvisorFactory getFixture(); |
|
|
|
protected abstract AspectJAdvisorFactory getFixture(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRejectsPerCflowAspect() { |
|
|
|
public void testRejectsPerCflowAspect() { |
|
|
|
@ -88,7 +88,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
assertTrue(ex.getMessage().indexOf("PERCFLOW") != -1); |
|
|
|
assertTrue(ex.getMessage().indexOf("PERCFLOW") != -1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRejectsPerCflowBelowAspect() { |
|
|
|
public void testRejectsPerCflowBelowAspect() { |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -105,11 +105,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
int realAge = 65; |
|
|
|
int realAge = 65; |
|
|
|
target.setAge(realAge); |
|
|
|
target.setAge(realAge); |
|
|
|
TestBean itb = (TestBean) createProxy(target, |
|
|
|
TestBean itb = (TestBean) createProxy(target, |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")), |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")), |
|
|
|
TestBean.class); |
|
|
|
TestBean.class); |
|
|
|
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]; |
|
|
|
SyntheticInstantiationAdvisor sia = (SyntheticInstantiationAdvisor) advised.getAdvisors()[1]; |
|
|
|
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
@ -121,10 +121,10 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
// Check that the perclause pointcut is valid
|
|
|
|
// Check that the perclause pointcut is valid
|
|
|
|
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut()); |
|
|
|
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut()); |
|
|
|
|
|
|
|
|
|
|
|
// Hit the method in the per clause to instantiate the aspect
|
|
|
|
// Hit the method in the per clause to instantiate the aspect
|
|
|
|
itb.getSpouse(); |
|
|
|
itb.getSpouse(); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(maaif.isMaterialized()); |
|
|
|
assertTrue(maaif.isMaterialized()); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Around advice must apply", 0, itb.getAge()); |
|
|
|
assertEquals("Around advice must apply", 0, itb.getAge()); |
|
|
|
@ -190,11 +190,11 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
int realAge = 65; |
|
|
|
int realAge = 65; |
|
|
|
target.setAge(realAge); |
|
|
|
target.setAge(realAge); |
|
|
|
TestBean itb = (TestBean) createProxy(target, |
|
|
|
TestBean itb = (TestBean) createProxy(target, |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")), |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")), |
|
|
|
TestBean.class); |
|
|
|
TestBean.class); |
|
|
|
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; |
|
|
|
// 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); |
|
|
|
@ -208,30 +208,30 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
// Check that the perclause pointcut is valid
|
|
|
|
// Check that the perclause pointcut is valid
|
|
|
|
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut()); |
|
|
|
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut()); |
|
|
|
|
|
|
|
|
|
|
|
// Hit the method in the per clause to instantiate the aspect
|
|
|
|
// Hit the method in the per clause to instantiate the aspect
|
|
|
|
itb.getSpouse(); |
|
|
|
itb.getSpouse(); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(maaif.isMaterialized()); |
|
|
|
assertTrue(maaif.isMaterialized()); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)); |
|
|
|
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Around advice must apply", 0, itb.getAge()); |
|
|
|
assertEquals("Around advice must apply", 0, itb.getAge()); |
|
|
|
assertEquals("Around advice must apply", 1, itb.getAge()); |
|
|
|
assertEquals("Around advice must apply", 1, itb.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodException { |
|
|
|
public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodException { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
int realAge = 65; |
|
|
|
int realAge = 65; |
|
|
|
target.setAge(realAge); |
|
|
|
target.setAge(realAge); |
|
|
|
PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory(); |
|
|
|
PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory(); |
|
|
|
TestBean itb = (TestBean) createProxy(target, |
|
|
|
TestBean itb = (TestBean) createProxy(target, |
|
|
|
getFixture().getAdvisors(aif), |
|
|
|
getFixture().getAdvisors(aif), |
|
|
|
TestBean.class); |
|
|
|
TestBean.class); |
|
|
|
assertEquals("No method calls", 0, aif.getInstantiationCount()); |
|
|
|
assertEquals("No method calls", 0, aif.getInstantiationCount()); |
|
|
|
assertEquals("Around advice must now apply", 0, itb.getAge()); |
|
|
|
assertEquals("Around advice must now apply", 0, itb.getAge()); |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
@ -245,19 +245,19 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
// Check that the perclause pointcut is valid
|
|
|
|
// Check that the perclause pointcut is valid
|
|
|
|
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)); |
|
|
|
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut()); |
|
|
|
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut()); |
|
|
|
|
|
|
|
|
|
|
|
// Hit the method in the per clause to instantiate the aspect
|
|
|
|
// Hit the method in the per clause to instantiate the aspect
|
|
|
|
itb.getSpouse(); |
|
|
|
itb.getSpouse(); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(maaif.isMaterialized()); |
|
|
|
assertTrue(maaif.isMaterialized()); |
|
|
|
|
|
|
|
|
|
|
|
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)); |
|
|
|
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)); |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("Around advice must still apply", 1, itb.getAge()); |
|
|
|
assertEquals("Around advice must still apply", 1, itb.getAge()); |
|
|
|
assertEquals("Around advice must still apply", 2, itb.getAge()); |
|
|
|
assertEquals("Around advice must still apply", 2, itb.getAge()); |
|
|
|
|
|
|
|
|
|
|
|
TestBean itb2 = (TestBean) createProxy(target, |
|
|
|
TestBean itb2 = (TestBean) createProxy(target, |
|
|
|
getFixture().getAdvisors(aif), |
|
|
|
getFixture().getAdvisors(aif), |
|
|
|
TestBean.class); |
|
|
|
TestBean.class); |
|
|
|
assertEquals(1, aif.getInstantiationCount()); |
|
|
|
assertEquals(1, aif.getInstantiationCount()); |
|
|
|
assertEquals("Around advice be independent for second instance", 0, itb2.getAge()); |
|
|
|
assertEquals("Around advice be independent for second instance", 0, itb2.getAge()); |
|
|
|
@ -282,20 +282,20 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNamedPointcutFromAspectLibraryWithBinding() { |
|
|
|
public void testNamedPointcutFromAspectLibraryWithBinding() { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new NamedPointcutAspectFromLibraryWithBinding(),"someBean")), |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new NamedPointcutAspectFromLibraryWithBinding(),"someBean")), |
|
|
|
ITestBean.class); |
|
|
|
ITestBean.class); |
|
|
|
itb.setAge(10); |
|
|
|
itb.setAge(10); |
|
|
|
assertEquals("Around advice must apply", 20, itb.getAge()); |
|
|
|
assertEquals("Around advice must apply", 20, itb.getAge()); |
|
|
|
assertEquals(20,target.getAge()); |
|
|
|
assertEquals(20,target.getAge()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void testNamedPointcuts(Object aspectInstance) { |
|
|
|
private void testNamedPointcuts(Object aspectInstance) { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
int realAge = 65; |
|
|
|
int realAge = 65; |
|
|
|
target.setAge(realAge); |
|
|
|
target.setAge(realAge); |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance,"someBean")), |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance,"someBean")), |
|
|
|
ITestBean.class); |
|
|
|
ITestBean.class); |
|
|
|
assertEquals("Around advice must apply", -1, itb.getAge()); |
|
|
|
assertEquals("Around advice must apply", -1, itb.getAge()); |
|
|
|
assertEquals(realAge, target.getAge()); |
|
|
|
assertEquals(realAge, target.getAge()); |
|
|
|
@ -304,8 +304,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithSingleArg() { |
|
|
|
public void testBindingWithSingleArg() { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(),"someBean")), |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(),"someBean")), |
|
|
|
ITestBean.class); |
|
|
|
ITestBean.class); |
|
|
|
itb.setAge(10); |
|
|
|
itb.setAge(10); |
|
|
|
assertEquals("Around advice must apply", 20, itb.getAge()); |
|
|
|
assertEquals("Around advice must apply", 20, itb.getAge()); |
|
|
|
@ -315,10 +315,10 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithMultipleArgsDifferentlyOrdered() { |
|
|
|
public void testBindingWithMultipleArgsDifferentlyOrdered() { |
|
|
|
ManyValuedArgs target = new ManyValuedArgs(); |
|
|
|
ManyValuedArgs target = new ManyValuedArgs(); |
|
|
|
ManyValuedArgs mva = (ManyValuedArgs) createProxy(target, |
|
|
|
ManyValuedArgs mva = (ManyValuedArgs) createProxy(target, |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ManyValuedArgs(),"someBean")), |
|
|
|
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ManyValuedArgs(),"someBean")), |
|
|
|
ManyValuedArgs.class); |
|
|
|
ManyValuedArgs.class); |
|
|
|
|
|
|
|
|
|
|
|
String a = "a"; |
|
|
|
String a = "a"; |
|
|
|
int b = 12; |
|
|
|
int b = 12; |
|
|
|
int c = 25; |
|
|
|
int c = 25; |
|
|
|
@ -327,7 +327,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
String expectedResult = a + b+ c + d + e; |
|
|
|
String expectedResult = a + b+ c + d + e; |
|
|
|
assertEquals(expectedResult, mva.mungeArgs(a, b, c, d, e)); |
|
|
|
assertEquals(expectedResult, mva.mungeArgs(a, b, c, d, e)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* In this case the introduction will be made. |
|
|
|
* In this case the introduction will be made. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -344,7 +344,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
assertFalse(lockable.locked()); |
|
|
|
assertFalse(lockable.locked()); |
|
|
|
lockable.lock(); |
|
|
|
lockable.lock(); |
|
|
|
assertTrue(lockable.locked()); |
|
|
|
assertTrue(lockable.locked()); |
|
|
|
|
|
|
|
|
|
|
|
NotLockable notLockable2Target = new NotLockable(); |
|
|
|
NotLockable notLockable2Target = new NotLockable(); |
|
|
|
NotLockable notLockable2 = (NotLockable) createProxy(notLockable2Target, |
|
|
|
NotLockable notLockable2 = (NotLockable) createProxy(notLockable2Target, |
|
|
|
getFixture().getAdvisors( |
|
|
|
getFixture().getAdvisors( |
|
|
|
@ -363,17 +363,17 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
assertTrue(lockable2.locked()); |
|
|
|
assertTrue(lockable2.locked()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() { |
|
|
|
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() { |
|
|
|
assertTrue(AopUtils.findAdvisorsThatCanApply( |
|
|
|
assertTrue(AopUtils.findAdvisorsThatCanApply( |
|
|
|
getFixture().getAdvisors( |
|
|
|
getFixture().getAdvisors( |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory( |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory( |
|
|
|
new MakeLockable(),"someBean")), |
|
|
|
new MakeLockable(),"someBean")), |
|
|
|
CannotBeUnlocked.class).isEmpty()); |
|
|
|
CannotBeUnlocked.class).isEmpty()); |
|
|
|
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size()); |
|
|
|
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testIntroductionOnTargetImplementingInterface() { |
|
|
|
public void testIntroductionOnTargetImplementingInterface() { |
|
|
|
CannotBeUnlocked target = new CannotBeUnlocked(); |
|
|
|
CannotBeUnlocked target = new CannotBeUnlocked(); |
|
|
|
@ -398,7 +398,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
// Ok
|
|
|
|
// Ok
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testIntroductionOnTargetExcludedByTypePattern() { |
|
|
|
public void testIntroductionOnTargetExcludedByTypePattern() { |
|
|
|
@ -415,7 +415,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testIntroductionBasedOnAnnotationMatch_Spr5307() { |
|
|
|
public void testIntroductionBasedOnAnnotationMatch_Spr5307() { |
|
|
|
AnnotatedTarget target = new AnnotatedTargetImpl(); |
|
|
|
AnnotatedTarget target = new AnnotatedTargetImpl(); |
|
|
|
|
|
|
|
|
|
|
|
List<Advisor> advisors = getFixture().getAdvisors( |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors( |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(),"someBean")); |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(),"someBean")); |
|
|
|
Object proxy = createProxy(target, |
|
|
|
Object proxy = createProxy(target, |
|
|
|
@ -430,19 +430,19 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
// TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
|
|
|
|
// TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
|
|
|
|
public void XtestIntroductionWithArgumentBinding() { |
|
|
|
public void XtestIntroductionWithArgumentBinding() { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
|
|
|
|
|
|
|
|
List<Advisor> advisors = getFixture().getAdvisors( |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors( |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeITestBeanModifiable(),"someBean")); |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeITestBeanModifiable(),"someBean")); |
|
|
|
advisors.addAll(getFixture().getAdvisors( |
|
|
|
advisors.addAll(getFixture().getAdvisors( |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean"))); |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean"))); |
|
|
|
|
|
|
|
|
|
|
|
Modifiable modifiable = (Modifiable) createProxy(target, |
|
|
|
Modifiable modifiable = (Modifiable) createProxy(target, |
|
|
|
advisors, |
|
|
|
advisors, |
|
|
|
ITestBean.class); |
|
|
|
ITestBean.class); |
|
|
|
assertTrue(modifiable instanceof Modifiable); |
|
|
|
assertTrue(modifiable instanceof Modifiable); |
|
|
|
Lockable lockable = (Lockable) modifiable; |
|
|
|
Lockable lockable = (Lockable) modifiable; |
|
|
|
assertFalse(lockable.locked()); |
|
|
|
assertFalse(lockable.locked()); |
|
|
|
|
|
|
|
|
|
|
|
ITestBean itb = (ITestBean) modifiable; |
|
|
|
ITestBean itb = (ITestBean) modifiable; |
|
|
|
assertFalse(modifiable.isModified()); |
|
|
|
assertFalse(modifiable.isModified()); |
|
|
|
int oldAge = itb.getAge(); |
|
|
|
int oldAge = itb.getAge(); |
|
|
|
@ -454,7 +454,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
assertFalse("Setting same value does not modify", modifiable.isModified()); |
|
|
|
assertFalse("Setting same value does not modify", modifiable.isModified()); |
|
|
|
itb.setName("And now for something completely different"); |
|
|
|
itb.setName("And now for something completely different"); |
|
|
|
assertTrue(modifiable.isModified()); |
|
|
|
assertTrue(modifiable.isModified()); |
|
|
|
|
|
|
|
|
|
|
|
lockable.lock(); |
|
|
|
lockable.lock(); |
|
|
|
assertTrue(lockable.locked()); |
|
|
|
assertTrue(lockable.locked()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
@ -474,8 +474,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
UnsupportedOperationException expectedException = new UnsupportedOperationException(); |
|
|
|
UnsupportedOperationException expectedException = new UnsupportedOperationException(); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean")); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean")); |
|
|
|
assertEquals("One advice method was found", 1, advisors.size()); |
|
|
|
assertEquals("One advice method was found", 1, advisors.size()); |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
advisors, |
|
|
|
advisors, |
|
|
|
ITestBean.class); |
|
|
|
ITestBean.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
itb.getAge(); |
|
|
|
itb.getAge(); |
|
|
|
@ -485,7 +485,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
assertSame(expectedException, ex); |
|
|
|
assertSame(expectedException, ex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO document this behaviour.
|
|
|
|
// TODO document this behaviour.
|
|
|
|
// Is it different AspectJ behaviour, at least for checked exceptions?
|
|
|
|
// Is it different AspectJ behaviour, at least for checked exceptions?
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -494,8 +494,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
RemoteException expectedException = new RemoteException(); |
|
|
|
RemoteException expectedException = new RemoteException(); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean")); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException),"someBean")); |
|
|
|
assertEquals("One advice method was found", 1, advisors.size()); |
|
|
|
assertEquals("One advice method was found", 1, advisors.size()); |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
advisors, |
|
|
|
advisors, |
|
|
|
ITestBean.class); |
|
|
|
ITestBean.class); |
|
|
|
try { |
|
|
|
try { |
|
|
|
itb.getAge(); |
|
|
|
itb.getAge(); |
|
|
|
@ -505,7 +505,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
assertSame(expectedException, ex.getCause()); |
|
|
|
assertSame(expectedException, ex.getCause()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) { |
|
|
|
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) { |
|
|
|
ProxyFactory pf = new ProxyFactory(target); |
|
|
|
ProxyFactory pf = new ProxyFactory(target); |
|
|
|
if (interfaces.length > 1 || interfaces[0].isInterface()) { |
|
|
|
if (interfaces.length > 1 || interfaces[0].isInterface()) { |
|
|
|
@ -533,8 +533,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect(); |
|
|
|
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect(); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect,"someBean")); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect,"someBean")); |
|
|
|
assertEquals("Two advice methods found", 2, advisors.size()); |
|
|
|
assertEquals("Two advice methods found", 2, advisors.size()); |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
ITestBean itb = (ITestBean) createProxy(target, |
|
|
|
advisors, |
|
|
|
advisors, |
|
|
|
ITestBean.class); |
|
|
|
ITestBean.class); |
|
|
|
itb.setName(""); |
|
|
|
itb.setName(""); |
|
|
|
assertEquals(0, itb.getAge()); |
|
|
|
assertEquals(0, itb.getAge()); |
|
|
|
@ -549,8 +549,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
|
|
|
|
|
|
|
|
ExceptionHandling afterReturningAspect = new ExceptionHandling(); |
|
|
|
ExceptionHandling afterReturningAspect = new ExceptionHandling(); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(afterReturningAspect,"someBean")); |
|
|
|
List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(afterReturningAspect,"someBean")); |
|
|
|
Echo echo = (Echo) createProxy(target, |
|
|
|
Echo echo = (Echo) createProxy(target, |
|
|
|
advisors, |
|
|
|
advisors, |
|
|
|
Echo.class); |
|
|
|
Echo.class); |
|
|
|
assertEquals(0, afterReturningAspect.successCount); |
|
|
|
assertEquals(0, afterReturningAspect.successCount); |
|
|
|
assertEquals("", echo.echo("")); |
|
|
|
assertEquals("", echo.echo("")); |
|
|
|
@ -886,45 +886,45 @@ public abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Aspect |
|
|
|
@Aspect |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
public void acceptChanges() { |
|
|
|
public void acceptChanges() { |
|
|
|
modified = false; |
|
|
|
modified = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isModified() { |
|
|
|
public boolean isModified() { |
|
|
|
return modified; |
|
|
|
return modified; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void markDirty() { |
|
|
|
public void markDirty() { |
|
|
|
this.modified = true; |
|
|
|
this.modified = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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(JoinPoint jp, |
|
|
|
public void recordModificationIfSetterArgumentDiffersFromOldValue(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, |
|
|
|
* modification status. We need the JoinPoint to get the |
|
|
|
* modification status. We need the JoinPoint to get the |
|
|
|
* setter method. We use newValue for comparison. |
|
|
|
* setter method. We use newValue for comparison. |
|
|
|
* We try to invoke the getter if possible. |
|
|
|
* We try to invoke the getter if possible. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
if (mixin.isModified()) { |
|
|
|
if (mixin.isModified()) { |
|
|
|
// Already changed, don't need to change again
|
|
|
|
// Already changed, don't need to change again
|
|
|
|
//System.out.println("changed");
|
|
|
|
//System.out.println("changed");
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Find the current raw value, by invoking the corresponding setter
|
|
|
|
// Find the current raw value, by invoking the corresponding setter
|
|
|
|
Method correspondingGetter = getGetterFromSetter(((MethodSignature) jp.getSignature()).getMethod()); |
|
|
|
Method correspondingGetter = getGetterFromSetter(((MethodSignature) jp.getSignature()).getMethod()); |
|
|
|
boolean modified = true; |
|
|
|
boolean modified = true; |
|
|
|
@ -946,12 +946,12 @@ abstract class AbstractMakeModifiable { |
|
|
|
mixin.markDirty(); |
|
|
|
mixin.markDirty(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Method getGetterFromSetter(Method setter) { |
|
|
|
private Method getGetterFromSetter(Method setter) { |
|
|
|
String getterName = setter.getName().replaceFirst("set", "get"); |
|
|
|
String getterName = setter.getName().replaceFirst("set", "get"); |
|
|
|
try { |
|
|
|
try { |
|
|
|
return setter.getDeclaringClass().getMethod(getterName, (Class[]) null); |
|
|
|
return setter.getDeclaringClass().getMethod(getterName, (Class[]) null); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (NoSuchMethodException ex) { |
|
|
|
catch (NoSuchMethodException ex) { |
|
|
|
// must be write only
|
|
|
|
// must be write only
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
@ -968,7 +968,7 @@ abstract class AbstractMakeModifiable { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Aspect |
|
|
|
@Aspect |
|
|
|
class MakeITestBeanModifiable extends AbstractMakeModifiable { |
|
|
|
class MakeITestBeanModifiable extends AbstractMakeModifiable { |
|
|
|
|
|
|
|
|
|
|
|
@DeclareParents(value = "test.beans.ITestBean+", |
|
|
|
@DeclareParents(value = "test.beans.ITestBean+", |
|
|
|
defaultImpl=ModifiableImpl.class) |
|
|
|
defaultImpl=ModifiableImpl.class) |
|
|
|
public static MutableModifable mixin; |
|
|
|
public static MutableModifable mixin; |
|
|
|
@ -982,7 +982,7 @@ class MakeITestBeanModifiable extends AbstractMakeModifiable { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Aspect |
|
|
|
@Aspect |
|
|
|
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...
|
|
|
|
// @DeclareParents(value = "(@Measured *)", // this would be a nice alternative...
|
|
|
|
defaultImpl=DefaultLockable.class) |
|
|
|
defaultImpl=DefaultLockable.class) |
|
|
|
@ -996,11 +996,11 @@ 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") |
|
|
|
public void checkNotLocked( |
|
|
|
public void checkNotLocked( |
|
|
|
Lockable mixin) // Bind to arg
|
|
|
|
Lockable mixin) // Bind to arg
|
|
|
|
@ -1043,9 +1043,9 @@ class CannotBeUnlocked implements Lockable, Comparable<Object> { |
|
|
|
interface Modifiable { |
|
|
|
interface Modifiable { |
|
|
|
|
|
|
|
|
|
|
|
boolean isModified(); |
|
|
|
boolean isModified(); |
|
|
|
|
|
|
|
|
|
|
|
void acceptChanges(); |
|
|
|
void acceptChanges(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -1057,14 +1057,14 @@ interface AnnotatedTarget { |
|
|
|
|
|
|
|
|
|
|
|
@Measured |
|
|
|
@Measured |
|
|
|
class AnnotatedTargetImpl implements AnnotatedTarget { |
|
|
|
class AnnotatedTargetImpl implements AnnotatedTarget { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@Retention(RetentionPolicy.RUNTIME) |
|
|
|
@interface Measured {} |
|
|
|
@interface Measured {} |
|
|
|
|
|
|
|
|
|
|
|
class NotLockable { |
|
|
|
class NotLockable { |
|
|
|
|
|
|
|
|
|
|
|
private int intValue; |
|
|
|
private int intValue; |
|
|
|
|
|
|
|
|
|
|
|
public int getIntValue() { |
|
|
|
public int getIntValue() { |
|
|
|
@ -1097,5 +1097,5 @@ class PerThisAspect { |
|
|
|
public void countSetter() { |
|
|
|
public void countSetter() { |
|
|
|
++count; |
|
|
|
++count; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|