Search in sources :

Example 11 with ApplicationRouteRegistry

use of com.vaadin.flow.server.startup.ApplicationRouteRegistry in project flow by vaadin.

the class VaadinServletContextInitializerTest method errorParameterServletContextListenerEvent_hasCustomRouteNotFoundViewExtendingRouteNotFoundError_customRouteNotFoundViewIsRegistered.

@Test
public void errorParameterServletContextListenerEvent_hasCustomRouteNotFoundViewExtendingRouteNotFoundError_customRouteNotFoundViewIsRegistered() throws Exception {
    // given
    initDefaultMocks();
    VaadinServletContextInitializer initializer = getStubbedVaadinServletContextInitializer();
    Runnable when = initRouteNotFoundMocksAndGetContextInitializedMockCall(initializer);
    class TestErrorView extends RouteNotFoundError {
    }
    Mockito.doAnswer(invocation -> Stream.of(TestErrorView.class)).when(initializer).findBySuperType(Mockito.anyCollection(), Mockito.eq(HasErrorParameter.class));
    // when
    when.run();
    // then
    ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(new VaadinServletContext(servletContext));
    final Class<? extends Component> navigationTarget = registry.getErrorNavigationTarget(new NotFoundException()).get().getNavigationTarget();
    Assert.assertEquals(TestErrorView.class, navigationTarget);
}
Also used : VaadinServletContext(com.vaadin.flow.server.VaadinServletContext) NotFoundException(com.vaadin.flow.router.NotFoundException) RouteNotFoundError(com.vaadin.flow.router.RouteNotFoundError) HasErrorParameter(com.vaadin.flow.router.HasErrorParameter) ApplicationRouteRegistry(com.vaadin.flow.server.startup.ApplicationRouteRegistry) Test(org.junit.Test)

Aggregations

ApplicationRouteRegistry (com.vaadin.flow.server.startup.ApplicationRouteRegistry)11 Test (org.junit.Test)9 Component (com.vaadin.flow.component.Component)6 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4 NotFoundException (com.vaadin.flow.router.NotFoundException)3 Route (com.vaadin.flow.router.Route)3 Push (com.vaadin.flow.component.page.Push)2 HasErrorParameter (com.vaadin.flow.router.HasErrorParameter)2 BootstrapContext (com.vaadin.flow.server.BootstrapHandler.BootstrapContext)2 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)2 VaadinServletContext (com.vaadin.flow.server.VaadinServletContext)2 JavaScriptBootstrapContext (com.vaadin.flow.server.communication.JavaScriptBootstrapHandler.JavaScriptBootstrapContext)2 UI (com.vaadin.flow.component.UI)1 BeforeEnterEvent (com.vaadin.flow.router.BeforeEnterEvent)1 ErrorNavigationEvent (com.vaadin.flow.router.ErrorNavigationEvent)1 ErrorParameter (com.vaadin.flow.router.ErrorParameter)1 Location (com.vaadin.flow.router.Location)1 NavigationEvent (com.vaadin.flow.router.NavigationEvent)1 NavigationState (com.vaadin.flow.router.NavigationState)1 NavigationStateBuilder (com.vaadin.flow.router.NavigationStateBuilder)1