use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method writeBootstrapPage_noPWA.
@Test
public void writeBootstrapPage_noPWA() throws IOException, ServiceException {
TestWebComponentBootstrapHandler handler = new TestWebComponentBootstrapHandler();
PwaRegistry registry = Mockito.mock(PwaRegistry.class);
PwaConfiguration conf = Mockito.mock(PwaConfiguration.class);
Mockito.when(registry.getPwaConfiguration()).thenReturn(conf);
Mockito.when(conf.isEnabled()).thenReturn(true);
Mockito.when(conf.getManifestPath()).thenReturn("bar");
PwaIcon icon = Mockito.mock(PwaIcon.class);
Mockito.when(icon.asElement()).thenReturn(new Element("h1"));
Mockito.when(registry.getHeaderIcons()).thenReturn(Collections.singletonList(icon));
VaadinServletService service = new MockVaadinServletService() {
@Override
protected PwaRegistry getPwaRegistry() {
return registry;
}
};
initLookup(service);
VaadinSession session = new MockVaadinSession(service);
session.lock();
session.setConfiguration(service.getDeploymentConfiguration());
MockDeploymentConfiguration config = (MockDeploymentConfiguration) service.getDeploymentConfiguration();
config.setEnableDevServer(false);
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(request.getServletPath()).thenReturn("/");
VaadinResponse response = getMockResponse(null);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Mockito.when(response.getOutputStream()).thenReturn(stream);
handler.synchronizedHandleRequest(session, request, response);
String result = stream.toString(StandardCharsets.UTF_8.name());
MatcherAssert.assertThat(result, CoreMatchers.not(CoreMatchers.containsString("bar")));
MatcherAssert.assertThat(result, CoreMatchers.not(CoreMatchers.containsString("h1")));
MatcherAssert.assertThat(result, CoreMatchers.not(CoreMatchers.containsString("baz")));
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method writeBootstrapPage_withExportChunk.
@Test
public void writeBootstrapPage_withExportChunk() throws IOException, ServiceException {
TestWebComponentBootstrapHandler handler = new TestWebComponentBootstrapHandler();
VaadinServletService service = new MockVaadinServletService();
initLookup(service);
VaadinSession session = new MockVaadinSession(service);
session.lock();
session.setConfiguration(service.getDeploymentConfiguration());
MockDeploymentConfiguration config = (MockDeploymentConfiguration) service.getDeploymentConfiguration();
config.setEnableDevServer(false);
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(request.getServletPath()).thenReturn("/");
VaadinResponse response = getMockResponse(null);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Mockito.when(response.getOutputStream()).thenReturn(stream);
handler.synchronizedHandleRequest(session, request, response);
String result = stream.toString(StandardCharsets.UTF_8.name());
Assert.assertTrue(result.contains("VAADIN/build/vaadin-export-2222.cache.js"));
Assert.assertFalse(result.contains("VAADIN/build/vaadin-bundle-1111.cache.js"));
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method writeBootstrapPage_scriptGuadedAndGizmoDisabled.
@Test
public void writeBootstrapPage_scriptGuadedAndGizmoDisabled() throws IOException, ServiceException {
TestWebComponentBootstrapHandler handler = new TestWebComponentBootstrapHandler();
VaadinServletService service = new MockVaadinServletService();
initLookup(service);
VaadinSession session = new MockVaadinSession(service);
session.lock();
session.setConfiguration(service.getDeploymentConfiguration());
MockDeploymentConfiguration config = (MockDeploymentConfiguration) service.getDeploymentConfiguration();
config.setEnableDevServer(false);
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
Mockito.when(request.getService()).thenReturn(service);
Mockito.when(request.getServletPath()).thenReturn("/");
VaadinResponse response = getMockResponse(null);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Mockito.when(response.getOutputStream()).thenReturn(stream);
handler.synchronizedHandleRequest(session, request, response);
String result = stream.toString(StandardCharsets.UTF_8.name());
int scriptIndex = result.indexOf("var hasScript = function(src)");
Assert.assertTrue(scriptIndex >= 0);
int guardIndex = result.indexOf("if (!hasScript(\"/VAADIN/build/vaadin-export-2222.cache.js\")) {");
Assert.assertTrue(guardIndex > scriptIndex);
int createScriptIndex = result.indexOf("document.createElement('script')");
Assert.assertTrue(createScriptIndex > guardIndex);
Assert.assertTrue(result.contains("\\\"devmodeGizmoEnabled\\\": false"));
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class PushHandlerTest method onMessage_notWebsocketTransport_requestStartIsNotCalledOnServiceInstance.
@Test
public void onMessage_notWebsocketTransport_requestStartIsNotCalledOnServiceInstance() {
VaadinServletService service = runTest((handler, resource) -> {
Mockito.when(resource.transport()).thenReturn(TRANSPORT.AJAX);
handler.onMessage(resource);
});
Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any());
}
use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.
the class PushHandlerTest method onConnect_notWebsocketTransport_requestStartIsNotCalledOnServiceInstance.
@Test
public void onConnect_notWebsocketTransport_requestStartIsNotCalledOnServiceInstance() {
VaadinServletService service = runTest((handler, resource) -> {
Mockito.when(resource.transport()).thenReturn(TRANSPORT.AJAX);
handler.onConnect(resource);
});
Mockito.verify(service, Mockito.times(0)).requestStart(Mockito.any(), Mockito.any());
}
Aggregations