Search in sources :

Example 11 with AlwaysLockedVaadinSession

use of com.vaadin.tests.util.AlwaysLockedVaadinSession in project flow by vaadin.

the class StreamResourceHandlerTest method setUp.

@Before
public void setUp() throws ServletException, ServiceException {
    VaadinService service = new MockVaadinServletService();
    session = new AlwaysLockedVaadinSession(service);
    request = Mockito.mock(VaadinServletRequest.class);
    ServletContext context = Mockito.mock(ServletContext.class);
    Mockito.when(request.getServletContext()).thenReturn(context);
    response = Mockito.mock(VaadinServletResponse.class);
}
Also used : VaadinServletResponse(com.vaadin.flow.server.VaadinServletResponse) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) ServletContext(javax.servlet.ServletContext) Before(org.junit.Before)

Example 12 with AlwaysLockedVaadinSession

use of com.vaadin.tests.util.AlwaysLockedVaadinSession in project flow by vaadin.

the class StreamRequestHandlerTest method setUp.

@Before
public void setUp() throws ServletException, ServiceException {
    VaadinService service = new MockVaadinServletService();
    session = new AlwaysLockedVaadinSession(service) {

        @Override
        public StreamResourceRegistry getResourceRegistry() {
            return streamResourceRegistry;
        }
    };
    streamResourceRegistry = new StreamResourceRegistry(session);
    request = Mockito.mock(VaadinServletRequest.class);
    ServletContext servletContext = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getMimeType(Mockito.anyString())).thenReturn(null);
    Mockito.when(request.getServletContext()).thenReturn(servletContext);
    response = Mockito.mock(VaadinResponse.class);
    ui = new MockUI();
    UI.setCurrent(ui);
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockUI(com.vaadin.tests.util.MockUI) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) StreamResourceRegistry(com.vaadin.flow.server.StreamResourceRegistry) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) VaadinService(com.vaadin.flow.server.VaadinService) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) ServletContext(javax.servlet.ServletContext) Before(org.junit.Before)

Example 13 with AlwaysLockedVaadinSession

use of com.vaadin.tests.util.AlwaysLockedVaadinSession 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 14 with AlwaysLockedVaadinSession

use of com.vaadin.tests.util.AlwaysLockedVaadinSession 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));
}
Also used : NavigationStateBuilder(com.vaadin.flow.router.NavigationStateBuilder) MockUI(com.vaadin.tests.util.MockUI) NavigationEvent(com.vaadin.flow.router.NavigationEvent) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Example 15 with AlwaysLockedVaadinSession

use of com.vaadin.tests.util.AlwaysLockedVaadinSession in project flow by vaadin.

the class NavigationStateRendererTest method handle_preserveOnRefresh_otherUIChildrenAreMoved.

@Test
public void handle_preserveOnRefresh_otherUIChildrenAreMoved() {
    // given a service with instantiator
    MockVaadinServletService service = createMockServiceWithInstantiator();
    // given a locked session
    MockVaadinSession session = new AlwaysLockedVaadinSession(service);
    session.setConfiguration(new MockDeploymentConfiguration());
    // given a NavigationStateRenderer mapping to PreservedView
    NavigationStateRenderer renderer = new NavigationStateRenderer(navigationStateFromTarget(PreservedView.class));
    // given the session has a cache of PreservedView at this location
    final PreservedView view = new PreservedView();
    AbstractNavigationStateRenderer.setPreservedChain(session, "ROOT.123", new Location("preserved"), new ArrayList<>(Arrays.asList(view)));
    // given an old UI that contains the component and an extra element
    MockUI ui0 = new MockUI(session);
    ui0.add(view);
    final Element otherElement = new Element("div");
    ui0.getElement().insertChild(1, otherElement);
    // given a new UI after a refresh with the same window name
    MockUI ui1 = new MockUI(session);
    ExtendedClientDetails details = Mockito.mock(ExtendedClientDetails.class);
    Mockito.when(details.getWindowName()).thenReturn("ROOT.123");
    ui1.getInternals().setExtendedClientDetails(details);
    // when a navigation event reaches the renderer
    renderer.handle(new NavigationEvent(new Router(new TestRouteRegistry()), new Location("preserved"), ui1, NavigationTrigger.PAGE_LOAD));
    // then both the view element and the other element are expected to be
    // transferred from the previous UI to the new UI
    final Set<Element> uiChildren = ui1.getElement().getChildren().collect(Collectors.toSet());
    Assert.assertEquals(2, uiChildren.size());
    Assert.assertTrue("Component element expected transferred", uiChildren.contains(view.getElement()));
    Assert.assertTrue("Extra element expected transferred", uiChildren.contains(otherElement));
}
Also used : NavigationEvent(com.vaadin.flow.router.NavigationEvent) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) Element(com.vaadin.flow.dom.Element) HasElement(com.vaadin.flow.component.HasElement) Router(com.vaadin.flow.router.Router) TestRouteRegistry(com.vaadin.flow.router.TestRouteRegistry) MockUI(com.vaadin.tests.util.MockUI) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) AlwaysLockedVaadinSession(com.vaadin.tests.util.AlwaysLockedVaadinSession) ExtendedClientDetails(com.vaadin.flow.component.page.ExtendedClientDetails) Location(com.vaadin.flow.router.Location) Test(org.junit.Test)

Aggregations

AlwaysLockedVaadinSession (com.vaadin.tests.util.AlwaysLockedVaadinSession)16 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)14 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)11 MockUI (com.vaadin.tests.util.MockUI)11 Location (com.vaadin.flow.router.Location)8 NavigationEvent (com.vaadin.flow.router.NavigationEvent)8 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)8 Test (org.junit.Test)8 Router (com.vaadin.flow.router.Router)7 ExtendedClientDetails (com.vaadin.flow.component.page.ExtendedClientDetails)6 TestRouteRegistry (com.vaadin.flow.router.TestRouteRegistry)6 Component (com.vaadin.flow.component.Component)5 Element (com.vaadin.flow.dom.Element)5 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 HasElement (com.vaadin.flow.component.HasElement)4 NavigationStateBuilder (com.vaadin.flow.router.NavigationStateBuilder)4 RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)4 VaadinService (com.vaadin.flow.server.VaadinService)4 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)4 UI (com.vaadin.flow.component.UI)3