|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -37,7 +37,6 @@ import org.aspectj.lang.annotation.DeclareParents; |
|
|
|
import org.aspectj.lang.annotation.DeclarePrecedence; |
|
|
|
import org.aspectj.lang.annotation.DeclarePrecedence; |
|
|
|
import org.aspectj.lang.annotation.Pointcut; |
|
|
|
import org.aspectj.lang.annotation.Pointcut; |
|
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
|
import org.aspectj.lang.reflect.MethodSignature; |
|
|
|
import org.junit.jupiter.api.Disabled; |
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import test.aop.DefaultLockable; |
|
|
|
import test.aop.DefaultLockable; |
|
|
|
import test.aop.Lockable; |
|
|
|
import test.aop.Lockable; |
|
|
|
@ -76,25 +75,24 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* To be overridden by concrete test subclasses. |
|
|
|
* To be overridden by concrete test subclasses. |
|
|
|
* @return the fixture |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected abstract AspectJAdvisorFactory getFixture(); |
|
|
|
protected abstract AspectJAdvisorFactory getFixture(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void rejectsPerCflowAspect() { |
|
|
|
void rejectsPerCflowAspect() { |
|
|
|
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(AopConfigException.class) |
|
|
|
getFixture().getAdvisors( |
|
|
|
.isThrownBy(() -> getFixture().getAdvisors( |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowAspect(), "someBean"))) |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowAspect(), "someBean"))) |
|
|
|
.withMessageContaining("PERCFLOW"); |
|
|
|
.withMessageContaining("PERCFLOW"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void rejectsPerCflowBelowAspect() { |
|
|
|
void rejectsPerCflowBelowAspect() { |
|
|
|
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(AopConfigException.class) |
|
|
|
getFixture().getAdvisors( |
|
|
|
.isThrownBy(() -> getFixture().getAdvisors( |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowBelowAspect(), "someBean"))) |
|
|
|
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowBelowAspect(), "someBean"))) |
|
|
|
.withMessageContaining("PERCFLOWBELOW"); |
|
|
|
.withMessageContaining("PERCFLOWBELOW"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -385,8 +383,7 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
assertThat(lockable.locked()).as("Already locked").isTrue(); |
|
|
|
assertThat(lockable.locked()).as("Already locked").isTrue(); |
|
|
|
lockable.lock(); |
|
|
|
lockable.lock(); |
|
|
|
assertThat(lockable.locked()).as("Real target ignores locking").isTrue(); |
|
|
|
assertThat(lockable.locked()).as("Real target ignores locking").isTrue(); |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(lockable::unlock); |
|
|
|
lockable.unlock()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -413,9 +410,7 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
lockable.locked(); |
|
|
|
lockable.locked(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@Disabled |
|
|
|
|
|
|
|
void introductionWithArgumentBinding() { |
|
|
|
void introductionWithArgumentBinding() { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
|
|
|
|
|
|
|
|
@ -523,6 +518,16 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "after throwing", "after", "around - end"); |
|
|
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "after throwing", "after", "around - end"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void parentAspect() { |
|
|
|
|
|
|
|
TestBean target = new TestBean("Jane", 42); |
|
|
|
|
|
|
|
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory( |
|
|
|
|
|
|
|
new IncrementingAspect(), "incrementingAspect"); |
|
|
|
|
|
|
|
ITestBean proxy = (ITestBean) createProxy(target, |
|
|
|
|
|
|
|
getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class); |
|
|
|
|
|
|
|
assertThat(proxy.getAge()).isEqualTo(86); // (42 + 1) * 2
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void failureWithoutExplicitDeclarePrecedence() { |
|
|
|
void failureWithoutExplicitDeclarePrecedence() { |
|
|
|
TestBean target = new TestBean(); |
|
|
|
TestBean target = new TestBean(); |
|
|
|
@ -647,7 +652,7 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
static class NamedPointcutAspectWithFQN { |
|
|
|
static class NamedPointcutAspectWithFQN { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean(); |
|
|
|
private final ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean(); |
|
|
|
|
|
|
|
|
|
|
|
@Pointcut("execution(* getAge())") |
|
|
|
@Pointcut("execution(* getAge())") |
|
|
|
void getAge() { |
|
|
|
void getAge() { |
|
|
|
@ -767,6 +772,31 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Aspect |
|
|
|
|
|
|
|
abstract static class DoublingAspect { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Around("execution(* getAge())") |
|
|
|
|
|
|
|
public Object doubleAge(ProceedingJoinPoint pjp) throws Throwable { |
|
|
|
|
|
|
|
return ((int) pjp.proceed()) * 2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Aspect |
|
|
|
|
|
|
|
static class IncrementingAspect extends DoublingAspect { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Object doubleAge(ProceedingJoinPoint pjp) throws Throwable { |
|
|
|
|
|
|
|
return ((int) pjp.proceed()) * 2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Around("execution(* getAge())") |
|
|
|
|
|
|
|
public int incrementAge(ProceedingJoinPoint pjp) throws Throwable { |
|
|
|
|
|
|
|
return ((int) pjp.proceed()) + 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Aspect |
|
|
|
@Aspect |
|
|
|
private static class InvocationTrackingAspect { |
|
|
|
private static class InvocationTrackingAspect { |
|
|
|
|
|
|
|
|
|
|
|
@ -824,7 +854,7 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
|
|
|
|
|
|
|
|
@Around("getAge()") |
|
|
|
@Around("getAge()") |
|
|
|
int preventExecution(ProceedingJoinPoint pjp) { |
|
|
|
int preventExecution(ProceedingJoinPoint pjp) { |
|
|
|
return 666; |
|
|
|
return 42; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -844,7 +874,7 @@ abstract class AbstractAspectJAdvisorFactoryTests { |
|
|
|
|
|
|
|
|
|
|
|
@Around("getAge()") |
|
|
|
@Around("getAge()") |
|
|
|
int preventExecution(ProceedingJoinPoint pjp) { |
|
|
|
int preventExecution(ProceedingJoinPoint pjp) { |
|
|
|
return 666; |
|
|
|
return 42; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1066,7 +1096,7 @@ class PerThisAspect { |
|
|
|
|
|
|
|
|
|
|
|
// Just to check that this doesn't cause problems with introduction processing
|
|
|
|
// Just to check that this doesn't cause problems with introduction processing
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean(); |
|
|
|
private final ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean(); |
|
|
|
|
|
|
|
|
|
|
|
@Around("execution(int *.getAge())") |
|
|
|
@Around("execution(int *.getAge())") |
|
|
|
int returnCountAsAge() { |
|
|
|
int returnCountAsAge() { |
|
|
|
|