tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1405748 - in /openejb/trunk/openejb: container/openejb-core/src/main/java/org/apache/openejb/junit/ server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/
Date Mon, 05 Nov 2012 11:23:58 GMT
Author: rmannibucau
Date: Mon Nov  5 11:23:58 2012
New Revision: 1405748

URL: http://svn.apache.org/viewvc?rev=1405748&view=rev
Log:
allowing webapp from applicationcomposer and @Classes to create the finder on the fly

Added:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Classes.java
      - copied, changed from r1405723, openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java
Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
    openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java?rev=1405748&r1=1405747&r2=1405748&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
Mon Nov  5 11:23:58 2012
@@ -44,6 +44,7 @@ import org.apache.openejb.jee.Enterprise
 import org.apache.openejb.jee.ManagedBean;
 import org.apache.openejb.jee.NamedModule;
 import org.apache.openejb.jee.TransactionType;
+import org.apache.openejb.jee.WebApp;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.apache.openejb.jee.oejb3.EjbDeployment;
@@ -140,6 +141,14 @@ public class ApplicationComposer extends
             }
         }
 
+        for (FrameworkMethod method : testClass.getAnnotatedMethods(Classes.class)) {
+            final Class<?> returnType = method.getMethod().getReturnType();
+            if (!returnType.equals(WebModule.class) && !returnType.equals(EjbModule.class)
+                    && !returnType.equals(WebApp.class) && !returnType.equals(EjbJar.class))
{
+                errors.add(new Exception("@Classes can't be used on a method returning "
+ returnType));
+            }
+        }
+
         int appModules = 0;
         int modules = 0;
 
@@ -285,19 +294,43 @@ public class ApplicationComposer extends
             for (FrameworkMethod method : testClass.getAnnotatedMethods(Module.class)) {
 
                 final Object obj = method.invokeExplosively(testInstance);
+                final Classes classesAnnotation = method.getAnnotation(Classes.class);
 
-                if (obj instanceof WebModule) { // will add the ejbmodule too
-                    DeploymentLoader.addWebModule((WebModule) obj, appModule);
+                if (obj instanceof WebApp) { // will add the ejbmodule too
+                    final WebApp webapp = (WebApp) obj;
+                    String root = webapp.getContextRoot();
+                    if (root == null) {
+                        root = "/openejb";
+                    }
+
+                    final WebModule webModule = new WebModule(webapp, root, Thread.currentThread().getContextClassLoader(),
"", root);
+                    if (classesAnnotation != null) {
+                        webModule.setFinder(finderFromClasses(classesAnnotation.value()));
+                    }
+                    DeploymentLoader.addWebModule(webModule, appModule);
+                } else if (obj instanceof WebModule) { // will add the ejbmodule too
+                    final WebModule webModule = (WebModule) obj;
+                    if (classesAnnotation != null) {
+                        webModule.setFinder(finderFromClasses(classesAnnotation.value()));
+                    }
+                    DeploymentLoader.addWebModule(webModule, appModule);
                 } else if (obj instanceof EjbModule) {
                     final EjbModule ejbModule = (EjbModule) obj;
+                    if (classesAnnotation != null) {
+                        ejbModule.setFinder(finderFromClasses(classesAnnotation.value()));
+                    }
                     ejbModule.initAppModule(appModule);
                     appModule.getEjbModules().add(ejbModule);
                 } else if (obj instanceof EjbJar) {
 
                     final EjbJar ejbJar = (EjbJar) obj;
                     setId(ejbJar, method);
-                    appModule.getEjbModules().add(new EjbModule(ejbJar));
 
+                    final EjbModule ejbModule = new EjbModule(ejbJar);
+                    appModule.getEjbModules().add(ejbModule);
+                    if (classesAnnotation != null) {
+                        ejbModule.setFinder(finderFromClasses(classesAnnotation.value()));
+                    }
                 } else if (obj instanceof EnterpriseBean) {
 
                     final EnterpriseBean bean = (EnterpriseBean) obj;
@@ -334,6 +367,9 @@ public class ApplicationComposer extends
                     final Beans beans = (Beans) obj;
                     final EjbModule ejbModule = new EjbModule(new EjbJar(method.getName()));
                     ejbModule.setBeans(beans);
+                    if (classesAnnotation != null) {
+                        ejbModule.setFinder(finderFromClasses(classesAnnotation.value()));
+                    }
                     appModule.getEjbModules().add(ejbModule);
 
                 } else if (obj instanceof Class[]) {
@@ -509,4 +545,8 @@ public class ApplicationComposer extends
             return module;
         }
     }
+
+    private static IAnnotationFinder finderFromClasses(final Class<?>[] value) {
+        return new AnnotationFinder(new ClassesArchive(value)).link();
+    }
 }

Copied: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Classes.java
(from r1405723, openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java)
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Classes.java?p2=openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Classes.java&p1=openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java&r1=1405723&r2=1405748&rev=1405748&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Module.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/Classes.java
Mon Nov  5 11:23:58 2012
@@ -23,5 +23,6 @@ import java.lang.annotation.Target;
 
 @Target(ElementType.METHOD)
 @Retention(RetentionPolicy.RUNTIME)
-public @interface Module {
+public @interface Classes {
+    Class<?>[] value() default {};
 }

Modified: openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java?rev=1405748&r1=1405747&r2=1405748&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java
(original)
+++ openejb/trunk/openejb/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/SimpleApplicationTest.java
Mon Nov  5 11:23:58 2012
@@ -20,8 +20,11 @@ import org.apache.cxf.jaxrs.client.WebCl
 import org.apache.openejb.OpenEjbContainer;
 import org.apache.openejb.assembler.classic.WebAppBuilder;
 import org.apache.openejb.config.WebModule;
+import org.apache.openejb.jee.ParamValue;
+import org.apache.openejb.jee.Servlet;
 import org.apache.openejb.jee.WebApp;
 import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Classes;
 import org.apache.openejb.junit.Component;
 import org.apache.openejb.junit.Configuration;
 import org.apache.openejb.junit.Module;
@@ -35,6 +38,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Response;
 import java.io.InputStream;
 import java.io.StringWriter;
@@ -59,11 +63,22 @@ public class SimpleApplicationTest {
     }
 
     @Module
-    public WebModule war() {
-        final WebModule webModule = new WebModule(new WebApp(), "/foo", Thread.currentThread().getContextClassLoader(),
"", "foo");
-        webModule.getRestApplications().add(MyRESTApplication.class.getName());
-        webModule.setFinder(new AnnotationFinder(new ClassesArchive(RestWithInjections.class,
SimpleEJB.class)));
-        return webModule;
+    @Classes({ RestWithInjections.class, SimpleEJB.class })
+    public WebApp war() {
+        final ParamValue config = new ParamValue();
+        config.setParamName("javax.ws.rs.Application");
+        config.setParamValue(MyRESTApplication.class.getName());
+
+        final Servlet servlet = new Servlet();
+        servlet.setServletName("REST Application");
+        servlet.setServletClass(Application.class.getName());
+        servlet.getInitParam().add(config);
+
+        final WebApp webApp = new WebApp();
+        webApp.setContextRoot("foo");
+        webApp.getServlet().add(servlet);
+
+        return webApp;
     }
 
     @Test



Mime
View raw message