|
|
@ -16,18 +16,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.aop;
|
|
|
|
package org.springframework.boot.autoconfigure.aop;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.springframework.boot.TestUtils;
|
|
|
|
import org.springframework.boot.TestUtils;
|
|
|
|
import org.springframework.boot.autoconfigure.aop.AopAutoConfigurationTests.TestInterface;
|
|
|
|
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Tests for {@link AopAutoConfiguration}.
|
|
|
|
* Tests for {@link AopAutoConfiguration}.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -43,12 +43,26 @@ public class AopAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private AnnotationConfigApplicationContext context;
|
|
|
|
private AnnotationConfigApplicationContext context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void testNoAopAutoConfiguration() {
|
|
|
|
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
|
|
|
|
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.aop.auto:false");
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
|
|
|
|
TestAspect aspect = this.context.getBean(TestAspect.class);
|
|
|
|
|
|
|
|
assertFalse(aspect.isCalled());
|
|
|
|
|
|
|
|
TestBean bean = this.context.getBean(TestBean.class);
|
|
|
|
|
|
|
|
bean.foo();
|
|
|
|
|
|
|
|
assertFalse(aspect.isCalled());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testAopAutoConfigurationProxyTargetClass() {
|
|
|
|
public void testAopAutoConfigurationProxyTargetClass() {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(TestConfiguration.class, AopAutoConfiguration.class);
|
|
|
|
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:true");
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:true");
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.aop.auto:true");
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
TestAspect aspect = this.context.getBean(TestAspect.class);
|
|
|
|
TestAspect aspect = this.context.getBean(TestAspect.class);
|
|
|
|
assertFalse(aspect.isCalled());
|
|
|
|
assertFalse(aspect.isCalled());
|
|
|
@ -57,13 +71,12 @@ public class AopAutoConfigurationTests {
|
|
|
|
assertTrue(aspect.isCalled());
|
|
|
|
assertTrue(aspect.isCalled());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void testAopAutoConfigurationNoProxyTargetClass() {
|
|
|
|
public void testAopAutoConfigurationNoProxyTargetClass() {
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context = new AnnotationConfigApplicationContext();
|
|
|
|
this.context.register(TestConfiguration.class, AopAutoConfiguration.class);
|
|
|
|
this.context.register(TestConfiguration.class, AopAutoConfiguration.class,
|
|
|
|
|
|
|
|
PropertyPlaceholderAutoConfiguration.class);
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:false");
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.aop.proxyTargetClass:false");
|
|
|
|
TestUtils.addEnviroment(this.context, "spring.aop.auto:true");
|
|
|
|
|
|
|
|
this.context.refresh();
|
|
|
|
this.context.refresh();
|
|
|
|
TestAspect aspect = this.context.getBean(TestAspect.class);
|
|
|
|
TestAspect aspect = this.context.getBean(TestAspect.class);
|
|
|
|
assertFalse(aspect.isCalled());
|
|
|
|
assertFalse(aspect.isCalled());
|
|
|
@ -78,6 +91,7 @@ public class AopAutoConfigurationTests {
|
|
|
|
public TestAspect aspect() {
|
|
|
|
public TestAspect aspect() {
|
|
|
|
return new TestAspect();
|
|
|
|
return new TestAspect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public TestInterface bean() {
|
|
|
|
public TestInterface bean() {
|
|
|
|
return new TestBean();
|
|
|
|
return new TestBean();
|
|
|
@ -89,18 +103,18 @@ public class AopAutoConfigurationTests {
|
|
|
|
public void foo() {
|
|
|
|
public void foo() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Aspect
|
|
|
|
@Aspect
|
|
|
|
protected static class TestAspect {
|
|
|
|
protected static class TestAspect {
|
|
|
|
private boolean called;
|
|
|
|
private boolean called;
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isCalled() {
|
|
|
|
public boolean isCalled() {
|
|
|
|
return called;
|
|
|
|
return this.called;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Before("execution(* foo(..))")
|
|
|
|
@Before("execution(* foo(..))")
|
|
|
|
public void before() {
|
|
|
|
public void before() {
|
|
|
|
called=true;
|
|
|
|
this.called = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|