Search in sources :

Example 6 with PwaConfiguration

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

the class TaskUpdateWebpackTest method should_enableCustomOfflinePath_when_customisedInPwa.

@Test
public void should_enableCustomOfflinePath_when_customisedInPwa() throws IOException {
    pwaConfiguration = new PwaConfiguration(AppShellWithOfflinePath.class.getAnnotation(PWA.class));
    createWebpackUpdater();
    webpackUpdater.execute();
    String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()).collect(Collectors.joining("\n"));
    Assert.assertTrue("offlinePath should be customizable", webpackGeneratedContents.contains("const offlinePath = 'off.html';"));
}
Also used : PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) Test(org.junit.Test)

Example 7 with PwaConfiguration

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

the class TaskUpdateWebpackTest method setup.

@Before
public void setup() throws Exception {
    baseDir = temporaryFolder.getRoot();
    frontendFolder = new File(baseDir, "frontend");
    frontendGeneratedFolder = new File(baseDir, DEFAULT_PROJECT_FRONTEND_GENERATED_DIR);
    FrontendStubs.createStubNode(true, true, baseDir.getAbsolutePath());
    pwaConfiguration = new PwaConfiguration(AppShell.class.getAnnotation(PWA.class));
    createWebpackUpdater();
    webpackConfig = new File(baseDir, WEBPACK_CONFIG);
    webpackGenerated = new File(baseDir, WEBPACK_GENERATED);
}
Also used : PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) File(java.io.File) Before(org.junit.Before)

Example 8 with PwaConfiguration

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

the class TaskUpdateWebpackTest method should_setPwaEnabledFalse_when_noPwa.

@Test
public void should_setPwaEnabledFalse_when_noPwa() throws IOException {
    pwaConfiguration = new PwaConfiguration();
    createWebpackUpdater();
    webpackUpdater.execute();
    String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()).collect(Collectors.joining("\n"));
    Assert.assertTrue("pwaEnabled expected false", webpackGeneratedContents.contains("const pwaEnabled = false;"));
}
Also used : PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) Test(org.junit.Test)

Example 9 with PwaConfiguration

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

the class TaskUpdateWebpackTest method should_setOfflineEnabledFalse_when_customisedInPwa.

@Test
public void should_setOfflineEnabledFalse_when_customisedInPwa() throws IOException {
    pwaConfiguration = new PwaConfiguration(AppShellWithDisabledOffline.class.getAnnotation(PWA.class));
    createWebpackUpdater();
    webpackUpdater.execute();
    String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()).collect(Collectors.joining("\n"));
    Assert.assertTrue("offlineEnabled expected false", webpackGeneratedContents.contains("const offlineEnabled = false;"));
}
Also used : PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) Test(org.junit.Test)

Example 10 with PwaConfiguration

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

the class FullDependenciesScanner method discoverPwa.

private PwaConfiguration discoverPwa() {
    try {
        Class<? extends Annotation> loadedPWAAnnotation = getFinder().loadClass(PWA.class.getName());
        Set<Class<?>> annotatedClasses = getFinder().getAnnotatedClasses(loadedPWAAnnotation);
        if (annotatedClasses.isEmpty()) {
            return new PwaConfiguration(useV14Bootstrap);
        } else if (annotatedClasses.size() != 1) {
            throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
        }
        Class<?> hopefullyAppShellClass = annotatedClasses.iterator().next();
        if (!useV14Bootstrap && !Arrays.stream(hopefullyAppShellClass.getInterfaces()).map(Class::getName).collect(Collectors.toList()).contains(AppShellConfigurator.class.getName())) {
            throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
        }
        Annotation pwa = annotationFinder.apply(hopefullyAppShellClass, loadedPWAAnnotation).get(0);
        String name = getAnnotationValueAsString(pwa, "name");
        String shortName = getAnnotationValueAsString(pwa, "shortName");
        String description = getAnnotationValueAsString(pwa, "description");
        String backgroundColor = getAnnotationValueAsString(pwa, "backgroundColor");
        String themeColor = getAnnotationValueAsString(pwa, "themeColor");
        String iconPath = getAnnotationValueAsString(pwa, "iconPath");
        String manifestPath = getAnnotationValueAsString(pwa, "manifestPath");
        String offlinePath = getAnnotationValueAsString(pwa, "offlinePath");
        String display = getAnnotationValueAsString(pwa, "display");
        String startPath = getAnnotationValueAsString(pwa, "startPath");
        String[] offlineResources = (String[]) getAnnotationValue(pwa, "offlineResources");
        boolean offline = (Boolean) getAnnotationValue(pwa, "offline");
        // required in @PWA annotation
        assert shortName != null;
        return new PwaConfiguration(true, name, shortName, description, backgroundColor, themeColor, iconPath, manifestPath, offlinePath, display, startPath, offlineResources, offline, useV14Bootstrap);
    } catch (ClassNotFoundException exception) {
        throw new IllegalStateException("Could not load PWA annotation class", exception);
    }
}
Also used : AppShellConfigurator(com.vaadin.flow.component.page.AppShellConfigurator) Annotation(java.lang.annotation.Annotation) PwaConfiguration(com.vaadin.flow.server.PwaConfiguration) PWA(com.vaadin.flow.server.PWA)

Aggregations

PwaConfiguration (com.vaadin.flow.server.PwaConfiguration)13 Test (org.junit.Test)10 PwaRegistry (com.vaadin.flow.server.PwaRegistry)3 AppShellConfigurator (com.vaadin.flow.component.page.AppShellConfigurator)2 PWA (com.vaadin.flow.server.PWA)2 File (java.io.File)2 Lookup (com.vaadin.flow.di.Lookup)1 MockVaadinServletService (com.vaadin.flow.server.MockVaadinServletService)1 MockVaadinSession (com.vaadin.flow.server.MockVaadinSession)1 PwaIcon (com.vaadin.flow.server.PwaIcon)1 VaadinResponse (com.vaadin.flow.server.VaadinResponse)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1 VaadinServletService (com.vaadin.flow.server.VaadinServletService)1 VaadinSession (com.vaadin.flow.server.VaadinSession)1 MockDeploymentConfiguration (com.vaadin.tests.util.MockDeploymentConfiguration)1 JsonObject (elemental.json.JsonObject)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Annotation (java.lang.annotation.Annotation)1