Search in sources :

Example 31 with VaadinService

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

the class FrontendUtilsTest method noStatsFile_assetsByChunkReturnsNull.

@Test
public void noStatsFile_assetsByChunkReturnsNull() throws IOException, ServiceException {
    VaadinService service = getServiceWithResource(null);
    String statsAssetsByChunkName = FrontendUtils.getStatsAssetsByChunkName(service);
    Assert.assertNull(statsAssetsByChunkName);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Test(org.junit.Test)

Example 32 with VaadinService

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

the class FrontendUtilsTest method faultyStatsFileReturnsNull.

@Test
public void faultyStatsFileReturnsNull() throws IOException, ServiceException {
    VaadinService service = setupStatsAssetMocks("InvalidStats.json");
    String statsAssetsByChunkName = FrontendUtils.getStatsAssetsByChunkName(service);
    Assert.assertNull(statsAssetsByChunkName);
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Test(org.junit.Test)

Example 33 with VaadinService

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

the class FrontendUtilsTest method clearCachedStatsContent_clearsCache.

@Test
public void clearCachedStatsContent_clearsCache() throws IOException, ServiceException {
    VaadinService service = setupStatsAssetMocks("ValidStats.json");
    assertNull("Stats cache should not be present", service.getContext().getAttribute(CACHE_KEY));
    // Can be invoked without cache - throws no exception
    FrontendUtils.clearCachedStatsContent(service);
    // Populates cache
    FrontendUtils.getStatsAssetsByChunkName(service);
    // Clears cache
    FrontendUtils.clearCachedStatsContent(service);
    assertNull("Stats cache should not be present", service.getContext().getAttribute(CACHE_KEY));
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Test(org.junit.Test)

Example 34 with VaadinService

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

the class FrontendUtilsTest method getStatsAssetsByChunkName_getStatsFromClassPath_populatesStatsCache.

@Test
public void getStatsAssetsByChunkName_getStatsFromClassPath_populatesStatsCache() throws IOException, ServiceException {
    VaadinService service = setupStatsAssetMocks("ValidStats.json");
    assertNull("Stats cache should not be present", service.getContext().getAttribute(CACHE_KEY));
    // Populates cache
    FrontendUtils.getStatsAssetsByChunkName(service);
    assertNotNull("Stats cache should be created", service.getContext().getAttribute(CACHE_KEY));
}
Also used : VaadinService(com.vaadin.flow.server.VaadinService) Test(org.junit.Test)

Example 35 with VaadinService

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

the class InternalErrorView method showCriticalNotification.

protected void showCriticalNotification(String caption, String message, String details, String url) {
    VaadinService service = VaadinService.getCurrent();
    VaadinResponse response = VaadinService.getCurrentResponse();
    try {
        service.writeUncachedStringResponse(response, JsonConstants.JSON_CONTENT_TYPE, VaadinService.createCriticalNotificationJSON(caption, message, details, url));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : VaadinResponse(com.vaadin.flow.server.VaadinResponse) VaadinService(com.vaadin.flow.server.VaadinService) IOException(java.io.IOException)

Aggregations

VaadinService (com.vaadin.flow.server.VaadinService)86 Test (org.junit.Test)39 DeploymentConfiguration (com.vaadin.flow.function.DeploymentConfiguration)19 VaadinSession (com.vaadin.flow.server.VaadinSession)18 Properties (java.util.Properties)15 VaadinContext (com.vaadin.flow.server.VaadinContext)12 Before (org.junit.Before)11 SpringInstantiatorTest (com.vaadin.flow.spring.instantiator.SpringInstantiatorTest)10 UI (com.vaadin.flow.component.UI)9 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)8 Lookup (com.vaadin.flow.di.Lookup)7 VaadinResponse (com.vaadin.flow.server.VaadinResponse)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ServletContext (javax.servlet.ServletContext)6 MockVaadinContext (com.vaadin.flow.server.MockVaadinContext)5 DefaultInstantiator (com.vaadin.flow.di.DefaultInstantiator)4 Instantiator (com.vaadin.flow.di.Instantiator)4 BrowserLiveReload (com.vaadin.flow.internal.BrowserLiveReload)4 DefaultDeploymentConfiguration (com.vaadin.flow.server.DefaultDeploymentConfiguration)4 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)4