Java Code Examples for com.vaadin.flow.server.startup.ApplicationRouteRegistry#getInstance()

The following examples show how to use com.vaadin.flow.server.startup.ApplicationRouteRegistry#getInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionRouteRegistryTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    registry = ApplicationRouteRegistry.getInstance(
            new VaadinServletContext(Mockito.mock(ServletContext.class)));

    vaadinService = Mockito.mock(MockService.class);
    Mockito.when(vaadinService.getRouteRegistry()).thenReturn(registry);

    VaadinService.setCurrent(vaadinService);

    session = new MockVaadinSession(vaadinService) {
        @Override
        public VaadinService getService() {
            return vaadinService;
        }
    };
}
 
Example 2
Source File: BootstrapContextTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void getPushAnnotation_routeTargetIsAbsent_pushFromTheErrorNavigationTargetIsUsed() {
    Mockito.when(request.getPathInfo()).thenReturn("/bar");

    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(ui.getSession().getService().getContext());
    registry.setErrorNavigationTargets(
            Collections.singleton(CustomRouteNotFound.class));

    BootstrapContext context = new BootstrapContext(request,
            Mockito.mock(VaadinResponse.class), session, ui, request -> "");

    Optional<Push> push = context
            .getPageConfigurationAnnotation(Push.class);
    Assert.assertTrue(push.isPresent());
    Push pushAnnotation = push.get();
    Assert.assertEquals(PushMode.AUTOMATIC, pushAnnotation.value());
    Assert.assertEquals(Transport.WEBSOCKET, pushAnnotation.transport());
}
 
Example 3
Source File: BootstrapContextTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void getPushAnnotation_routeTargetIsAbsent_pushIsDefinedOnParentLayout_pushFromTheErrorNavigationTargetParentLayoutIsUsed() {
    Mockito.when(request.getPathInfo()).thenReturn("/bar");

    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(ui.getSession().getService().getContext());
    registry.setErrorNavigationTargets(
            Collections.singleton(AnotherCustomRouteNotFound.class));

    BootstrapContext context = new BootstrapContext(request,
            Mockito.mock(VaadinResponse.class), session, ui, request -> "");

    Optional<Push> push = context
            .getPageConfigurationAnnotation(Push.class);
    Assert.assertTrue(push.isPresent());
    Push pushAnnotation = push.get();
    Assert.assertEquals(PushMode.MANUAL, pushAnnotation.value());
    Assert.assertEquals(Transport.LONG_POLLING, pushAnnotation.transport());
}
 
Example 4
Source File: RouteConfigurationTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    servletContext = new MockServletContext();
    vaadinContext = new VaadinServletContext(servletContext);
    registry = ApplicationRouteRegistry
            .getInstance(vaadinContext);

    vaadinService = Mockito.mock(MockService.class);
    Mockito.when(vaadinService.getRouteRegistry()).thenReturn(registry);
    Mockito.when(vaadinService.getContext()).thenReturn(vaadinContext);

    VaadinService.setCurrent(vaadinService);

    session = new MockVaadinSession(vaadinService) {
        @Override
        public VaadinService getService() {
            return vaadinService;
        }
    };
}
 
Example 5
Source File: RouteUtilTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry() {
    // given
    @Route("a")
    class A extends Component {
    }
    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(new MockVaadinServletService().getContext());

    // when
    RouteUtil.updateRouteRegistry(registry, Collections.singleton(A.class),
            Collections.emptySet(), Collections.emptySet());

    // then
    Assert.assertTrue(registry.getConfiguration().hasRoute("a"));
}
 
Example 6
Source File: RouteUtilTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void deletedRouteAnnotatedClass_updateRouteRegistry_routeIsRemovedFromRegistry() {
    // given
    @Route("a")
    class A extends Component {
    }
    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(new MockVaadinServletService().getContext());
    registry.setRoute("a", A.class, Collections.emptyList());
    Assert.assertTrue(registry.getConfiguration().hasRoute("a"));

    // when
    RouteUtil.updateRouteRegistry(registry, Collections.emptySet(),
            Collections.emptySet(), Collections.singleton(A.class));

    // then
    Assert.assertFalse(registry.getConfiguration().hasRoute("a"));
}
 
Example 7
Source File: RouteUtilTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry() {
    // given
    @Route("aa")
    class A extends Component {
    }
    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(new MockVaadinServletService().getContext());
    registry.setRoute("a", A.class, Collections.emptyList());
    Assert.assertTrue(registry.getConfiguration().hasRoute("a"));

    // when
    RouteUtil.updateRouteRegistry(registry, Collections.emptySet(),
            Collections.singleton(A.class), Collections.emptySet());

    // then
    Assert.assertFalse(registry.getConfiguration().hasRoute("a"));
    Assert.assertTrue(registry.getConfiguration().hasRoute("aa"));
}
 
Example 8
Source File: RouteUtilTest.java    From flow with Apache License 2.0 6 votes vote down vote up
@Test
public void deannotatedRouteClass_updateRouteRegistry_routeIsRemovedFromRegistry() {
    // given
    class A extends Component {
    }
    ApplicationRouteRegistry registry = ApplicationRouteRegistry
            .getInstance(new MockVaadinServletService().getContext());
    registry.setRoute("a", A.class, Collections.emptyList());
    Assert.assertTrue(registry.getConfiguration().hasRoute("a"));

    // when
    RouteUtil.updateRouteRegistry(registry, Collections.emptySet(),
            Collections.singleton(A.class), Collections.emptySet());

    // then
    Assert.assertFalse(registry.getConfiguration().hasRoute("a"));
}
 
Example 9
Source File: VertxVaadinService.java    From vertx-vaadin with MIT License 4 votes vote down vote up
@Override
protected RouteRegistry getRouteRegistry() {
    return ApplicationRouteRegistry.getInstance(vertxVaadin.servletContext());
}
 
Example 10
Source File: VaadinServletService.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
protected RouteRegistry getRouteRegistry() {
    return ApplicationRouteRegistry.getInstance(getContext());
}
 
Example 11
Source File: RouteConfiguration.java    From flow with Apache License 2.0 4 votes vote down vote up
private static RouteRegistry getApplicationRegistry() {
    return ApplicationRouteRegistry
            .getInstance(VaadinService.getCurrent().getContext());
}
 
Example 12
Source File: NavigationStateRendererTest.java    From flow with Apache License 2.0 4 votes vote down vote up
@Before
public void init() {
    RouteRegistry registry = ApplicationRouteRegistry.getInstance(
            new VaadinServletContext(Mockito.mock(ServletContext.class)));
    router = new Router(registry);
}