tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r1134213 - in /openejb/trunk/openejb3/tck/cdi-embedded/src/test: java/org/apache/openejb/tck/cdi/embedded/ContainersImpl.java resources/failing.xml resources/passing.xml
Date Fri, 10 Jun 2011 07:09:41 GMT
Author: dblevins
Date: Fri Jun 10 07:09:41 2011
New Revision: 1134213

URL: http://svn.apache.org/viewvc?rev=1134213&view=rev
Log:
Workaround for CDITCK-216: No Support for standalone EJBContainer

Modified:
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/ContainersImpl.java
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/failing.xml
    openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml

Modified: openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/ContainersImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/ContainersImpl.java?rev=1134213&r1=1134212&r2=1134213&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/ContainersImpl.java
(original)
+++ openejb/trunk/openejb3/tck/cdi-embedded/src/test/java/org/apache/openejb/tck/cdi/embedded/ContainersImpl.java
Fri Jun 10 07:09:41 2011
@@ -18,26 +18,32 @@ package org.apache.openejb.tck.cdi.embed
 
 import org.apache.openejb.OpenEJB;
 import org.apache.openejb.assembler.classic.Assembler;
-import org.apache.openejb.cdi.ThreadSingletonService;
 import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.SetAccessible;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.container.BeanManagerImpl;
 import org.jboss.testharness.api.DeploymentException;
+import org.jboss.testharness.impl.packaging.ear.EjbJarXml;
+import org.jboss.testharness.impl.packaging.ear.PersistenceXml;
 import org.jboss.testharness.spi.Containers;
 
 import javax.ejb.embeddable.EJBContainer;
 import java.io.BufferedOutputStream;
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.Flushable;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.AccessibleObject;
+import java.io.OutputStream;
 import java.lang.reflect.Field;
+import java.net.URL;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
 
 /**
  * @version $Rev$ $Date$
@@ -80,14 +86,11 @@ public class ContainersImpl implements C
         return true;
     }
 
-    private void dump(Object o)
-    {
-        try
-        {
+    private void dump(Object o) {
+        try {
             final Class<? extends Object> clazz = o.getClass();
 
-            for (Field field : clazz.getDeclaredFields())
-            {
+            for (Field field : clazz.getDeclaredFields()) {
                 SetAccessible.on(field);
 
                 if (Collection.class.isAssignableFrom(field.getType())) {
@@ -95,29 +98,105 @@ public class ContainersImpl implements C
                     System.out.println(field.getName() + "\t= " + collection.size());
                 }
             }
-        }
-        catch (Exception e)
-        {
+        } catch (Exception e) {
 
         }
     }
 
+    private URL getResource(Class clazz, String path) {
+        final String resourcePath = clazz.getPackage().getName().replace(".", "/") + "/"
+ path;
+
+        return clazz.getClassLoader().getResource(resourcePath);
+    }
+
     private File writeToFile(InputStream archive, String name) throws IOException {
         final File file = File.createTempFile("deploy", "-" + name);
         file.deleteOnExit();
 
-        final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
-
         try {
-            int i = -1;
-            while ((i = archive.read()) != -1) out.write(i);
-        } finally {
-            out.close();
-        }
 
+            Map<String, URL> resources = new HashMap<String, URL>();
+            
+            final Class<?> clazz = this.getClass().getClassLoader().loadClass(name.replace(".jar",
""));
+
+            if (clazz.isAnnotationPresent(EjbJarXml.class)) {
+                final URL resource = getResource(clazz, clazz.getAnnotation(EjbJarXml.class).value());
+                
+                if (resource != null) resources.put("META-INF/ejb-jar.xml", resource);
+            }
+
+            if (clazz.isAnnotationPresent(PersistenceXml.class)) {
+                final URL resource = getResource(clazz, clazz.getAnnotation(PersistenceXml.class).value());
+                
+                if (resource != null) resources.put("META-INF/persistence.xml", resource);
+            }
+
+            final boolean isJar = name.endsWith(".jar");
+
+            final ZipInputStream zin = new ZipInputStream(archive);
+            final ZipOutputStream zout = new ZipOutputStream(new BufferedOutputStream(new
FileOutputStream(file)));
+
+            for (ZipEntry entry; (entry = zin.getNextEntry()) != null; ) {
+                String entryName = entry.getName();
+
+                if (entryName.startsWith("WEB-INF")) {
+                    System.out.println(entryName);
+                }
+                if (isJar && entryName.startsWith("WEB-INF/classes/")) {
+                    entryName = entryName.replaceFirst("WEB-INF/classes/","");
+                }
+
+                InputStream src = zin;
+
+                if (resources.containsKey(entryName)) {
+                    src = resources.get(entryName).openStream();
+                }
+
+                resources.remove(entryName);
+
+                zout.putNextEntry(new ZipEntry(entryName));
+
+                copy(src, zout);
+            }
+
+            for (Map.Entry<String, URL> entry : resources.entrySet()) {
+
+                zout.putNextEntry(new ZipEntry(entry.getKey()));
+
+                copy(entry.getValue().openStream(), zout);
+            }
+
+            close(zin);
+            close(zout);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
         return file;
     }
 
+    private static void copy(InputStream from, OutputStream to) throws IOException {
+        byte[] buffer = new byte[1024];
+        int length = 0;
+        while ((length = from.read(buffer)) != -1) {
+            to.write(buffer, 0, length);
+        }
+    }
+
+    public static void close(Closeable closeable) throws IOException {
+        if (closeable == null) return;
+        try {
+            if (closeable instanceof Flushable) {
+                ((Flushable) closeable).flush();
+            }
+        } catch (IOException e) {
+        }
+        try {
+            closeable.close();
+        } catch (IOException e) {
+        }
+    }
+
+
     @Override
     public DeploymentException getDeploymentException() {
         return new DeploymentException(exception.getLocalizedMessage(), exception);

Modified: openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/failing.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/failing.xml?rev=1134213&r1=1134212&r2=1134213&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/failing.xml (original)
+++ openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/failing.xml Fri Jun 10 07:09:41
2011
@@ -16,11 +16,9 @@
       <class name="org.jboss.jsr299.tck.tests.context.request.ejb.EJBRequestContextTest"/>
       <class name="org.jboss.jsr299.tck.tests.deployment.packaging.bundledLibrary.LibraryInEarTest"/>
       <class name="org.jboss.jsr299.tck.tests.event.observer.enterprise.EnterpriseEventInheritenceTest"/>
-      <class name="org.jboss.jsr299.tck.tests.extensions.container.event.ContainerEventTest"/>
       <class name="org.jboss.jsr299.tck.tests.extensions.processBean.ProcessSessionBeanTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.builtin.BuiltInBeansTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.definition.EnterpriseBeanDefinitionTest"/>
-      <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.definition.EnterpriseBeanViaXmlTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.lifecycle.EnterpriseBeanLifecycleTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.newBean.NewEnterpriseBeanICTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.remove.EnterpriseBeanRemoveMethodTest"/>

Modified: openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml?rev=1134213&r1=1134212&r2=1134213&view=diff
==============================================================================
--- openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml (original)
+++ openejb/trunk/openejb3/tck/cdi-embedded/src/test/resources/passing.xml Fri Jun 10 07:09:41
2011
@@ -115,6 +115,7 @@
       <class name="org.jboss.jsr299.tck.tests.extensions.annotated.AlternativeMetaDataTest"/>
       <class name="org.jboss.jsr299.tck.tests.extensions.bean.bytype.BeanByTypeTest"/>
       <class name="org.jboss.jsr299.tck.tests.extensions.beanManager.BeanManagerTest"/>
+      <class name="org.jboss.jsr299.tck.tests.extensions.container.event.ContainerEventTest"/>
       <class name="org.jboss.jsr299.tck.tests.extensions.producer.ProducerTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.disposal.method.definition.DisposalMethodDefinitionTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.disposal.method.definition.broken.initializerUnallowed.InitializerUnallowedDefinitionTest"/>
@@ -130,6 +131,7 @@
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.broken.statelessWithConversationScope.StatelessWithConversationScopeTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.broken.statelessWithRequestScope.StatelessWithRequestScopeTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.broken.statelessWithSessionScope.StatelessWithSessionScopeTest"/>
+      <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.definition.EnterpriseBeanViaXmlTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.enterprise.newBean.NewEnterpriseBeanTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.initializer.InitializerMethodTest"/>
       <class name="org.jboss.jsr299.tck.tests.implementation.initializer.broken.methodAnnotatedProduces.InitializerMethodAnnotatedProducesTest"/>



Mime
View raw message