Search in sources :

Example 6 with MockVaadinContext

use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.

the class RouteUtilTest method newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry.

@Test
public void newRouteAnnotatedClass_updateRouteRegistry_routeIsAddedToRegistry() {
    // given
    @Route("a")
    class A extends Component {
    }
    MockVaadinServletService service = new MockVaadinServletService() {

        @Override
        public VaadinContext getContext() {
            return new MockVaadinContext();
        }
    };
    ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(service.getContext());
    // when
    RouteUtil.updateRouteRegistry(registry, Collections.singleton(A.class), Collections.emptySet(), Collections.emptySet());
    // then
    Assert.assertTrue(registry.getConfiguration().hasRoute("a"));
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) Component(com.vaadin.flow.component.Component) ApplicationRouteRegistry(com.vaadin.flow.server.startup.ApplicationRouteRegistry) Route(com.vaadin.flow.router.Route) Test(org.junit.Test)

Example 7 with MockVaadinContext

use of com.vaadin.flow.server.MockVaadinContext 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());
    }
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 8 with MockVaadinContext

use of com.vaadin.flow.server.MockVaadinContext 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());
    }
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) RouteConfiguration(com.vaadin.flow.router.RouteConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) DeploymentConfiguration(com.vaadin.flow.function.DeploymentConfiguration)

Example 9 with MockVaadinContext

use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.

the class ErrorStateRendererTest method configureMocks.

private UI configureMocks() {
    MockVaadinServletService service = new MockVaadinServletService() {

        @Override
        public VaadinContext getContext() {
            return new MockVaadinContext();
        }
    };
    MockVaadinSession session = new AlwaysLockedVaadinSession(service);
    session.setConfiguration(new MockDeploymentConfiguration());
    MockUI ui = new MockUI(session);
    return ui;
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockUI(com.vaadin.tests.util.MockUI) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration)

Example 10 with MockVaadinContext

use of com.vaadin.flow.server.MockVaadinContext in project flow by vaadin.

the class RouteUtilTest method renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry.

@Test
public void renamedRouteAnnotatedClass_updateRouteRegistry_routeIsUpdatedInRegistry() {
    // given
    @Route("aa")
    class A extends Component {
    }
    MockVaadinServletService service = new MockVaadinServletService() {

        @Override
        public VaadinContext getContext() {
            return new MockVaadinContext();
        }
    };
    ApplicationRouteRegistry registry = ApplicationRouteRegistry.getInstance(service.getContext());
    registry.setRoute("a", A.class, Collections.emptyList());
    Assert.assertTrue(registry.getConfiguration().hasRoute("a"));
    // when
    RouteUtil.updateRouteRegistry(registry, Collections.emptySet(), Collections.singleton(A.class), Collections.emptySet());
    // then
    Assert.assertFalse(registry.getConfiguration().hasRoute("a"));
    Assert.assertTrue(registry.getConfiguration().hasRoute("aa"));
}
Also used : MockVaadinContext(com.vaadin.flow.server.MockVaadinContext) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) Component(com.vaadin.flow.component.Component) ApplicationRouteRegistry(com.vaadin.flow.server.startup.ApplicationRouteRegistry) Route(com.vaadin.flow.router.Route) Test(org.junit.Test)

Aggregations

MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)12 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)5 Before (org.junit.Before)5 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)4 VaadinContext (com.vaadin.flow.server.VaadinContext)4 VaadinService (com.vaadin.flow.server.VaadinService)4 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)4 ApplicationRouteRegistry (com.vaadin.flow.server.startup.ApplicationRouteRegistry)4 AlwaysLockedVaadinSession (com.vaadin.tests.util.AlwaysLockedVaadinSession)3 Test (org.junit.Test)3 Component (com.vaadin.flow.component.Component)2 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 Route (com.vaadin.flow.router.Route)2 RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)2 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)2 RouteRegistry (com.vaadin.flow.server.RouteRegistry)2 VaadinResponse (com.vaadin.flow.server.VaadinResponse)2 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)2 VaadinServletService (com.vaadin.flow.server.VaadinServletService)2 Properties (java.util.Properties)2