BAEL-3180: Simplify spring-aop tests

This commit is contained in:
Krzysiek 2019-12-28 22:34:21 +01:00
parent 17dc359d5b
commit 531b01ec86
6 changed files with 59 additions and 71 deletions

View File

@ -6,7 +6,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }

View File

@ -1,54 +1,54 @@
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd"> xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<bean id="sampleAdder" <bean id="sampleAdder"
class="com.baeldung.logger.SampleAdder" /> class="com.baeldung.logger.SampleAdder" />
<bean id="doBeforeAspect" class="com.baeldung.logger.AdderBeforeAspect" /> <bean id="doBeforeAspect" class="com.baeldung.logger.AdderBeforeAspect" />
<bean id="doAfterAspect" class="com.baeldung.logger.AdderAfterAspect" /> <bean id="doAfterAspect" class="com.baeldung.logger.AdderAfterAspect" />
<bean id="doAfterThrowingAspect" class="com.baeldung.logger.AdderAfterThrowAspect" /> <bean id="doAfterThrowingAspect" class="com.baeldung.logger.AdderAfterThrowAspect" />
<bean id="doAfterReturningAspect" class="com.baeldung.logger.AdderAfterReturnAspect" /> <bean id="doAfterReturningAspect" class="com.baeldung.logger.AdderAfterReturnAspect" />
<bean id="doAroundAspect" class="com.baeldung.logger.AdderAroundAspect" /> <bean id="doAroundAspect" class="com.baeldung.logger.AdderAroundAspect" />
<aop:config> <aop:config>
<aop:aspect id="aspects" ref="doBeforeAspect"> <aop:aspect id="aspects" ref="doBeforeAspect">
<aop:pointcut id="pointCutBefore" <aop:pointcut id="pointCutBefore"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" /> expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:before method="beforeAdvice" pointcut-ref="pointCutBefore" /> <aop:before method="beforeAdvice" pointcut-ref="pointCutBefore" />
</aop:aspect> </aop:aspect>
<aop:aspect id="aspects" ref="doAfterAspect"> <aop:aspect id="aspects" ref="doAfterAspect">
<aop:pointcut id="pointCutAfter" <aop:pointcut id="pointCutAfter"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" /> expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after method="afterAdvice" pointcut-ref="pointCutAfter" /> <aop:after method="afterAdvice" pointcut-ref="pointCutAfter" />
</aop:aspect> </aop:aspect>
<aop:aspect id="aspects" ref="doAfterReturningAspect"> <aop:aspect id="aspects" ref="doAfterReturningAspect">
<aop:pointcut id="pointCutAfterReturning" <aop:pointcut id="pointCutAfterReturning"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" /> expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-returning method="afterReturn" <aop:after-returning method="afterReturn"
returning="returnValue" pointcut-ref="pointCutAfterReturning" /> returning="returnValue" pointcut-ref="pointCutAfterReturning" />
</aop:aspect> </aop:aspect>
<aop:aspect id="aspects" ref="doAfterThrowingAspect"> <aop:aspect id="aspects" ref="doAfterThrowingAspect">
<aop:pointcut id="pointCutAfterThrowing" <aop:pointcut id="pointCutAfterThrowing"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" /> expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-throwing method="afterThrow" <aop:after-throwing method="afterThrow"
throwing="error" pointcut-ref="pointCutAfterThrowing" /> throwing="error" pointcut-ref="pointCutAfterThrowing" />
</aop:aspect> </aop:aspect>
<aop:aspect id="aspects" ref="doAroundAspect"> <aop:aspect id="aspects" ref="doAroundAspect">
<aop:pointcut id="pointCutAround" <aop:pointcut id="pointCutAround"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" /> expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:around method="aroundAdvice" pointcut-ref="pointCutAround" /> <aop:around method="aroundAdvice" pointcut-ref="pointCutAround" />
</aop:aspect> </aop:aspect>
</aop:config> </aop:config>
</beans> </beans>

View File

@ -1,11 +0,0 @@
package com.baeldung;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
@Configuration
@ComponentScan(basePackages = { "com.baeldung.pointcutadvice" })
@EnableAspectJAutoProxy
public class TestConfig {
}

View File

@ -1,6 +1,6 @@
package com.baeldung.pointcutadvice; package com.baeldung.pointcutadvice;
import com.baeldung.TestConfig; import com.baeldung.Application;
import com.baeldung.pointcutadvice.dao.FooDao; import com.baeldung.pointcutadvice.dao.FooDao;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -23,7 +23,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = {Application.class}, loader = AnnotationConfigContextLoader.class)
public class AopLoggingIntegrationTest { public class AopLoggingIntegrationTest {
@Before @Before

View File

@ -1,6 +1,6 @@
package com.baeldung.pointcutadvice; package com.baeldung.pointcutadvice;
import com.baeldung.TestConfig; import com.baeldung.Application;
import com.baeldung.pointcutadvice.dao.FooDao; import com.baeldung.pointcutadvice.dao.FooDao;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -23,7 +23,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { TestConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = {Application.class}, loader = AnnotationConfigContextLoader.class)
public class AopPerformanceIntegrationTest { public class AopPerformanceIntegrationTest {
@Before @Before

View File

@ -1,6 +1,6 @@
package com.baeldung.pointcutadvice; package com.baeldung.pointcutadvice;
import com.baeldung.TestConfig; import com.baeldung.Application;
import com.baeldung.pointcutadvice.dao.FooDao; import com.baeldung.pointcutadvice.dao.FooDao;
import com.baeldung.pointcutadvice.events.FooCreationEventListener; import com.baeldung.pointcutadvice.events.FooCreationEventListener;
import org.junit.Before; import org.junit.Before;
@ -21,7 +21,7 @@ import java.util.regex.Pattern;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = {Application.class}, loader = AnnotationConfigContextLoader.class)
public class AopPublishingIntegrationTest { public class AopPublishingIntegrationTest {
@Before @Before