Search in sources :

Example 11 with Router

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

Example 12 with Router

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

the class RouterConfigurationTest method getParentViewsWithoutParent.

@Test
public void getParentViewsWithoutParent() {
    Router router = new Router();
    router.reconfigure(conf -> {
        conf.setRoute("route", TestView.class);
    });
    assertParentViews(router, TestView.class);
}
Also used : Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 13 with Router

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

the class RouterConfigurationTest method testSetErrorViewWithParent.

@Test
public void testSetErrorViewWithParent() {
    Router router = new Router();
    router.reconfigure(conf -> {
        conf.setErrorView(ErrorView.class, ParentView.class);
    });
    assertErrorView(router, ErrorView.class);
    assertParentViews(router, ErrorView.class, ParentView.class);
}
Also used : Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 14 with Router

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

the class RouterConfigurationTest method getParentViewsManyLevels.

@Test
public void getParentViewsManyLevels() {
    Router router = new Router();
    router.reconfigure(conf -> {
        conf.setRoute("route", TestView.class);
        conf.setParentView(TestView.class, ParentView.class);
        conf.setParentView(ParentView.class, AnotherParentView.class);
    });
    assertParentViews(router, TestView.class, ParentView.class, AnotherParentView.class);
}
Also used : Router(com.vaadin.flow.router.legacy.Router) Test(org.junit.Test)

Example 15 with Router

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

the class RouterTest method testReconfigureThreadSafety.

@Test
public void testReconfigureThreadSafety() throws InterruptedException {
    Router router = new Router();
    Resolver newResolver = e -> null;
    CountDownLatch configUpdated = new CountDownLatch(1);
    CountDownLatch configVerified = new CountDownLatch(1);
    Thread updaterThread = new Thread() {

        @Override
        public void run() {
            router.reconfigure(config -> {
                config.setResolver(newResolver);
                // Signal that config has been updated
                configUpdated.countDown();
                // configuration is not yet in effect
                try {
                    configVerified.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            });
        }
    };
    updaterThread.start();
    // Wait until updater thread has updated the config
    configUpdated.await();
    Assert.assertNotSame("Update should not yet be visible", newResolver, router.getConfiguration().getResolver());
    // Allow the update thread to exit the configure method
    configVerified.countDown();
    // Wait for updater thread to finish
    updaterThread.join();
    Assert.assertSame("Update should now be visible", newResolver, router.getConfiguration().getResolver());
}
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) Resolver(com.vaadin.flow.router.legacy.Resolver) Router(com.vaadin.flow.router.legacy.Router) CountDownLatch(java.util.concurrent.CountDownLatch) 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