summaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/tb3
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/com/vaadin/tests/tb3')
-rw-r--r--uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java97
-rw-r--r--uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java27
-rw-r--r--uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java158
-rw-r--r--uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java41
-rw-r--r--uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java10
-rw-r--r--uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java218
-rw-r--r--uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java207
-rw-r--r--uitest/src/com/vaadin/tests/tb3/WebsocketTest.java24
8 files changed, 561 insertions, 221 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java b/uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java
new file mode 100644
index 0000000000..a3bee26675
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/tb3/AffectedTB3TestLocator.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.tb3;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class AffectedTB3TestLocator extends TB3TestLocator {
+
+ private final ChangedTB3TestLocator changedTB3TestLocator;
+
+ public AffectedTB3TestLocator() {
+ changedTB3TestLocator = new ChangedTB3TestLocator();
+ }
+
+ @Override
+ protected <T> List<Class<? extends T>> findClasses(Class<T> baseClass,
+ String basePackage, String[] ignoredPackages) throws IOException {
+ List<Class<? extends T>> allTestClasses = super.findClasses(baseClass,
+ basePackage, ignoredPackages);
+
+ List<Class<? extends T>> changedTestClasses = changedTB3TestLocator
+ .findClasses(baseClass, basePackage, ignoredPackages);
+
+ return getAffectedTestClasses(allTestClasses, changedTestClasses);
+ }
+
+ private <T> List<Class<? extends T>> getAffectedTestClasses(
+ List<Class<? extends T>> allTestClasses,
+ List<Class<? extends T>> changedTestClasses) throws IOException {
+ List<Class<? extends T>> affectedWithPackageTestClasses = getTestClassesWithAffectedPackageName(allTestClasses);
+ List<Class<? extends T>> affectedTestClasses = new ArrayList<Class<? extends T>>();
+ affectedTestClasses.addAll(affectedWithPackageTestClasses);
+
+ // Removing duplicate entries before adding changed test classes.
+ for (Class<? extends T> changedTestClass : changedTestClasses) {
+ for (Class<? extends T> affectedTestClass : affectedWithPackageTestClasses) {
+ if (!changedTestClass.getName().equals(
+ affectedTestClass.getName())) {
+ affectedTestClasses.add(changedTestClass);
+
+ break;
+ }
+ }
+ }
+ return affectedTestClasses;
+ }
+
+ private <T> List<Class<? extends T>> getTestClassesWithAffectedPackageName(
+ List<Class<? extends T>> classes) {
+ List<Class<? extends T>> affectedTestClasses = new ArrayList<Class<? extends T>>();
+ List<String> affectedFiles = getAffectedFiles();
+
+ for (Class c : classes) {
+ String[] packageParts = c.getName().split("\\.");
+ String lastPart = packageParts[packageParts.length - 2];
+
+ for (String f : affectedFiles) {
+ if (f.toLowerCase().contains(lastPart.toLowerCase())) {
+ affectedTestClasses.add(c);
+
+ // Break here not to accidentally add the same test class
+ // multiple times if it matches more than one file.
+ break;
+ }
+ }
+ }
+
+ return affectedTestClasses;
+ }
+
+ private List<String> getAffectedFiles() {
+ List<String> affectedFilePaths = new ArrayList<String>();
+
+ for (String path : changedTB3TestLocator.getChangedFilePaths()) {
+ if (!path.toLowerCase().contains("test")) {
+ affectedFilePaths.add(path);
+ }
+ }
+
+ return affectedFilePaths;
+ }
+} \ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java b/uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java
new file mode 100644
index 0000000000..6736bc3990
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/tb3/AffectedTB3Tests.java
@@ -0,0 +1,27 @@
+package com.vaadin.tests.tb3;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.model.InitializationError;
+
+import com.vaadin.tests.tb3.AffectedTB3Tests.AffectedTB3TestSuite;
+
+/**
+ * Test suite that runs tests from test classes which have changes or have
+ * similar package name compare the the changes files in the current workspace.
+ * If there are no changes in the workspace, it will run the changes to test
+ * classes introduced in the HEAD commit.
+ *
+ * @author Vaadin Ltd
+ */
+@RunWith(AffectedTB3TestSuite.class)
+public class AffectedTB3Tests {
+
+ public static class AffectedTB3TestSuite extends TB3TestSuite {
+
+ public AffectedTB3TestSuite(Class<?> klass) throws InitializationError {
+ super(klass, AbstractTB3Test.class, "com.vaadin.tests",
+ new String[] { "com.vaadin.tests.integration" },
+ new AffectedTB3TestLocator());
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java b/uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java
new file mode 100644
index 0000000000..b425de48b5
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/tb3/ChangedTB3TestLocator.java
@@ -0,0 +1,158 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.tb3;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jgit.api.DiffCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.diff.DiffEntry.ChangeType;
+import org.eclipse.jgit.diff.DiffFormatter;
+import org.eclipse.jgit.diff.RawTextComparator;
+import org.eclipse.jgit.errors.AmbiguousObjectException;
+import org.eclipse.jgit.errors.IncorrectObjectTypeException;
+import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.errors.NoWorkTreeException;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.eclipse.jgit.util.io.DisabledOutputStream;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ChangedTB3TestLocator extends TB3TestLocator {
+
+ @Override
+ protected <T> List<Class<? extends T>> findClasses(Class<T> baseClass,
+ String basePackage, String[] ignoredPackages) throws IOException {
+
+ return getChangedTestClasses(baseClass);
+ }
+
+ protected List<String> getChangedFilePaths() {
+ List<String> filePaths = new ArrayList<String>();
+
+ for (DiffEntry diff : getDiffs()) {
+ if (diff.getChangeType() != ChangeType.DELETE) {
+ filePaths.add(diff.getNewPath());
+ System.out.println("Using changed file: " + diff.getNewPath());
+ }
+ }
+
+ return filePaths;
+ }
+
+ private List<DiffEntry> getDiffs() {
+ try {
+ FileRepositoryBuilder builder = new FileRepositoryBuilder();
+ Repository repository = builder.setWorkTree(new File("."))
+ .readEnvironment() // scan environment GIT_* variables
+ .findGitDir() // scan up the file system tree
+ .build();
+
+ List<DiffEntry> diffsInWorkingTree = getDiffsInWorkingTree(repository);
+
+ if (diffsInWorkingTree.isEmpty()) {
+ return getDiffsInHead(repository);
+ }
+
+ return diffsInWorkingTree;
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoWorkTreeException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (GitAPIException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private List<DiffEntry> getDiffsInWorkingTree(Repository repository)
+ throws GitAPIException {
+ Git git = new Git(repository);
+ DiffCommand diffCommand = git.diff();
+
+ List<DiffEntry> diffsInWorkingTree = new ArrayList<DiffEntry>();
+
+ for (DiffEntry diff : diffCommand.call()) {
+ // Exclude temporary junit files.
+ if (!diff.getNewPath().startsWith("uitest/junit")) {
+ diffsInWorkingTree.add(diff);
+ }
+ }
+
+ return diffsInWorkingTree;
+ }
+
+ private List<DiffEntry> getDiffsInHead(Repository repository)
+ throws AmbiguousObjectException, IncorrectObjectTypeException,
+ IOException, MissingObjectException {
+ RevWalk rw = new RevWalk(repository);
+ ObjectId head = repository.resolve(Constants.HEAD);
+ RevCommit commit = rw.parseCommit(head);
+ RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
+ DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
+ df.setRepository(repository);
+ df.setDiffComparator(RawTextComparator.DEFAULT);
+ df.setDetectRenames(true);
+ List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
+
+ return diffs;
+ }
+
+ private <T> List<Class<? extends T>> getChangedTestClasses(
+ Class<T> baseClass) {
+ List<String> changedTestFilePaths = getTestFilePaths();
+ List<Class<? extends T>> testClasses = new ArrayList<Class<? extends T>>();
+
+ for (String filePath : changedTestFilePaths) {
+ String path = filePath.replace("uitest/src/", "").replace(".java",
+ "");
+ String className = path.replace("/", ".");
+ addClassIfMatches(testClasses, className, baseClass);
+ }
+
+ return testClasses;
+ }
+
+ private List<String> getTestFilePaths() {
+ List<String> changedTestFilePaths = new ArrayList<String>();
+
+ for (String filePath : getChangedFilePaths()) {
+ if (filePath.toLowerCase().startsWith("uitest")
+ && filePath.toLowerCase().endsWith(".java")) {
+ changedTestFilePaths.add(filePath);
+ }
+ }
+
+ return changedTestFilePaths;
+ }
+
+}
diff --git a/uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java b/uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java
new file mode 100644
index 0000000000..2200566b84
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/tb3/ChangedTB3Tests.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.tb3;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.model.InitializationError;
+
+import com.vaadin.tests.tb3.ChangedTB3Tests.ChangedTB3TestsSuite;
+
+/**
+ * Test suite that runs tests from test classes which have changes in the
+ * current workspace. If there are no changes in the workspace, it will run the
+ * changes to test classes introduced in the HEAD commit.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+@RunWith(ChangedTB3TestsSuite.class)
+public class ChangedTB3Tests {
+ public static class ChangedTB3TestsSuite extends TB3TestSuite {
+ public ChangedTB3TestsSuite(Class<?> klass) throws InitializationError {
+ super(klass, AbstractTB3Test.class, "com.vaadin.tests",
+ new String[] { "com.vaadin.tests.integration" },
+ new ChangedTB3TestLocator());
+
+ }
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java
index d6eed3e5c8..ebcb02002e 100644
--- a/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java
+++ b/uitest/src/com/vaadin/tests/tb3/MultiBrowserTest.java
@@ -40,6 +40,16 @@ import org.openqa.selenium.remote.DesiredCapabilities;
*/
public abstract class MultiBrowserTest extends PrivateTB3Configuration {
+ protected List<DesiredCapabilities> getBrowsersSupportingWebSocket() {
+ List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(getAllBrowsers());
+
+ browsers.remove(Browser.IE8.getDesiredCapabilities());
+ browsers.remove(Browser.IE9.getDesiredCapabilities());
+ browsers.remove(Browser.PHANTOMJS.getDesiredCapabilities());
+
+ return browsers;
+ }
+
protected List<DesiredCapabilities> getBrowsersExcludingPhantomJS() {
List<DesiredCapabilities> browsers = new ArrayList<DesiredCapabilities>(getAllBrowsers());
diff --git a/uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java b/uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java
new file mode 100644
index 0000000000..a0fbf51195
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/tb3/TB3TestLocator.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.tb3;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Modifier;
+import java.net.JarURLConnection;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+
+public class TB3TestLocator {
+ /**
+ * Traverses the directory on the classpath (inside or outside a Jar file)
+ * specified by 'basePackage'. Collects all classes inside the location
+ * which can be assigned to 'baseClass' except for classes inside packages
+ * listed in 'ignoredPackages'.
+ *
+ * @param baseClass
+ * @param basePackage
+ * @param ignorePackages
+ * @return
+ */
+ public Class<?>[] findTests(Class<? extends AbstractTB3Test> baseClass,
+ String basePackage, String[] ignorePackages) {
+ try {
+ List<?> l = findClasses(baseClass, basePackage, ignorePackages);
+ return l.toArray(new Class[] {});
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Traverses the directory on the classpath (inside or outside a Jar file)
+ * specified by 'basePackage'. Collects all classes inside the location
+ * which can be assigned to 'baseClass' except for classes inside packages
+ * listed in 'ignoredPackages'.
+ *
+ * @param baseClass
+ * @param basePackage
+ * @param ignoredPackages
+ * @return
+ * @throws IOException
+ */
+ protected <T> List<Class<? extends T>> findClasses(Class<T> baseClass,
+ String basePackage, String[] ignoredPackages) throws IOException {
+ List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
+ String basePackageDirName = "/" + basePackage.replace('.', '/');
+ URL location = baseClass.getResource(basePackageDirName);
+ if (location.getProtocol().equals("file")) {
+ try {
+ File f = new File(location.toURI());
+ if (!f.exists()) {
+ throw new IOException("Directory " + f.toString()
+ + " does not exist");
+ }
+ findPackages(f, basePackage, baseClass, classes,
+ ignoredPackages);
+ } catch (URISyntaxException e) {
+ throw new IOException(e.getMessage());
+ }
+ } else if (location.getProtocol().equals("jar")) {
+ JarURLConnection juc = (JarURLConnection) location.openConnection();
+ findClassesInJar(juc, basePackage, baseClass, classes);
+ }
+
+ Collections.sort(classes, new Comparator<Class<? extends T>>() {
+
+ @Override
+ public int compare(Class<? extends T> o1, Class<? extends T> o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+
+ });
+
+ return classes;
+ }
+
+ /**
+ * Traverses the given directory and collects all classes which are inside
+ * the given 'javaPackage' and can be assigned to the given 'baseClass'. The
+ * found classes are added to 'result'.
+ *
+ * @param parent
+ * The directory to traverse
+ * @param javaPackage
+ * The java package which 'parent' contains
+ * @param baseClass
+ * The class which the target classes extend
+ * @param result
+ * The collection to which found classes are added
+ * @param ignoredPackages
+ * A collection of packages (including sub packages) to ignore
+ */
+ private <T> void findPackages(File parent, String javaPackage,
+ Class<T> baseClass, Collection<Class<? extends T>> result,
+ String[] ignoredPackages) {
+ for (String ignoredPackage : ignoredPackages) {
+ if (javaPackage.equals(ignoredPackage)) {
+ return;
+ }
+ }
+
+ for (File file : parent.listFiles()) {
+ if (file.isDirectory()) {
+ findPackages(file, javaPackage + "." + file.getName(),
+ baseClass, result, ignoredPackages);
+ } else if (file.getName().endsWith(".class")) {
+ String fullyQualifiedClassName = javaPackage + "."
+ + file.getName().replace(".class", "");
+ addClassIfMatches(result, fullyQualifiedClassName, baseClass);
+ }
+ }
+
+ }
+
+ /**
+ * Traverses a Jar file using the given connection and collects all classes
+ * which are inside the given 'javaPackage' and can be assigned to the given
+ * 'baseClass'. The found classes are added to 'result'.
+ *
+ * @param javaPackage
+ * The java package containing the classes (classes may be in a
+ * sub package)
+ * @param baseClass
+ * The class which the target classes extend
+ * @param result
+ * The collection to which found classes are added
+ * @throws IOException
+ */
+ private <T> void findClassesInJar(JarURLConnection juc, String javaPackage,
+ Class<T> baseClass, Collection<Class<? extends T>> result)
+ throws IOException {
+ String javaPackageDir = javaPackage.replace('.', '/');
+ Enumeration<JarEntry> ent = juc.getJarFile().entries();
+ while (ent.hasMoreElements()) {
+ JarEntry e = ent.nextElement();
+ if (e.getName().endsWith(".class")
+ && e.getName().startsWith(javaPackageDir)) {
+ String fullyQualifiedClassName = e.getName().replace('/', '.')
+ .replace(".class", "");
+ addClassIfMatches(result, fullyQualifiedClassName, baseClass);
+ }
+ }
+ }
+
+ /**
+ * Verifies that the class represented by 'fullyQualifiedClassName' can be
+ * loaded, assigned to 'baseClass' and is not an abstract or anonymous
+ * class.
+ *
+ * @param result
+ * The collection to add to
+ * @param fullyQualifiedClassName
+ * The candidate class
+ * @param baseClass
+ * The class 'fullyQualifiedClassName' should be assignable to
+ */
+ @SuppressWarnings("unchecked")
+ protected <T> void addClassIfMatches(Collection<Class<? extends T>> result,
+ String fullyQualifiedClassName, Class<T> baseClass) {
+ try {
+ // Try to load the class
+
+ Class<?> c = Class.forName(fullyQualifiedClassName);
+ if (!baseClass.isAssignableFrom(c)) {
+ return;
+ }
+ if (!includeInSuite(c)) {
+ return;
+ }
+
+ if (!Modifier.isAbstract(c.getModifiers()) && !c.isAnonymousClass()) {
+ result.add((Class<? extends T>) c);
+ }
+ } catch (Exception e) {
+ // Could ignore that class cannot be loaded
+ e.printStackTrace();
+ } catch (LinkageError e) {
+ // Ignore. Client side classes will at least throw LinkageErrors
+ }
+
+ }
+
+ /**
+ * @return true if the class should be included in the suite, false if not
+ */
+ private boolean includeInSuite(Class<?> c) {
+ if (c.getAnnotation(ExcludeFromSuite.class) != null) {
+ return false;
+ }
+
+ return true;
+ }
+} \ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java
index 703d01c122..b0554ce0f6 100644
--- a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java
+++ b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java
@@ -16,21 +16,8 @@
package com.vaadin.tests.tb3;
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Modifier;
-import java.net.JarURLConnection;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-import java.util.jar.JarEntry;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;
@@ -59,194 +46,16 @@ public class TB3TestSuite extends Suite {
public TB3TestSuite(Class<?> klass,
Class<? extends AbstractTB3Test> baseClass, String basePackage,
String[] ignorePackages) throws InitializationError {
- super(klass, findTests(baseClass, basePackage, ignorePackages));
- setScheduler(new ParallelScheduler(service));
+ this(klass, baseClass, basePackage, ignorePackages,
+ new TB3TestLocator());
}
- /**
- * Traverses the directory on the classpath (inside or outside a Jar file)
- * specified by 'basePackage'. Collects all classes inside the location
- * which can be assigned to 'baseClass' except for classes inside packages
- * listed in 'ignoredPackages'.
- *
- * @param baseClass
- * @param basePackage
- * @param ignorePackages
- * @return
- */
- private static Class<?>[] findTests(
+ public TB3TestSuite(Class<?> klass,
Class<? extends AbstractTB3Test> baseClass, String basePackage,
- String[] ignorePackages) {
- try {
- List<?> l = findClasses(baseClass, basePackage, ignorePackages);
- return l.toArray(new Class[] {});
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
-
- /**
- * Traverses the directory on the classpath (inside or outside a Jar file)
- * specified by 'basePackage'. Collects all classes inside the location
- * which can be assigned to 'baseClass' except for classes inside packages
- * listed in 'ignoredPackages'.
- *
- * @param baseClass
- * @param basePackage
- * @param ignoredPackages
- * @return
- * @throws IOException
- */
- private static <T> List<Class<? extends T>> findClasses(Class<T> baseClass,
- String basePackage, String[] ignoredPackages) throws IOException {
- List<Class<? extends T>> classes = new ArrayList<Class<? extends T>>();
- String basePackageDirName = "/" + basePackage.replace('.', '/');
- URL location = baseClass.getResource(basePackageDirName);
- if (location.getProtocol().equals("file")) {
- try {
- File f = new File(location.toURI());
- if (!f.exists()) {
- throw new IOException("Directory " + f.toString()
- + " does not exist");
- }
- findPackages(f, basePackage, baseClass, classes,
- ignoredPackages);
- } catch (URISyntaxException e) {
- throw new IOException(e.getMessage());
- }
- } else if (location.getProtocol().equals("jar")) {
- JarURLConnection juc = (JarURLConnection) location.openConnection();
- findClassesInJar(juc, basePackage, baseClass, classes);
- }
-
- Collections.sort(classes, new Comparator<Class<? extends T>>() {
-
- @Override
- public int compare(Class<? extends T> o1, Class<? extends T> o2) {
- return o1.getName().compareTo(o2.getName());
- }
-
- });
- return classes;
- }
-
- /**
- * Traverses the given directory and collects all classes which are inside
- * the given 'javaPackage' and can be assigned to the given 'baseClass'. The
- * found classes are added to 'result'.
- *
- * @param parent
- * The directory to traverse
- * @param javaPackage
- * The java package which 'parent' contains
- * @param baseClass
- * The class which the target classes extend
- * @param result
- * The collection to which found classes are added
- * @param ignoredPackages
- * A collection of packages (including sub packages) to ignore
- */
- private static <T> void findPackages(File parent, String javaPackage,
- Class<T> baseClass, Collection<Class<? extends T>> result,
- String[] ignoredPackages) {
- for (String ignoredPackage : ignoredPackages) {
- if (javaPackage.equals(ignoredPackage)) {
- return;
- }
- }
-
- for (File file : parent.listFiles()) {
- if (file.isDirectory()) {
- findPackages(file, javaPackage + "." + file.getName(),
- baseClass, result, ignoredPackages);
- } else if (file.getName().endsWith(".class")) {
- String fullyQualifiedClassName = javaPackage + "."
- + file.getName().replace(".class", "");
- addClassIfMatches(result, fullyQualifiedClassName, baseClass);
- }
- }
-
- }
-
- /**
- * Traverses a Jar file using the given connection and collects all classes
- * which are inside the given 'javaPackage' and can be assigned to the given
- * 'baseClass'. The found classes are added to 'result'.
- *
- * @param javaPackage
- * The java package containing the classes (classes may be in a
- * sub package)
- * @param baseClass
- * The class which the target classes extend
- * @param result
- * The collection to which found classes are added
- * @throws IOException
- */
- private static <T> void findClassesInJar(JarURLConnection juc,
- String javaPackage, Class<T> baseClass,
- Collection<Class<? extends T>> result) throws IOException {
- String javaPackageDir = javaPackage.replace('.', '/');
- Enumeration<JarEntry> ent = juc.getJarFile().entries();
- while (ent.hasMoreElements()) {
- JarEntry e = ent.nextElement();
- if (e.getName().endsWith(".class")
- && e.getName().startsWith(javaPackageDir)) {
- String fullyQualifiedClassName = e.getName().replace('/', '.')
- .replace(".class", "");
- addClassIfMatches(result, fullyQualifiedClassName, baseClass);
- }
- }
- }
-
- /**
- * Verifies that the class represented by 'fullyQualifiedClassName' can be
- * loaded, assigned to 'baseClass' and is not an abstract or anonymous
- * class.
- *
- * @param result
- * The collection to add to
- * @param fullyQualifiedClassName
- * The candidate class
- * @param baseClass
- * The class 'fullyQualifiedClassName' should be assignable to
- */
- @SuppressWarnings("unchecked")
- private static <T> void addClassIfMatches(
- Collection<Class<? extends T>> result,
- String fullyQualifiedClassName, Class<T> baseClass) {
- try {
- // Try to load the class
-
- Class<?> c = Class.forName(fullyQualifiedClassName);
- if (!baseClass.isAssignableFrom(c)) {
- return;
- }
- if (!includeInSuite(c)) {
- return;
- }
-
- if (!Modifier.isAbstract(c.getModifiers()) && !c.isAnonymousClass()) {
- result.add((Class<? extends T>) c);
- }
- } catch (Exception e) {
- // Could ignore that class cannot be loaded
- e.printStackTrace();
- } catch (LinkageError e) {
- // Ignore. Client side classes will at least throw LinkageErrors
- }
-
- }
-
- /**
- * @return true if the class should be included in the suite, false if not
- */
- private static boolean includeInSuite(Class<?> c) {
- if (c.getAnnotation(ExcludeFromSuite.class) != null) {
- return false;
- }
-
- return true;
+ String[] ignorePackages, TB3TestLocator testLocator)
+ throws InitializationError {
+ super(klass, testLocator.findTests(baseClass, basePackage,
+ ignorePackages));
+ setScheduler(new ParallelScheduler(service));
}
}
diff --git a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java
index 778c8b9113..ddcc6d5d76 100644
--- a/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java
+++ b/uitest/src/com/vaadin/tests/tb3/WebsocketTest.java
@@ -35,30 +35,10 @@ import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
* @author Vaadin Ltd
*/
@TestCategory("push")
-public abstract class WebsocketTest extends PrivateTB3Configuration {
- private static List<DesiredCapabilities> websocketBrowsers = new ArrayList<DesiredCapabilities>();
- static {
- websocketBrowsers.addAll(MultiBrowserTest.getAllBrowsers());
- websocketBrowsers.remove(Browser.IE8.getDesiredCapabilities());
- websocketBrowsers.remove(Browser.IE9.getDesiredCapabilities());
- websocketBrowsers.remove(Browser.PHANTOMJS.getDesiredCapabilities());
- }
-
- /**
- * @return All supported browsers which are actively tested and support
- * websockets
- */
- public static List<DesiredCapabilities> getWebsocketBrowsers() {
- return Collections.unmodifiableList(websocketBrowsers);
- }
+public abstract class WebsocketTest extends MultiBrowserTest {
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.tests.tb3.AbstractTB3Test#getBrowserToRunOn()
- */
@Override
public List<DesiredCapabilities> getBrowsersToTest() {
- return new ArrayList<DesiredCapabilities>(getWebsocketBrowsers());
+ return new ArrayList<DesiredCapabilities>(getBrowsersSupportingWebSocket());
}
}