sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1530327 - in /sis/branches/JDK7: ./ application/ application/sis-console/src/test/java/org/apache/sis/test/suite/ core/sis-metadata/src/test/java/org/apache/sis/test/suite/ core/sis-referencing/src/test/java/org/apache/sis/test/suite/ core...
Date Tue, 08 Oct 2013 16:02:51 GMT
Author: desruisseaux
Date: Tue Oct  8 16:02:50 2013
New Revision: 1530327

URL: http://svn.apache.org/r1530327
Log:
Maven execute test suites instead of individual test cases, for control on test order and
test dependencies.

Modified:
    sis/branches/JDK7/application/pom.xml
    sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
    sis/branches/JDK7/pom.xml
    sis/branches/JDK7/profiles/sis-french-profile/src/test/java/org/apache/sis/test/suite/FrenchProfileSuite.java
    sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
    sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java

Modified: sis/branches/JDK7/application/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/pom.xml?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/application/pom.xml (original)
+++ sis/branches/JDK7/application/pom.xml Tue Oct  8 16:02:50 2013
@@ -97,6 +97,10 @@
 
     <!-- Test dependencies -->
     <dependency>
+      <groupId>org.opengis</groupId>
+      <artifactId>geoapi-conformance</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.sis.core</groupId>
       <artifactId>sis-utility</artifactId>
       <version>${project.version}</version>

Modified: sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/application/sis-console/src/test/java/org/apache/sis/test/suite/ConsoleTestSuite.java
[UTF-8] Tue Oct  8 16:02:50 2013
@@ -43,6 +43,7 @@ public final strictfp class ConsoleTestS
      */
     @BeforeClass
     public static void verifyTestList() {
-        verifyTestList(ConsoleTestSuite.class, BASE_TEST_CLASSES);
+        assertNoMissingTest(ConsoleTestSuite.class);
+        verifyTestList(ConsoleTestSuite.class);
     }
 }

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
[UTF-8] Tue Oct  8 16:02:50 2013
@@ -78,6 +78,7 @@ public final strictfp class MetadataTest
      */
     @BeforeClass
     public static void verifyTestList() {
-        verifyTestList(MetadataTestSuite.class, BASE_TEST_CLASSES);
+        assertNoMissingTest(MetadataTestSuite.class);
+        verifyTestList(MetadataTestSuite.class);
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Tue Oct  8 16:02:50 2013
@@ -65,6 +65,7 @@ public final strictfp class ReferencingT
      */
     @BeforeClass
     public static void verifyTestList() {
-        verifyTestList(ReferencingTestSuite.class, BASE_TEST_CLASSES);
+        assertNoMissingTest(ReferencingTestSuite.class);
+        verifyTestList(ReferencingTestSuite.class);
     }
 }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/TestSuite.java [UTF-8]
Tue Oct  8 16:02:50 2013
@@ -16,8 +16,12 @@
  */
 package org.apache.sis.test;
 
-import java.util.Map;
-import java.util.IdentityHashMap;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.HashSet;
+import java.io.File;
+import java.net.URL;
+import java.net.URISyntaxException;
 import org.apache.sis.util.Classes;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
@@ -30,16 +34,16 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.16)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @RunWith(Suite.class)
 public abstract strictfp class TestSuite {
     /**
      * The default set of base classes that all test cases are expected to extends.
-     * This is the usual argument value to the {@link #verifyTestList(Class, Class[])} method.
+     * This is the default argument value for {@link #verifyTestList(Class)} method.
      */
-    protected static final Class<?>[] BASE_TEST_CLASSES = {
+    private static final Class<?>[] BASE_TEST_CLASSES = {
         TestCase.class,
         org.opengis.test.TestCase.class
     };
@@ -51,6 +55,81 @@ public abstract strictfp class TestSuite
     }
 
     /**
+     * Verifies that we did not forgot to declare some test classes in the given suite.
+     * This method scans the directory for {@code *Test.class} files.
+     *
+     * @param suite The suite for which to check for missing tests.
+     */
+    protected static void assertNoMissingTest(final Class<? extends TestSuite> suite)
{
+        final ClassLoader loader = suite.getClassLoader();
+        final URL url = loader.getResource(suite.getName().replace('.', '/') + ".class");
+        assertNotNull("Test suite class not found.", url);
+        File root;
+        try {
+            root = new File(url.toURI());
+        } catch (URISyntaxException | IllegalArgumentException e) {
+            // If not a file, then it is probably an entry in a JAR file.
+            fail(e.toString());
+            return;
+        }
+        for (File c = new File(suite.getName().replace('.', File.separatorChar)); (c = c.getParentFile())
!= null;) {
+            root = root.getParentFile();
+            assertNotNull("Unexpected directory structure.", root);
+            assertEquals("Unexpected directory structure.", c.getName(), root.getName());
+        }
+        /*
+         * At this point, we found the root "org" package. Verifies if we are in the Maven
target directory.
+         * In some IDE configuration, all the ".class" files are in the same directory, in
which case the
+         * verification performed by this method become irrelevant.
+         */
+        if (!new File(root.getParent(), ".." + File.separatorChar + "pom.xml").isFile())
{
+            return;
+        }
+        /*
+         * Now scan all "*Test.class" in the "target/org" directory and and sub-directories,
+         * and fail on the first missing test file if any.
+         */
+        final Set<Class<?>> tests = new HashSet<>(Arrays.asList(suite.getAnnotation(Suite.SuiteClasses.class).value()));
+        removeExistingTests(loader, root, new StringBuilder(120).append(root.getName()),
tests);
+        assertTrue(tests.toString(), tests.isEmpty());
+    }
+
+    /**
+     * Ensures that all tests in the given directory and sub-directories exit in the given
set.
+     * This method invokes itself recursively for scanning the sub-directories.
+     */
+    private static void removeExistingTests(final ClassLoader loader, final File directory,
+            final StringBuilder path, final Set<Class<?>> tests)
+    {
+        final int length = path.append('.').length();
+        for (final File file : directory.listFiles()) {
+            if (!file.isHidden()) {
+                final String name = file.getName();
+                if (!name.startsWith(".")) {
+                    path.append(name);
+                    if (file.isDirectory()) {
+                        removeExistingTests(loader, file, path, tests);
+                    } else {
+                        if (name.endsWith("Test.class")) {
+                            path.setLength(path.length() - 6); // Remove trailing ".class"
+                            final String classname = path.toString();
+                            final Class<?> test;
+                            try {
+                                test = Class.forName(classname, false, loader);
+                            } catch (ClassNotFoundException e) {
+                                fail(e.toString());
+                                return;
+                            }
+                            assertTrue(classname, tests.remove(test));
+                        }
+                    }
+                    path.setLength(length);
+                }
+            }
+        }
+    }
+
+    /**
      * Verifies the list of tests before the suite is run.
      * This method verifies the following conditions:
      *
@@ -65,17 +144,29 @@ public abstract strictfp class TestSuite
      * {@preformat java
      *    &#64;BeforeClass
      *    public static void verifyTestList() {
-     *        verifyTestList(MetadataTestSuite.class, BASE_TEST_CLASSES);
+     *        assertNoMissingTest(MyTestSuite.class);
+     *        verifyTestList(MyTestSuite.class);
      *    }
      * }
      *
-     * @param suite The suite for which to verify order.
+     * @param suite The suite for which to verify test order.
+     */
+    protected static void verifyTestList(final Class<? extends TestSuite> suite) {
+        verifyTestList(suite, BASE_TEST_CLASSES);
+    }
+
+    /**
+     * Same verification than {@link #verifyTestList(Class)}, except that the set of base
classes
+     * is explicitely specified. This method is preferred to {@code verifyTestList(Class)}
only in
+     * the rare cases where some test cases need to extend something else than geoapi-conformance
+     * or Apache SIS test class.
+     *
+     * @param suite The suite for which to verify test order.
      * @param baseTestClasses The set of base classes that all test cases are expected to
extends.
-     *        This is usually {@link #BASE_TEST_CLASSES}.
      */
     protected static void verifyTestList(final Class<? extends TestSuite> suite, final
Class<?>[] baseTestClasses) {
         final Class<?>[] testCases = suite.getAnnotation(Suite.SuiteClasses.class).value();
-        final Map<Class<?>,Boolean> done = new IdentityHashMap<>(testCases.length);
+        final Set<Class<?>> done = new HashSet<>(testCases.length);
         for (final Class<?> testCase : testCases) {
             if (!Classes.isAssignableToAny(testCase, baseTestClasses)) {
                 fail("Class " + testCase.getCanonicalName() + " does not extends TestCase.");
@@ -83,13 +174,13 @@ public abstract strictfp class TestSuite
             final DependsOn dependencies = testCase.getAnnotation(DependsOn.class);
             if (dependencies != null) {
                 for (final Class<?> dependency : dependencies.value()) {
-                    if (!done.containsKey(dependency)) {
+                    if (!done.contains(dependency)) {
                         fail("Class " + testCase.getCanonicalName() + " depends on " + dependency.getCanonicalName()
                                 + ", but the dependency has not been found before the test.");
                     }
                 }
             }
-            if (done.put(testCase, Boolean.TRUE) != null) {
+            if (!done.add(testCase)) {
                 fail("Class " + testCase.getCanonicalName() + " is declared twice.");
             }
         }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Tue Oct  8 16:02:50 2013
@@ -124,6 +124,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.jaxb.gco.StringAdapterTest.class,
     org.apache.sis.internal.jaxb.gco.MeasureTest.class,
     org.apache.sis.internal.jaxb.gco.PropertyTypeTest.class,
+    org.apache.sis.internal.jaxb.gmd.LanguageMarshallingTest.class,
     org.apache.sis.util.iso.NameMarshallingTest.class
 })
 public final strictfp class UtilityTestSuite extends TestSuite {
@@ -133,6 +134,7 @@ public final strictfp class UtilityTestS
      */
     @BeforeClass
     public static void verifyTestList() {
-        verifyTestList(UtilityTestSuite.class, BASE_TEST_CLASSES);
+        assertNoMissingTest(UtilityTestSuite.class);
+        verifyTestList(UtilityTestSuite.class);
     }
 }

Modified: sis/branches/JDK7/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/pom.xml?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/pom.xml (original)
+++ sis/branches/JDK7/pom.xml Tue Oct  8 16:02:50 2013
@@ -438,12 +438,22 @@ Apache SIS is a free software, Java lang
         </configuration>
       </plugin>
 
+      <!-- Execute test suites instead of individual test cases. -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <includes>
+            <include>**/*TestSuite.java</include>
+          </includes>
+        </configuration>
+      </plugin>
+
       <!-- JAR packaging
            Note: <index> and <addClasspath> are mutually exclusive: when both
are enabled,
            the META-INF/INDEX.LIST file has precedence over the "Class-Path" entry in the
            META-INF/MANIFEST.MF file,  thus causing java.lang.NoClassDefFoundError if the
-           INDEX.LIST file is incomplete (which seem to happen in practice).
-      -->
+           INDEX.LIST file is incomplete (which seem to happen in practice). -->
       <plugin>
         <artifactId>maven-jar-plugin</artifactId>
         <configuration>

Modified: sis/branches/JDK7/profiles/sis-french-profile/src/test/java/org/apache/sis/test/suite/FrenchProfileSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/profiles/sis-french-profile/src/test/java/org/apache/sis/test/suite/FrenchProfileSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/profiles/sis-french-profile/src/test/java/org/apache/sis/test/suite/FrenchProfileSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/profiles/sis-french-profile/src/test/java/org/apache/sis/test/suite/FrenchProfileSuite.java
[UTF-8] Tue Oct  8 16:02:50 2013
@@ -41,6 +41,7 @@ public final strictfp class FrenchProfil
      */
     @BeforeClass
     public static void verifyTestList() {
-        verifyTestList(UtilityTestSuite.class, BASE_TEST_CLASSES);
+        assertNoMissingTest(FrenchProfileSuite.class);
+        verifyTestList(FrenchProfileSuite.class);
     }
 }

Modified: sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-netcdf/src/test/java/org/apache/sis/test/suite/NetcdfTestSuite.java
[UTF-8] Tue Oct  8 16:02:50 2013
@@ -50,6 +50,7 @@ public final strictfp class NetcdfTestSu
      */
     @BeforeClass
     public static void verifyTestList() {
+        assertNoMissingTest(NetcdfTestSuite.class);
         verifyTestList(NetcdfTestSuite.class, new Class<?>[] {
             TestCase.class,
             IOTestCase.class

Modified: sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java?rev=1530327&r1=1530326&r2=1530327&view=diff
==============================================================================
--- sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/storage/sis-storage/src/test/java/org/apache/sis/test/suite/StorageTestSuite.java
[UTF-8] Tue Oct  8 16:02:50 2013
@@ -48,6 +48,7 @@ public final strictfp class StorageTestS
      */
     @BeforeClass
     public static void verifyTestList() {
-        verifyTestList(StorageTestSuite.class, BASE_TEST_CLASSES);
+        assertNoMissingTest(StorageTestSuite.class);
+        verifyTestList(StorageTestSuite.class);
     }
 }



Mime
View raw message