Search in sources :

Example 1 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method invalidRoute_attachedLink.

@Test(expected = IllegalArgumentException.class)
public void invalidRoute_attachedLink() {
    Router router = new Router();
    RouterTestUI ui = new RouterTestUI(router);
    router.reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    RouterLink link = new RouterLink();
    ui.add(link);
    link.setRoute(TestView.class);
}
Also used : RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 2 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method invalidRoute_explicitRouter.

@Test(expected = IllegalArgumentException.class)
public void invalidRoute_explicitRouter() {
    Router router = new Router();
    router.reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    new RouterLink(router, "Show something", TestView.class);
}
Also used : TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 3 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterLinkTest method setRoute_attachedLink.

@Test
public void setRoute_attachedLink() {
    RouterTestUI ui = new RouterTestUI(new Router());
    ui.getRouterInterface().get().reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    RouterLink link = new RouterLink();
    ui.add(link);
    link.setRoute(TestView.class, "foo");
    Assert.assertTrue(link.getElement().hasAttribute("href"));
    Assert.assertEquals("show/foo", link.getElement().getAttribute("href"));
}
Also used : RouterTestUI(com.vaadin.flow.router.legacy.RouterTest.RouterTestUI) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 4 with Router

use of com.vaadin.flow.router.legacy.Router in project flow by vaadin.

the class RouterConfigurationTest method getRoute.

@Test
public void getRoute() {
    Router router = new Router();
    router.reconfigure(conf -> {
        conf.setRoute("route1", TestView.class, ParentView.class);
        conf.setRoute("route2", AnotherTestView.class);
    });
    assertRoute(router, TestView.class, "route1");
    assertRoute(router, AnotherTestView.class, "route2");
    assertRoute(router, ParentView.class, null);
}
Also used : Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 5 with Router

use of com.vaadin.flow.router.legacy.Router 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)

Aggregations

Router (com.vaadin.flow.router.legacy.Router)44 Test (org.junit.Test)44 Location (com.vaadin.flow.router.Location)17 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)16 UI (com.vaadin.flow.component.UI)15 NavigationEvent (com.vaadin.flow.router.NavigationEvent)8 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)7 VaadinRequest (com.vaadin.flow.server.VaadinRequest)7 HistoryStateChangeEvent (com.vaadin.flow.component.page.History.HistoryStateChangeEvent)6 ImmutableRouterConfiguration (com.vaadin.flow.router.legacy.ImmutableRouterConfiguration)6 RouterConfiguration (com.vaadin.flow.router.legacy.RouterConfiguration)6 ErrorView (com.vaadin.flow.router.legacy.ViewRendererTest.ErrorView)6 VaadinResponse (com.vaadin.flow.server.VaadinResponse)6 VaadinService (com.vaadin.flow.server.VaadinService)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)5 NavigationHandler (com.vaadin.flow.router.NavigationHandler)5 NavigationTrigger (com.vaadin.flow.router.NavigationTrigger)5 RouterInterface (com.vaadin.flow.router.RouterInterface)5 Resolver (com.vaadin.flow.router.legacy.Resolver)5