tomee-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1405751&view=rev
Log:
some sugar to create WebApp (better integration with ApplicationComposer)

Modified:
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/junit/ApplicationComposer.java
    openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/WebApp.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=1405751&r1=1405750&r2=1405751&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:46:16 2012
@@ -86,7 +86,7 @@ public class ApplicationComposer extends
     private static final Class[] MODULE_TYPES = { IAnnotationFinder.class, ClassesArchive.class,
             AppModule.class, WebModule.class, EjbModule.class,
             Application.class,
-            EjbJar.class, EnterpriseBean.class,
+            WebApp.class, EjbJar.class, EnterpriseBean.class,
             Persistence.class, PersistenceUnit.class,
             Connector.class, Beans.class,
             Class[].class

Modified: openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/WebApp.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/WebApp.java?rev=1405751&r1=1405750&r2=1405751&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/WebApp.java
(original)
+++ openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/WebApp.java
Mon Nov  5 11:46:16 2012
@@ -17,7 +17,6 @@
  */
 package org.apache.openejb.jee;
 
-import java.util.Collections;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
@@ -29,9 +28,10 @@ import javax.xml.bind.annotation.XmlType
 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Collection;
 import java.util.Map;
 
 /**
@@ -636,4 +636,52 @@ public class WebApp implements WebCommon
         }
         return Collections.emptyList();
     }
+
+    private Servlet findServlet(final String name) {
+        for (Servlet s : getServlet()) {
+            if (name.equals(s.getServletName())) {
+                return s;
+            }
+        }
+        return null;
+    }
+
+    public WebApp addServlet(final String name, final String clazz, final String... mappings)
{
+        final Servlet servletToAdd = new Servlet();
+        servletToAdd.setServletName(name);
+        servletToAdd.setServletClass(clazz);
+
+        if (mappings != null && mappings.length > 0) {
+            final ServletMapping sm = new ServletMapping();
+            sm.setServletName(name);
+
+            for (String mapping : mappings) {
+                if (servletMapping == null) {
+                    servletMapping = new ArrayList<ServletMapping>();
+                }
+
+                sm.getUrlPattern().add(mapping);
+            }
+            servletMapping.add(sm);
+        }
+
+        getServlet().add(servletToAdd);
+
+        return this;
+    }
+
+    public WebApp addInitParam(final String servletName, final String name, final String
value) {
+        final ParamValue paramValue = new ParamValue();
+        paramValue.setParamName(name);
+        paramValue.setParamValue(value);
+
+        findServlet(servletName).getInitParam().add(paramValue);
+
+        return this;
+    }
+
+    public WebApp contextRoot(final String root) {
+        setContextRoot(root);
+        return this;
+    }
 }

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=1405751&r1=1405750&r2=1405751&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:46:16 2012
@@ -19,9 +19,6 @@ package org.apache.openejb.server.cxf.rs
 import org.apache.cxf.jaxrs.client.WebClient;
 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;
@@ -32,8 +29,6 @@ import org.apache.openejb.server.cxf.rs.
 import org.apache.openejb.server.cxf.rs.beans.RestWithInjections;
 import org.apache.openejb.server.cxf.rs.beans.SimpleEJB;
 import org.apache.openejb.web.LightweightWebAppBuilder;
-import org.apache.xbean.finder.AnnotationFinder;
-import org.apache.xbean.finder.archive.ClassesArchive;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -65,20 +60,10 @@ public class SimpleApplicationTest {
     @Module
     @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;
+        return new WebApp()
+                .contextRoot("foo")
+                .addServlet("REST Application", Application.class.getName())
+                .addInitParam("REST Application", "javax.ws.rs.Application", MyRESTApplication.class.getName());
     }
 
     @Test



Mime
View raw message