Search in sources :

Example 16 with HandlerInterceptor

use of org.springframework.web.servlet.HandlerInterceptor in project spring-framework by spring-projects.

the class MappedInterceptorTests method afterCompletion.

@Test
void afterCompletion() throws Exception {
    HandlerInterceptor delegate = mock(HandlerInterceptor.class);
    new MappedInterceptor(null, delegate).afterCompletion(mock(HttpServletRequest.class), mock(HttpServletResponse.class), null, mock(Exception.class));
    then(delegate).should().afterCompletion(any(), any(), any(), any());
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 17 with HandlerInterceptor

use of org.springframework.web.servlet.HandlerInterceptor in project spring-framework by spring-projects.

the class MappedInterceptorTests method preHandle.

@Test
void preHandle() throws Exception {
    HandlerInterceptor delegate = mock(HandlerInterceptor.class);
    new MappedInterceptor(null, delegate).preHandle(mock(HttpServletRequest.class), mock(HttpServletResponse.class), null);
    then(delegate).should().preHandle(any(HttpServletRequest.class), any(HttpServletResponse.class), any());
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 18 with HandlerInterceptor

use of org.springframework.web.servlet.HandlerInterceptor in project spring-framework by spring-projects.

the class MappedInterceptorTests method postHandle.

@Test
void postHandle() throws Exception {
    HandlerInterceptor delegate = mock(HandlerInterceptor.class);
    new MappedInterceptor(null, delegate).postHandle(mock(HttpServletRequest.class), mock(HttpServletResponse.class), null, mock(ModelAndView.class));
    then(delegate).should().postHandle(any(), any(), any(), any());
}
Also used : HttpServletRequest(jakarta.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) ModelAndView(org.springframework.web.servlet.ModelAndView) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 19 with HandlerInterceptor

use of org.springframework.web.servlet.HandlerInterceptor in project gocd by gocd.

the class InterceptorInjectorTest method testShouldMergeInterceptors.

@Test
public void testShouldMergeInterceptors() throws Throwable {
    HandlerInterceptor interceptorOfFramework = new HandlerInterceptorSub();
    HandlerInterceptor interceptorOfTab = new HandlerInterceptorSub();
    HandlerInterceptor[] interceptorsOfFramework = new HandlerInterceptor[] { interceptorOfFramework };
    HandlerInterceptor[] interceptorsOfTab = new HandlerInterceptor[] { interceptorOfTab };
    ProceedingJoinPoint proceedingJoinPoint = mock(ProceedingJoinPoint.class);
    when(proceedingJoinPoint.proceed()).thenReturn(new HandlerExecutionChain(null, interceptorsOfTab));
    InterceptorInjector injector = new InterceptorInjector();
    injector.setInterceptors(interceptorsOfFramework);
    HandlerExecutionChain handlers = injector.mergeInterceptorsToTabs(proceedingJoinPoint);
    assertEquals(2, handlers.getInterceptors().length);
    assertSame(interceptorOfFramework, handlers.getInterceptors()[0]);
    assertSame(interceptorOfTab, handlers.getInterceptors()[1]);
}
Also used : HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.jupiter.api.Test)

Example 20 with HandlerInterceptor

use of org.springframework.web.servlet.HandlerInterceptor in project gocd by gocd.

the class InterceptorInjectorTest method testShouldJustReturnInterceptorsOfFrameworkIfNoTabInterceptors.

@Test
public void testShouldJustReturnInterceptorsOfFrameworkIfNoTabInterceptors() throws Throwable {
    HandlerInterceptor interceptorOfFramework = new HandlerInterceptorSub();
    HandlerInterceptor[] interceptorsOfFramework = new HandlerInterceptor[] { interceptorOfFramework };
    ProceedingJoinPoint proceedingJoinPoint = mock(ProceedingJoinPoint.class);
    when(proceedingJoinPoint.proceed()).thenReturn(new HandlerExecutionChain(null, null));
    InterceptorInjector injector = new InterceptorInjector();
    injector.setInterceptors(interceptorsOfFramework);
    HandlerExecutionChain handlers = injector.mergeInterceptorsToTabs(proceedingJoinPoint);
    assertEquals(1, handlers.getInterceptors().length);
    assertSame(interceptorOfFramework, handlers.getInterceptors()[0]);
}
Also used : HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.jupiter.api.Test)

Aggregations

HandlerInterceptor (org.springframework.web.servlet.HandlerInterceptor)30 HandlerExecutionChain (org.springframework.web.servlet.HandlerExecutionChain)14 Test (org.junit.jupiter.api.Test)10 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)8 Test (org.junit.Test)6 RequestMappingHandlerMapping (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping)6 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)5 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)3 ArrayList (java.util.ArrayList)3 Nullable (org.springframework.lang.Nullable)3 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)3 MappedInterceptor (org.springframework.web.servlet.handler.MappedInterceptor)3 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)3 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2