use of com.vaadin.flow.server.VaadinResponse 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.VaadinResponse in project flow by vaadin.
the class WebComponentBootstrapHandlerTest method writeBootstrapPage_spepe.
@Test
public void writeBootstrapPage_spepe() throws Exception {
WebComponentBootstrapHandler handler = new WebComponentBootstrapHandler();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Element head = new Document("").normalise().head();
VaadinResponse response = getMockResponse(stream);
handler.writeBootstrapPage("", response, head, "");
String resultingScript = stream.toString(StandardCharsets.UTF_8.name());
}
use of com.vaadin.flow.server.VaadinResponse 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.VaadinResponse in project flow by vaadin.
the class WebpackHandlerTest method devModeNotReady_handleRequest_returnsHtml.
@Test
public void devModeNotReady_handleRequest_returnsHtml() throws Exception {
handler = startWebpack();
VaadinResponse response = Mockito.mock(VaadinResponse.class);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Mockito.when(response.getOutputStream()).thenReturn(stream);
handler.handleRequest(Mockito.mock(VaadinSession.class), Mockito.mock(VaadinRequest.class), response);
String devModeNotReadyContents = stream.toString("UTF-8");
Document document = Jsoup.parse(devModeNotReadyContents);
Assert.assertTrue("expected a head child", document.head().children().size() > 0);
Assert.assertTrue("expected a body child", document.body().children().size() > 0);
Mockito.verify(response).setContentType("text/html;charset=utf-8");
}
use of com.vaadin.flow.server.VaadinResponse in project flow by vaadin.
the class WebpackHandlerTest method avoidStoringPortOfFailingWebPackDevServer_failWebpackStart_startWebPackSucessfullyAfter.
@Test
public void avoidStoringPortOfFailingWebPackDevServer_failWebpackStart_startWebPackSucessfullyAfter() throws Exception {
handler = startWebpack();
waitForDevServer();
removeDevModeHandlerInstance();
// dev mode handler should fail because of non-existent npm
// folder: it
// means the port number should not have been written
// use non-existent folder for as npmFolder, it should fail the
// validation (which means server instance won't be reused)
WebpackHandler newhHandler = new WebpackHandler(lookup, 0, new File(npmFolder, UUID.randomUUID().toString()), CompletableFuture.completedFuture(null));
VaadinResponse response = Mockito.mock(VaadinResponse.class);
Mockito.when(response.getOutputStream()).thenReturn(new ByteArrayOutputStream());
boolean proceed = true;
Throwable cause = null;
while (proceed) {
try {
proceed = newhHandler.handleRequest(Mockito.mock(VaadinSession.class), Mockito.mock(VaadinRequest.class), response);
} catch (IllegalStateException ise) {
proceed = false;
cause = ise.getCause();
}
}
Assert.assertNotNull(cause);
Assert.assertTrue(cause instanceof ExecutionFailedException);
}
Aggregations