aboutsummaryrefslogtreecommitdiffstats
path: root/test/dependency-rewrite
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-05-02 08:30:59 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-05-02 08:30:59 +0300
commitf8921dc387a572b12ac7c9c6f4677e5a1d0e5b70 (patch)
treebe13f735bb10458e54d80e722242c902c5f2b8e5 /test/dependency-rewrite
parent9c443c9de42343a94df5f7040bfed731f8d8f84e (diff)
downloadvaadin-framework-f8921dc387a572b12ac7c9c6f4677e5a1d0e5b70.tar.gz
vaadin-framework-f8921dc387a572b12ac7c9c6f4677e5a1d0e5b70.zip
Add support for pluggable filters for rewriting dependencies (#9182)
* Add support for pluggable filters for rewriting dependencies Fixes #9151
Diffstat (limited to 'test/dependency-rewrite')
-rw-r--r--test/dependency-rewrite/pom.xml30
-rw-r--r--test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/ApplicationDependencyFilter.java26
-rw-r--r--test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyDynamicUI.java34
-rw-r--r--test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/DependencyInitialUI.java21
-rw-r--r--test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyService.java27
-rw-r--r--test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIProvider.java22
-rw-r--r--test/dependency-rewrite/src/main/java/com/vaadin/test/dependencyrewrite/MyUIServlet.java22
-rw-r--r--test/dependency-rewrite/src/main/webapp/VAADIN/sub/jquery.js5
-rw-r--r--test/dependency-rewrite/src/test/java/com/vaadin/test/dependencyrewrite/DependencyFilterIT.java29
9 files changed, 216 insertions, 0 deletions
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"));
+ }
+
+}