Search in sources :

Example 11 with RouterConfiguration

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

the class RouterConfigurationTest method assertRoutePriority.

private static void assertRoutePriority(String location, String strongerRoute, String weakerRoute) {
    // First verify that the test makes sense
    assertMatches(location, strongerRoute);
    assertMatches(location, weakerRoute);
    NavigationHandler weakerHandler = createNoopHandler();
    NavigationHandler strongerHandler = createNoopHandler();
    RouterConfiguration configuration = createConfiguration();
    configuration.setRoute(strongerRoute, strongerHandler);
    configuration.setRoute(weakerRoute, weakerHandler);
    Optional<NavigationHandler> handler = configuration.resolveRoute(new Location(location));
    Assert.assertSame(handler.get(), strongerHandler);
    // Do the same again with setRoute run in the opposite order
    configuration = createConfiguration();
    configuration.setRoute(weakerRoute, weakerHandler);
    configuration.setRoute(strongerRoute, strongerHandler);
    handler = configuration.resolveRoute(new Location(location));
    Assert.assertSame(handler.get(), strongerHandler);
}
Also used : RouterConfiguration(com.vaadin.flow.router.legacy.RouterConfiguration) NavigationHandler(com.vaadin.flow.router.NavigationHandler) Location(com.vaadin.flow.router.Location)

Example 12 with RouterConfiguration

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

the class RouterTest method testConfigurationImmutable.

@Test(expected = IllegalStateException.class)
public void testConfigurationImmutable() {
    Router router = new Router();
    ImmutableRouterConfiguration configuration = router.getConfiguration();
    ((RouterConfiguration) configuration).setResolver(e -> null);
}
Also used : ImmutableRouterConfiguration(com.vaadin.flow.router.legacy.ImmutableRouterConfiguration) Router(com.vaadin.flow.router.legacy.Router) ImmutableRouterConfiguration(com.vaadin.flow.router.legacy.ImmutableRouterConfiguration) RouterConfiguration(com.vaadin.flow.router.legacy.RouterConfiguration) Test(org.junit.Test)

Example 13 with RouterConfiguration

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

the class RouterTest method testLeakedConfigurationImmutable.

@Test
public void testLeakedConfigurationImmutable() {
    Router router = new Router();
    AtomicReference<RouterConfiguration> configurationLeak = new AtomicReference<>();
    router.reconfigure(configurationLeak::set);
    Resolver newResolver = e -> null;
    configurationLeak.get().setResolver(newResolver);
    Assert.assertNotSame(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) AtomicReference(java.util.concurrent.atomic.AtomicReference) ImmutableRouterConfiguration(com.vaadin.flow.router.legacy.ImmutableRouterConfiguration) RouterConfiguration(com.vaadin.flow.router.legacy.RouterConfiguration) Test(org.junit.Test)

Aggregations

RouterConfiguration (com.vaadin.flow.router.legacy.RouterConfiguration)13 Test (org.junit.Test)11 Location (com.vaadin.flow.router.Location)5 NavigationHandler (com.vaadin.flow.router.NavigationHandler)4 ImmutableRouterConfiguration (com.vaadin.flow.router.legacy.ImmutableRouterConfiguration)2 Router (com.vaadin.flow.router.legacy.Router)2 UI (com.vaadin.flow.component.UI)1 HistoryStateChangeEvent (com.vaadin.flow.component.page.History.HistoryStateChangeEvent)1 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)1 NavigationEvent (com.vaadin.flow.router.NavigationEvent)1 NavigationTrigger (com.vaadin.flow.router.NavigationTrigger)1 RouterInterface (com.vaadin.flow.router.RouterInterface)1 DefaultErrorView (com.vaadin.flow.router.legacy.DefaultErrorView)1 Resolver (com.vaadin.flow.router.legacy.Resolver)1 ErrorView (com.vaadin.flow.router.legacy.ViewRendererTest.ErrorView)1 TestView (com.vaadin.flow.router.legacy.ViewRendererTest.TestView)1 MockServletConfig (com.vaadin.flow.server.MockServletConfig)1 VaadinRequest (com.vaadin.flow.server.VaadinRequest)1 VaadinResponse (com.vaadin.flow.server.VaadinResponse)1 VaadinService (com.vaadin.flow.server.VaadinService)1