use of com.vaadin.flow.router.TestRouteRegistry in project flow by vaadin.
the class BootstrapHandlerTest method setup.
@Before
public void setup() {
TestRouteRegistry routeRegistry = new TestRouteRegistry();
BootstrapHandler.clientEngineFile = "foobar";
testUI = new TestUI();
deploymentConfiguration = new MockDeploymentConfiguration("test/");
service = Mockito.spy(new MockVaadinServletService(deploymentConfiguration));
Mockito.when(service.getRouteRegistry()).thenReturn(routeRegistry);
Mockito.when(service.getRouter()).thenReturn(new Router(routeRegistry) {
@Override
public void initializeUI(UI ui, VaadinRequest initRequest) {
// injected
if (routeRegistry.hasNavigationTargets()) {
super.initializeUI(ui, initRequest);
}
}
});
session = Mockito.spy(new MockVaadinSession(service));
session.lock();
session.setConfiguration(deploymentConfiguration);
testUI.getInternals().setSession(session);
browser = Mockito.mock(WebBrowser.class);
Mockito.when(browser.isEs6Supported()).thenReturn(false);
Mockito.when(session.getBrowser()).thenReturn(browser);
}
use of com.vaadin.flow.router.TestRouteRegistry in project flow by vaadin.
the class LocationObserverTest method navigation_and_locale_change_should_fire_locale_change_observer.
@Test
public void navigation_and_locale_change_should_fire_locale_change_observer() throws InvalidRouteConfigurationException {
router = new Router(new TestRouteRegistry());
ui = new RouterTestUI(router);
router.getRegistry().setNavigationTargets(Collections.singleton(Translations.class));
ui.navigate("");
Assert.assertEquals("Expected event amount was wrong", 1, eventCollector.size());
Assert.assertEquals("Received locale change event for locale: " + Locale.getDefault().getDisplayName(), eventCollector.get(0));
ui.setLocale(Locale.CANADA);
Assert.assertEquals("Expected event amount was wrong", 2, eventCollector.size());
Assert.assertEquals("Received locale change event for locale: " + Locale.CANADA.getDisplayName(), eventCollector.get(1));
}
use of com.vaadin.flow.router.TestRouteRegistry in project flow by vaadin.
the class RouteRegistryInitializerTest method init.
@Before
public void init() {
routeRegistryInitializer = new RouteRegistryInitializer();
registry = new TestRouteRegistry();
servletContext = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getAttribute(RouteRegistry.class.getName())).thenReturn(registry);
}
use of com.vaadin.flow.router.TestRouteRegistry 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