Search in sources :

Example 21 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class DependencyLoaderTest method loadScript.

@Test
public void loadScript() {
    String TEST_URL = "http://foo.bar/baz.js";
    new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.JAVASCRIPT, TEST_URL, LoadMode.EAGER).toJson()));
    assertEquals(Collections.singletonList(TEST_URL), mockResourceLoader.loadingScripts);
}
Also used : Dependency(com.vaadin.flow.shared.ui.Dependency) Test(org.junit.Test)

Example 22 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class DependencyLoaderTest method createInlineDependency.

private JsonObject createInlineDependency(Dependency.Type dependencyType, String contents) {
    JsonObject json = new Dependency(dependencyType, "", LoadMode.INLINE).toJson();
    json.remove(Dependency.KEY_URL);
    json.put(Dependency.KEY_CONTENTS, contents);
    return json;
}
Also used : JsonObject(elemental.json.JsonObject) Dependency(com.vaadin.flow.shared.ui.Dependency)

Example 23 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class DependencyList method handleDuplicateDependency.

private void handleDuplicateDependency(Dependency newDependency, Dependency currentDependency) {
    if (newDependency.getLoadMode() != currentDependency.getLoadMode()) {
        final LoadMode moreEagerLoadMode = LoadMode.values()[Math.min(newDependency.getLoadMode().ordinal(), currentDependency.getLoadMode().ordinal())];
        getLogger().warn("Dependency with url {} was imported with two different loading strategies: {} and {}. The dependency will be loaded as {}.", newDependency.getUrl(), newDependency.getLoadMode(), currentDependency.getLoadMode(), moreEagerLoadMode);
        urlToLoadedDependency.replace(newDependency.getUrl(), new Dependency(newDependency.getType(), newDependency.getUrl(), moreEagerLoadMode));
    }
}
Also used : LoadMode(com.vaadin.flow.shared.ui.LoadMode) Dependency(com.vaadin.flow.shared.ui.Dependency)

Example 24 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class GwtDependencyLoaderTest method testEnsureLazyDependenciesLoadedInOrder.

public void testEnsureLazyDependenciesLoadedInOrder() {
    String jsUrl1 = "/1.js";
    String jsUrl2 = "/2.js";
    String cssUrl1 = "/1.css";
    String cssUrl2 = "/2.css";
    String htmlUrl1 = "/1.html";
    String htmlUrl2 = "/2.html";
    new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.JAVASCRIPT, jsUrl1, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.JAVASCRIPT, jsUrl2, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.STYLESHEET, cssUrl1, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.STYLESHEET, cssUrl2, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.HTML_IMPORT, htmlUrl1, LoadMode.LAZY).toJson(), new Dependency(Dependency.Type.HTML_IMPORT, htmlUrl2, LoadMode.LAZY).toJson()));
    assertEquals("jsUrl1 should come before jsUrl2, because it was added earlier", Arrays.asList(jsUrl1, jsUrl2), mockResourceLoader.loadingScripts);
    assertEquals("cssUrl1 should come before cssUrl2, because it was added earlier", Arrays.asList(cssUrl1, cssUrl2), mockResourceLoader.loadingStyles);
    assertEquals("htmlUrl1 should come before htmlUrl2, because it was added earlier", Arrays.asList(htmlUrl1, htmlUrl2), mockResourceLoader.loadingHtml);
}
Also used : Dependency(com.vaadin.flow.shared.ui.Dependency)

Example 25 with Dependency

use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.

the class DependencyTest method checkJsonSerialization.

@Test
public void checkJsonSerialization() {
    Dependency dependency = new Dependency(Dependency.Type.HTML_IMPORT, "url", LoadMode.INLINE);
    JsonObject dependencyJson = dependency.toJson();
    assertThat("No contents should be present in json now", dependencyJson.hasKey(Dependency.KEY_CONTENTS), is(false));
    assertThat("Dependency type should match corresponding enum name in pojo", dependencyJson.getString(Dependency.KEY_TYPE), is(dependency.getType().name()));
    assertThat("Dependency url should match corresponding url in pojo", dependencyJson.getString(Dependency.KEY_URL), is(dependency.getUrl()));
    assertThat("Dependency load mode should match corresponding enum name in pojo", dependencyJson.getString(Dependency.KEY_LOAD_MODE), is(dependency.getLoadMode().name()));
}
Also used : JsonObject(elemental.json.JsonObject) Dependency(com.vaadin.flow.shared.ui.Dependency) Test(org.junit.Test)

Aggregations

Dependency (com.vaadin.flow.shared.ui.Dependency)30 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)8 LoadMode (com.vaadin.flow.shared.ui.LoadMode)7 List (java.util.List)7 HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)6 JsonObject (elemental.json.JsonObject)6 DependencyFilter (com.vaadin.flow.server.DependencyFilter)5 VaadinUriResolver (com.vaadin.flow.shared.VaadinUriResolver)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Collections (java.util.Collections)5 Element (org.jsoup.nodes.Element)5 Tag (com.vaadin.flow.component.Tag)4 UI (com.vaadin.flow.component.UI)4 VaadinService (com.vaadin.flow.server.VaadinService)3 VaadinServlet (com.vaadin.flow.server.VaadinServlet)3 VaadinSession (com.vaadin.flow.server.VaadinSession)3 Type (com.vaadin.flow.shared.ui.Dependency.Type)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3