Repository: tomee
Updated Branches:
  refs/heads/master c27dbf5d9 -> 16f874061


TOMEE-1689 ensuring ear test files can be found using @RunWith as well


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/a33a5ca4
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/a33a5ca4
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/a33a5ca4

Branch: refs/heads/master
Commit: a33a5ca49bf96d835895b4053e81943dcc844865
Parents: c27dbf5
Author: Romain Manni-Bucau <rmannibu...@gmail.com>
Authored: Wed Dec 30 09:30:58 2015 +0100
Committer: Romain Manni-Bucau <rmannibu...@gmail.com>
Committed: Wed Dec 30 09:30:58 2015 +0100

----------------------------------------------------------------------
 .../openejb/arquillian/common/Discover.java     | 32 ++++++++++++++++++++
 .../apache/openejb/arquillian/common/Setup.java |  2 +-
 .../arquillian/common/TestClassDiscoverer.java  | 32 ++++++++++++++++----
 3 files changed, 59 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/a33a5ca4/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Discover.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Discover.java
 
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Discover.java
new file mode 100644
index 0000000..5b49912
--- /dev/null
+++ 
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Discover.java
@@ -0,0 +1,32 @@
+/*
+ * 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.openejb.arquillian.common;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Used to mark a class as a potential test in arquillian.
+ * Useful when the test class is not found by itself (see TestClassDiscover 
logic).
+ */
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface Discover {
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/a33a5ca4/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
 
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
index c390190..1d67531 100644
--- 
a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
+++ 
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
@@ -349,7 +349,7 @@ public class Setup {
     public static void installArquillianBeanDiscoverer(final File home) {
         final File destination = new File(home, TOMEE_BEAN_DISCOVERER_JAR);
         ShrinkWrap.create(JavaArchive.class, destination.getName())
-                .addClasses(BeanDicovererInstaller.class, 
TestClassDiscoverer.class, ArquillianFilterRunner.class)
+                .addClasses(BeanDicovererInstaller.class, 
TestClassDiscoverer.class, ArquillianFilterRunner.class, Discover.class)
                 .addAsManifestResource(new 
StringAsset(BeanDicovererInstaller.class.getName()), 
ArchivePaths.create("org.apache.openejb.extension"))
                 .as(ZipExporter.class).exportTo(destination, false);
     }

http://git-wip-us.apache.org/repos/asf/tomee/blob/a33a5ca4/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
----------------------------------------------------------------------
diff --git 
a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
 
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
index 12021e1..818b2de 100644
--- 
a/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
+++ 
b/arquillian/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TestClassDiscoverer.java
@@ -53,13 +53,13 @@ public class TestClassDiscoverer implements 
AdditionalBeanDiscoverer {
         final Map<Class<?>, WebModule> webTestClasses = new HashMap<>();
         final Set<ClassLoader> saw = new HashSet<>();
         if (module.getClassLoader() != null) {
-            addTests(findMarkers(module.getClassLoader()), 
module.getEarLibFinder(), testClasses);
+            addTests(findMarkers(module.getClassLoader()), 
findClassMarkers(module.getClassLoader()), module.getEarLibFinder(), 
testClasses);
             saw.add(module.getClassLoader());
         }
         for (final WebModule web : module.getWebModules()) {
             if (web.getClassLoader() != null && 
!saw.contains(web.getClassLoader())) {
-                final Set<Class<?>> classes = new HashSet<Class<?>>();
-                addTests(findMarkers(web.getClassLoader()), web.getFinder(), 
classes);
+                final Set<Class<?>> classes = new HashSet<>();
+                addTests(findMarkers(web.getClassLoader()), 
findClassMarkers(web.getClassLoader()), web.getFinder(), classes);
                 saw.add(web.getClassLoader());
                 for (final Class<?> c : classes) {
                     webTestClasses.put(c, web);
@@ -82,13 +82,13 @@ public class TestClassDiscoverer implements 
AdditionalBeanDiscoverer {
         }
         for (final EjbModule ejb : module.getEjbModules()) {
             if (ejb.getClassLoader() != null && 
!saw.contains(ejb.getClassLoader())) {
-                addTests(findMarkers(ejb.getClassLoader()), ejb.getFinder(), 
testClasses);
+                addTests(findMarkers(ejb.getClassLoader()), 
findClassMarkers(ejb.getClassLoader()), ejb.getFinder(), testClasses);
                 saw.add(ejb.getClassLoader());
             }
         }
         for (final ConnectorModule connector : module.getConnectorModules()) {
             if (connector.getClassLoader() != null && 
!saw.contains(connector.getClassLoader())) {
-                addTests(findMarkers(connector.getClassLoader()), 
connector.getFinder(), testClasses);
+                addTests(findMarkers(connector.getClassLoader()), 
findClassMarkers(connector.getClassLoader()), connector.getFinder(), 
testClasses);
                 saw.add(connector.getClassLoader());
             }
         }
@@ -177,6 +177,18 @@ public class TestClassDiscoverer implements 
AdditionalBeanDiscoverer {
         return module;
     }
 
+    private Set<Class<? extends Annotation>> findClassMarkers(final 
ClassLoader contextClassLoader) {
+        final Set<Class<? extends Annotation>> testMarkers = new HashSet<>();
+        for (final String s : asList("org.junit.runner.RunWith", 
Discover.class.getName())) {
+            try {
+                testMarkers.add((Class<? extends Annotation>) 
contextClassLoader.loadClass(s));
+            } catch (final Throwable e) {
+                // no-op
+            }
+        }
+        return testMarkers;
+    }
+
     private Set<Class<? extends Annotation>> findMarkers(final ClassLoader 
contextClassLoader) {
         final Set<Class<? extends Annotation>> testMarkers = new HashSet<>();
         for (final String s : asList("org.junit.Test", 
"org.testng.annotations.Test")) {
@@ -189,7 +201,8 @@ public class TestClassDiscoverer implements 
AdditionalBeanDiscoverer {
         return testMarkers;
     }
 
-    private static void addTests(final Set<Class<? extends Annotation>> 
testMarkers, final IAnnotationFinder finder, final Set<Class<?>> testClasses) {
+    private static void addTests(final Set<Class<? extends Annotation>> 
testMarkers, final Set<Class<? extends Annotation>> classMarkers,
+                                 final IAnnotationFinder finder, final 
Set<Class<?>> testClasses) {
         if (finder == null) {
             return;
         }
@@ -207,6 +220,13 @@ public class TestClassDiscoverer implements 
AdditionalBeanDiscoverer {
                 // no-op
             }
         }
+        for (final Class<? extends Annotation> marker : classMarkers) {
+            try {
+                testClasses.addAll(finder.findAnnotatedClasses(marker));
+            } catch (final NoClassDefFoundError ncdfe) {
+                // no-op
+            }
+        }
     }
 
     private String findTestName(final File folder, final ClassLoader 
classLoader) {

Reply via email to