Search in sources :

Example 6 with VaadinServletService

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")));
}
Also used : MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) VaadinSession(com.vaadin.flow.server.VaadinSession) Element(org.jsoup.nodes.Element) 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) PwaIcon(com.vaadin.flow.server.PwaIcon) VaadinResponse(com.vaadin.flow.server.VaadinResponse) PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) MockVaadinSession(com.vaadin.flow.server.MockVaadinSession) PwaRegistry(com.vaadin.flow.server.PwaRegistry) Test(org.junit.Test)

Example 7 with VaadinServletService

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"));
}
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 8 with VaadinServletService

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"));
}
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 VaadinServletService

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());
}
Also used : MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Test(org.junit.Test)

Example 10 with VaadinServletService

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());
}
Also used : MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Test(org.junit.Test)

Aggregations

VaadinServletService (com.vaadin.flow.server.VaadinServletService)23 Test (org.junit.Test)14 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)10 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)9 VaadinSession (com.vaadin.flow.server.VaadinSession)8 Properties (java.util.Properties)7 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)6 VaadinServlet (com.vaadin.flow.server.VaadinServlet)6 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)5 VaadinService (com.vaadin.flow.server.VaadinService)5 Before (org.junit.Before)5 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)4 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)4 URL (java.net.URL)4 Collections (java.util.Collections)4 ServletContext (javax.servlet.ServletContext)4 Lookup (com.vaadin.flow.di.Lookup)3 ResourceProvider (com.vaadin.flow.di.ResourceProvider)3 CurrentInstance (com.vaadin.flow.internal.CurrentInstance)3 VaadinResponse (com.vaadin.flow.server.VaadinResponse)3