use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testAdviceSupportListeners.
@Test
public void testAdviceSupportListeners() throws Throwable {
TestBean target = new TestBean();
target.setAge(21);
ProxyFactory pc = new ProxyFactory(target);
CountingAdvisorListener l = new CountingAdvisorListener(pc);
pc.addListener(l);
RefreshCountingAdvisorChainFactory acf = new RefreshCountingAdvisorChainFactory();
// Should be automatically added as a listener
pc.addListener(acf);
assertThat(pc.isActive()).isFalse();
assertThat(l.activates).isEqualTo(0);
assertThat(acf.refreshes).isEqualTo(0);
ITestBean proxied = (ITestBean) createProxy(pc);
assertThat(acf.refreshes).isEqualTo(1);
assertThat(l.activates).isEqualTo(1);
assertThat(pc.isActive()).isTrue();
assertThat(proxied.getAge()).isEqualTo(target.getAge());
assertThat(l.adviceChanges).isEqualTo(0);
NopInterceptor di = new NopInterceptor();
pc.addAdvice(0, di);
assertThat(l.adviceChanges).isEqualTo(1);
assertThat(acf.refreshes).isEqualTo(2);
assertThat(proxied.getAge()).isEqualTo(target.getAge());
pc.removeAdvice(di);
assertThat(l.adviceChanges).isEqualTo(2);
assertThat(acf.refreshes).isEqualTo(3);
assertThat(proxied.getAge()).isEqualTo(target.getAge());
pc.getProxy();
assertThat(l.activates).isEqualTo(1);
pc.removeListener(l);
assertThat(l.adviceChanges).isEqualTo(2);
pc.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()));
// No longer counting
assertThat(l.adviceChanges).isEqualTo(2);
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class MethodValidationPostProcessor method afterPropertiesSet.
@Override
public void afterPropertiesSet() {
Pointcut pointcut = new AnnotationMatchingPointcut(this.validatedAnnotationType, true);
this.advisor = new DefaultPointcutAdvisor(pointcut, createMethodValidationAdvice(this.validator));
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method sessionAttributeExposureWithInterface.
@SuppressWarnings("rawtypes")
@PathPatternsParameterizedTest
void sessionAttributeExposureWithInterface(boolean usePathPatterns) throws Exception {
initDispatcherServlet(MySessionAttributesControllerImpl.class, usePathPatterns, wac -> {
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPage");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(request.getAttribute("viewName")).isEqualTo("page1");
HttpSession session = request.getSession();
assertThat(session).isNotNull();
assertThat(session.getAttribute("object1") != null).isTrue();
assertThat(session.getAttribute("object2") != null).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object1")).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object2")).isTrue();
request = new MockHttpServletRequest("POST", "/myPage");
request.setSession(session);
response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(request.getAttribute("viewName")).isEqualTo("page2");
assertThat(session.getAttribute("object1") != null).isTrue();
assertThat(session.getAttribute("object2") != null).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object1")).isTrue();
assertThat(((Map) session.getAttribute("model")).containsKey("object2")).isTrue();
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class JdkProxyControllerTests method initServlet.
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerclass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerclass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.
the class CglibProxyControllerTests method initServlet.
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerClass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(@Nullable WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerClass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setProxyTargetClass(true);
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
Pointcut pointcut = new AnnotationMatchingPointcut(Controller.class);
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, new SimpleTraceInterceptor(true));
wac.getBeanFactory().registerSingleton("advisor", advisor);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
Aggregations