Search in sources :

Example 11 with RouteRegistry

use of com.vaadin.flow.server.RouteRegistry in project flow by vaadin.

the class RouteNotFoundErrorTest method setErrorParameter_productionMode_pathContainRoutesTemplate_renderedElementHasNoRoutes.

@Test
public void setErrorParameter_productionMode_pathContainRoutesTemplate_renderedElementHasNoRoutes() {
    RouteNotFoundError page = new RouteNotFoundError();
    BeforeEnterEvent event = Mockito.mock(BeforeEnterEvent.class);
    Location location = Mockito.mock(Location.class);
    Mockito.when(location.getPath()).thenReturn("{{routes}}");
    Mockito.when(event.getLocation()).thenReturn(location);
    UI ui = Mockito.mock(UI.class);
    VaadinSession session = Mockito.mock(VaadinSession.class);
    Mockito.when(ui.getSession()).thenReturn(session);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(session.getConfiguration()).thenReturn(config);
    Mockito.when(config.isProductionMode()).thenReturn(true);
    Mockito.when(event.getUI()).thenReturn(ui);
    ErrorParameter<NotFoundException> param = new ErrorParameter<NotFoundException>(NotFoundException.class, new NotFoundException());
    Router router = Mockito.mock(Router.class);
    Mockito.when(event.getSource()).thenReturn(router);
    RouteRegistry registry = Mockito.mock(RouteRegistry.class);
    Mockito.when(router.getRegistry()).thenReturn(registry);
    RouteData data = new RouteData(Collections.emptyList(), "bar", Collections.emptyList(), RouteTarget.class, Collections.emptyList());
    Mockito.when(registry.getRegisteredRoutes()).thenReturn(Collections.singletonList(data));
    event.getSource().getRegistry().getRegisteredRoutes();
    page.setErrorParameter(event, param);
    MatcherAssert.assertThat(page.getElement().toString(), CoreMatchers.not(CoreMatchers.containsString("bar")));
}
Also used : UI(com.vaadin.flow.component.UI) VaadinSession(com.vaadin.flow.server.VaadinSession) RouteRegistry(com.vaadin.flow.server.RouteRegistry) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration) Test(org.junit.Test)

Example 12 with RouteRegistry

use of com.vaadin.flow.server.RouteRegistry in project flow by vaadin.

the class RouteConfigurationTest method mockRegistry.

private RouteRegistry mockRegistry() {
    RouteRegistry registry = Mockito.mock(RouteRegistry.class);
    VaadinContext context = new MockVaadinContext();
    Mockito.when(registry.getContext()).thenReturn(context);
    return registry;
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) VaadinContext(com.vaadin.flow.server.VaadinContext) ApplicationRouteRegistry(com.vaadin.flow.server.startup.ApplicationRouteRegistry) RouteRegistry(com.vaadin.flow.server.RouteRegistry) SessionRouteRegistry(com.vaadin.flow.server.SessionRouteRegistry)

Example 13 with RouteRegistry

use of com.vaadin.flow.server.RouteRegistry 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)

Aggregations

RouteRegistry (com.vaadin.flow.server.RouteRegistry)13 ApplicationRouteRegistry (com.vaadin.flow.server.startup.ApplicationRouteRegistry)6 SessionRouteRegistry (com.vaadin.flow.server.SessionRouteRegistry)5 Test (org.junit.Test)5 Router (com.vaadin.flow.router.Router)4 UI (com.vaadin.flow.component.UI)3 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 NotFoundException (com.vaadin.flow.router.NotFoundException)2 Route (com.vaadin.flow.router.Route)2 NavigationRouteTarget (com.vaadin.flow.router.internal.NavigationRouteTarget)2 RouteTarget (com.vaadin.flow.router.internal.RouteTarget)2 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)2 VaadinContext (com.vaadin.flow.server.VaadinContext)2 VaadinSession (com.vaadin.flow.server.VaadinSession)2 SpringServlet (com.vaadin.flow.spring.SpringServlet)2 Component (com.vaadin.flow.component.Component)1 UIInternals (com.vaadin.flow.component.internal.UIInternals)1 Page (com.vaadin.flow.component.page.Page)1 Lookup (com.vaadin.flow.di.Lookup)1 AnnotationReader (com.vaadin.flow.internal.AnnotationReader)1