Search in sources :

Example 21 with VaadinServletService

use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.

the class WebComponentBootstrapHandlerTest method writeBootstrapPage_noExportChunk.

@Test
public void writeBootstrapPage_noExportChunk() 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.setApplicationOrSystemProperty(SERVLET_PARAMETER_STATISTICS_JSON, VAADIN_SERVLET_RESOURCES + "config/stats_no_export.json");
    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);
    // no "export" chunk, expect "bundle" in result instead
    String result = stream.toString(StandardCharsets.UTF_8.name());
    Assert.assertTrue(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 22 with VaadinServletService

use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.

the class FrontendUtilsTest method getStatsAssetsByChunkName_getStatsFromClassPath_delegateToGetApplicationResource.

@Test
public void getStatsAssetsByChunkName_getStatsFromClassPath_delegateToGetApplicationResource() throws IOException {
    VaadinServletService service = mockServletService();
    ResourceProvider provider = mockResourceProvider(service);
    FrontendUtils.getStatsAssetsByChunkName(service);
    Mockito.verify(provider).getApplicationResource("foo");
}
Also used : ResourceProvider(com.vaadin.flow.di.ResourceProvider) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService) Test(org.junit.Test)

Example 23 with VaadinServletService

use of com.vaadin.flow.server.VaadinServletService in project flow by vaadin.

the class FrontendUtilsTest method mockServletService.

private VaadinServletService mockServletService() {
    VaadinServletService service = Mockito.mock(VaadinServletService.class);
    VaadinServlet servlet = Mockito.mock(VaadinServlet.class);
    Mockito.when(service.getServlet()).thenReturn(servlet);
    return service;
}
Also used : VaadinServlet(com.vaadin.flow.server.VaadinServlet) MockVaadinServletService(com.vaadin.flow.server.MockVaadinServletService) VaadinServletService(com.vaadin.flow.server.VaadinServletService)

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