use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class WebComponentProviderTest method mockRequest.
private VaadinRequest mockRequest(boolean hasConfig) {
VaadinContext context = Mockito.mock(VaadinContext.class);
VaadinService service = Mockito.mock(VaadinService.class);
VaadinRequest request = Mockito.mock(VaadinRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
WebComponentConfigurationRegistry registry = Mockito.mock(WebComponentConfigurationRegistry.class);
Mockito.when(context.getAttribute(Mockito.eq(WebComponentConfigurationRegistry.class), Mockito.any())).thenReturn(registry);
Mockito.when(registry.hasConfigurations()).thenReturn(hasConfig);
Mockito.when(request.getPathInfo()).thenReturn("/web-component/a-b.js");
return request;
}
use of com.vaadin.flow.server.VaadinService 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.flow.server.VaadinService 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.flow.server.VaadinService in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method getMockResponse.
private VaadinResponse getMockResponse(ByteArrayOutputStream stream) throws IOException {
VaadinResponse response = Mockito.mock(VaadinResponse.class);
VaadinService service = Mockito.mock(VaadinService.class);
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(response.getOutputStream()).thenReturn(stream);
Mockito.when(response.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
Mockito.when(context.getAttribute(eq(WebComponentConfigurationRegistry.class), any())).thenReturn(Mockito.mock(WebComponentConfigurationRegistry.class));
return response;
}
use of com.vaadin.flow.server.VaadinService in project flow by vaadin.
the class InvalidateHttpSessionView method onAttach.
@Override
protected void onAttach(AttachEvent attachEvent) {
VaadinService service = attachEvent.getSession().getService();
String id = attachEvent.getSession().getSession().getId();
Div div = new Div();
div.setText(id);
div.setId("current-session-id");
add(div);
SessionId closedSessionId = attachEvent.getSession().getService().getContext().getAttribute(SessionId.class);
if (closedSessionId != null) {
div = new Div();
div.setText(closedSessionId.id);
div.setId("invalidated-session-id");
add(div);
}
service.addSessionDestroyListener(event -> {
SessionId sessionId = new SessionId(id);
service.getContext().setAttribute(SessionId.class, sessionId);
});
NativeButton button = new NativeButton("Invalidate HTTP session", event -> attachEvent.getSession().getSession().invalidate());
add(button);
button.setId("invalidate-session");
}
Aggregations