From a682e3b5341e5cf21e84c1dbbb2bc98743674392 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 16 Sep 2013 14:31:37 +0300 Subject: Refactored build scripts to support TB2, TB3 + integration tests (#12572) * Main build configuration triggers unit tests for all modules and uitest/build.xml testbench tests in parallel * uitest/build.xml triggers Jetty startup and integration (server) tests in parallel. After the server has started, TB2 and TB3 tests are run in parallel. * Server integration tests for servlet containers are run using TB3 and the com.vaadin.tests.tb3.ServletIntegrationTests test suite. * Portlet integration tests are still run using TB2 test scripts Change-Id: Ie6bffd4e68b4889074e9c470faa3c65f923e55c4 --- build.xml | 15 +- uitest/build.xml | 55 ++++++ uitest/integration_tests.xml | 91 ++++----- uitest/src/com/vaadin/tests/tb3/AllTB3Tests.java | 42 ++++ uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java | 223 ++++++++++++++++++++++ uitest/tb3test.xml | 33 ++++ uitest/test.xml | 21 +- 7 files changed, 411 insertions(+), 69 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/tb3/AllTB3Tests.java create mode 100644 uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java create mode 100644 uitest/tb3test.xml diff --git a/build.xml b/build.xml index 5f748d8f40..bef7f7a2f3 100644 --- a/build.xml +++ b/build.xml @@ -43,19 +43,16 @@ + + - - - - - - - + - + + + diff --git a/uitest/build.xml b/uitest/build.xml index bd0f49ae1e..76b75e9203 100644 --- a/uitest/build.xml +++ b/uitest/build.xml @@ -9,6 +9,7 @@ + @@ -107,6 +108,11 @@ + + + + + @@ -148,4 +154,53 @@ WHAT? No JUnit tests for ${module.name}! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/uitest/integration_tests.xml b/uitest/integration_tests.xml index 78e053991e..f1b2070bc8 100644 --- a/uitest/integration_tests.xml +++ b/uitest/integration_tests.xml @@ -1,6 +1,6 @@ - + @@ -32,33 +32,22 @@ + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + @@ -73,7 +62,7 @@ - + @@ -90,7 +79,7 @@ - + @@ -107,6 +96,27 @@ + + + + + + + + + + + + + + + + + + + + + @@ -333,7 +343,7 @@ - + @@ -341,7 +351,8 @@ + requires its own lock --> + @@ -387,7 +398,6 @@ - @@ -446,31 +456,24 @@ - - - - - - - - + - + Starting legacy (TB2) test for ${target-server} + + + Starting TB3 test for ${target-server} + + + + + - - - - - - - diff --git a/uitest/src/com/vaadin/tests/tb3/AllTB3Tests.java b/uitest/src/com/vaadin/tests/tb3/AllTB3Tests.java new file mode 100644 index 0000000000..bd9027bec2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/AllTB3Tests.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2013 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.AllTB3Tests.AllTB3TestsSuite; + +/** + * Test consisting of all TB3 tests except integration tests (classes extending + * AbstractTB3Test, excludes package com.vaadin.test.integration). + * + * @author Vaadin Ltd + */ +@RunWith(AllTB3TestsSuite.class) +public class AllTB3Tests { + + public static class AllTB3TestsSuite extends TB3TestSuite { + + public AllTB3TestsSuite(Class klass) throws InitializationError { + super(klass, AbstractTB3Test.class, "com.vaadin.tests", + new String[] { "com.vaadin.tests.integration" }); + } + + } + +} diff --git a/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java new file mode 100644 index 0000000000..dc187000d2 --- /dev/null +++ b/uitest/src/com/vaadin/tests/tb3/TB3TestSuite.java @@ -0,0 +1,223 @@ +/* + * Copyright 2000-2013 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; + +import org.junit.runners.Suite; +import org.junit.runners.model.InitializationError; + +/** + * Test suite which consists of all the TB3 tests passed in the constructor. + * Runs the tests in parallel using a {@link ParallelScheduler} + * + * @author Vaadin Ltd + */ +public class TB3TestSuite extends Suite { + + public TB3TestSuite(Class klass, + Class baseClass, String basePackage, + String[] ignorePackages) throws InitializationError { + super(klass, findTests(baseClass, basePackage, ignorePackages)); + setScheduler(new ParallelScheduler()); + } + + /** + * 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( + Class 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 List> findClasses(Class baseClass, + String basePackage, String[] ignoredPackages) throws IOException { + List> classes = new ArrayList>(); + 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>() { + + @Override + public int compare(Class o1, Class 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 void findPackages(File parent, String javaPackage, + Class baseClass, Collection> 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 void findClassesInJar(JarURLConnection juc, + String javaPackage, Class baseClass, + Collection> result) throws IOException { + String javaPackageDir = javaPackage.replace('.', '/'); + Enumeration 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 void addClassIfMatches( + Collection> result, + String fullyQualifiedClassName, Class baseClass) { + try { + // Try to load the class + + Class c = Class.forName(fullyQualifiedClassName); + if (!baseClass.isAssignableFrom(c)) { + return; + } + if (!Modifier.isAbstract(c.getModifiers()) && !c.isAnonymousClass()) { + result.add((Class) 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 + } + + } + +} \ No newline at end of file diff --git a/uitest/tb3test.xml b/uitest/tb3test.xml new file mode 100644 index 0000000000..92008ff9f3 --- /dev/null +++ b/uitest/tb3test.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/uitest/test.xml b/uitest/test.xml index 3baccb4117..dd6964e59c 100644 --- a/uitest/test.xml +++ b/uitest/test.xml @@ -83,7 +83,7 @@ - + @@ -161,12 +161,10 @@ - + - - - - + + @@ -177,15 +175,6 @@ - - - - - - - - - - + -- cgit v1.2.3