commit
7d5b613c20
|
@ -1,12 +1,14 @@
|
|||
package com.baeldung.interceptor;
|
||||
|
||||
import javax.interceptor.InterceptorBinding;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.interceptor.InterceptorBinding;
|
||||
|
||||
@InterceptorBinding
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Audited {}
|
||||
public @interface Audited {
|
||||
}
|
||||
|
|
|
@ -3,12 +3,13 @@ package com.baeldung.interceptor;
|
|||
import javax.interceptor.AroundInvoke;
|
||||
import javax.interceptor.Interceptor;
|
||||
import javax.interceptor.InvocationContext;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Audited @Interceptor
|
||||
@Audited
|
||||
@Interceptor
|
||||
public class AuditedInterceptor {
|
||||
public static boolean calledBefore = false;
|
||||
public static boolean calledAfter = false;
|
||||
|
||||
@AroundInvoke
|
||||
public Object auditMethod(InvocationContext ctx) throws Exception {
|
||||
calledBefore = true;
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
package com.baeldung.spring.aspect;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import java.util.List;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
@Aspect
|
||||
public class SpringTestAspect {
|
||||
@Autowired
|
||||
private List<String> accumulator;
|
||||
|
||||
@Around("execution(* com.baeldung.spring.service.SpringSuperService.*(..))")
|
||||
public Object advice(ProceedingJoinPoint jp) throws Throwable {
|
||||
public Object auditMethod(ProceedingJoinPoint jp) throws Throwable {
|
||||
String methodName = jp.getSignature().getName();
|
||||
accumulator.add("Call to " + methodName);
|
||||
Object obj = jp.proceed();
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
package com.baeldung.spring.configuration;
|
||||
|
||||
import com.baeldung.spring.aspect.SpringTestAspect;
|
||||
import com.baeldung.spring.service.SpringSuperService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.baeldung.spring.aspect.SpringTestAspect;
|
||||
import com.baeldung.spring.service.SpringSuperService;
|
||||
|
||||
@Configuration
|
||||
@EnableAspectJAutoProxy
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package com.baeldung.test;
|
||||
|
||||
import com.baeldung.interceptor.Audited;
|
||||
import com.baeldung.interceptor.AuditedInterceptor;
|
||||
import com.baeldung.service.SuperService;
|
||||
import org.jboss.weld.environment.se.Weld;
|
||||
import org.jboss.weld.environment.se.WeldContainer;
|
||||
import org.junit.After;
|
||||
|
@ -10,16 +7,13 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.enterprise.inject.spi.BeanManager;
|
||||
import javax.enterprise.inject.spi.InterceptionType;
|
||||
import javax.enterprise.inject.spi.Interceptor;
|
||||
import javax.enterprise.util.AnnotationLiteral;
|
||||
|
||||
import static javafx.beans.binding.Bindings.select;
|
||||
import com.baeldung.interceptor.AuditedInterceptor;
|
||||
import com.baeldung.service.SuperService;
|
||||
|
||||
public class TestInterceptor {
|
||||
Weld weld;
|
||||
WeldContainer container;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
weld = new Weld();
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
package com.baeldung.test;
|
||||
|
||||
import com.baeldung.spring.configuration.AppConfig;
|
||||
import com.baeldung.spring.service.SpringSuperService;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
|
||||
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
|
||||
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import com.baeldung.spring.configuration.AppConfig;
|
||||
import com.baeldung.spring.service.SpringSuperService;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = { AppConfig.class })
|
||||
|
|
Loading…
Reference in New Issue