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);
}
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);
}
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;
}
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));
}
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));
}
Aggregations