use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.
the class DependencyLoaderTest method loadFrontendDependencyWithContext.
@Test
public void loadFrontendDependencyWithContext() {
String TEST_URL = "frontend://my-component.html";
ApplicationConfiguration config = new ApplicationConfiguration();
registry.set(ApplicationConfiguration.class, config);
config.setFrontendRootUrl("context://es6/");
config.setContextRootUrl("http://someplace.com/");
new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.HTML_IMPORT, TEST_URL, LoadMode.EAGER).toJson()));
assertEquals(Collections.singletonList("http://someplace.com/es6/my-component.html"), mockResourceLoader.loadingHtml);
}
use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.
the class DependencyLoaderTest method loadFrontendDependency.
@Test
public void loadFrontendDependency() {
String TEST_URL = "frontend://my-component.html";
ApplicationConfiguration config = new ApplicationConfiguration();
registry.set(ApplicationConfiguration.class, config);
config.setFrontendRootUrl("http://someplace.com/es6/");
new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.HTML_IMPORT, TEST_URL, LoadMode.EAGER).toJson()));
assertEquals(Collections.singletonList("http://someplace.com/es6/my-component.html"), mockResourceLoader.loadingHtml);
}
use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.
the class DependencyLoaderTest method ensureEagerDependenciesLoadedInOrder.
@Test
public void ensureEagerDependenciesLoadedInOrder() {
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.EAGER).toJson(), new Dependency(Dependency.Type.JAVASCRIPT, jsUrl2, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.STYLESHEET, cssUrl1, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.STYLESHEET, cssUrl2, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.HTML_IMPORT, htmlUrl1, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.HTML_IMPORT, htmlUrl2, LoadMode.EAGER).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 TestingServiceInitListener method serviceInit.
@Override
public void serviceInit(ServiceInitEvent event) {
initCount.incrementAndGet();
event.addRequestHandler((session, request, response) -> {
requestCount.incrementAndGet();
return false;
});
event.addDependencyFilter((dependencies, context) -> {
// used by DependencyFilterUI
if (dependencies.stream().anyMatch(dependency -> dependency.getUrl().startsWith("replaceme://"))) {
List<Dependency> newList = new ArrayList<>();
newList.add(new Dependency(Dependency.Type.HTML_IMPORT, "frontend://com/vaadin/flow/uitest/ui/dependencies/filtered.html", LoadMode.EAGER));
dependencies.stream().filter(dependency -> !dependency.getUrl().startsWith("replaceme://")).forEach(newList::add);
dependencies = newList;
} else // used by BundledTemplateInTemplateWithIdView
if (dependencies.stream().anyMatch(dependency -> dependency.getUrl().startsWith("bundle://"))) {
List<Dependency> newList = new ArrayList<>();
newList.add(new Dependency(Dependency.Type.HTML_IMPORT, "frontend://com/vaadin/flow/uitest/ui/template/BundleIdTemplate.html", LoadMode.EAGER));
dependencies = newList;
}
return dependencies;
});
}
use of com.vaadin.flow.shared.ui.Dependency in project flow by vaadin.
the class UidlWriterTest method checkAllTypesOfDependencies.
@Test
public void checkAllTypesOfDependencies() {
UI ui = initializeUIForDependenciesTest(new TestUI());
UidlWriter uidlWriter = new UidlWriter();
addInitialComponentDependencies(ui, uidlWriter);
ui.add(new ComponentWithAllDependencyTypes());
JsonObject response = uidlWriter.createUidl(ui, false);
Map<LoadMode, List<JsonObject>> dependenciesMap = Stream.of(LoadMode.values()).map(mode -> response.getArray(mode.name())).flatMap(JsonUtils::<JsonObject>stream).collect(Collectors.toMap(jsonObject -> LoadMode.valueOf(jsonObject.getString(Dependency.KEY_LOAD_MODE)), Collections::singletonList, (list1, list2) -> {
List<JsonObject> result = new ArrayList<>(list1);
result.addAll(list2);
return result;
}));
assertThat("Dependencies with all types of load mode should be present in this response", dependenciesMap.size(), is(LoadMode.values().length));
List<JsonObject> eagerDependencies = dependenciesMap.get(LoadMode.EAGER);
assertThat("Should have 3 eager dependencies", eagerDependencies, hasSize(3));
assertThat("Eager dependencies should not have inline contents", eagerDependencies.stream().filter(json -> json.hasKey(Dependency.KEY_CONTENTS)).collect(Collectors.toList()), hasSize(0));
assertThat("Should have 3 different eager urls", eagerDependencies.stream().map(json -> json.getString(Dependency.KEY_URL)).map(url -> url.substring(ApplicationConstants.FRONTEND_PROTOCOL_PREFIX.length())).collect(Collectors.toList()), containsInAnyOrder("eager.js", "eager.html", "eager.css"));
assertThat("Should have 3 different eager dependency types", eagerDependencies.stream().map(json -> json.getString(Dependency.KEY_TYPE)).map(Dependency.Type::valueOf).collect(Collectors.toList()), containsInAnyOrder(Dependency.Type.values()));
List<JsonObject> lazyDependencies = dependenciesMap.get(LoadMode.LAZY);
assertThat("Should have 3 lazy dependencies", lazyDependencies, hasSize(3));
assertThat("Lazy dependencies should not have inline contents", lazyDependencies.stream().filter(json -> json.hasKey(Dependency.KEY_CONTENTS)).collect(Collectors.toList()), hasSize(0));
assertThat("Should have 3 different lazy urls", lazyDependencies.stream().map(json -> json.getString(Dependency.KEY_URL)).map(url -> url.substring(ApplicationConstants.FRONTEND_PROTOCOL_PREFIX.length())).collect(Collectors.toList()), containsInAnyOrder("lazy.js", "lazy.html", "lazy.css"));
assertThat("Should have 3 different lazy dependency types", lazyDependencies.stream().map(json -> json.getString(Dependency.KEY_TYPE)).map(Dependency.Type::valueOf).collect(Collectors.toList()), containsInAnyOrder(Dependency.Type.values()));
List<JsonObject> inlineDependencies = dependenciesMap.get(LoadMode.INLINE);
assertInlineDependencies(inlineDependencies, ApplicationConstants.FRONTEND_PROTOCOL_PREFIX);
}
Aggregations