use of com.vaadin.flow.server.RouteRegistry in project flow by vaadin.
the class RouteConfigurationTest method registeredRouteWithAlias_allPathsAreRegistered.
@Test
public void registeredRouteWithAlias_allPathsAreRegistered() {
RouteRegistry registry = mockRegistry();
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(registry);
routeConfiguration.setAnnotatedRoute(MyRouteWithAliases.class);
Mockito.verify(registry).setRoute("withAliases", MyRouteWithAliases.class, Collections.emptyList());
Mockito.verify(registry).setRoute("version", MyRouteWithAliases.class, Collections.emptyList());
Mockito.verify(registry).setRoute("person", MyRouteWithAliases.class, Collections.emptyList());
}
use of com.vaadin.flow.server.RouteRegistry in project flow by vaadin.
the class RouteConfigurationTest method routeWithParent_parentsAreCollectedCorrectly.
@Test
public void routeWithParent_parentsAreCollectedCorrectly() {
RouteRegistry registry = mockRegistry();
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(registry);
routeConfiguration.setAnnotatedRoute(SingleLayout.class);
Mockito.verify(registry).setRoute("single", SingleLayout.class, Collections.singletonList(MainLayout.class));
routeConfiguration.setAnnotatedRoute(DoubleLayout.class);
Mockito.verify(registry).setRoute("double", DoubleLayout.class, Arrays.asList(MiddleLayout.class, MainLayout.class));
}
use of com.vaadin.flow.server.RouteRegistry in project flow by vaadin.
the class RouteConfigurationTest method setRoutes_allExpectedRoutesAreSet.
@Test
public void setRoutes_allExpectedRoutesAreSet() {
RouteRegistry registry = mockRegistry();
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(registry);
Mockito.doAnswer(invocation -> {
Object[] args = invocation.getArguments();
((Command) args[0]).execute();
return null;
}).when(registry).update(Mockito.any(Command.class));
routeConfiguration.update(() -> {
routeConfiguration.getHandledRegistry().clean();
Arrays.asList(MyRoute.class, MyInfo.class, MyPalace.class, MyModular.class).forEach(routeConfiguration::setAnnotatedRoute);
});
Mockito.verify(registry).update(Mockito.any());
Mockito.verify(registry).setRoute("home", MyRoute.class, Collections.emptyList());
Mockito.verify(registry).setRoute("info", MyInfo.class, Collections.emptyList());
Mockito.verify(registry).setRoute("palace", MyPalace.class, Collections.emptyList());
Mockito.verify(registry).setRoute("modular", MyModular.class, Collections.emptyList());
}
use of com.vaadin.flow.server.RouteRegistry in project flow by vaadin.
the class RouteConfigurationTest method parentLayoutAnnotatedClass_parentsCorrecltCollected.
@Test
public void parentLayoutAnnotatedClass_parentsCorrecltCollected() {
RouteRegistry registry = Mockito.mock(RouteRegistry.class);
RouteConfiguration routeConfiguration = RouteConfiguration.forRegistry(registry);
routeConfiguration.setParentAnnotatedRoute("middle", MiddleLayout.class);
Mockito.verify(registry).setRoute("middle", MiddleLayout.class, Collections.singletonList(MainLayout.class));
}
use of com.vaadin.flow.server.RouteRegistry in project flow by vaadin.
the class ViewAccessCheckerTest method setupRequest.
private Result setupRequest(Class navigationTarget, User user, boolean productionMode) {
CurrentInstance.clearAll();
Principal principal;
String[] roles;
if (user == User.USER_NO_ROLES) {
principal = AccessAnnotationCheckerTest.USER_PRINCIPAL;
roles = new String[0];
} else if (user == User.NORMAL_USER) {
principal = AccessAnnotationCheckerTest.USER_PRINCIPAL;
roles = new String[] { "user" };
} else if (user == User.ADMIN) {
principal = AccessAnnotationCheckerTest.USER_PRINCIPAL;
roles = new String[] { "admin" };
} else {
principal = null;
roles = new String[0];
}
VaadinServletRequest vaadinServletRequest = Mockito.mock(VaadinServletRequest.class);
HttpServletRequest httpServletRequest = AccessAnnotationCheckerTest.createRequest(principal, roles);
Mockito.when(vaadinServletRequest.getHttpServletRequest()).thenReturn(httpServletRequest);
CurrentInstance.set(VaadinRequest.class, vaadinServletRequest);
Router router = Mockito.mock(Router.class);
UI ui = Mockito.mock(UI.class);
Page page = Mockito.mock(Page.class);
Mockito.when(ui.getPage()).thenReturn(page);
VaadinSession vaadinSession = Mockito.mock(VaadinSession.class);
Mockito.when(ui.getSession()).thenReturn(vaadinSession);
DeploymentConfiguration configuration = Mockito.mock(DeploymentConfiguration.class);
Mockito.when(vaadinSession.getConfiguration()).thenReturn(configuration);
Mockito.when(configuration.isProductionMode()).thenReturn(productionMode);
UIInternals uiInternals = Mockito.mock(UIInternals.class);
Mockito.when(ui.getInternals()).thenReturn(uiInternals);
Mockito.when(uiInternals.getRouter()).thenReturn(router);
Mockito.when(router.getErrorNavigationTarget(Mockito.any())).thenAnswer(invocation -> {
Class<?> exceptionClass = invocation.getArguments()[0].getClass();
if (exceptionClass == NotFoundException.class) {
return Optional.of(new ErrorTargetEntry(RouteNotFoundError.class, NotFoundException.class));
} else {
return Optional.empty();
}
});
Location location = new Location(getRoute(navigationTarget));
NavigationEvent navigationEvent = new NavigationEvent(router, location, ui, NavigationTrigger.ROUTER_LINK);
BeforeEnterEvent event = new BeforeEnterEvent(navigationEvent, navigationTarget, new ArrayList<>());
RouteRegistry routeRegistry = Mockito.mock(RouteRegistry.class);
Mockito.when(router.getRegistry()).thenReturn(routeRegistry);
Mockito.when(routeRegistry.getNavigationTarget(Mockito.anyString())).thenAnswer(invocation -> {
String url = (String) invocation.getArguments()[0];
if (location.getPath().equals(url)) {
return Optional.of(navigationTarget);
} else {
return Optional.empty();
}
});
HttpSession session = Mockito.mock(HttpSession.class);
Map<String, Object> sessionAttributes = new HashMap<>();
Mockito.when(httpServletRequest.getSession()).thenReturn(session);
Mockito.doAnswer(invocation -> {
String key = (String) invocation.getArguments()[0];
Object value = invocation.getArguments()[1];
sessionAttributes.put(key, value);
return null;
}).when(session).setAttribute(Mockito.anyString(), Mockito.any());
Result info = new Result();
info.event = event;
info.sessionAttributes = sessionAttributes;
Mockito.doAnswer(invocation -> {
info.redirectUsingPageLocation = (String) invocation.getArguments()[0];
return null;
}).when(page).setLocation(Mockito.anyString());
return info;
}
Aggregations