Search in sources :

Example 16 with Router

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

the class RouterTest method testChangeLocation.

@Test
public void testChangeLocation() {
    UI ui = new RouterTestUI();
    Router router = new Router();
    TestResolver resolver = new TestResolver();
    router.reconfigure(c -> c.setResolver(resolver));
    VaadinRequest request = requestWithPathInfo(null);
    router.initializeUI(ui, request);
    Assert.assertEquals(Arrays.asList(""), resolver.resolvedLocation.get().getSegments());
    resolver.resolvedLocation.set(null);
    resolver.handledEvent.set(null);
    ui.getPage().getHistory().getHistoryStateChangeHandler().onHistoryStateChange(new HistoryStateChangeEvent(ui.getPage().getHistory(), null, new Location("foo"), NavigationTrigger.HISTORY));
    Assert.assertEquals(Arrays.asList("foo"), resolver.resolvedLocation.get().getSegments());
}
Also used : HistoryStateChangeEvent(com.vaadin.flow.component.page.History.HistoryStateChangeEvent) UI(com.vaadin.flow.component.UI) Router(com.vaadin.flow.router.legacy.Router) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 17 with Router

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

the class RouterTest method testResolverError_noCurrentResponse.

@Test
public void testResolverError_noCurrentResponse() {
    UI ui = new RouterTestUI();
    Router router = new Router();
    router.reconfigure(c -> c.setResolver(event -> Optional.empty()));
    router.navigate(ui, new Location(""), NavigationTrigger.PROGRAMMATIC);
    Assert.assertTrue(ui.getElement().getTextRecursively().contains("404"));
}
Also used : Arrays(java.util.Arrays) ServletException(javax.servlet.ServletException) CurrentInstance(com.vaadin.flow.internal.CurrentInstance) ErrorView(com.vaadin.flow.router.legacy.ViewRendererTest.ErrorView) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArgumentCaptor(org.mockito.ArgumentCaptor) After(org.junit.After) Location(com.vaadin.flow.router.Location) UI(com.vaadin.flow.component.UI) TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) NavigationTrigger(com.vaadin.flow.router.NavigationTrigger) ServletConfig(javax.servlet.ServletConfig) NavigationHandler(com.vaadin.flow.router.NavigationHandler) VaadinResponse(com.vaadin.flow.server.VaadinResponse) VaadinServlet(com.vaadin.flow.server.VaadinServlet) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test) VaadinRequest(com.vaadin.flow.server.VaadinRequest) RouterInterface(com.vaadin.flow.router.RouterInterface) Resolver(com.vaadin.flow.router.legacy.Resolver) ImmutableRouterConfiguration(com.vaadin.flow.router.legacy.ImmutableRouterConfiguration) DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) NotThreadSafe(net.jcip.annotations.NotThreadSafe) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) HistoryStateChangeEvent(com.vaadin.flow.component.page.History.HistoryStateChangeEvent) MockServletConfig(com.vaadin.flow.server.MockServletConfig) VaadinService(com.vaadin.flow.server.VaadinService) Optional(java.util.Optional) Assert(org.junit.Assert) NavigationEvent(com.vaadin.flow.router.NavigationEvent) RouterConfiguration(com.vaadin.flow.router.legacy.RouterConfiguration) Router(com.vaadin.flow.router.legacy.Router) UI(com.vaadin.flow.component.UI) Router(com.vaadin.flow.router.legacy.Router) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 18 with Router

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

the class RouterTest method testNavigateToEmptyLocation_triggersDefaultErrorView.

@Test
public void testNavigateToEmptyLocation_triggersDefaultErrorView() {
    UI ui = new RouterTestUI();
    Router router = new Router();
    router.reconfigure(c -> {
    });
    router.navigate(ui, new Location(""), NavigationTrigger.PROGRAMMATIC);
    Assert.assertEquals(new DefaultErrorView().getText(), ui.getElement().getTextRecursively());
}
Also used : DefaultErrorView(com.vaadin.flow.router.legacy.DefaultErrorView) UI(com.vaadin.flow.component.UI) Router(com.vaadin.flow.router.legacy.Router) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 19 with Router

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

the class RouterLinkTest method reconfigureRouterLink_attachedLink.

@Test
public void reconfigureRouterLink_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, "other");
    Assert.assertEquals("show/other", link.getElement().getAttribute("href"));
    link.setRoute(router, TestView.class, "changed");
    Assert.assertEquals("show/changed", 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 20 with Router

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

the class RouterLinkTest method createRouterLink_explicitRouter.

@Test
public void createRouterLink_explicitRouter() {
    Router router = new Router();
    router.reconfigure(c -> c.setRoute("show/{bar}", TestView.class));
    RouterLink link = new RouterLink(router, "Show something", TestView.class, "something");
    Assert.assertEquals("Show something", link.getText());
    Assert.assertTrue(link.getElement().hasAttribute(ApplicationConstants.ROUTER_LINK_ATTRIBUTE));
    Assert.assertTrue(link.getElement().hasAttribute("href"));
    Assert.assertEquals("show/something", link.getElement().getAttribute("href"));
}
Also used : TestView(com.vaadin.flow.router.legacy.ViewRendererTest.TestView) Router(com.vaadin.flow.router.legacy.Router) 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