SLING-3151 Use OakOnly and JackrabbitOnly JUnit categories in integration tests
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1538994 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 3928651..ac58ab0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git a/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java b/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java
deleted file mode 100644
index 581a28b..0000000
--- a/src/test/java/org/apache/sling/launchpad/testing/LoggingSuite.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.testing;
-
-import junit.framework.Test;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-
-import org.slf4j.Logger;
-
-/**
- * Simple TestSuite subclass which logs when each test is starting.
- */
-class LoggingSuite extends TestSuite {
-
- private Logger logger;
-
- private int lastRuns;
-
- private int lastErrors;
-
- private int lastFailures;
-
- LoggingSuite(String name, Logger logger) {
- super(name);
- this.logger = logger;
- }
-
- @Override
- public void run(TestResult result) {
- // result.addListener(new SlingTestListener());
- super.run(result);
- }
-
- @Override
- public void runTest(Test test, TestResult result) {
- final String name = getName(test);
- final String startMessage = String.format("Running %s", name);
- System.out.println(startMessage);
- logger.info(startMessage);
-
- super.runTest(test, result);
-
- final String endMessage = String.format(
- "Tests run: %d, Failures: %d, Errors: %d, Skipped: %d",
- result.runCount() - lastRuns, result.failureCount() - lastFailures,
- result.errorCount() - lastErrors,
- test.countTestCases() - result.runCount() + lastRuns);
- System.out.println(endMessage);
- logger.info(endMessage);
-
- lastRuns = result.runCount();
- lastFailures = result.failureCount();
- lastErrors = result.errorCount();
- }
-
- private String getName(Test t) {
- return (t instanceof TestSuite) ? ((TestSuite) t).getName() : t.toString();
- }
-
-}
diff --git a/src/test/java/org/apache/sling/launchpad/testing/TestAll.java b/src/test/java/org/apache/sling/launchpad/testing/TestAll.java
deleted file mode 100644
index 17f38ed..0000000
--- a/src/test/java/org/apache/sling/launchpad/testing/TestAll.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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.testing;
-
-import java.io.File;
-import java.io.IOException;
-import java.lang.reflect.Modifier;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.regex.Pattern;
-
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import static org.junit.Assert.fail;
-import org.junit.runner.RunWith;
-import org.junit.runners.AllTests;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/** Collect our tests and run them with our LoggingSuite */
- @RunWith(AllTests.class)
-public class TestAll {
- private static final Logger LOGGER = LoggerFactory.getLogger(TestAll.class);
-
- @SuppressWarnings("unchecked")
- public static TestSuite suite() {
- final ClassLoader sysClassLoader = TestAll.class.getClassLoader();
- final List<String> matchingClasses = new ArrayList<String>();
- // Get the URLs
- final URL[] urls = ((URLClassLoader) sysClassLoader).getURLs();
- final String testPattern = System.getProperty("integrationTestPattern",
- "**/launchpad/*/integrationtest/**/*Test");
- final String testRegex = convertToRegex(testPattern);
- final Pattern pattern = Pattern.compile(testRegex);
- for (URL u : urls) {
- try {
- matchingClasses.addAll(scanFile(new File(u.toURI()), pattern));
- } catch (URISyntaxException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- final TestSuite suite = new LoggingSuite("Sling Integration Tests matching " + testPattern, LOGGER);
- int counter=0;
- for (String classFile : matchingClasses) {
- String className = classFileToName(classFile);
- try {
- final Class<TestCase> c = (Class<TestCase>) sysClassLoader.loadClass(className);
- if (!c.isInterface() && !Modifier.isAbstract(c.getModifiers())) {
- suite.addTest(new JUnit4TestAdapter(c));
- counter++;
- LOGGER.info("Added " + className);
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
-
- if(counter==0) {
- fail("No test classes found in classpath using Pattern " + testRegex);
- }
- LOGGER.info("{} test classes found using Pattern {}", counter, testRegex);
- return suite;
- }
-
- /**
- * @param classFile
- * @return
- */
- private static String classFileToName(String classFile) {
- String className = classFile.substring(0,
- classFile.length() - (".class".length())).replace('/', '.');
- if (className.charAt(0) == '.') {
- className = className.substring(1);
- }
- return className;
- }
-
- /**
- * @param testPattern
- * @return
- */
- private static String convertToRegex(String testPattern) {
- return testPattern.replace("**/", ".a?").replace("*", ".a?").replace(
- ".a?", ".*?").replace("/", "\\/")
- + "\\.class$";
- }
-
- /**
- * @param u
- * @return
- * @throws IOException
- * @throws URISyntaxException
- */
- private static List<String> scanFile(File f, Pattern pattern)
- throws URISyntaxException, IOException {
- List<String> classPathMatches = new ArrayList<String>();
- if (f.isFile()) {
- scanJar(f, pattern, classPathMatches);
- } else {
- scanDir(f, pattern, classPathMatches, f.getPath().length());
- }
- return classPathMatches;
- }
-
- /**
- * @param f
- * @param pattern
- * @return
- */
- private static void scanDir(File f, Pattern pattern,
- List<String> classPathMatches, int trim) {
- if (f.isFile()) {
- String name = f.getPath().substring(trim);
- if (pattern.matcher(name).matches()) {
- classPathMatches.add(name);
- }
- } else {
- for (File cf : f.listFiles()) {
- scanDir(cf, pattern, classPathMatches, trim);
- }
- }
- }
-
- /**
- * @param u
- * @return
- * @throws URISyntaxException
- * @throws IOException
- */
- private static void scanJar(File f, Pattern pattern,
- List<String> classPathMatches) throws URISyntaxException,
- IOException {
- JarFile jarFile = new JarFile(f);
- for (Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements();) {
- JarEntry je = e.nextElement();
- String entryName = je.getName();
- if (pattern.matcher(entryName).matches()) {
- classPathMatches.add(entryName);
- }
- }
- jarFile.close();
- }
-
-}