use of com.vaadin.flow.router.NavigationEvent in project flow by vaadin.
the class RouterConfigurationTest method defaultErrorHandlerStatusCode.
@Test
public void defaultErrorHandlerStatusCode() {
Router router = new Router();
int statusCode = router.getConfiguration().getErrorHandler().handle(new NavigationEvent(router, new Location(""), new UI(), NavigationTrigger.PROGRAMMATIC));
Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, statusCode);
}
use of com.vaadin.flow.router.NavigationEvent in project flow by vaadin.
the class ViewRendererTest method testViewInstantiationCustomization.
@Test
public void testViewInstantiationCustomization() {
// override default implementation of reusing the views if possible
ViewRenderer renderer = new TestViewRenderer(TestView.class, ParentView.class) {
@Override
protected <T extends View> T getView(Class<T> viewType, NavigationEvent event) {
// always return a new view
return ReflectTools.createInstance(viewType);
}
};
renderer.handle(dummyEvent);
View view1 = dummyEvent.getUI().getInternals().getActiveViewChain().get(0);
View parentView1 = dummyEvent.getUI().getInternals().getActiveViewChain().get(1);
renderer.handle(dummyEvent);
View view2 = dummyEvent.getUI().getInternals().getActiveViewChain().get(0);
View parentView2 = dummyEvent.getUI().getInternals().getActiveViewChain().get(1);
Assert.assertNotSame(view1, view2);
Assert.assertNotSame(parentView1, parentView2);
}
use of com.vaadin.flow.router.NavigationEvent in project flow by vaadin.
the class NavigationStateRendererTest method handle_RouterLinkTriggerNullState_IllegalStateException.
@Test
public void handle_RouterLinkTriggerNullState_IllegalStateException() {
// given a service with instantiator
MockVaadinServletService service = createMockServiceWithInstantiator();
service.setRouter(router);
// given a locked session
MockVaadinSession session = new AlwaysLockedVaadinSession(service);
session.setConfiguration(new MockDeploymentConfiguration());
// given a NavigationStateRenderer mapping to RegularView
new NavigationStateBuilder(router).withTarget(RegularView.class).build();
NavigationStateRenderer renderer = new NavigationStateRenderer(navigationStateFromTarget(RegularView.class));
MockUI ui = new MockUI(session);
expectedException.expect(IllegalStateException.class);
renderer.handle(new NavigationEvent(router, new Location("regular"), ui, NavigationTrigger.ROUTER_LINK, null, false));
}
use of com.vaadin.flow.router.NavigationEvent in project flow by vaadin.
the class NavigationStateRendererTest method createMockServiceWithInstantiator.
private MockVaadinServletService createMockServiceWithInstantiator() {
MockVaadinServletService service = new MockVaadinServletService();
service.init(new MockInstantiator() {
@Override
public <T extends HasElement> T createRouteTarget(Class<T> routeTargetType, NavigationEvent event) {
try {
return routeTargetType.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
});
return service;
}
use of com.vaadin.flow.router.NavigationEvent in project flow by vaadin.
the class NavigationStateRendererTest method instantiatorUse.
@Test
public void instantiatorUse() throws ServiceException {
MockVaadinServletService service = new MockVaadinServletService();
service.init(new MockInstantiator() {
@Override
public <T extends HasElement> T createRouteTarget(Class<T> routeTargetType, NavigationEvent event) {
Assert.assertEquals(Component.class, routeTargetType);
return (T) new Text("foo");
}
});
MockUI ui = new MockUI(new MockVaadinSession(service));
NavigationEvent event = new NavigationEvent(new Router(new TestRouteRegistry()), new Location(""), ui, NavigationTrigger.PAGE_LOAD);
NavigationStateRenderer renderer = new NavigationStateRenderer(navigationStateFromTarget(ChildConfiguration.class));
Component routeTarget = renderer.getRouteTarget(Component.class, event);
Assert.assertEquals(Text.class, routeTarget.getClass());
UI.setCurrent(null);
}
Aggregations