use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class UITest method initUI.
private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException {
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
VaadinResponse response = Mockito.mock(VaadinResponse.class);
String pathInfo;
if (initialLocation.isEmpty()) {
pathInfo = null;
} else {
Assert.assertFalse(initialLocation.startsWith("/"));
pathInfo = "/" + initialLocation;
}
Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
VaadinService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
service.setCurrentInstances(request, response);
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(config.isProductionMode()).thenReturn(false);
session.lock();
session.setConfiguration(config);
ui.getInternals().setSession(session);
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getInternals().getRouter().getRegistry());
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
Arrays.asList(RootNavigationTarget.class, FooBarNavigationTarget.class, Parameterized.class, FooBarParamNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
});
ui.doInit(request, 0);
ui.getInternals().getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
session.unlock();
if (statusCodeCaptor != null) {
Mockito.verify(response).setStatus(statusCodeCaptor.capture());
}
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class InvalidUrlTest method initUI.
private static void initUI(UI ui, String initialLocation, ArgumentCaptor<Integer> statusCodeCaptor) throws InvalidRouteConfigurationException, ServiceException {
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
VaadinResponse response = Mockito.mock(VaadinResponse.class);
String pathInfo;
if (initialLocation.isEmpty()) {
pathInfo = null;
} else {
Assert.assertFalse(initialLocation.startsWith("/"));
pathInfo = "/" + initialLocation;
}
Mockito.when(request.getPathInfo()).thenReturn(pathInfo);
VaadinService service = new MockVaadinServletService() {
@Override
public VaadinContext getContext() {
return new MockVaadinContext();
}
};
service.setCurrentInstances(request, response);
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
DeploymentConfiguration config = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(config.isProductionMode()).thenReturn(false);
session.lock();
session.setConfiguration(config);
ui.getInternals().setSession(session);
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(ui.getRouter().getRegistry());
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
Arrays.asList(UITest.RootNavigationTarget.class, UITest.FooBarNavigationTarget.class).forEach(routeConfiguration::setAnnotatedRoute);
});
ui.doInit(request, 0);
ui.getRouter().initializeUI(ui, BootstrapHandlerTest.requestToLocation(request));
session.unlock();
if (statusCodeCaptor != null) {
Mockito.verify(response).setStatus(statusCodeCaptor.capture());
}
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class SessionRouteRegistryTest method getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsNotRoot_mainRouteIsReturned.
@Test
public void getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsNotRoot_mainRouteIsReturned() {
SessionRouteRegistry registry = getRegistry(session);
RouteConfiguration configuration = RouteConfiguration.forRegistry(registry);
configuration.setAnnotatedRoute(RouteWithRootAlias.class);
Optional<String> url = registry.getTargetUrl(RouteWithRootAlias.class, RouteParameters.empty());
Assert.assertTrue(url.isPresent());
Assert.assertEquals("foo", url.get());
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class SessionRouteRegistryTest method getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsParamerterized_routeAliasIsReturned.
@Test
public void getTargetUrl_annotatedRoute_rootIsAlias_mainRouteIsParamerterized_routeAliasIsReturned() {
SessionRouteRegistry registry = getRegistry(session);
RouteConfiguration configuration = RouteConfiguration.forRegistry(registry);
configuration.setAnnotatedRoute(ParameterizedRouteWithRootAlias.class);
Optional<String> url = registry.getTargetUrl(ParameterizedRouteWithRootAlias.class, RouteParameters.empty());
Assert.assertTrue(url.isPresent());
Assert.assertEquals("", url.get());
}
use of com.vaadin.flow.router.RouteConfiguration in project flow by vaadin.
the class BootstrapHandlerTest method initUI.
private void initUI(UI ui, VaadinRequest request, Set<Class<? extends Component>> navigationTargets) throws InvalidRouteConfigurationException {
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(service.getRouteRegistry());
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
navigationTargets.forEach(routeConfiguration::setAnnotatedRoute);
});
initUI(ui, request);
}
Aggregations