Search in sources :

Example 6 with VaadinResponse

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"));
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) VaadinSession(com.vaadin.flow.server.VaadinSession) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 7 with VaadinResponse

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());
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) Element(org.jsoup.nodes.Element) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 8 with VaadinResponse

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"));
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) VaadinSession(com.vaadin.flow.server.VaadinSession) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) MockDeploymentConfiguration(com.vaadin.tests.util.MockDeploymentConfiguration) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 9 with VaadinResponse

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");
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) VaadinSession(com.vaadin.flow.server.VaadinSession) VaadinRequest(com.vaadin.flow.server.VaadinRequest) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jsoup.nodes.Document) AbstractDevModeTest(com.vaadin.base.devserver.startup.AbstractDevModeTest) Test(org.junit.Test)

Example 10 with VaadinResponse

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);
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) ExecutionFailedException(com.vaadin.flow.server.ExecutionFailedException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) AbstractDevModeTest(com.vaadin.base.devserver.startup.AbstractDevModeTest) Test(org.junit.Test)

Aggregations

VaadinResponse (com.vaadin.flow.server.VaadinResponse)24 Test (org.junit.Test)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 VaadinRequest (com.vaadin.flow.server.VaadinRequest)8 VaadinSession (com.vaadin.flow.server.VaadinSession)8 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)7 Document (org.jsoup.nodes.Document)7 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)6 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)6 VaadinService (com.vaadin.flow.server.VaadinService)6 Element (org.jsoup.nodes.Element)6 UI (com.vaadin.flow.component.UI)3 Location (com.vaadin.flow.router.Location)3 VaadinServletService (com.vaadin.flow.server.VaadinServletService)3 WebComponentConfigurationRegistry (com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry)3 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)3 Optional (java.util.Optional)3 AbstractDevModeTest (com.vaadin.base.devserver.startup.AbstractDevModeTest)2 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)2 RouteConfiguration (com.vaadin.flow.router.RouteConfiguration)2