Test status quo for invocation order of all advice types
Prior to this commit we did not have tests in place to verify the status quo for the invocation order of all advice types when declared within a single aspect, either via the <aop:aspect> XML namespace or AspectJ auto-proxy support. This commit introduces such tests that demonstrate where such ordering is broken or suboptimal. The only test for which the advice invocation order is correct or at least as expected is the afterAdviceTypes() test method in ReflectiveAspectJAdvisorFactoryTests, where an AOP proxy is hand crafted using ReflectiveAspectJAdvisorFactory without the use of Spring's AspectJPrecedenceComparator. See gh-25186
This commit is contained in:
parent
04c8de4e50
commit
fbeecf3bf8
|
@ -19,6 +19,7 @@ package org.springframework.aop.config;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@ -45,14 +46,14 @@ class AopNamespaceHandlerAdviceOrderIntegrationTests {
|
||||||
class AfterAdviceFirstTests {
|
class AfterAdviceFirstTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void afterAdviceIsInvokedFirst(@Autowired Echo echo, @Autowired EchoAspect aspect) throws Exception {
|
void afterAdviceIsInvokedFirst(@Autowired Echo echo, @Autowired InvocationTrackingAspect aspect) throws Exception {
|
||||||
assertThat(aspect.invocations).isEmpty();
|
assertThat(aspect.invocations).isEmpty();
|
||||||
assertThat(echo.echo(42)).isEqualTo(42);
|
assertThat(echo.echo(42)).isEqualTo(42);
|
||||||
assertThat(aspect.invocations).containsExactly("after", "after returning");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after", "after returning");
|
||||||
|
|
||||||
aspect.invocations.clear();
|
aspect.invocations.clear();
|
||||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> echo.echo(new Exception()));
|
assertThatExceptionOfType(Exception.class).isThrownBy(() -> echo.echo(new Exception()));
|
||||||
assertThat(aspect.invocations).containsExactly("after", "after throwing");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after", "after throwing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,14 +63,14 @@ class AopNamespaceHandlerAdviceOrderIntegrationTests {
|
||||||
class AfterAdviceLastTests {
|
class AfterAdviceLastTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void afterAdviceIsInvokedLast(@Autowired Echo echo, @Autowired EchoAspect aspect) throws Exception {
|
void afterAdviceIsInvokedLast(@Autowired Echo echo, @Autowired InvocationTrackingAspect aspect) throws Exception {
|
||||||
assertThat(aspect.invocations).isEmpty();
|
assertThat(aspect.invocations).isEmpty();
|
||||||
assertThat(echo.echo(42)).isEqualTo(42);
|
assertThat(echo.echo(42)).isEqualTo(42);
|
||||||
assertThat(aspect.invocations).containsExactly("after returning", "after");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after returning", "after");
|
||||||
|
|
||||||
aspect.invocations.clear();
|
aspect.invocations.clear();
|
||||||
assertThatExceptionOfType(Exception.class).isThrownBy(() -> echo.echo(new Exception()));
|
assertThatExceptionOfType(Exception.class).isThrownBy(() -> echo.echo(new Exception()));
|
||||||
assertThat(aspect.invocations).containsExactly("after throwing", "after");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after throwing", "after");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,18 +85,29 @@ class AopNamespaceHandlerAdviceOrderIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class EchoAspect {
|
static class InvocationTrackingAspect {
|
||||||
|
|
||||||
List<String> invocations = new ArrayList<>();
|
List<String> invocations = new ArrayList<>();
|
||||||
|
|
||||||
void echo() {
|
Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
invocations.add("around - start");
|
||||||
|
try {
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
invocations.add("around - end");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void succeeded() {
|
void before() {
|
||||||
|
invocations.add("before");
|
||||||
|
}
|
||||||
|
|
||||||
|
void afterReturning() {
|
||||||
invocations.add("after returning");
|
invocations.add("after returning");
|
||||||
}
|
}
|
||||||
|
|
||||||
void failed() {
|
void afterThrowing() {
|
||||||
invocations.add("after throwing");
|
invocations.add("after throwing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,13 @@ package org.springframework.aop.framework.autoproxy;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.After;
|
import org.aspectj.lang.annotation.After;
|
||||||
import org.aspectj.lang.annotation.AfterReturning;
|
import org.aspectj.lang.annotation.AfterReturning;
|
||||||
import org.aspectj.lang.annotation.AfterThrowing;
|
import org.aspectj.lang.annotation.AfterThrowing;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.junit.jupiter.api.Nested;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -47,25 +50,39 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
*/
|
*/
|
||||||
class AspectJAutoProxyAdviceOrderIntegrationTests {
|
class AspectJAutoProxyAdviceOrderIntegrationTests {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link After @After} advice declared as first <em>after</em> method in source code.
|
||||||
|
*/
|
||||||
@Nested
|
@Nested
|
||||||
@SpringJUnitConfig(AfterAdviceFirstConfig.class)
|
@SpringJUnitConfig(AfterAdviceFirstConfig.class)
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
class AfterAdviceFirstTests {
|
class AfterAdviceFirstTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void afterAdviceIsInvokedFirst(@Autowired Echo echo, @Autowired AfterAdviceFirstAspect aspect) throws Exception {
|
void afterAdviceIsNotInvokedLast(@Autowired Echo echo, @Autowired AfterAdviceFirstAspect aspect) throws Exception {
|
||||||
assertThat(aspect.invocations).isEmpty();
|
assertThat(aspect.invocations).isEmpty();
|
||||||
assertThat(echo.echo(42)).isEqualTo(42);
|
assertThat(echo.echo(42)).isEqualTo(42);
|
||||||
assertThat(aspect.invocations).containsExactly("after", "after returning");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after", "after returning");
|
||||||
|
|
||||||
aspect.invocations.clear();
|
aspect.invocations.clear();
|
||||||
assertThatExceptionOfType(Exception.class).isThrownBy(
|
assertThatExceptionOfType(Exception.class).isThrownBy(
|
||||||
() -> echo.echo(new Exception()));
|
() -> echo.echo(new Exception()));
|
||||||
assertThat(aspect.invocations).containsExactly("after", "after throwing");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after", "after throwing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test class uses {@link AfterAdviceLastAspect} which declares its
|
||||||
|
* {@link After @After} advice as the last <em>after advice type</em> method
|
||||||
|
* in its source code.
|
||||||
|
*
|
||||||
|
* <p>On Java versions prior to JDK 7, we would have expected the {@code @After}
|
||||||
|
* advice method to be invoked after {@code @AfterThrowing} and
|
||||||
|
* {@code @AfterReturning} advice methods due to the AspectJ precedence
|
||||||
|
* rules implemented in
|
||||||
|
* {@link org.springframework.aop.aspectj.autoproxy.AspectJPrecedenceComparator}.
|
||||||
|
*/
|
||||||
@Nested
|
@Nested
|
||||||
@SpringJUnitConfig(AfterAdviceLastConfig.class)
|
@SpringJUnitConfig(AfterAdviceLastConfig.class)
|
||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
|
@ -75,14 +92,12 @@ class AspectJAutoProxyAdviceOrderIntegrationTests {
|
||||||
void afterAdviceIsNotInvokedLast(@Autowired Echo echo, @Autowired AfterAdviceLastAspect aspect) throws Exception {
|
void afterAdviceIsNotInvokedLast(@Autowired Echo echo, @Autowired AfterAdviceLastAspect aspect) throws Exception {
|
||||||
assertThat(aspect.invocations).isEmpty();
|
assertThat(aspect.invocations).isEmpty();
|
||||||
assertThat(echo.echo(42)).isEqualTo(42);
|
assertThat(echo.echo(42)).isEqualTo(42);
|
||||||
// On Java versions prior to JDK 7, we would expect the @After advice to be invoked last.
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after", "after returning");
|
||||||
assertThat(aspect.invocations).containsExactly("after", "after returning");
|
|
||||||
|
|
||||||
aspect.invocations.clear();
|
aspect.invocations.clear();
|
||||||
assertThatExceptionOfType(Exception.class).isThrownBy(
|
assertThatExceptionOfType(Exception.class).isThrownBy(
|
||||||
() -> echo.echo(new Exception()));
|
() -> echo.echo(new Exception()));
|
||||||
// On Java versions prior to JDK 7, we would expect the @After advice to be invoked last.
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "around - end", "after", "after throwing");
|
||||||
assertThat(aspect.invocations).containsExactly("after", "after throwing");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,14 +160,30 @@ class AspectJAutoProxyAdviceOrderIntegrationTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterReturning("echo()")
|
@AfterReturning("echo()")
|
||||||
void succeeded() {
|
void afterReturning() {
|
||||||
invocations.add("after returning");
|
invocations.add("after returning");
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterThrowing("echo()")
|
@AfterThrowing("echo()")
|
||||||
void failed() {
|
void afterThrowing() {
|
||||||
invocations.add("after throwing");
|
invocations.add("after throwing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before("echo()")
|
||||||
|
void before() {
|
||||||
|
invocations.add("before");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Around("echo()")
|
||||||
|
Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
invocations.add("around - start");
|
||||||
|
try {
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
invocations.add("around - end");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,13 +198,29 @@ class AspectJAutoProxyAdviceOrderIntegrationTests {
|
||||||
void echo() {
|
void echo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Around("echo()")
|
||||||
|
Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
invocations.add("around - start");
|
||||||
|
try {
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
invocations.add("around - end");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before("echo()")
|
||||||
|
void before() {
|
||||||
|
invocations.add("before");
|
||||||
|
}
|
||||||
|
|
||||||
@AfterReturning("echo()")
|
@AfterReturning("echo()")
|
||||||
void succeeded() {
|
void afterReturning() {
|
||||||
invocations.add("after returning");
|
invocations.add("after returning");
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterThrowing("echo()")
|
@AfterThrowing("echo()")
|
||||||
void failed() {
|
void afterThrowing() {
|
||||||
invocations.add("after throwing");
|
invocations.add("after throwing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,16 @@
|
||||||
|
|
||||||
<bean id="echo" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$Echo"/>
|
<bean id="echo" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$Echo"/>
|
||||||
|
|
||||||
<bean id="echoAspect" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$EchoAspect" />
|
<bean id="invocationTrackingAspect" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$InvocationTrackingAspect" />
|
||||||
|
|
||||||
<aop:config>
|
<aop:config>
|
||||||
<aop:aspect id="echoAdvice" ref="echoAspect">
|
<aop:aspect id="echoAdvice" ref="invocationTrackingAspect">
|
||||||
<aop:pointcut id="echoMethod" expression="execution(* echo(*))" />
|
<aop:pointcut id="echoMethod" expression="execution(* echo(*))" />
|
||||||
|
<aop:around method="around" pointcut-ref="echoMethod" />
|
||||||
|
<aop:before method="before" pointcut-ref="echoMethod" />
|
||||||
<aop:after method="after" pointcut-ref="echoMethod" />
|
<aop:after method="after" pointcut-ref="echoMethod" />
|
||||||
<aop:after-throwing method="failed" pointcut-ref="echoMethod" />
|
<aop:after-throwing method="afterThrowing" pointcut-ref="echoMethod" />
|
||||||
<aop:after-returning method="succeeded" pointcut-ref="echoMethod" />
|
<aop:after-returning method="afterReturning" pointcut-ref="echoMethod" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
</aop:config>
|
</aop:config>
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,15 @@
|
||||||
|
|
||||||
<bean id="echo" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$Echo"/>
|
<bean id="echo" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$Echo"/>
|
||||||
|
|
||||||
<bean id="echoAspect" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$EchoAspect" />
|
<bean id="invocationTrackingAspect" class="org.springframework.aop.config.AopNamespaceHandlerAdviceOrderIntegrationTests$InvocationTrackingAspect" />
|
||||||
|
|
||||||
<aop:config>
|
<aop:config>
|
||||||
<aop:aspect id="echoAdvice" ref="echoAspect">
|
<aop:aspect id="echoAdvice" ref="invocationTrackingAspect">
|
||||||
<aop:pointcut id="echoMethod" expression="execution(* echo(*))" />
|
<aop:pointcut id="echoMethod" expression="execution(* echo(*))" />
|
||||||
<aop:after-returning method="succeeded" pointcut-ref="echoMethod" />
|
<aop:around method="around" pointcut-ref="echoMethod" />
|
||||||
<aop:after-throwing method="failed" pointcut-ref="echoMethod" />
|
<aop:before method="before" pointcut-ref="echoMethod" />
|
||||||
|
<aop:after-throwing method="afterThrowing" pointcut-ref="echoMethod" />
|
||||||
|
<aop:after-returning method="afterReturning" pointcut-ref="echoMethod" />
|
||||||
<aop:after method="after" pointcut-ref="echoMethod" />
|
<aop:after method="after" pointcut-ref="echoMethod" />
|
||||||
</aop:aspect>
|
</aop:aspect>
|
||||||
</aop:config>
|
</aop:config>
|
||||||
|
|
|
@ -455,7 +455,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
TestBean target = new TestBean();
|
TestBean target = new TestBean();
|
||||||
UnsupportedOperationException expectedException = new UnsupportedOperationException();
|
UnsupportedOperationException expectedException = new UnsupportedOperationException();
|
||||||
List<Advisor> advisors = getFixture().getAdvisors(
|
List<Advisor> advisors = getFixture().getAdvisors(
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
|
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionThrowingAspect(expectedException), "someBean"));
|
||||||
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
|
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
|
||||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(
|
||||||
|
@ -469,7 +469,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
TestBean target = new TestBean();
|
TestBean target = new TestBean();
|
||||||
RemoteException expectedException = new RemoteException();
|
RemoteException expectedException = new RemoteException();
|
||||||
List<Advisor> advisors = getFixture().getAdvisors(
|
List<Advisor> advisors = getFixture().getAdvisors(
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
|
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionThrowingAspect(expectedException), "someBean"));
|
||||||
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
|
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
|
||||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||||
assertThatExceptionOfType(UndeclaredThrowableException.class).isThrownBy(
|
assertThatExceptionOfType(UndeclaredThrowableException.class).isThrownBy(
|
||||||
|
@ -510,18 +510,18 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void afterAdviceTypes() throws Exception {
|
void afterAdviceTypes() throws Exception {
|
||||||
ExceptionHandling aspect = new ExceptionHandling();
|
InvocationTrackingAspect aspect = new InvocationTrackingAspect();
|
||||||
List<Advisor> advisors = getFixture().getAdvisors(
|
List<Advisor> advisors = getFixture().getAdvisors(
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(aspect, "exceptionHandlingAspect"));
|
new SingletonMetadataAwareAspectInstanceFactory(aspect, "exceptionHandlingAspect"));
|
||||||
Echo echo = (Echo) createProxy(new Echo(), advisors, Echo.class);
|
Echo echo = (Echo) createProxy(new Echo(), advisors, Echo.class);
|
||||||
|
|
||||||
assertThat(aspect.invocations).isEmpty();
|
assertThat(aspect.invocations).isEmpty();
|
||||||
assertThat(echo.echo(42)).isEqualTo(42);
|
assertThat(echo.echo(42)).isEqualTo(42);
|
||||||
assertThat(aspect.invocations).containsExactly("after returning", "after");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "after returning", "after", "around - end");
|
||||||
|
|
||||||
aspect.invocations.clear();
|
aspect.invocations.clear();
|
||||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() -> echo.echo(new FileNotFoundException()));
|
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() -> echo.echo(new FileNotFoundException()));
|
||||||
assertThat(aspect.invocations).containsExactly("after throwing", "after");
|
assertThat(aspect.invocations).containsExactly("around - start", "before", "after throwing", "after", "around - end");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -742,11 +742,11 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
static class ExceptionAspect {
|
static class ExceptionThrowingAspect {
|
||||||
|
|
||||||
private final Exception ex;
|
private final Exception ex;
|
||||||
|
|
||||||
ExceptionAspect(Exception ex) {
|
ExceptionThrowingAspect(Exception ex) {
|
||||||
this.ex = ex;
|
this.ex = ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
|
|
||||||
|
|
||||||
@Aspect
|
@Aspect
|
||||||
static class ExceptionHandling {
|
private static class InvocationTrackingAspect {
|
||||||
|
|
||||||
List<String> invocations = new ArrayList<>();
|
List<String> invocations = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -778,13 +778,29 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||||
void echo() {
|
void echo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Around("echo()")
|
||||||
|
Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
invocations.add("around - start");
|
||||||
|
try {
|
||||||
|
return joinPoint.proceed();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
invocations.add("around - end");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before("echo()")
|
||||||
|
void before() {
|
||||||
|
invocations.add("before");
|
||||||
|
}
|
||||||
|
|
||||||
@AfterReturning("echo()")
|
@AfterReturning("echo()")
|
||||||
void succeeded() {
|
void afterReturning() {
|
||||||
invocations.add("after returning");
|
invocations.add("after returning");
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterThrowing("echo()")
|
@AfterThrowing("echo()")
|
||||||
void failed() {
|
void afterThrowing() {
|
||||||
invocations.add("after throwing");
|
invocations.add("after throwing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 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.
|
||||||
|
@ -22,6 +22,7 @@ import test.aop.PerTargetAspect;
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
|
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
|
||||||
import org.springframework.aop.aspectj.AspectJExpressionPointcutTests;
|
import org.springframework.aop.aspectj.AspectJExpressionPointcutTests;
|
||||||
|
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionThrowingAspect;
|
||||||
import org.springframework.aop.framework.AopConfigException;
|
import org.springframework.aop.framework.AopConfigException;
|
||||||
import org.springframework.beans.testfixture.beans.TestBean;
|
import org.springframework.beans.testfixture.beans.TestBean;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ public class AspectJPointcutAdvisorTests {
|
||||||
|
|
||||||
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(
|
InstantiationModelAwarePointcutAdvisorImpl ajpa = new InstantiationModelAwarePointcutAdvisorImpl(
|
||||||
ajexp, TestBean.class.getMethod("getAge"), af,
|
ajexp, TestBean.class.getMethod("getAge"), af,
|
||||||
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null), "someBean"),
|
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionThrowingAspect(null), "someBean"),
|
||||||
1, "someBean");
|
1, "someBean");
|
||||||
|
|
||||||
assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isSameAs(Pointcut.TRUE);
|
assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isSameAs(Pointcut.TRUE);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 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.
|
||||||
|
@ -22,7 +22,7 @@ import test.aop.PerTargetAspect;
|
||||||
|
|
||||||
import org.springframework.aop.Pointcut;
|
import org.springframework.aop.Pointcut;
|
||||||
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
|
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
|
||||||
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionAspect;
|
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionThrowingAspect;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
@ -42,7 +42,7 @@ class AspectMetadataTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void singletonAspect() {
|
void singletonAspect() {
|
||||||
AspectMetadata am = new AspectMetadata(ExceptionAspect.class, "someBean");
|
AspectMetadata am = new AspectMetadata(ExceptionThrowingAspect.class, "someBean");
|
||||||
assertThat(am.isPerThisOrPerTarget()).isFalse();
|
assertThat(am.isPerThisOrPerTarget()).isFalse();
|
||||||
assertThat(am.getPerClausePointcut()).isSameAs(Pointcut.TRUE);
|
assertThat(am.getPerClausePointcut()).isSameAs(Pointcut.TRUE);
|
||||||
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.SINGLETON);
|
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.SINGLETON);
|
||||||
|
|
Loading…
Reference in New Issue