Search in sources :

Example 6 with RouteConfiguration

use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.

the class UITest method initUI.

private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException {
    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    VaadinResponse response = Mockito.mock(VaadinResponse.class);
    String pathInfo;
    if (initialLocation.isEmpty()) {
        pathInfo = null;
    } else {
        Assert.assertFalse(initialLocation.startsWith("/"));
        pathInfo = "/" + initialLocation;
    }
    Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
    VaadinService service = new MockVaadinServletService() {

        @Override
        public VaadinContext getContext() {
            return new MockVaadinContext();
        }
    };
    service.setCurrentInstances(request, response);
    MockVaadinSession session = new AlwaysLockedVaadinSession(service);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(config.isProductionMode()).thenReturn(false);
    session.lock();
    session.setConfiguration(config);
    ui.getInternals().setSession(session);
    RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getInternals().getRouter().getRegistry());
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        Arrays.asList(RootNavigationTarget.class, FooBarNavigationTarget.class, Parameterized.class, FooBarParamNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
    });
    ui.doInit(request, 0);
    ui.getInternals().getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
    session.unlock();
    if (statusCodeCaptor != null) {
        Mockito.verify(response).setStatus(statusCodeCaptor.capture());
    }
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 7 with RouteConfiguration

use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.

the class InvalidUrlTest method initUI.

private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException, ServiceException {
    VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
    VaadinResponse response = Mockito.mock(VaadinResponse.class);
    String pathInfo;
    if (initialLocation.isEmpty()) {
        pathInfo = null;
    } else {
        Assert.assertFalse(initialLocation.startsWith("/"));
        pathInfo = "/" + initialLocation;
    }
    Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
    VaadinService service = new MockVaadinServletService() {

        @Override
        public VaadinContext getContext() {
            return new MockVaadinContext();
        }
    };
    service.setCurrentInstances(request, response);
    MockVaadinSession session = new AlwaysLockedVaadinSession(service);
    DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
    Mockito.when(config.isProductionMode()).thenReturn(false);
    session.lock();
    session.setConfiguration(config);
    ui.getInternals().setSession(session);
    RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getRouter().getRegistry());
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        Arrays.asList(UITest.RootNavigationTarget.class, UITest.FooBarNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
    });
    ui.doInit(request, 0);
    ui.getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
    session.unlock();
    if (statusCodeCaptor != null) {
        Mockito.verify(response).setStatus(statusCodeCaptor.capture());
    }
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 8 with RouteConfiguration

use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.

the class SessionRouteRegistryTest method getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsNotRoot_mainRouteIsReturned.

@Test
public void getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsNotRoot_mainRouteIsReturned() {
    SessionRouteRegistry registry = getRegistry(session);
    RouteConfiguration configuration = RouteConfiguration.forRegistry(registry);
    configuration.setAnnotatedRoute(RouteWithRootAlias.class);
    Optional<String> url = registry.getTargetUrl(RouteWithRootAlias.class, RouteParameters.empty());
    Assert.assertTrue(url.isPresent());
    Assert.assertEquals("foo", url.get());
}
Also used : RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) Test(org.junit.Test)

Example 9 with RouteConfiguration

use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.

the class SessionRouteRegistryTest method getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsParamerterized_routeAliasIsReturned.

@Test
public void getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsParamerterized_routeAliasIsReturned() {
    SessionRouteRegistry registry = getRegistry(session);
    RouteConfiguration configuration = RouteConfiguration.forRegistry(registry);
    configuration.setAnnotatedRoute(ParameterizedRouteWithRootAlias.class);
    Optional<String> url = registry.getTargetUrl(ParameterizedRouteWithRootAlias.class, RouteParameters.empty());
    Assert.assertTrue(url.isPresent());
    Assert.assertEquals("", url.get());
}
Also used : RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) Test(org.junit.Test)

Example 10 with RouteConfiguration

use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.

the class BootstrapHandlerTest method initUI.

private void initUI(UI ui, VaadinRequest request, Set<Class<? extends Component>> navigationTargets) throws InvalidRouteConfigurationException {
    RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(service.getRouteRegistry());
    routeConfiguration.update(() -> {
        routeConfiguration.getHandledRegistry().clean();
        navigationTargets.forEach(routeConfiguration::setAnnotatedRoute);
    });
    initUI(ui, request);
}
Also used : RouteConfiguration(com.vaadin.flow.router.RouteConfiguration)

Aggregations

RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)12 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)3 Lookup (com.vaadin.flow.di.Lookup)2 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)2 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)2 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)2 VaadinResponse (com.vaadin.flow.server.VaadinResponse)2 VaadinService (com.vaadin.flow.server.VaadinService)2 AlwaysLockedVaadinSession (com.vaadin.tests.util.AlwaysLockedVaadinSession)2 Test (org.junit.Test)2 Component (com.vaadin.flow.component.Component)1 PushConfiguration (com.vaadin.flow.component.PushConfiguration)1 UI (com.vaadin.flow.component.UI)1 Push (com.vaadin.flow.component.page.Push)1 AnnotationReader (com.vaadin.flow.internal.AnnotationReader)1 ParentLayout (com.vaadin.flow.router.ParentLayout)1 Route (com.vaadin.flow.router.Route)1 RouteAlias (com.vaadin.flow.router.RouteAlias)1 RoutePathProvider (com.vaadin.flow.router.RoutePathProvider)1