SLING-4819 allow to undeploy bundles optionally after execution of IT
authorKonrad Windszus <kwin@apache.org>
Thu, 17 Sep 2015 07:16:01 +0000 (07:16 +0000)
committerKonrad Windszus <kwin@apache.org>
Thu, 17 Sep 2015 07:16:01 +0000 (07:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1703505 13f79535-47bb-0310-9956-ffa450edef68

src/main/java/org/apache/sling/junit/remote/testrunner/SlingRemoteTestRunner.java
src/main/java/org/apache/sling/junit/remote/testrunner/package-info.java [new file with mode: 0644]

index a352436..7bdf4d8 100644 (file)
@@ -26,12 +26,17 @@ import org.apache.sling.junit.remote.httpclient.RemoteTestHttpClient;
 import org.apache.sling.testing.tools.http.RequestCustomizer;
 import org.apache.sling.testing.tools.http.RequestExecutor;
 import org.apache.sling.testing.tools.sling.SlingTestBase;
+import org.junit.After;
 import org.junit.internal.AssumptionViolatedException;
 import org.junit.internal.runners.model.EachTestNotifier;
+import org.junit.internal.runners.model.MultipleFailureException;
+import org.junit.internal.runners.statements.RunAfters;
 import org.junit.runner.Description;
 import org.junit.runner.notification.RunNotifier;
 import org.junit.runners.ParentRunner;
+import org.junit.runners.model.FrameworkMethod;
 import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.Statement;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -163,4 +168,27 @@ public class SlingRemoteTestRunner extends ParentRunner<SlingRemoteTest> {
             eachNotifier.fireTestFinished();
         }
     }
+
+    /**
+     * Similar to {@link ParentRunner#classBlock} but will call the methods annotated with @After in addition.
+     */
+    @Override
+    protected Statement classBlock(RunNotifier notifier) {
+        Statement statement = childrenInvoker(notifier);
+        statement = withBeforeClasses(statement);
+        // call @After class in addition
+        statement = withAfter(statement);
+        statement = withAfterClasses(statement);
+        return statement;
+    }
+    
+    /**
+     * Returns a {@link Statement}: run all non-overridden {@code @After} methods on this class and superclasses after
+     * executing {@code statement}; all After methods are always executed: exceptions thrown by previous steps are
+     * combined, if necessary, with exceptions from After methods into a {@link MultipleFailureException}.
+     */
+    private Statement withAfter(Statement statement) {
+        List<FrameworkMethod> afters = getTestClass().getAnnotatedMethods(After.class);
+        return afters.isEmpty() ? statement : new RunAfters(statement, afters, testParameters);
+    }
 }
diff --git a/src/main/java/org/apache/sling/junit/remote/testrunner/package-info.java b/src/main/java/org/apache/sling/junit/remote/testrunner/package-info.java
new file mode 100644 (file)
index 0000000..0c4853d
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+@Version("1.1.0")
+package org.apache.sling.junit.remote.testrunner;
+
+import aQute.bnd.annotation.Version;
+