Search in sources :

Example 16 with Dependency

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

the class ComponentTest method usesChain.

@Test
public void usesChain() {
    UIInternals internals = new UI().getInternals();
    internals.addComponentDependencies(UsesUsesComponentWithDependencies.class);
    Map<String, Dependency> pendingDependencies = getDependenciesMap(internals.getDependencyList().getPendingSendToClient());
    Assert.assertEquals(5, pendingDependencies.size());
    assertDependency(Dependency.Type.HTML_IMPORT, "usesuses.html", pendingDependencies);
    assertDependency(Dependency.Type.HTML_IMPORT, "html.html", pendingDependencies);
    assertDependency(Dependency.Type.JAVASCRIPT, "uses.js", pendingDependencies);
    assertDependency(Dependency.Type.JAVASCRIPT, "js.js", pendingDependencies);
    assertDependency(Dependency.Type.STYLESHEET, "css.css", pendingDependencies);
}
Also used : UIInternals(com.vaadin.flow.component.internal.UIInternals) Dependency(com.vaadin.flow.shared.ui.Dependency) Test(org.junit.Test)

Example 17 with Dependency

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

the class ComponentTest method circularDependencies.

@Test
public void circularDependencies() {
    UIInternals internals = new UI().getInternals();
    DependencyList dependencyList = internals.getDependencyList();
    internals.addComponentDependencies(CircularDependencies1.class);
    Map<String, Dependency> pendingDependencies = getDependenciesMap(dependencyList.getPendingSendToClient());
    Assert.assertEquals(2, pendingDependencies.size());
    assertDependency(Dependency.Type.JAVASCRIPT, "dep1.js", pendingDependencies);
    assertDependency(Dependency.Type.JAVASCRIPT, "dep2.js", pendingDependencies);
    internals = new UI().getInternals();
    dependencyList = internals.getDependencyList();
    internals.addComponentDependencies(CircularDependencies2.class);
    pendingDependencies = getDependenciesMap(dependencyList.getPendingSendToClient());
    Assert.assertEquals(2, pendingDependencies.size());
    assertDependency(Dependency.Type.JAVASCRIPT, "dep2.js", pendingDependencies);
    assertDependency(Dependency.Type.JAVASCRIPT, "dep1.js", pendingDependencies);
}
Also used : DependencyList(com.vaadin.flow.component.internal.DependencyList) UIInternals(com.vaadin.flow.component.internal.UIInternals) Dependency(com.vaadin.flow.shared.ui.Dependency) Test(org.junit.Test)

Example 18 with Dependency

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

the class ComponentTest method assertDependency.

private void assertDependency(Dependency.Type type, String url, Map<String, Dependency> pendingDependencies) {
    Dependency dependency = pendingDependencies.get("frontend://" + url);
    Assert.assertNotNull("Could not locate a dependency object for url=" + url, dependency);
    Assert.assertEquals(type, dependency.getType());
    Assert.assertEquals("frontend://" + url, dependency.getUrl());
}
Also used : Dependency(com.vaadin.flow.shared.ui.Dependency)

Example 19 with Dependency

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

the class DefaultTemplateParserTest method defaultParser_useDependencyFilters_noHtmlDependencies_throws.

@Test(expected = IllegalStateException.class)
public void defaultParser_useDependencyFilters_noHtmlDependencies_throws() {
    DependencyFilter filter = (list, context) -> {
        list.clear();
        list.add(new Dependency(Type.STYLESHEET, "something.css", LoadMode.EAGER));
        list.add(new Dependency(Type.JAVASCRIPT, "something.js", LoadMode.EAGER));
        return list;
    };
    Mockito.when(service.getDependencyFilters()).thenReturn(Collections.singletonList(filter));
    DefaultTemplateParser.getInstance().getTemplateContent(ImportsInspectTemplate.class, "foo");
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) TemplateData(com.vaadin.flow.component.polymertemplate.TemplateParser.TemplateData) WrappedHttpSession(com.vaadin.flow.server.WrappedHttpSession) ServletException(javax.servlet.ServletException) Mock(org.mockito.Mock) CurrentInstance(com.vaadin.flow.internal.CurrentInstance) VaadinUriResolverFactory(com.vaadin.flow.server.VaadinUriResolverFactory) Comment(org.jsoup.nodes.Comment) VaadinUriResolver(com.vaadin.flow.shared.VaadinUriResolver) Dependency(com.vaadin.flow.shared.ui.Dependency) Type(com.vaadin.flow.shared.ui.Dependency.Type) Assert.assertThat(org.junit.Assert.assertThat) MockitoAnnotations(org.mockito.MockitoAnnotations) Tag(com.vaadin.flow.component.Tag) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Element(org.jsoup.nodes.Element) After(org.junit.After) DependencyFilter(com.vaadin.flow.server.DependencyFilter) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) Before(org.junit.Before) HttpSession(javax.servlet.http.HttpSession) VaadinSession(com.vaadin.flow.server.VaadinSession) Matchers.empty(org.hamcrest.Matchers.empty) VaadinServlet(com.vaadin.flow.server.VaadinServlet) Test(org.junit.Test) VaadinRequest(com.vaadin.flow.server.VaadinRequest) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) NotThreadSafe(net.jcip.annotations.NotThreadSafe) HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) Node(org.jsoup.nodes.Node) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) VaadinService(com.vaadin.flow.server.VaadinService) LoadMode(com.vaadin.flow.shared.ui.LoadMode) ServletContext(javax.servlet.ServletContext) ModelClass(com.vaadin.flow.component.polymertemplate.PolymerTemplateTest.ModelClass) ServiceException(com.vaadin.flow.server.ServiceException) Assert(org.junit.Assert) Collections(java.util.Collections) VaadinServletService(com.vaadin.flow.server.VaadinServletService) DependencyFilter(com.vaadin.flow.server.DependencyFilter) Dependency(com.vaadin.flow.shared.ui.Dependency) Test(org.junit.Test)

Example 20 with Dependency

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

the class DependencyLoaderTest method loadMultiple.

@Test
public void loadMultiple() {
    String TEST_JS_URL = "http://foo.bar/baz.js";
    String TEST_JS_URL2 = "/my.js";
    String TEST_CSS_URL = "https://x.yz/styles.css";
    new DependencyLoader(registry).loadDependencies(createDependenciesMap(new Dependency(Dependency.Type.JAVASCRIPT, TEST_JS_URL, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.JAVASCRIPT, TEST_JS_URL2, LoadMode.EAGER).toJson(), new Dependency(Dependency.Type.STYLESHEET, TEST_CSS_URL, LoadMode.EAGER).toJson()));
    assertEquals(Arrays.asList(TEST_JS_URL, TEST_JS_URL2), mockResourceLoader.loadingScripts);
    assertEquals(Collections.singletonList(TEST_CSS_URL), mockResourceLoader.loadingStyles);
}
Also used : 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