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
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

View File

@ -1,54 +1,54 @@
<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: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: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">
<bean id="sampleAdder"
class="com.baeldung.logger.SampleAdder" />
<bean id="doBeforeAspect" class="com.baeldung.logger.AdderBeforeAspect" />
<bean id="doAfterAspect" class="com.baeldung.logger.AdderAfterAspect" />
<bean id="doAfterThrowingAspect" class="com.baeldung.logger.AdderAfterThrowAspect" />
<bean id="doAfterReturningAspect" class="com.baeldung.logger.AdderAfterReturnAspect" />
<bean id="doAroundAspect" class="com.baeldung.logger.AdderAroundAspect" />
<aop:config>
<aop:aspect id="aspects" ref="doBeforeAspect">
<aop:pointcut id="pointCutBefore"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:before method="beforeAdvice" pointcut-ref="pointCutBefore" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAfterAspect">
<aop:pointcut id="pointCutAfter"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after method="afterAdvice" pointcut-ref="pointCutAfter" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAfterReturningAspect">
<aop:pointcut id="pointCutAfterReturning"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-returning method="afterReturn"
returning="returnValue" pointcut-ref="pointCutAfterReturning" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAfterThrowingAspect">
<aop:pointcut id="pointCutAfterThrowing"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-throwing method="afterThrow"
throwing="error" pointcut-ref="pointCutAfterThrowing" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAroundAspect">
<aop:pointcut id="pointCutAround"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:around method="aroundAdvice" pointcut-ref="pointCutAround" />
</aop:aspect>
</aop:config>
<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: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: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">
<bean id="sampleAdder"
class="com.baeldung.logger.SampleAdder" />
<bean id="doBeforeAspect" class="com.baeldung.logger.AdderBeforeAspect" />
<bean id="doAfterAspect" class="com.baeldung.logger.AdderAfterAspect" />
<bean id="doAfterThrowingAspect" class="com.baeldung.logger.AdderAfterThrowAspect" />
<bean id="doAfterReturningAspect" class="com.baeldung.logger.AdderAfterReturnAspect" />
<bean id="doAroundAspect" class="com.baeldung.logger.AdderAroundAspect" />
<aop:config>
<aop:aspect id="aspects" ref="doBeforeAspect">
<aop:pointcut id="pointCutBefore"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:before method="beforeAdvice" pointcut-ref="pointCutBefore" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAfterAspect">
<aop:pointcut id="pointCutAfter"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after method="afterAdvice" pointcut-ref="pointCutAfter" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAfterReturningAspect">
<aop:pointcut id="pointCutAfterReturning"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-returning method="afterReturn"
returning="returnValue" pointcut-ref="pointCutAfterReturning" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAfterThrowingAspect">
<aop:pointcut id="pointCutAfterThrowing"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:after-throwing method="afterThrow"
throwing="error" pointcut-ref="pointCutAfterThrowing" />
</aop:aspect>
<aop:aspect id="aspects" ref="doAroundAspect">
<aop:pointcut id="pointCutAround"
expression="execution(* com.baeldung.logger.SampleAdder+.*(..))" />
<aop:around method="aroundAdvice" pointcut-ref="pointCutAround" />
</aop:aspect>
</aop:config>
</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;
import com.baeldung.TestConfig;
import com.baeldung.Application;
import com.baeldung.pointcutadvice.dao.FooDao;
import org.junit.Before;
import org.junit.Test;
@ -23,7 +23,7 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestConfig.class}, loader = AnnotationConfigContextLoader.class)
@ContextConfiguration(classes = {Application.class}, loader = AnnotationConfigContextLoader.class)
public class AopLoggingIntegrationTest {
@Before

View File

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

View File

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