Search in sources :

Example 6 with SpringServlet

use of com.vaadin.flow.spring.SpringServlet in project flow by vaadin.

the class RequestUtilTest method setupMockServlet.

private SpringServlet setupMockServlet() {
    SpringServlet servlet = Mockito.mock(SpringServlet.class);
    SpringVaadinServletService service = Mockito.mock(SpringVaadinServletService.class);
    Router router = Mockito.mock(Router.class);
    RouteRegistry routeRegistry = Mockito.mock(RouteRegistry.class);
    Mockito.when(springServletRegistration.getServlet()).thenReturn(servlet);
    Mockito.when(servlet.getService()).thenReturn(service);
    Mockito.when(service.getRouter()).thenReturn(router);
    Mockito.when(router.getRegistry()).thenReturn(routeRegistry);
    return servlet;
}
Also used : RouteRegistry(com.vaadin.flow.server.RouteRegistry) Router(com.vaadin.flow.router.Router) SpringVaadinServletService(com.vaadin.flow.spring.SpringVaadinServletService) SpringServlet(com.vaadin.flow.spring.SpringServlet)

Example 7 with SpringServlet

use of com.vaadin.flow.spring.SpringServlet in project flow by vaadin.

the class RequestUtilTest method testAnonymousRouteRequest_rootMappedServlet_publicView.

@Test
public void testAnonymousRouteRequest_rootMappedServlet_publicView() {
    Mockito.when(vaadinConfigurationProperties.getUrlMapping()).thenReturn("/*");
    SpringServlet servlet = setupMockServlet();
    addRoute(servlet, PublicRootView.class);
    addRoute(servlet, AnotherPublicView.class);
    MockHttpServletRequest request = createRequest(null);
    request.setServletPath("/");
    Assert.assertTrue(requestUtil.isAnonymousRoute(request));
    request = createRequest("other");
    request.setServletPath("/");
    Assert.assertTrue(requestUtil.isAnonymousRoute(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SpringServlet(com.vaadin.flow.spring.SpringServlet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with SpringServlet

use of com.vaadin.flow.spring.SpringServlet in project flow by vaadin.

the class RequestUtilTest method testAnonymousRouteRequest_fooMappedServlet_publicView.

@Test
public void testAnonymousRouteRequest_fooMappedServlet_publicView() {
    Mockito.when(vaadinConfigurationProperties.getUrlMapping()).thenReturn("/foo/*");
    SpringServlet servlet = setupMockServlet();
    addRoute(servlet, PublicRootView.class);
    addRoute(servlet, AnotherPublicView.class);
    MockHttpServletRequest request = createRequest(null);
    request.setServletPath("/foo/");
    Assert.assertTrue(requestUtil.isAnonymousRoute(request));
    request = createRequest("");
    request.setServletPath("/foo/");
    Assert.assertTrue(requestUtil.isAnonymousRoute(request));
    request = createRequest("/");
    request.setServletPath("/foo/");
    Assert.assertTrue(requestUtil.isAnonymousRoute(request));
    request = createRequest("other");
    request.setServletPath("/foo/");
    Assert.assertTrue(requestUtil.isAnonymousRoute(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SpringServlet(com.vaadin.flow.spring.SpringServlet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with SpringServlet

use of com.vaadin.flow.spring.SpringServlet in project flow by vaadin.

the class RequestUtilTest method testAnonymousRouteRequest_fooMappedServlet_publicViewPathOutsideServlet.

@Test
public void testAnonymousRouteRequest_fooMappedServlet_publicViewPathOutsideServlet() {
    Mockito.when(vaadinConfigurationProperties.getUrlMapping()).thenReturn("/foo/*");
    SpringServlet servlet = setupMockServlet();
    addRoute(servlet, PublicRootView.class);
    addRoute(servlet, AnotherPublicView.class);
    MockHttpServletRequest request = createRequest(null);
    request.setServletPath("/");
    Assert.assertFalse(requestUtil.isAnonymousRoute(request));
    request = createRequest("other");
    request.setServletPath("/");
    Assert.assertFalse(requestUtil.isAnonymousRoute(request));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) SpringServlet(com.vaadin.flow.spring.SpringServlet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SpringServlet (com.vaadin.flow.spring.SpringServlet)9 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)5 Router (com.vaadin.flow.router.Router)2 RouteRegistry (com.vaadin.flow.server.RouteRegistry)2 VaadinService (com.vaadin.flow.server.VaadinService)2 Properties (java.util.Properties)2 ServletConfig (javax.servlet.ServletConfig)2 ServletContext (javax.servlet.ServletContext)2 Div (com.vaadin.flow.component.html.Div)1 Instantiator (com.vaadin.flow.di.Instantiator)1 Lookup (com.vaadin.flow.di.Lookup)1 ResourceProvider (com.vaadin.flow.di.ResourceProvider)1 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)1 I18NProvider (com.vaadin.flow.i18n.I18NProvider)1 NavigationRouteTarget (com.vaadin.flow.router.internal.NavigationRouteTarget)1 RouteTarget (com.vaadin.flow.router.internal.RouteTarget)1 ServiceInitEvent (com.vaadin.flow.server.ServiceInitEvent)1 StaticFileHandlerFactory (com.vaadin.flow.server.StaticFileHandlerFactory)1