use of com.vaadin.flow.server.startup.ApplicationRouteRegistry in project flow by vaadin.
the class RouteUtilTest method deannotatedRouteClass_updateRouteRegistry_routeIsRemovedFromRegistry.
@Test
public void deannotatedRouteClass_updateRouteRegistry_routeIsRemovedFromRegistry() {
// given
class A extends Component {
}
MockVaadinServletService service = new MockVaadinServletService();
ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(service.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"));
}
use of com.vaadin.flow.server.startup.ApplicationRouteRegistry in project flow by vaadin.
the class RouteUtilTest method newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry.
@Test
public void newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry() {
// given
@Route("a")
class A extends Component {
}
MockVaadinServletService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(service.getContext());
// when
RouteUtil.updateRouteRegistry(registry, Collections.singleton(A.class), Collections.emptySet(), Collections.emptySet());
// then
Assert.assertTrue(registry.getConfiguration().hasRoute("a"));
}
use of com.vaadin.flow.server.startup.ApplicationRouteRegistry in project flow by vaadin.
the class CustomRouteRegistry method getInstance.
public static CustomRouteRegistry getInstance(VaadinContext context) {
assert context != null;
RegistryWrapper attribute;
synchronized (context) {
attribute = context.getAttribute(RegistryWrapper.class);
if (attribute == null) {
final CustomRouteRegistry registry = new CustomRouteRegistry(context);
attribute = new RegistryWrapper(registry);
context.setAttribute(attribute);
// Get collected application routes
final ApplicationRouteRegistry instance = ApplicationRouteRegistry.getInstance(context);
instance.getRegisteredRoutes().forEach(routeData -> {
registry.setRoute(routeData.getTemplate(), routeData.getNavigationTarget(), routeData.getParentLayouts());
});
// Add only NotFoundException and Exception ignoring other error
// views collected
Map<Class<? extends Exception>, Class<? extends Component>> map = new HashMap<>();
map.put(NotFoundException.class, CustomNotFoundView.class);
registry.configure(configuration -> map.forEach(configuration::setErrorRoute));
}
}
return attribute.getRegistry();
}
use of com.vaadin.flow.server.startup.ApplicationRouteRegistry in project flow by vaadin.
the class RouteUtilTest method renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry.
@Test
public void renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry() {
// given
@Route("aa")
class A extends Component {
}
MockVaadinServletService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(service.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"));
}
use of com.vaadin.flow.server.startup.ApplicationRouteRegistry in project flow by vaadin.
the class BootstrapContextTest method getPushAnnotation_routeTargetIsAbsent_pushFromTheErrorNavigationTargetIsUsed.
@Test
public void getPushAnnotation_routeTargetIsAbsent_pushFromTheErrorNavigationTargetIsUsed() {
Mockito.when(request.getParameter(ApplicationConstants.REQUEST_LOCATION_PARAMETER)).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());
}
Aggregations