You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2015/07/08 18:22:11 UTC
karaf git commit: Add rules to ignore tests that are not supported on
JDK 8
Repository: karaf
Updated Branches:
refs/heads/master 352ec82e0 -> 96f9b6c25
Add rules to ignore tests that are not supported on JDK 8
Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/96f9b6c2
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/96f9b6c2
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/96f9b6c2
Branch: refs/heads/master
Commit: 96f9b6c2503df7cdd01b37bf4f5bf181ede794fa
Parents: 352ec82
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Jul 8 18:22:02 2015 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Jul 8 18:22:02 2015 +0200
----------------------------------------------------------------------
.../itests/features/EnterpriseFeaturesTest.java | 8 ++
.../itests/features/PaxCdiFeaturesTest.java | 13 +++
.../org/apache/karaf/itests/util/RunIfRule.java | 109 +++++++++++++++++++
.../apache/karaf/itests/util/RunIfRules.java | 40 +++++++
4 files changed, 170 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf/blob/96f9b6c2/itests/src/test/java/org/apache/karaf/itests/features/EnterpriseFeaturesTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/features/EnterpriseFeaturesTest.java b/itests/src/test/java/org/apache/karaf/itests/features/EnterpriseFeaturesTest.java
index a38ea86..a17587a 100644
--- a/itests/src/test/java/org/apache/karaf/itests/features/EnterpriseFeaturesTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/features/EnterpriseFeaturesTest.java
@@ -14,6 +14,9 @@
package org.apache.karaf.itests.features;
import org.apache.karaf.itests.KarafTestSupport;
+import org.apache.karaf.itests.util.RunIfRules.RunIfNotOnJdk8;
+import org.apache.karaf.itests.util.RunIfRule;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
@@ -24,6 +27,9 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
@ExamReactorStrategy(PerClass.class)
public class EnterpriseFeaturesTest extends KarafTestSupport {
+ @Rule
+ public RunIfRule rule = new RunIfRule();
+
@Test
public void installTransaction100Feature() throws Exception {
installAssertAndUninstallFeature("transaction", "1.0.0");
@@ -55,11 +61,13 @@ public class EnterpriseFeaturesTest extends KarafTestSupport {
}
@Test
+ @RunIfNotOnJdk8
public void installOpenJpa222Feature() throws Exception {
installAssertAndUninstallFeature("openjpa", "2.2.2");
}
@Test
+ @RunIfNotOnJdk8
public void installOpenJpa230Feature() throws Exception {
installAssertAndUninstallFeature("openjpa", "2.3.0");
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/96f9b6c2/itests/src/test/java/org/apache/karaf/itests/features/PaxCdiFeaturesTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/features/PaxCdiFeaturesTest.java b/itests/src/test/java/org/apache/karaf/itests/features/PaxCdiFeaturesTest.java
index f3c8ffe..c61e9aa 100644
--- a/itests/src/test/java/org/apache/karaf/itests/features/PaxCdiFeaturesTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/features/PaxCdiFeaturesTest.java
@@ -14,7 +14,10 @@
package org.apache.karaf.itests.features;
import org.apache.karaf.itests.KarafTestSupport;
+import org.apache.karaf.itests.util.RunIfRule;
+import org.apache.karaf.itests.util.RunIfRules.RunIfNotOnJdk8;
import org.junit.Ignore;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.PaxExam;
@@ -25,6 +28,9 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
@ExamReactorStrategy(PerClass.class)
public class PaxCdiFeaturesTest extends KarafTestSupport {
+ @Rule
+ public RunIfRule rule = new RunIfRule();
+
@Test
public void installPaxCdiFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi");
@@ -62,37 +68,44 @@ public class PaxCdiFeaturesTest extends KarafTestSupport {
}
@Test
+ @RunIfNotOnJdk8
public void installPaxCdiWebFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi-web");
}
@Test
+ @RunIfNotOnJdk8
public void installPaxCdi11WebFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi-1.1-web");
}
@Test
+ @RunIfNotOnJdk8
public void installPaxCdi12WebFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi-1.2-web");
}
@Test
+ @RunIfNotOnJdk8
public void installPaxCdiWebWeldFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi-web-weld");
}
@Test
+ @RunIfNotOnJdk8
public void installPaxCdi11WebWeldFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi-1.1-web-weld");
}
@Test
@Ignore
+ @RunIfNotOnJdk8
public void installPaxCdi12WebWeldFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi-1.2-web-weld");
}
@Test
+ @RunIfNotOnJdk8
public void installPaxCdiWebOpenwebbeansFeature() throws Exception {
installAssertAndUninstallFeatures("pax-cdi-web-openwebbeans");
}
http://git-wip-us.apache.org/repos/asf/karaf/blob/96f9b6c2/itests/src/test/java/org/apache/karaf/itests/util/RunIfRule.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/util/RunIfRule.java b/itests/src/test/java/org/apache/karaf/itests/util/RunIfRule.java
new file mode 100644
index 0000000..f0befa0
--- /dev/null
+++ b/itests/src/test/java/org/apache/karaf/itests/util/RunIfRule.java
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.karaf.itests.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Assume;
+import org.junit.rules.MethodRule;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+public class RunIfRule implements MethodRule {
+
+ public interface RunIfCondition {
+ boolean isSatisfied();
+ }
+
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
+ @Inherited
+ public @interface RunIf {
+ Class<? extends RunIfCondition> condition();
+ }
+
+ public Statement apply(Statement base, FrameworkMethod method, Object target) {
+ List<RunIf> ignores = findRunIfs(method.getAnnotations(), new ArrayList<RunIf>(), new HashSet<Class>());
+ if (ignores.isEmpty()) {
+ return base;
+ }
+ for (RunIf ignore : ignores) {
+ RunIfCondition condition = newCondition(ignore, target);
+ if (!condition.isSatisfied()) {
+ return new IgnoreStatement(condition);
+ }
+ }
+ return base;
+ }
+
+ private List<RunIf> findRunIfs(Annotation[] annotations, List<RunIf> ignores, Set<Class> tested) {
+ for (Annotation annotation : annotations) {
+ if (tested.add(annotation.getClass())) {
+ if (annotation instanceof RunIf) {
+ ignores.add((RunIf) annotation);
+ } else {
+ findRunIfs(annotation.getClass().getAnnotations(), ignores, tested);
+ for (Class cl : annotation.getClass().getInterfaces()) {
+ findRunIfs(cl.getAnnotations(), ignores, tested);
+ }
+ }
+ }
+ }
+ return ignores;
+ }
+
+ private RunIfCondition newCondition(RunIf annotation, Object instance) {
+ final Class<? extends RunIfCondition> cond = annotation.condition();
+ try {
+ if (cond.isMemberClass()) {
+ if (Modifier.isStatic(cond.getModifiers())) {
+ return cond.getDeclaredConstructor(new Class<?>[]{}).newInstance();
+ } else if (instance != null && instance.getClass().isAssignableFrom(cond.getDeclaringClass())) {
+ return cond.getDeclaredConstructor(new Class<?>[]{instance.getClass()}).newInstance(instance);
+ }
+ throw new IllegalArgumentException("Unable to instanciate " + cond.getClass().getName());
+ } else {
+ return cond.newInstance();
+ }
+ } catch (RuntimeException re) {
+ throw re;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static class IgnoreStatement extends Statement {
+ private RunIfCondition condition;
+
+ IgnoreStatement(RunIfCondition condition) {
+ this.condition = condition;
+ }
+
+ @Override
+ public void evaluate() {
+ Assume.assumeTrue("Ignored by " + condition.getClass().getSimpleName(), false);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf/blob/96f9b6c2/itests/src/test/java/org/apache/karaf/itests/util/RunIfRules.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/util/RunIfRules.java b/itests/src/test/java/org/apache/karaf/itests/util/RunIfRules.java
new file mode 100644
index 0000000..35c253b
--- /dev/null
+++ b/itests/src/test/java/org/apache/karaf/itests/util/RunIfRules.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.karaf.itests.util;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import org.apache.karaf.itests.util.RunIfRule.RunIf;
+import org.apache.karaf.itests.util.RunIfRule.RunIfCondition;
+
+public class RunIfRules {
+
+ @RunIf(condition = RunIfNotOnJdk8Condition.class)
+ @Retention(RetentionPolicy.RUNTIME)
+ @Inherited
+ public @interface RunIfNotOnJdk8 {
+
+ }
+
+ public static class RunIfNotOnJdk8Condition implements RunIfCondition {
+ @Override
+ public boolean isSatisfied() {
+ String jdk = System.getProperty("java.specification.version");
+ return jdk.equals("1.5") || jdk.equals("1.6") || jdk.equals("1.7");
+ }
+ }
+
+}