use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class SpringClassesSerializableTest method createStore.
private TestBeanStore createStore() {
final Properties initParameters = new Properties();
ApplicationConfiguration appConfig = Mockito.mock(ApplicationConfiguration.class);
Mockito.when(appConfig.getPropertyNames()).thenReturn(Collections.emptyEnumeration());
VaadinContext context = Mockito.mock(VaadinContext.class);
Mockito.when(context.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(appConfig);
Mockito.when(appConfig.getContext()).thenReturn(context);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
VaadinService service = new VaadinServletService(new VaadinServlet(), new DefaultDeploymentConfiguration(appConfig, getClass(), initParameters)) {
@Override
public VaadinContext getContext() {
return context;
}
};
VaadinSession session = new TestSession(service);
TestBeanStore store = new TestBeanStore(session);
return store;
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class WebComponentProviderTest method init.
@Before
public void init() {
MockitoAnnotations.initMocks(this);
// same code as used for local variables in
registry = setUpRegistry();
// some tests
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(session.getService()).thenReturn(service);
Mockito.when(service.getContext()).thenReturn(context);
Mockito.when(context.getAttribute(WebComponentConfigurationRegistry.class)).then(invocationOnMock -> registry);
Mockito.when(context.getAttribute(eq(WebComponentConfigurationRegistry.class), any())).then(invocationOnMock -> registry);
Mockito.doAnswer(invocationOnMock -> registry = (WebComponentConfigurationRegistry) invocationOnMock.getArguments()[0]).when(context).setAttribute(any(WebComponentConfigurationRegistry.class));
VaadinService.setCurrent(service);
Mockito.when(service.getInstantiator()).thenReturn(new MockInstantiator());
Mockito.when(service.getDeploymentConfiguration()).thenReturn(configuration);
VaadinServletService service = Mockito.mock(VaadinServletService.class);
Mockito.doCallRealMethod().when(service).getContextRootRelativePath(Mockito.any());
Mockito.doCallRealMethod().when(service).getContextRootRelativePath(Mockito.any());
provider = new WebComponentProvider();
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class PushHandlerTest method onMessage_websocketTransport_requestStartIsCalledOnServiceInstance.
@Test
public void onMessage_websocketTransport_requestStartIsCalledOnServiceInstance() {
VaadinServletService service = runTest((handler, resource) -> {
Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
handler.onMessage(resource);
});
Mockito.verify(service).requestStart(Mockito.any(), Mockito.any());
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class PushHandlerTest method onConnect_websocketTransport_requestStartIsCalledOnServiceInstance.
@Test
public void onConnect_websocketTransport_requestStartIsCalledOnServiceInstance() {
VaadinServletService service = runTest((handler, resource) -> {
Mockito.when(resource.transport()).thenReturn(TRANSPORT.WEBSOCKET);
handler.onConnect(resource);
});
Mockito.verify(service).requestStart(Mockito.any(), Mockito.any());
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method serveNotFoundIndexHtml_requestWithRootPath_failsWithIOException.
@Test
public void serveNotFoundIndexHtml_requestWithRootPath_failsWithIOException() throws IOException {
VaadinServletService vaadinService = Mockito.mock(VaadinServletService.class);
Mockito.when(vaadinService.getDeploymentConfiguration()).thenReturn(deploymentConfiguration);
Mockito.when(vaadinService.getContext()).thenReturn(context);
final Lookup lookup = Mockito.mock(Lookup.class);
ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(lookup);
Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(resourceProvider);
URL resource = Mockito.mock(URL.class);
Mockito.when(resourceProvider.getApplicationResource(VAADIN_WEBAPP_RESOURCES + INDEX_HTML)).thenReturn(resource);
when(resource.openStream()).thenReturn(null);
VaadinServletRequest vaadinRequest = Mockito.mock(VaadinServletRequest.class);
Mockito.when(vaadinRequest.getService()).thenReturn(vaadinService);
String path = DEFAULT_FRONTEND_DIR + "index.html";
String expectedError = String.format("Failed to load content of '%1$s'. " + "It is required to have '%1$s' file when " + "using client side bootstrapping.", path);
exceptionRule.expect(IOException.class);
exceptionRule.expectMessage(expectedError);
indexHtmlRequestHandler.synchronizedHandleRequest(session, vaadinRequest, response);
}
Aggregations