use of com.vaadin.flow.server.MockServletConfig in project flow by vaadin.
the class RouterLinkTest method invalidRouteWhenConstructing.
@Test(expected = IllegalArgumentException.class)
public void invalidRouteWhenConstructing() throws ServletException {
VaadinServlet servlet = new VaadinServlet();
Properties initParams = new Properties();
initParams.setProperty(Constants.SERVLET_PARAMETER_USING_NEW_ROUTING, "false");
servlet.init(new MockServletConfig(initParams));
try {
VaadinService.setCurrent(servlet.getService());
servlet.getService().getRouter().reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
new RouterLink("Show something", TestView.class);
} finally {
VaadinService.setCurrent(null);
}
}
use of com.vaadin.flow.server.MockServletConfig in project flow by vaadin.
the class RouterTest method testResolveError.
@Test
public void testResolveError() throws ServletException {
UI ui = new RouterTestUI();
VaadinRequest request = Mockito.mock(VaadinRequest.class);
VaadinResponse response = Mockito.mock(VaadinResponse.class);
ServletConfig servletConfig = new MockServletConfig();
VaadinServlet servlet = new VaadinServlet();
servlet.init(servletConfig);
VaadinService service = servlet.getService();
service.setCurrentInstances(request, response);
Router router = new Router();
router.reconfigure(c -> c.setResolver(event -> Optional.empty()));
router.navigate(ui, new Location(""), NavigationTrigger.PROGRAMMATIC);
Assert.assertTrue(ui.getElement().getTextRecursively().contains("404"));
// 404 code should be sent ONLY on initial request
Mockito.verifyZeroInteractions(response);
// to verify that the setup has been correct and the mocks work,
// test the case where 404 should be sent
router.initializeUI(ui, request);
ArgumentCaptor<Integer> statusCodeCaptor = ArgumentCaptor.forClass(Integer.class);
Mockito.verify(response).setStatus(statusCodeCaptor.capture());
Assert.assertEquals(Integer.valueOf(HttpServletResponse.SC_NOT_FOUND), statusCodeCaptor.getValue());
}
Aggregations