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);
}
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;
}
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));
}
}
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);
}
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()));
}
Aggregations