diff options
Diffstat (limited to 'test')
13 files changed, 266 insertions, 0 deletions
diff --git a/test/dependency-rewrite-addon/pom.xml b/test/dependency-rewrite-addon/pom.xml new file mode 100644 index 0000000000..f822e34b77 --- /dev/null +++ b/test/dependency-rewrite-addon/pom.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-test</artifactId> + <version>8.1-SNAPSHOT</version> + </parent> + <artifactId>vaadin-test-dependency-rewrite-addon</artifactId> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-test-widget-set-testutil</artifactId> + </dependency> + </dependencies> + +</project> diff --git a/test/dependency-rewrite-addon/src/main/java/com/vaadin/test/dependencyrewriteaddon/RewriteJQueryFilter.java b/test/dependency-rewrite-addon/src/main/java/com/vaadin/test/dependencyrewriteaddon/RewriteJQueryFilter.java new file mode 100644 index 0000000000..415bb9b093 --- /dev/null +++ b/test/dependency-rewrite-addon/src/main/java/com/vaadin/test/dependencyrewriteaddon/RewriteJQueryFilter.java @@ -0,0 +1,28 @@ +package com.vaadin.test.dependencyrewriteaddon; + +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import com.vaadin.server.DependencyFilter; +import com.vaadin.ui.Dependency; +import com.vaadin.ui.Dependency.Type; + +public class RewriteJQueryFilter implements DependencyFilter { + + @Override + public List<Dependency> filter(List<Dependency> dependencies, + FilterContext filterContext) { + List<Dependency> filtered = new ArrayList<>(); + for (Dependency dependency : dependencies) { + if (dependency.getType() == Type.JAVASCRIPT && dependency.getUrl() + .toLowerCase(Locale.ENGLISH).contains("jquery")) { + filtered.add( + new Dependency(Type.JAVASCRIPT, "vaadin://jquery.js")); + } else { + filtered.add(dependency); + } + } + return filtered; + } +} diff --git a/test/dependency-rewrite-addon/src/main/resources/META-INF/services/com.vaadin.server.DependencyFilter b/test/dependency-rewrite-addon/src/main/resources/META-INF/services/com.vaadin.server.DependencyFilter new file mode 100644 index 0000000000..f62efa26fd --- /dev/null +++ b/test/dependency-rewrite-addon/src/main/resources/META-INF/services/com.vaadin.server.DependencyFilter @@ -0,0 +1 @@ +com.vaadin.test.dependencyrewriteaddon.RewriteJQueryFilter diff --git a/test/dependency-rewrite/pom.xml b/test/dependency-rewrite/pom.xml new file mode 100644 index 0000000000..d776eba883 --- /dev/null +++ b/test/dependency-rewrite/pom.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-test</artifactId> + <version>8.1-SNAPSHOT</version> + </parent> + <artifactId>vaadin-test-dependency-rewrite</artifactId> + <packaging>war</packaging> + + <dependencies> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-test-widget-set-testutil</artifactId> + </dependency> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-client-compiled</artifactId> + </dependency> + <dependency> + <groupId>com.vaadin</groupId> + <artifactId>vaadin-test-dependency-rewrite-addon</artifactId> + <version>${project.version}</version> + </dependency> + + </dependencies> + +</project> diff --git a/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/ApplicationDependencyFilter.java b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/ApplicationDependencyFilter.java new file mode 100644 index 0000000000..63e1db0377 --- /dev/null +++ b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/ApplicationDependencyFilter.java @@ -0,0 +1,26 @@ +package com.vaadin.test.dependencyrewrite; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.DependencyFilter; +import com.vaadin.ui.Dependency; + +public class ApplicationDependencyFilter implements DependencyFilter { + + @Override + public List<Dependency> filter(List<Dependency> dependencies, + FilterContext filterContext) { + List<Dependency> filtered = new ArrayList<>(); + for (Dependency dependency : dependencies) { + if (dependency.getUrl().startsWith("vaadin://")) { + filtered.add(new Dependency(dependency.getType(), dependency + .getUrl().replace("vaadin://", "vaadin://sub/"))); + } else { + filtered.add(dependency); + } + } + return filtered; + } + +} diff --git a/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyDynamicUI.java b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyDynamicUI.java new file mode 100644 index 0000000000..ec696713f1 --- /dev/null +++ b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyDynamicUI.java @@ -0,0 +1,34 @@ +package com.vaadin.test.dependencyrewrite; + +import com.vaadin.annotations.JavaScript; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +public class DependencyDynamicUI extends UI { + + @JavaScript("http://jquery.com/jquery-1.2.3.js") + public static class MyJqueryLabel extends Label { + public MyJqueryLabel() { + super("MyJqueryLabel"); + } + } + + @JavaScript("vaadin://jquery-33.3.3.js") + public static class MyJqueryLabel2 extends Label { + public MyJqueryLabel2() { + super("MyJqueryLabel2"); + } + } + + @Override + protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new MyJqueryLabel()); + layout.addComponent(new MyJqueryLabel2()); + + setContent(layout); + } + +} diff --git a/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyInitialUI.java b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyInitialUI.java new file mode 100644 index 0000000000..3e600c2aaa --- /dev/null +++ b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyInitialUI.java @@ -0,0 +1,21 @@ +package com.vaadin.test.dependencyrewrite; + +import com.vaadin.annotations.JavaScript; +import com.vaadin.server.VaadinRequest; +import com.vaadin.test.dependencyrewrite.DependencyDynamicUI.MyJqueryLabel; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +@JavaScript("http://jquery.com/jquery-12.2.3.js") +@JavaScript("vaadin://jquery-323.3.3.js") +public class DependencyInitialUI extends UI { + + @Override + protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.addComponent(new MyJqueryLabel()); + + setContent(layout); + } + +} diff --git a/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyService.java b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyService.java new file mode 100644 index 0000000000..5723a93885 --- /dev/null +++ b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyService.java @@ -0,0 +1,27 @@ +package com.vaadin.test.dependencyrewrite; + +import java.util.List; + +import com.vaadin.server.DependencyFilter; +import com.vaadin.server.DeploymentConfiguration; +import com.vaadin.server.ServiceException; +import com.vaadin.server.VaadinServlet; +import com.vaadin.server.VaadinServletService; + +public class MyService extends VaadinServletService { + + public MyService(VaadinServlet servlet, + DeploymentConfiguration deploymentConfiguration) + throws ServiceException { + super(servlet, deploymentConfiguration); + } + + @Override + protected List<DependencyFilter> createDependencyFilters() + throws ServiceException { + List<DependencyFilter> list = super.createDependencyFilters(); + list.add(new ApplicationDependencyFilter()); + return list; + } + +} diff --git a/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIProvider.java b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIProvider.java new file mode 100644 index 0000000000..dd4675888a --- /dev/null +++ b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIProvider.java @@ -0,0 +1,22 @@ +package com.vaadin.test.dependencyrewrite; + +import com.vaadin.server.UIClassSelectionEvent; +import com.vaadin.server.UIProvider; +import com.vaadin.ui.UI; + +public class MyUIProvider extends UIProvider { + + @Override + public Class<? extends UI> getUIClass(UIClassSelectionEvent event) { + String url = event.getRequest().getPathInfo(); + if (url.contains("/dynamic/")) { + return DependencyDynamicUI.class; + } else if (url.contains("/initial/")) { + return DependencyInitialUI.class; + } else { + return null; + } + + } + +} diff --git a/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIServlet.java b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIServlet.java new file mode 100644 index 0000000000..dbddf3d970 --- /dev/null +++ b/test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIServlet.java @@ -0,0 +1,22 @@ +package com.vaadin.test.dependencyrewrite; + +import javax.servlet.annotation.WebInitParam; +import javax.servlet.annotation.WebServlet; + +import com.vaadin.server.DeploymentConfiguration; +import com.vaadin.server.ServiceException; +import com.vaadin.server.VaadinServlet; +import com.vaadin.server.VaadinServletService;; + +@WebServlet(urlPatterns = { + "/*" }, name = "MyUIServlet", asyncSupported = true, initParams = @WebInitParam(name = "UIProvider", value = "com.vaadin.test.dependencyrewrite.MyUIProvider")) +public class MyUIServlet extends VaadinServlet { + @Override + protected VaadinServletService createServletService( + DeploymentConfiguration deploymentConfiguration) + throws ServiceException { + MyService service = new MyService(this, deploymentConfiguration); + service.init(); + return service; + } +} diff --git a/test/dependency-rewrite/src/main/webapp/VAADIN/sub/jquery.js b/test/dependency-rewrite/src/main/webapp/VAADIN/sub/jquery.js new file mode 100644 index 0000000000..b6aa9b8a0f --- /dev/null +++ b/test/dependency-rewrite/src/main/webapp/VAADIN/sub/jquery.js @@ -0,0 +1,5 @@ +if (!window.jqueryLoaded) { + window.jqueryLoaded = 1; +} else { + window.jqueryLoaded++; +} diff --git a/test/dependency-rewrite/src/test/java/com/vaadin/test/dependencyrewrite/DependencyFilterIT.java b/test/dependency-rewrite/src/test/java/com/vaadin/test/dependencyrewrite/DependencyFilterIT.java new file mode 100644 index 0000000000..5256def3f5 --- /dev/null +++ b/test/dependency-rewrite/src/test/java/com/vaadin/test/dependencyrewrite/DependencyFilterIT.java @@ -0,0 +1,29 @@ +package com.vaadin.test.dependencyrewrite; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.phantomjs.PhantomJSDriver; + +import com.vaadin.testbench.TestBenchTestCase; + +public class DependencyFilterIT extends TestBenchTestCase { + + @Test + public void dynamicallyAddedResources() { + setDriver(new PhantomJSDriver()); + getDriver().get("http://localhost:8080/dynamic/"); + Assert.assertEquals(1L, ((JavascriptExecutor) getDriver()) + .executeScript("return window.jqueryLoaded")); + } + + @Test + public void initiallyLoadedResources() { + setDriver(new PhantomJSDriver()); + getDriver().get("http://localhost:8080/initial/"); + // 2 because of https://github.com/vaadin/framework/issues/9181 + Assert.assertEquals(2L, ((JavascriptExecutor) getDriver()) + .executeScript("return window.jqueryLoaded")); + } + +} diff --git a/test/pom.xml b/test/pom.xml index 9987f99082..919ef28ac7 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -107,6 +107,8 @@ <module>servlet-containers/jsp-integration</module> <module>bean-api-validation</module> <module>bean-impl-validation</module> + <module>dependency-rewrite-addon</module> + <module>dependency-rewrite</module> </modules> <build> |