Search in sources :

Example 41 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithUnconditionalPointcut.

@Test
public void manualGroovyBeanWithUnconditionalPointcut() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    testAdvice(new DefaultPointcutAdvisor(logAdvice), logAdvice, target, "GroovyServiceImpl");
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 42 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithDynamicPointcutProxyTargetClass.

@Test
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 43 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class GroovyAspectTests method manualGroovyBeanWithDynamicPointcut.

@Test
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
    TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(new ClassPathResource("GroovyServiceImpl.grv", getClass())));
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
}
Also used : ResourceScriptSource(org.springframework.scripting.support.ResourceScriptSource) AspectJExpressionPointcut(org.springframework.aop.aspectj.AspectJExpressionPointcut) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 44 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class ServletAnnotationControllerHandlerMethodTests method requestMappingInterfaceWithProxy.

@PathPatternsParameterizedTest
void requestMappingInterfaceWithProxy(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(IMyControllerImpl.class, usePathPatterns, wac -> {
        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", "/handle");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("handle null");
    request = new MockHttpServletRequest("GET", "/handle");
    request.addParameter("p", "value");
    response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("handle value");
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) SimpleTraceInterceptor(org.springframework.aop.interceptor.SimpleTraceInterceptor) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Example 45 with DefaultPointcutAdvisor

use of org.springframework.aop.support.DefaultPointcutAdvisor in project spring-framework by spring-projects.

the class ServletAnnotationControllerHandlerMethodTests method proxiedFormController.

@PathPatternsParameterizedTest
void proxiedFormController(boolean usePathPatterns) throws Exception {
    initDispatcherServlet(MyFormController.class, usePathPatterns, wac -> {
        wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.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", "/myPath.do");
    request.addParameter("name", "name1");
    request.addParameter("age", "value2");
    MockHttpServletResponse response = new MockHttpServletResponse();
    getServlet().service(request, response);
    assertThat(response.getContentAsString()).isEqualTo("myView-name1-typeMismatch-tb1-myValue");
}
Also used : DefaultAdvisorAutoProxyCreator(org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator) SimpleTraceInterceptor(org.springframework.aop.interceptor.SimpleTraceInterceptor) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) DefaultPointcutAdvisor(org.springframework.aop.support.DefaultPointcutAdvisor) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) PathPatternsParameterizedTest(org.springframework.web.servlet.handler.PathPatternsParameterizedTest)

Aggregations

DefaultPointcutAdvisor (org.springframework.aop.support.DefaultPointcutAdvisor)45 Test (org.junit.jupiter.api.Test)29 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)16 SimpleTraceInterceptor (org.springframework.aop.interceptor.SimpleTraceInterceptor)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)14 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)12 NopInterceptor (org.springframework.aop.testfixture.interceptor.NopInterceptor)11 TestBean (org.springframework.beans.testfixture.beans.TestBean)11 Advisor (org.springframework.aop.Advisor)8 DefaultIntroductionAdvisor (org.springframework.aop.support.DefaultIntroductionAdvisor)7 CountingBeforeAdvice (org.springframework.aop.testfixture.advice.CountingBeforeAdvice)7 SerializableNopInterceptor (org.springframework.aop.testfixture.interceptor.SerializableNopInterceptor)7 AspectJExpressionPointcut (org.springframework.aop.aspectj.AspectJExpressionPointcut)6 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)5 Pointcut (org.springframework.aop.Pointcut)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 ResourceScriptSource (org.springframework.scripting.support.ResourceScriptSource)4 Test (org.junit.Test)3 NameMatchMethodPointcut (org.springframework.aop.support.NameMatchMethodPointcut)3 StaticMethodMatcherPointcutAdvisor (org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor)3