Search in sources :

Example 11 with Location

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

the class RouterConfigurationTest method routeMatches.

private static boolean routeMatches(String location, String route) {
    RouterConfiguration configuration = createConfiguration();
    configuration.setRoute(route, createNoopHandler());
    Optional<NavigationHandler> resolveRoute = configuration.resolveRoute(new Location(location));
    return resolveRoute.isPresent();
}
Also used : RouterConfiguration(com.vaadin.flow.router.legacy.RouterConfiguration) NavigationHandler(com.vaadin.flow.router.NavigationHandler) Location(com.vaadin.flow.router.Location)

Example 12 with Location

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

the class RouterConfigurationTest method normalViewStatusCode.

@Test
public void normalViewStatusCode() {
    Router router = new Router();
    router.reconfigure(c -> c.setRoute("*", ParentView.class));
    int statusCode = router.getConfiguration().resolveRoute(new Location("")).get().handle(new NavigationEvent(router, new Location(""), new UI(), NavigationTrigger.PROGRAMMATIC));
    Assert.assertEquals(HttpServletResponse.SC_OK, statusCode);
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) ParentView(com.vaadin.flow.router.legacy.ViewRendererTest.ParentView) UI(com.vaadin.flow.component.UI) Router(com.vaadin.flow.router.legacy.Router) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 13 with Location

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

the class RouterConfigurationTest method customErrorViewStatusCode.

@Test
public void customErrorViewStatusCode() {
    Router router = new Router();
    router.reconfigure(c -> {
        c.setErrorView(ParentView.class);
    });
    int statusCode = router.getConfiguration().getErrorHandler().handle(new NavigationEvent(router, new Location(""), new UI(), NavigationTrigger.PROGRAMMATIC));
    Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, statusCode);
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) UI(com.vaadin.flow.component.UI) Router(com.vaadin.flow.router.legacy.Router) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 14 with Location

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

the class RouterConfigurationTest method testRemoveRoutes.

@Test
public void testRemoveRoutes() {
    RouterConfiguration configuration = createConfiguration();
    NavigationHandler navigationHandler = createNoopHandler();
    configuration.setRoute("foo", navigationHandler);
    configuration.setRoute("{name}", navigationHandler);
    configuration.setRoute("*", navigationHandler);
    configuration.removeRoute("foo");
    Assert.assertNotNull(configuration.resolveRoute(new Location("foo")));
    configuration.removeRoute("{otherName}");
    Assert.assertNotNull(configuration.resolveRoute(new Location("foo")));
    configuration.removeRoute("*");
    // Should resolve to empty optional only after removing all the routes
    Assert.assertFalse(configuration.resolveRoute(new Location("foo")).isPresent());
}
Also used : RouterConfiguration(com.vaadin.flow.router.legacy.RouterConfiguration) NavigationHandler(com.vaadin.flow.router.NavigationHandler) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 15 with Location

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

the class RouterConfigurationTest method testParentViewsWithoutParent.

@Test
public void testParentViewsWithoutParent() {
    UI ui = new UI();
    Router router = new Router();
    router.reconfigure(conf -> {
        conf.setRoute("route", TestView.class);
        conf.setParentView(TestView.class, ParentView.class);
        conf.setParentView(ParentView.class, AnotherParentView.class);
    });
    router.navigate(ui, new Location("route"), NavigationTrigger.PROGRAMMATIC);
    Assert.assertEquals(ParentView.class, router.getConfiguration().getParentView(TestView.class).get());
    Assert.assertEquals(AnotherParentView.class, router.getConfiguration().getParentView(ParentView.class).get());
    Assert.assertEquals(Arrays.asList(TestView.class, ParentView.class, AnotherParentView.class), getViewChainTypes(ui));
}
Also used : AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) ParentView(com.vaadin.flow.router.legacy.ViewRendererTest.ParentView) UI(com.vaadin.flow.component.UI) AnotherParentView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherParentView) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) AnotherTestView(com.vaadin.flow.router.legacy.ViewRendererTest.AnotherTestView) Router(com.vaadin.flow.router.legacy.Router) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Aggregations

Location (com.vaadin.flow.router.Location)51 Test (org.junit.Test)40 UI (com.vaadin.flow.component.UI)15 Router (com.vaadin.flow.router.legacy.Router)15 NavigationEvent (com.vaadin.flow.router.NavigationEvent)10 NavigationHandler (com.vaadin.flow.router.NavigationHandler)8 RouterConfiguration (com.vaadin.flow.router.legacy.RouterConfiguration)7 HistoryStateChangeEvent (com.vaadin.flow.component.page.History.HistoryStateChangeEvent)6 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)6 NavigationTrigger (com.vaadin.flow.router.NavigationTrigger)5 QueryParameters (com.vaadin.flow.router.QueryParameters)5 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)5 VaadinRequest (com.vaadin.flow.server.VaadinRequest)5 VaadinResponse (com.vaadin.flow.server.VaadinResponse)5 Optional (java.util.Optional)4 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)3 RouterInterface (com.vaadin.flow.router.RouterInterface)3 ImmutableRouterConfiguration (com.vaadin.flow.router.legacy.ImmutableRouterConfiguration)3 Resolver (com.vaadin.flow.router.legacy.Resolver)3 RouteSegmentVisitor (com.vaadin.flow.router.legacy.RouteLocation.RouteSegmentVisitor)3