You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/11/05 14:25:06 UTC

svn commit: r1538994 - in /sling/trunk: bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/ launchpad/integration-tests/ launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ l...

Author: bdelacretaz
Date: Tue Nov  5 13:25:06 2013
New Revision: 1538994

URL: http://svn.apache.org/r1538994
Log:
SLING-3151 Use OakOnly and JackrabbitOnly JUnit categories in integration tests

Added:
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/JackrabbitOnly.java
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/OakOnly.java
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JUnitCategoriesTest.java
Removed:
    sling/trunk/launchpad/testing/src/test/java/
Modified:
    sling/trunk/launchpad/integration-tests/pom.xml
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RepositoryNameTest.java
    sling/trunk/launchpad/testing/pom.xml

Added: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/JackrabbitOnly.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/JackrabbitOnly.java?rev=1538994&view=auto
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/JackrabbitOnly.java (added)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/JackrabbitOnly.java Tue Nov  5 13:25:06 2013
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.sling.commons.testing.junit.categories;
+
+/** JUnit Category for tests that run on Jackrabbit only */
+public interface JackrabbitOnly {
+}
\ No newline at end of file

Added: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/OakOnly.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/OakOnly.java?rev=1538994&view=auto
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/OakOnly.java (added)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/junit/categories/OakOnly.java Tue Nov  5 13:25:06 2013
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.sling.commons.testing.junit.categories;
+
+/** JUnit Category for tests that run on Oak only */
+public interface OakOnly {    
+}
\ No newline at end of file

Modified: sling/trunk/launchpad/integration-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/pom.xml?rev=1538994&r1=1538993&r2=1538994&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/pom.xml (original)
+++ sling/trunk/launchpad/integration-tests/pom.xml Tue Nov  5 13:25:06 2013
@@ -74,6 +74,7 @@
           <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-surefire-plugin</artifactId>
+            <version>2.16</version>
             <configuration>
               <testClassesDirectory>${project.build.outputDirectory}</testClassesDirectory>
               <systemProperties>
@@ -104,6 +105,47 @@
         </plugins>
       </build>
     </profile>
+    <profile>
+        <id>jackrabbit</id>
+        <activation>
+            <activeByDefault>true</activeByDefault>
+            <property>
+                <name>sling.run.modes</name>
+                <value>!oak</value>
+            </property>
+        </activation>
+        <build>
+            <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-surefire-plugin</artifactId>
+                    <configuration>
+                        <excludedGroups>org.apache.sling.commons.testing.junit.categories.OakOnly</excludedGroups>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </build>
+    </profile>
+    <profile>
+        <id>oak</id>
+        <activation>
+            <property>
+                <name>sling.run.modes</name>
+                <value>oak</value>
+            </property>
+        </activation>
+        <build>
+            <plugins>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-surefire-plugin</artifactId>
+                    <configuration>
+                        <excludedGroups>org.apache.sling.commons.testing.junit.categories.JackrabbitOnly</excludedGroups>
+                    </configuration>
+                </plugin>
+            </plugins>
+        </build>
+    </profile>
   </profiles>
 
   <dependencies>

Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JUnitCategoriesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JUnitCategoriesTest.java?rev=1538994&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JUnitCategoriesTest.java (added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JUnitCategoriesTest.java Tue Nov  5 13:25:06 2013
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.sling.launchpad.webapp.integrationtest;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.commons.testing.junit.categories.JackrabbitOnly;
+import org.apache.sling.commons.testing.junit.categories.OakOnly;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/** Verify the our JUnit categories are set up correctly */
+public class JUnitCategoriesTest {
+    private static final Logger log = LoggerFactory.getLogger(JUnitCategoriesTest.class);
+    private static final List<String> executedTests = new ArrayList<String>();
+    
+    @BeforeClass
+    public static void clearExecutedTests() {
+        executedTests.clear();
+    }
+    
+    @AfterClass
+    public static void checkExecutedTests() {
+        if(executedTests.size() < 1) {
+            fail("At least one of the Jackrabbit/Oak test categories should be active");
+        } else if(executedTests.size() > 1) {
+            fail("Only one of the Jackrabbit/Oak test category should be active:" + executedTests);
+        }
+        log.info("JUnit categories are set up correctly:" + executedTests);
+    }
+    
+    @Category(JackrabbitOnly.class)
+    @Test
+    public void jackrabbitTest() {
+        executedTests.add("Jackrabbit-only test was executed");
+    }
+    
+    @Category(OakOnly.class)
+    @Test
+    public void oakTest() {
+        executedTests.add("Oak-only test was executed");
+    }
+}
\ No newline at end of file

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RepositoryNameTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RepositoryNameTest.java?rev=1538994&r1=1538993&r2=1538994&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RepositoryNameTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/RepositoryNameTest.java Tue Nov  5 13:25:06 2013
@@ -16,40 +16,49 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
-import java.util.HashMap;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
 
 import org.apache.sling.commons.json.JSONObject;
-import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.commons.testing.junit.categories.JackrabbitOnly;
+import org.apache.sling.commons.testing.junit.categories.OakOnly;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 /** Verify the repository name, to make sure we're testing the right one */
-public class RepositoryNameTest extends HttpTestBase {
-    
-    /** We use the same property that Sling uses to switch between repositories */
-    public static final String RUN_MODE_PROP = "sling.run.modes";
-    public static final String DEFAULT_RUN_MODE = "jackrabbit";
+public class RepositoryNameTest {
+
+    private final HttpTest H = new HttpTest();
     
-    public static final Map<String, String> RUNMODE_TO_NAME = new HashMap<String, String>();
+    @Before
+    public void setup() throws Exception {
+        H.setUp();
+    }
     
-    static {
-        RUNMODE_TO_NAME.put("jackrabbit", "Jackrabbit");
-        RUNMODE_TO_NAME.put("oak", "Apache Jackrabbit Oak");
+    @After
+    public void cleanup() throws Exception {
+        H.tearDown();
     }
     
-    public void testName() throws Exception {
-        final String runMode = System.getProperty(RUN_MODE_PROP, DEFAULT_RUN_MODE);
-        final String expectedName = RUNMODE_TO_NAME.get(runMode);
-        assertNotNull("Expecting to have a repository name for run mode " + runMode, expectedName);
-        
+    private void assertRepositoryName(String expectedName) throws Exception {
         final String path = "/testing/RepositoryDescriptors.json";
-        final JSONObject json = new JSONObject(getContent(HTTP_BASE_URL + path, CONTENT_TYPE_JSON));
+        final JSONObject json = new JSONObject(H.getContent(HttpTest.HTTP_BASE_URL + path, HttpTest.CONTENT_TYPE_JSON));
         final String key = "jcr.repository.name";
         final String actualName = json.getJSONObject("descriptors").getString(key);
-        if(!expectedName.equals(actualName)) {
-            fail(
-                "Repository descriptor '" + key + "' value '" + actualName + "' does not match expected value '" + expectedName + "'. "
-                + "Note that this test uses the " + RUN_MODE_PROP + " system property to select the expected value."
-            );
-        }
+        assertEquals("Expecting the correct value for " + key, expectedName, actualName);
+    }
+    
+    @Category(JackrabbitOnly.class)
+    @Test
+    public void checkJackrabbitName() throws Exception {
+        assertRepositoryName("Jackrabbit");
+    }
+    
+    @Category(OakOnly.class)
+    @Test
+    public void checkOakName() throws Exception {
+        assertRepositoryName("Apache Jackrabbit Oak");
     }
-}
+}
\ No newline at end of file

Modified: sling/trunk/launchpad/testing/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/pom.xml?rev=1538994&r1=1538993&r2=1538994&view=diff
==============================================================================
--- sling/trunk/launchpad/testing/pom.xml (original)
+++ sling/trunk/launchpad/testing/pom.xml Tue Nov  5 13:25:06 2013
@@ -218,58 +218,31 @@
             <build>
                 <plugins>
                     <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-surefire-plugin</artifactId>
+                        <artifactId>maven-failsafe-plugin</artifactId>
+                        <version>2.16</version>
                         <executions>
                             <execution>
-                                <id>surefire-integration-test</id>
-                                <phase>integration-test</phase>
                                 <goals>
-                                    <goal>test</goal>
+                                    <goal>integration-test</goal>
+                                    <goal>verify</goal>
                                 </goals>
-                                <configuration>
-                                    <!--  needed to make it possible to scan the jar -->
-                                    <useManifestOnlyJar>false</useManifestOnlyJar>
-                                
-                                    <excludes>
-                                        <exclude>none</exclude>
-                                    </excludes>
-                                    <includes>
-                                        <include>
-                                            **/launchpad/testing/TestAll.java
-                                        </include>
-                                    </includes>
-                                    <systemProperties>
-                                        <!--
-                                            WARNING: make sure these URLs are consistent with the
-                                            maven-launchpad-plugin settings below.
-                                        -->
-                                        <property>
-                                            <name>
-                                                launchpad.http.server.url
-                                            </name>
-                                            <value>
-                                                http://${test.host}:${http.port}/
-                                            </value>
-                                        </property>
-                                        <property>
-                                            <name>
-                                                launchpad.webdav.server.url
-                                            </name>
-                                            <value>
-                                                http://${test.host}:${http.port}/${webdav.workspace.path}
-                                            </value>
-                                        </property>
-                                        <property>
-                                            <name>HttpTestBase.readyTimeoutSeconds</name>
-                                            <value>
-                                                ${HttpTestBase.readyTimeoutSeconds}
-                                            </value>
-                                        </property>
-                                    </systemProperties>
-                                </configuration>
                             </execution>
                         </executions>
+                        <configuration>
+                            <dependenciesToScan>
+                                <dependency>org.apache.sling:org.apache.sling.launchpad.integration-tests</dependency>
+                            </dependenciesToScan>
+                            <includes>
+                                <include>**/*Test.java</include>
+                                <include>**/*IT.java</include>
+                            </includes>
+                            <excludedGroups>${sling.it.excludedGroups}</excludedGroups>
+                            <systemPropertyVariables>
+                                <launchpad.http.server.url>http://${test.host}:${http.port}/</launchpad.http.server.url>
+                                <launchpad.webdav.server.url>http://${test.host}:${http.port}/${webdav.workspace.path}</launchpad.webdav.server.url>
+                                <HttpTestBase.readyTimeoutSeconds>${HttpTestBase.readyTimeoutSeconds}</HttpTestBase.readyTimeoutSeconds>
+                            </systemPropertyVariables>
+                        </configuration>
                     </plugin>
                     <plugin>
                         <groupId>org.apache.sling</groupId>
@@ -299,34 +272,29 @@
             </build>
         </profile>
         <profile>
-            <!--
-                By default, do not run the integration tests in the test phase, as they have
-                no Sling instance to talk to.
-            -->
-            <id>disableIntegrationTestsInTestPhase</id>
+            <id>jackrabbit</id>
             <activation>
+                <activeByDefault>true</activeByDefault>
                 <property>
-                    <name>!maven.test.skip</name>
+                    <name>sling.run.modes</name>
+                    <value>!oak</value>
                 </property>
             </activation>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-surefire-plugin</artifactId>
-                        <configuration>
-                            <excludes>
-                                <exclude>
-                                    ${integration.test.code.path}/**/*.java
-                                </exclude>
-                                <exclude>
-                                     **/launchpad/testing/TestAll.java
-                                </exclude>
-                            </excludes>
-                        </configuration>
-                    </plugin>
-                </plugins>
-            </build>
+            <properties>
+                <sling.it.excludedGroups>org.apache.sling.commons.testing.junit.categories.OakOnly</sling.it.excludedGroups>
+            </properties>
+        </profile>
+        <profile>
+            <id>oak</id>
+            <activation>
+                <property>
+                    <name>sling.run.modes</name>
+                    <value>oak</value>
+                </property>
+            </activation>
+            <properties>
+                <sling.it.excludedGroups>org.apache.sling.commons.testing.junit.categories.JackrabbitOnly</sling.it.excludedGroups>
+            </properties>
         </profile>
         <profile>
             <id>pax-web</id>
@@ -509,6 +477,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+          <groupId>junit</groupId>
+          <artifactId>junit</artifactId>
+          <version>4.11</version>
+          <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>test</scope>