Search in sources :

Example 1 with TestRouteRegistry

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);
}
Also used : UI(com.vaadin.flow.component.UI) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) Router(com.vaadin.flow.router.Router) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) Before(org.junit.Before)

Example 2 with TestRouteRegistry

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));
}
Also used : Router(com.vaadin.flow.router.Router) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) Test(org.junit.Test)

Example 3 with TestRouteRegistry

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);
}
Also used : TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) ServletContext(javax.servlet.ServletContext) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) Before(org.junit.Before)

Example 4 with TestRouteRegistry

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);
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) Router(com.vaadin.flow.router.Router) Text(com.vaadin.flow.component.Text) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) MockUI(com.vaadin.tests.util.MockUI) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) MockInstantiator(com.vaadin.flow.server.MockInstantiator) Component(com.vaadin.flow.component.Component) Location(com.vaadin.flow.router.Location) NavigationStateRenderer(com.vaadin.flow.router.internal.NavigationStateRenderer) Test(org.junit.Test)

Aggregations

TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)4 Router (com.vaadin.flow.router.Router)3 Before (org.junit.Before)2 Test (org.junit.Test)2 Component (com.vaadin.flow.component.Component)1 Text (com.vaadin.flow.component.Text)1 UI (com.vaadin.flow.component.UI)1 Location (com.vaadin.flow.router.Location)1 NavigationEvent (com.vaadin.flow.router.NavigationEvent)1 NavigationStateRenderer (com.vaadin.flow.router.internal.NavigationStateRenderer)1 MockInstantiator (com.vaadin.flow.server.MockInstantiator)1 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)1 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)1 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)1 MockUI (com.vaadin.tests.util.MockUI)1 ServletContext (javax.servlet.ServletContext)1