You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomee.apache.org by Romain Manni-Bucau <rm...@gmail.com> on 2011/10/27 06:29:28 UTC

Fwd: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Hi,

Why beanmanager stuff is not enough?

- Romain

---------- Message transféré ----------
De : <jg...@apache.org>
Date : 27 oct. 2011 01:08
Objet : svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./
arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
arquillian-tomee-remote/
arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
arquillian-to...
À : <co...@openejb.apache.org>

Author: jgallimore
Date: Wed Oct 26 23:08:05 2011
New Revision: 1189526

URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
Log:
Progress on supporting enriching tests with @EJB fields

Added:

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
Removed:

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
Modified:

 openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java

 openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
   openejb/trunk/arquillian-tomee/pom.xml

Modified:
openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
(original)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
Wed Oct 26 23:08:05 2011
@@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
 import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
 import org.jboss.shrinkwrap.api.Archive;
 import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
 import org.jboss.shrinkwrap.descriptor.api.Descriptor;

 public abstract class TomEEContainer implements
DeployableContainer<TomEEConfiguration> {
@@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
    }

    public ProtocolDescription getDefaultProtocol() {
-        return new ProtocolDescription("Servlet 3.0");
+        return new ProtocolDescription("Servlet 2.5");
    }

    public ProtocolMetaData deploy(Archive<?> archive) throws
DeploymentException {
@@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
            moduleIds.put(archive.getName(), file.getAbsolutePath());

            HTTPContext httpContext = new HTTPContext("0.0.0.0",
configuration.getHttpPort());
-            httpContext.add(new Servlet("ArquillianServletRunner", "/" +
getArchiveNameWithoutExtension(archive)));
+            if (archive instanceof WebArchive) {
+               httpContext.add(new Servlet("ArquillianServletRunner", "/" +
getArchiveNameWithoutExtension(archive)));
+            } else {
+               httpContext.add(new Servlet("ArquillianServletRunner",
"/arquillian-protocol"));
+            }
+
            // we should probably get all servlets and add them to the
context
            return new ProtocolMetaData().addContext(httpContext);
        } catch (Exception e) {

Modified: openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
==============================================================================
--- openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
(original)
+++ openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml Wed Oct
26 23:08:05 2011
@@ -333,5 +333,12 @@
       <artifactId>swizzle-stream</artifactId>
       <version>1.0.2</version>
    </dependency>
+    <dependency>
+       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
+       <artifactId>shrinkwrap-descriptors-impl</artifactId>
+       <version>1.1.0-alpha-2</version>
+       <type>jar</type>
+       <scope>compile</scope>
+    </dependency>
  </dependencies>
 </project>

Modified:
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
(original)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
Wed Oct 26 23:08:05 2011
@@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend

                   System.setProperty("catalina.home",
openejbHome.getAbsolutePath());
                           System.setProperty("catalina.base",
openejbHome.getAbsolutePath());
+
System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
                           Paths paths = new Paths(new
File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
                           Installer installer = new Installer(paths, true);
                           installer.installAll();

Added:
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
(added)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
Wed Oct 26 23:08:05 2011
@@ -0,0 +1,18 @@
+package org.apache.openejb.arquillian.remote;
+
+import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
+import
org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+
+public class RemoteTomEEEJBEnricherArchiveAppender implements
AuxiliaryArchiveAppender
+{
+          @Override
+          public Archive<?> createAuxiliaryArchive()
+          {
+             return ShrinkWrap.create(JavaArchive.class,
"arquillian-tomee-testenricher-ejb.jar")
+                         .addClasses(RemoteTomEEEnricher.class,
RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
+
.addAsServiceProvider(RemoteLoadableExtension.class,
RemoteTomEEEJBEnricherExtension.class);
+          }
+       }
\ No newline at end of file

Added:
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
(added)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
Wed Oct 26 23:08:05 2011
@@ -0,0 +1,13 @@
+package org.apache.openejb.arquillian.remote;
+
+import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
+import org.jboss.arquillian.test.spi.TestEnricher;
+
+public class RemoteTomEEEJBEnricherExtension implements
RemoteLoadableExtension {
+    @Override public void register(ExtensionBuilder builder) {
+       // only load if EJB is on ClassPath
+        if(Validate.classExists("javax.ejb.EJB")) {
+           builder.service(TestEnricher.class,
org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
+        }
+    }
+}

Modified:
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
(original)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
Wed Oct 26 23:08:05 2011
@@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
 import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
 import org.jboss.arquillian.test.spi.TestEnricher;

+import javax.ejb.EJB;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.InjectionTarget;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.List;

 public class RemoteTomEEEnricher implements TestEnricher {
-    @Override public void enrich(Object testCase) {
-//        BeanManager mgr = getBeanManager();
-//        if (mgr != null) {
-//            AnnotatedType<?> type =  mgr.createAnnotatedType(getClass());
-//            InjectionTarget<Object> injectionTarget =
(InjectionTarget<Object>) mgr.createInjectionTarget(type);
-//            CreationalContext<Object> context =
mgr.createCreationalContext(null);
-//
-//            injectionTarget.inject(testCase, context);
-//            injectionTarget.postConstruct(this);
-//        } else {
-//            throw new NullPointerException("bean manager is null");
-//        }
-
-        /* TODO: see if this code could be called after tests
-                *
-                * if (injectionTarget != null) {
-                *        injectionTarget.preDestroy(this);
-                *    }
-                *   if (context != null) {
-                *        context.release();
-                *    }
-                *
-                *   injectionTarget = null;
-                *   context = null;
-                */
-    }
-
-    @Override public Object[] resolve(Method method) {
-        return new Object[method.getParameterTypes().length];
-    }
-
-    public BeanManager getBeanManager() {
-        return ThreadSingletonServiceImpl.get().getBeanManagerImpl();
-    }
+
+       private static final String ANNOTATION_NAME = "javax.ejb.EJB";
+
+       public void enrich(Object testCase) {
+               BeanManager mgr = getBeanManager();
+               if (mgr != null) {
+                       AnnotatedType<?> type =
mgr.createAnnotatedType(getClass());
+                       InjectionTarget<Object> injectionTarget =
(InjectionTarget<Object>) mgr.createInjectionTarget(type);
+                       CreationalContext<Object> context =
mgr.createCreationalContext(null);
+
+                       injectionTarget.inject(testCase, context);
+                       injectionTarget.postConstruct(this);
+               }
+
+               try {
+                       if (SecurityActions.isClassPresent(ANNOTATION_NAME))
{
+                               @SuppressWarnings("unchecked")
+                               Class<? extends Annotation> ejbAnnotation =
(Class<? extends Annotation>)
SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
+
+                               List<Field> annotatedFields =
SecurityActions.getFieldsWithAnnotation(testCase.getClass(), ejbAnnotation);
+
+                               for (Field field : annotatedFields) {
+                                       if (field.get(testCase) == null) {
+                                               EJB fieldAnnotation = (EJB)
field.getAnnotation(ejbAnnotation);
+                                               Object ejb =
lookupEJB(field.getType(), fieldAnnotation.mappedName());
+                                               field.set(testCase, ejb);
+                                       }
+                               }
+
+                               List<Method> methods =
SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
ejbAnnotation);
+
+                               for (Method method : methods) {
+                                       if
(method.getParameterTypes().length != 1) {
+                                               throw new
RuntimeException("@EJB only allowed on single argument methods");
+                                       }
+                                       if
(!method.getName().startsWith("set")) {
+                                               throw new
RuntimeException("@EJB only allowed on 'set' methods");
+                                       }
+                                       EJB parameterAnnotation = null; //
method.getParameterAnnotations()[0]
+                                       for (Annotation annotation :
method.getParameterAnnotations()[0]) {
+                                               if
(EJB.class.isAssignableFrom(annotation.annotationType())) {
+                                                       parameterAnnotation
= (EJB) annotation;
+                                               }
+                                       }
+                                       String mappedName =
parameterAnnotation == null ? null : parameterAnnotation.mappedName();
+                                       Object ejb =
lookupEJB(method.getParameterTypes()[0], mappedName);
+                                       method.invoke(testCase, ejb);
+                               }
+
+                       }
+               } catch (Exception e) {
+
+               }
+
+       }
+
+       protected Object lookupEJB(Class<?> fieldType, String mappedName)
throws Exception {
+               // TODO: figure out test context ?
+               Context initcontext = new InitialContext();
+
+               // TODO: These names are not spec compliant; fieldType needs
to be a
+               // bean type here,
+               // but usually is just an interface of a bean. These seldom
work.
+               String[] jndiNames = {
"openejb:global/global/test/test.jar/" + fieldType.getSimpleName() + "Bean",
+                               "openejb:global/global/test/test.jar/" +
fieldType.getSimpleName(),
+                               "java:global/test/test.jar/" +
fieldType.getSimpleName() + "Bean",
+                               "java:global/test/test.jar/" +
fieldType.getSimpleName(),
+                               "java:global/test.ear/test/" +
fieldType.getSimpleName() + "Bean",
+                               "java:global/test.ear/test/" +
fieldType.getSimpleName(),
+                               "java:global/test/" +
fieldType.getSimpleName(),
+                               "java:global/test/" +
fieldType.getSimpleName() + "Bean",
+                               "java:global/test/" +
fieldType.getSimpleName() + "/no-interface",
+                               "test/" + fieldType.getSimpleName() +
"Bean/local",
+                               "test/" + fieldType.getSimpleName() +
"Bean/remote",
+                               "test/" + fieldType.getSimpleName() +
"/no-interface",
+                               fieldType.getSimpleName() + "Bean/local",
+                               fieldType.getSimpleName() + "Bean/remote",
+                               fieldType.getSimpleName() + "/no-interface",
+                               "ejblocal:" + fieldType.getCanonicalName(),
+                               fieldType.getCanonicalName() };
+               if ((mappedName != null) && (!mappedName.equals(""))) {
+                       // Use only the mapped name to lookup this EJB
+                       jndiNames = new String[] { mappedName };
+               }
+
+               for (String jndiName : jndiNames) {
+                       try {
+                               return initcontext.lookup(jndiName);
+                       } catch (NamingException e) {
+                               // no-op, try next
+                       }
+               }
+               throw new NamingException("No EJB found in JNDI");
+       }
+
+       @Override
+       public Object[] resolve(Method method) {
+               return new Object[method.getParameterTypes().length];
+       }
+
+       public BeanManager getBeanManager() {
+               return
ThreadSingletonServiceImpl.get().getBeanManagerImpl();
+       }
 }

Modified:
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
(original)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
Wed Oct 26 23:08:05 2011
@@ -1,12 +1,12 @@
 package org.apache.openejb.arquillian.remote;

 import
org.jboss.arquillian.container.spi.client.container.DeployableContainer;
+import
org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
 import org.jboss.arquillian.core.spi.LoadableExtension;
-import org.jboss.arquillian.test.spi.TestEnricher;

 public class RemoteTomEEExtension implements LoadableExtension {
    @Override public void register(ExtensionBuilder builder) {
        builder.service(DeployableContainer.class,
RemoteTomEEContainer.class)
-            .service(TestEnricher.class, RemoteTomEEEnricher.class);
+            .service(AuxiliaryArchiveAppender.class,
RemoteTomEEEJBEnricherArchiveAppender.class);
    }
 }

Added:
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
(added)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
Wed Oct 26 23:08:05 2011
@@ -0,0 +1,249 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * 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.openejb.arquillian.remote;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * SecurityActions
+ *
+ * A set of privileged actions that are not to leak out
+ * of this package
+ *
+ * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+final class SecurityActions
+{
+
+
//-------------------------------------------------------------------------------||
+   // Constructor
------------------------------------------------------------------||
+
//-------------------------------------------------------------------------------||
+
+   /**
+    * No instantiation
+    */
+   private SecurityActions()
+   {
+      throw new UnsupportedOperationException("No instantiation");
+   }
+
+
//-------------------------------------------------------------------------------||
+   // Utility Methods
--------------------------------------------------------------||
+
//-------------------------------------------------------------------------------||
+
+   /**
+    * Obtains the Thread Context ClassLoader
+    */
+   static ClassLoader getThreadContextClassLoader()
+   {
+      return AccessController.doPrivileged(GetTcclAction.INSTANCE);
+   }
+
+   /**
+    * Obtains the Constructor specified from the given Class and argument
types
+    * @param clazz
+    * @param argumentTypes
+    * @return
+    * @throws NoSuchMethodException
+    */
+   static Constructor<?> getConstructor(final Class<?> clazz, final
Class<?>... argumentTypes)
+         throws NoSuchMethodException
+   {
+      try
+      {
+         return AccessController.doPrivileged(new
PrivilegedExceptionAction<Constructor<?>>()
+         {
+            public Constructor<?> run() throws NoSuchMethodException
+            {
+               return clazz.getConstructor(argumentTypes);
+            }
+         });
+      }
+      // Unwrap
+      catch (final PrivilegedActionException pae)
+      {
+         final Throwable t = pae.getCause();
+         // Rethrow
+         if (t instanceof NoSuchMethodException)
+         {
+            throw (NoSuchMethodException) t;
+         }
+         else
+         {
+            // No other checked Exception thrown by Class.getConstructor
+            try
+            {
+               throw (RuntimeException) t;
+            }
+            // Just in case we've really messed up
+            catch (final ClassCastException cce)
+            {
+               throw new RuntimeException("Obtained unchecked Exception;
this code should never be reached", t);
+            }
+         }
+      }
+   }
+
+   /**
+    * Create a new instance by finding a constructor that matches the
argumentTypes signature
+    * using the arguments for instantiation.
+    *
+    * @param className Full classname of class to create
+    * @param argumentTypes The constructor argument types
+    * @param arguments The constructor arguments
+    * @return a new instance
+    * @throws IllegalArgumentException if className, argumentTypes, or
arguments are null
+    * @throws RuntimeException if any exceptions during creation
+    * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
+    * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
+    */
+   static <T> T newInstance(final String className, final Class<?>[]
argumentTypes, final Object[] arguments,
+         final Class<T> expectedType)
+   {
+      if (className == null)
+      {
+         throw new IllegalArgumentException("ClassName must be specified");
+      }
+      if (argumentTypes == null)
+      {
+         throw new IllegalArgumentException("ArgumentTypes must be
specified. Use empty array if no arguments");
+      }
+      if (arguments == null)
+      {
+         throw new IllegalArgumentException("Arguments must be specified.
Use empty array if no arguments");
+      }
+      final Object obj;
+      try
+      {
+         final ClassLoader tccl = getThreadContextClassLoader();
+         final Class<?> implClass = Class.forName(className, false, tccl);
+         Constructor<?> constructor = getConstructor(implClass,
argumentTypes);
+         obj = constructor.newInstance(arguments);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Could not create new instance of " +
className
+               + ", missing package from classpath?", e);
+      }
+
+      // Cast
+      try
+      {
+         return expectedType.cast(obj);
+      }
+      catch (final ClassCastException cce)
+      {
+         // Reconstruct so we get some useful information
+         throw new ClassCastException("Incorrect expected type, " +
expectedType.getName() + ", defined for "
+               + obj.getClass().getName());
+      }
+   }
+
+   public static boolean isClassPresent(String name)
+   {
+      try
+      {
+         ClassLoader classLoader = getThreadContextClassLoader();
+         classLoader.loadClass(name);
+         return true;
+      }
+      catch (ClassNotFoundException e)
+      {
+         return false;
+      }
+   }
+
+   public static List<Field> getFieldsWithAnnotation(final Class<?> source,
final Class<? extends Annotation> annotationClass)
+   {
+      List<Field> declaredAccessableFields =
AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
+      {
+         public List<Field> run()
+         {
+            List<Field> foundFields = new ArrayList<Field>();
+            Class<?> nextSource = source;
+            while (nextSource != Object.class) {
+               for(Field field : nextSource.getDeclaredFields())
+               {
+                  if(field.isAnnotationPresent(annotationClass))
+                  {
+                     if(!field.isAccessible())
+                     {
+                        field.setAccessible(true);
+                     }
+                     foundFields.add(field);
+                  }
+               }
+               nextSource = nextSource.getSuperclass();
+            }
+            return foundFields;
+         }
+      });
+      return declaredAccessableFields;
+   }
+
+   public static List<Method> getMethodsWithAnnotation(final Class<?>
source, final Class<? extends Annotation> annotationClass)
+   {
+      List<Method> declaredAccessableMethods =
AccessController.doPrivileged(new PrivilegedAction<List<Method>>()
+      {
+         public List<Method> run()
+         {
+            List<Method> foundMethods = new ArrayList<Method>();
+            for(Method method : source.getDeclaredMethods())
+            {
+               if(method.isAnnotationPresent(annotationClass))
+               {
+                  if(!method.isAccessible())
+                  {
+                     method.setAccessible(true);
+                  }
+                  foundMethods.add(method);
+               }
+            }
+            return foundMethods;
+         }
+      });
+      return declaredAccessableMethods;
+   }
+
+
//-------------------------------------------------------------------------------||
+   // Inner Classes
----------------------------------------------------------------||
+
//-------------------------------------------------------------------------------||
+
+   /**
+    * Single instance to get the TCCL
+    */
+   private enum GetTcclAction implements PrivilegedAction<ClassLoader> {
+      INSTANCE;
+
+      public ClassLoader run()
+      {
+         return Thread.currentThread().getContextClassLoader();
+      }
+
+   }
+
+}

Modified:
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
==============================================================================
---
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
(original)
+++
openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
Wed Oct 26 23:08:05 2011
@@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.net.URL;

+import javax.ejb.EJB;
+
 import junit.framework.Assert;

 import org.jboss.arquillian.container.test.api.Deployment;
@@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
 @RunWith(Arquillian.class)
 public class TomEEContainerTest {

-    @Deployment(testable = false)
+    @Deployment
    public static WebArchive createDeployment() {
-        return ShrinkWrap.create(WebArchive.class,
"test.war").addClass(TestServlet.class).addClass(TestEjb.class)
+        return ShrinkWrap.create(WebArchive.class,
"test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
                .setWebXML(new
StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
"/Test").exportAsString()));
    }

-    @Test
-    public void nothing(){}
+    @EJB
+    private TestEjb ejb;
+
+    @Test
+    public void testEjbIsNotNull() throws Exception {
+       Assert.assertNotNull(ejb);
+    }

+    @Test
    public void testShouldBeAbleToAccessServletAndEjb() throws Exception {
        InputStream is = new URL("http://localhost:9080/test/Test
").openStream();
        ByteArrayOutputStream os = new ByteArrayOutputStream();

Modified: openejb/trunk/arquillian-tomee/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
==============================================================================
--- openejb/trunk/arquillian-tomee/pom.xml (original)
+++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05 2011
@@ -49,7 +49,7 @@

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <version.arquillian>1.0.0.CR1</version.arquillian>
+    <version.arquillian>1.0.0.CR4</version.arquillian>
    <version.cdi-api>1.0</version.cdi-api>
    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>

Varying Global JNDI Names (Re: svn commit: r1189526)

Posted by David Blevins <da...@gmail.com>.
On Oct 27, 2011, at 11:26 PM, Jonathan Gallimore wrote:

> the global
> individual names it uses are slightly different to ours:
> Java:global/test.ear/test vs Java:global/test/test.jar.

Interesting.  Both look wrong to me.  My recollection is that app and module names should not contain the extension. So java:global/test/test/ would be the right prefix.

Added a JIRA for tests specifically for this:

  https://issues.apache.org/jira/browse/TOMEE-44

They exist in the TCK, but having our own would be nice.


-David


Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Jonathan Gallimore <jo...@gmail.com>.
Hehe.. I'll go for the surprise :) - I'll give it a go as soon as I can.

On Fri, Oct 28, 2011 at 2:17 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> i just tried a kind of joke (sorry ;)) and i was asking if you wanted
> suspense or not
>
> - Romain
>
>
> 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
>
> > I haven't had a chance to check it out yet, but I definitely appreciate
> > your
> > efforts - many thanks! Not quite sure what "do i let you the surprise of
> > the
> > solution i used?" means, but I'll definitely check out your solution and
> > make sure I understand it :-).
> >
> > Thanks
> >
> > Jon
> >
> > On Fri, Oct 28, 2011 at 2:09 PM, Romain Manni-Bucau
> > <rm...@gmail.com>wrote:
> >
> > > your remote test case works
> > >
> > > do i let you the surprise of the solution i used?
> > >
> > > - Romain
> > >
> > >
> > > 2011/10/28 Romain Manni-Bucau <rm...@gmail.com>
> > >
> > > > i'm making it working in embedded mode now, just some minute to let
> me
> > > > commited
> > > >
> > > > PS: i really would like to avoid to contribute our own enricher if it
> > is
> > > > not something directly linked to openejb
> > > >
> > > > - Romain
> > > >
> > > >
> > > >
> > > > 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
> > > >
> > > >> On Fri, Oct 28, 2011 at 1:27 PM, Romain Manni-Bucau
> > > >> <rm...@gmail.com>wrote:
> > > >>
> > > >> > @RunAsClient = @Deployment(testable = false) (personnally i prefer
> > the
> > > >> > first
> > > >> > one but i don't really care ;))
> > > >> >
> > > >> > if one of both is not true then the EJBInjectionEnricher is not
> > > called.
> > > >> >
> > > >> > One way to avoid it is to use "Local" protocol instead of "servlet
> > > 3.0"
> > > >> in
> > > >> > our container.
> > > >> >
> > > >> >
> > > >> I think we need to make sure this works for the
> > > @Deployment(testable=true)
> > > >> without @RunAsClient case as well. It doesn't for me at the moment -
> > > this
> > > >> seems to be how a lot of the tests are setup in the showcase.
> > > >>
> > > >> When I've been running this, my experience is the Arquillian EJB
> > > enricher
> > > >> is
> > > >> called, but can't inject the bean (it can't lookup java:global, and
> > the
> > > >> global names we deploy are different to what it expects to see),
> hence
> > > the
> > > >> code I added to the remote adapter. I'm happy to show you this on a
> > > screen
> > > >> share if you like.
> > > >>
> > > >>
> > > >>
> > > >> > I prefer to avoid to copy paste existing code.
> > > >> >
> > > >>
> > > >> +1. How about moving the enricher code to the common module?
> > > >>
> > > >>
> > > >> >
> > > >> > i'll try to connect this evening or tmr to help you on this point.
> > > >> >
> > > >>
> > > >> Thanks, I really appreciate it. I'm busy due to another commitment
> > this
> > > >> evening, but I'll be working on this and rehearsing for JAX all
> > weekend.
> > > >>
> > > >>
> > > >> >
> > > >> > Maybe we can start forking arquillian showcase on github (i think
> > you
> > > >> had
> > > >> > an
> > > >> > account?)
> > > >> >
> > > >>
> > > >> +1. I do have a github a/c (jgallimore) and I have a fork of this on
> > > there
> > > >> already. We ought to update the poms and arquillian .xml files and
> > > figure
> > > >> out if there's any gaps.
> > > >>
> > > >> Cheers
> > > >>
> > > >> Jon
> > > >>
> > > >
> > > >
> > >
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
i just tried a kind of joke (sorry ;)) and i was asking if you wanted
suspense or not

- Romain


2011/10/28 Jonathan Gallimore <jo...@gmail.com>

> I haven't had a chance to check it out yet, but I definitely appreciate
> your
> efforts - many thanks! Not quite sure what "do i let you the surprise of
> the
> solution i used?" means, but I'll definitely check out your solution and
> make sure I understand it :-).
>
> Thanks
>
> Jon
>
> On Fri, Oct 28, 2011 at 2:09 PM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
> > your remote test case works
> >
> > do i let you the surprise of the solution i used?
> >
> > - Romain
> >
> >
> > 2011/10/28 Romain Manni-Bucau <rm...@gmail.com>
> >
> > > i'm making it working in embedded mode now, just some minute to let me
> > > commited
> > >
> > > PS: i really would like to avoid to contribute our own enricher if it
> is
> > > not something directly linked to openejb
> > >
> > > - Romain
> > >
> > >
> > >
> > > 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
> > >
> > >> On Fri, Oct 28, 2011 at 1:27 PM, Romain Manni-Bucau
> > >> <rm...@gmail.com>wrote:
> > >>
> > >> > @RunAsClient = @Deployment(testable = false) (personnally i prefer
> the
> > >> > first
> > >> > one but i don't really care ;))
> > >> >
> > >> > if one of both is not true then the EJBInjectionEnricher is not
> > called.
> > >> >
> > >> > One way to avoid it is to use "Local" protocol instead of "servlet
> > 3.0"
> > >> in
> > >> > our container.
> > >> >
> > >> >
> > >> I think we need to make sure this works for the
> > @Deployment(testable=true)
> > >> without @RunAsClient case as well. It doesn't for me at the moment -
> > this
> > >> seems to be how a lot of the tests are setup in the showcase.
> > >>
> > >> When I've been running this, my experience is the Arquillian EJB
> > enricher
> > >> is
> > >> called, but can't inject the bean (it can't lookup java:global, and
> the
> > >> global names we deploy are different to what it expects to see), hence
> > the
> > >> code I added to the remote adapter. I'm happy to show you this on a
> > screen
> > >> share if you like.
> > >>
> > >>
> > >>
> > >> > I prefer to avoid to copy paste existing code.
> > >> >
> > >>
> > >> +1. How about moving the enricher code to the common module?
> > >>
> > >>
> > >> >
> > >> > i'll try to connect this evening or tmr to help you on this point.
> > >> >
> > >>
> > >> Thanks, I really appreciate it. I'm busy due to another commitment
> this
> > >> evening, but I'll be working on this and rehearsing for JAX all
> weekend.
> > >>
> > >>
> > >> >
> > >> > Maybe we can start forking arquillian showcase on github (i think
> you
> > >> had
> > >> > an
> > >> > account?)
> > >> >
> > >>
> > >> +1. I do have a github a/c (jgallimore) and I have a fork of this on
> > there
> > >> already. We ought to update the poms and arquillian .xml files and
> > figure
> > >> out if there's any gaps.
> > >>
> > >> Cheers
> > >>
> > >> Jon
> > >>
> > >
> > >
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Jonathan Gallimore <jo...@gmail.com>.
I haven't had a chance to check it out yet, but I definitely appreciate your
efforts - many thanks! Not quite sure what "do i let you the surprise of the
solution i used?" means, but I'll definitely check out your solution and
make sure I understand it :-).

Thanks

Jon

On Fri, Oct 28, 2011 at 2:09 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> your remote test case works
>
> do i let you the surprise of the solution i used?
>
> - Romain
>
>
> 2011/10/28 Romain Manni-Bucau <rm...@gmail.com>
>
> > i'm making it working in embedded mode now, just some minute to let me
> > commited
> >
> > PS: i really would like to avoid to contribute our own enricher if it is
> > not something directly linked to openejb
> >
> > - Romain
> >
> >
> >
> > 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
> >
> >> On Fri, Oct 28, 2011 at 1:27 PM, Romain Manni-Bucau
> >> <rm...@gmail.com>wrote:
> >>
> >> > @RunAsClient = @Deployment(testable = false) (personnally i prefer the
> >> > first
> >> > one but i don't really care ;))
> >> >
> >> > if one of both is not true then the EJBInjectionEnricher is not
> called.
> >> >
> >> > One way to avoid it is to use "Local" protocol instead of "servlet
> 3.0"
> >> in
> >> > our container.
> >> >
> >> >
> >> I think we need to make sure this works for the
> @Deployment(testable=true)
> >> without @RunAsClient case as well. It doesn't for me at the moment -
> this
> >> seems to be how a lot of the tests are setup in the showcase.
> >>
> >> When I've been running this, my experience is the Arquillian EJB
> enricher
> >> is
> >> called, but can't inject the bean (it can't lookup java:global, and the
> >> global names we deploy are different to what it expects to see), hence
> the
> >> code I added to the remote adapter. I'm happy to show you this on a
> screen
> >> share if you like.
> >>
> >>
> >>
> >> > I prefer to avoid to copy paste existing code.
> >> >
> >>
> >> +1. How about moving the enricher code to the common module?
> >>
> >>
> >> >
> >> > i'll try to connect this evening or tmr to help you on this point.
> >> >
> >>
> >> Thanks, I really appreciate it. I'm busy due to another commitment this
> >> evening, but I'll be working on this and rehearsing for JAX all weekend.
> >>
> >>
> >> >
> >> > Maybe we can start forking arquillian showcase on github (i think you
> >> had
> >> > an
> >> > account?)
> >> >
> >>
> >> +1. I do have a github a/c (jgallimore) and I have a fork of this on
> there
> >> already. We ought to update the poms and arquillian .xml files and
> figure
> >> out if there's any gaps.
> >>
> >> Cheers
> >>
> >> Jon
> >>
> >
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
your remote test case works

do i let you the surprise of the solution i used?

- Romain


2011/10/28 Romain Manni-Bucau <rm...@gmail.com>

> i'm making it working in embedded mode now, just some minute to let me
> commited
>
> PS: i really would like to avoid to contribute our own enricher if it is
> not something directly linked to openejb
>
> - Romain
>
>
>
> 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
>
>> On Fri, Oct 28, 2011 at 1:27 PM, Romain Manni-Bucau
>> <rm...@gmail.com>wrote:
>>
>> > @RunAsClient = @Deployment(testable = false) (personnally i prefer the
>> > first
>> > one but i don't really care ;))
>> >
>> > if one of both is not true then the EJBInjectionEnricher is not called.
>> >
>> > One way to avoid it is to use "Local" protocol instead of "servlet 3.0"
>> in
>> > our container.
>> >
>> >
>> I think we need to make sure this works for the @Deployment(testable=true)
>> without @RunAsClient case as well. It doesn't for me at the moment - this
>> seems to be how a lot of the tests are setup in the showcase.
>>
>> When I've been running this, my experience is the Arquillian EJB enricher
>> is
>> called, but can't inject the bean (it can't lookup java:global, and the
>> global names we deploy are different to what it expects to see), hence the
>> code I added to the remote adapter. I'm happy to show you this on a screen
>> share if you like.
>>
>>
>>
>> > I prefer to avoid to copy paste existing code.
>> >
>>
>> +1. How about moving the enricher code to the common module?
>>
>>
>> >
>> > i'll try to connect this evening or tmr to help you on this point.
>> >
>>
>> Thanks, I really appreciate it. I'm busy due to another commitment this
>> evening, but I'll be working on this and rehearsing for JAX all weekend.
>>
>>
>> >
>> > Maybe we can start forking arquillian showcase on github (i think you
>> had
>> > an
>> > account?)
>> >
>>
>> +1. I do have a github a/c (jgallimore) and I have a fork of this on there
>> already. We ought to update the poms and arquillian .xml files and figure
>> out if there's any gaps.
>>
>> Cheers
>>
>> Jon
>>
>
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
i'm making it working in embedded mode now, just some minute to let me
commited

PS: i really would like to avoid to contribute our own enricher if it is not
something directly linked to openejb

- Romain


2011/10/28 Jonathan Gallimore <jo...@gmail.com>

> On Fri, Oct 28, 2011 at 1:27 PM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
> > @RunAsClient = @Deployment(testable = false) (personnally i prefer the
> > first
> > one but i don't really care ;))
> >
> > if one of both is not true then the EJBInjectionEnricher is not called.
> >
> > One way to avoid it is to use "Local" protocol instead of "servlet 3.0"
> in
> > our container.
> >
> >
> I think we need to make sure this works for the @Deployment(testable=true)
> without @RunAsClient case as well. It doesn't for me at the moment - this
> seems to be how a lot of the tests are setup in the showcase.
>
> When I've been running this, my experience is the Arquillian EJB enricher
> is
> called, but can't inject the bean (it can't lookup java:global, and the
> global names we deploy are different to what it expects to see), hence the
> code I added to the remote adapter. I'm happy to show you this on a screen
> share if you like.
>
>
>
> > I prefer to avoid to copy paste existing code.
> >
>
> +1. How about moving the enricher code to the common module?
>
>
> >
> > i'll try to connect this evening or tmr to help you on this point.
> >
>
> Thanks, I really appreciate it. I'm busy due to another commitment this
> evening, but I'll be working on this and rehearsing for JAX all weekend.
>
>
> >
> > Maybe we can start forking arquillian showcase on github (i think you had
> > an
> > account?)
> >
>
> +1. I do have a github a/c (jgallimore) and I have a fork of this on there
> already. We ought to update the poms and arquillian .xml files and figure
> out if there's any gaps.
>
> Cheers
>
> Jon
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Jonathan Gallimore <jo...@gmail.com>.
On Fri, Oct 28, 2011 at 1:27 PM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> @RunAsClient = @Deployment(testable = false) (personnally i prefer the
> first
> one but i don't really care ;))
>
> if one of both is not true then the EJBInjectionEnricher is not called.
>
> One way to avoid it is to use "Local" protocol instead of "servlet 3.0" in
> our container.
>
>
I think we need to make sure this works for the @Deployment(testable=true)
without @RunAsClient case as well. It doesn't for me at the moment - this
seems to be how a lot of the tests are setup in the showcase.

When I've been running this, my experience is the Arquillian EJB enricher is
called, but can't inject the bean (it can't lookup java:global, and the
global names we deploy are different to what it expects to see), hence the
code I added to the remote adapter. I'm happy to show you this on a screen
share if you like.



> I prefer to avoid to copy paste existing code.
>

+1. How about moving the enricher code to the common module?


>
> i'll try to connect this evening or tmr to help you on this point.
>

Thanks, I really appreciate it. I'm busy due to another commitment this
evening, but I'll be working on this and rehearsing for JAX all weekend.


>
> Maybe we can start forking arquillian showcase on github (i think you had
> an
> account?)
>

+1. I do have a github a/c (jgallimore) and I have a fork of this on there
already. We ought to update the poms and arquillian .xml files and figure
out if there's any gaps.

Cheers

Jon

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Jon,

@RunAsClient = @Deployment(testable = false) (personnally i prefer the first
one but i don't really care ;))

if one of both is not true then the EJBInjectionEnricher is not called.

One way to avoid it is to use "Local" protocol instead of "servlet 3.0" in
our container.

I prefer to avoid to copy paste existing code.

i'll try to connect this evening or tmr to help you on this point.

Maybe we can start forking arquillian showcase on github (i think you had an
account?)

- Romain


2011/10/28 Jonathan Gallimore <jo...@gmail.com>

> Hi Romain,
>
> Thanks for the commit. Your test does work for me, but I still can't run
> the
> ejb tests in the Arquillian showcase, and your test doesn't work if I
> remove
> the @RunAsClient annotation (i.e. running the test in the container with
> the
> app). The tests in the showcase do (or at least should) work with other
> containers, so my view is that they should work with TomEE just by adding
> the profiles for our adapters to the pom.xml and the settings to
> arquillian.xml.
>
> Do you any objection if we use the EJB/CDI enricher code I put in the
> remote
> adapter the other day in both adapters?
>
> I'm presenting at JAX on Tuesday, and it would be great if this
> functionality works in both the Remote and Embedded adapters - I think the
> Arquillian demo will be a bit disappointing without it. Obviously I'm happy
> to carry on looking for a better long-term solution for getting the
> injections working with the tests running on the server.
>
> Jon
>
> On Fri, Oct 28, 2011 at 9:03 AM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
> > Note: David spoke about adding the class test in the application deployed
> > as
> > a managed bean...it is probably the best solution from an injection point
> > of
> > view but the test class is not instantiated by us so the managed stuff is
> > useless out of the box...i'm not sure how good is this solution since it
> > can
> > make us rewrite all (almost ;)) the arquillian stuff
> >
> > - Romain
> >
> >
> > 2011/10/28 Romain Manni-Bucau <rm...@gmail.com>
> >
> > > i looked testenricher implementation from jboss and...the cdi one is
> > almost
> > > the same than mine so i guess mine is useless
> > >
> > > i made the ejb injection for the embedded case working.
> > >
> > > i think it is just a bit more complicated for the remote case but
> almost
> > > the same philosophy.
> > >
> > > you can have a look, i added a test case to make it work.
> > >
> > > - Romain
> > >
> > >
> > >
> > > 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
> > >
> > >> Neither the arquillian-showcase-ejb example, nor my own test in the
> > >> moviefun
> > >> example for testing ejbs work with the embedded adapter as it stands
> > >> either
> > >> - the ejb isn't getting injected.
> > >>
> > >> I'd be grateful if you could give it a try with the latest code.
> > >>
> > >> I'm afraid I don't understand your last point about @DeploymentScoped.
> > >> Where
> > >> does that need to go? Do I have to change the showcase code beyond
> > >> referencing the adapters in the pom? I'm not sure I like that.
> > >>
> > >> There does seem to be an issue where the default ejbenricher with
> > >> arquillian
> > >> would work, except 1. it can't lookup Java:global. I've created an ear
> > and
> > >> confirmed I can't look it up from a servlet either, and 2. the global
> > >> individual names it uses are slightly different to ours:
> > >> Java:global/test.ear/test vs Java:global/test/test.jar.
> > >>
> > >> The first issue really doesn't seem right to me and I think we'll need
> > to
> > >> solve that.
> > >>
> > >> Jon
> > >> On Oct 27, 2011 11:45 PM, "Romain Manni-Bucau" <rmannibucau@gmail.com
> >
> > >> wrote:
> > >>
> > >> > i don't get why it doesn't work since everything is in the same
> > webapp?
> > >> >
> > >> > Note: the ejbenricher needs the context to use to lookup, it can be
> > set
> > >> > using @Inject @DeployementScoped private Instance<Context> context;
> > then
> > >> > context.set(new InitialContext()) (in the container)
> > >> >
> > >> > - Romain
> > >> >
> > >> >
> > >> > 2011/10/27 Romain Manni-Bucau <rm...@gmail.com>
> > >> >
> > >> > > Weird, it seems to work in embedded case.
> > >> > >
> > >> > > Le 27 oct. 2011 13:29, "Jonathan Gallimore" <
> > >> > jonathan.gallimore@gmail.com>
> > >> > > a écrit :
> > >> > >
> > >> > >  When I first saw your email, I did wonder whether the bean
> manager
> > >> code
> > >> > >> would be enough, and maybe I was just missing the ArchiveAppender
> > >> stuff
> > >> > to
> > >> > >> get the Enricher over to the server side. I've retested with the
> > EJB
> > >> > >> lookup
> > >> > >> commented out, and unfortunately, It didn't work without my
> change
> > >> for
> > >> > the
> > >> > >> test case I was using (arquillian-showcase-ejb).
> > >> > >>
> > >> > >> Jon
> > >> > >>
> > >> > >> On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
> > >> > >> <rm...@gmail.com>wrote:
> > >> > >>
> > >> > >> > Hi,
> > >> > >> >
> > >> > >> > Why beanmanager stuff is not enough?
> > >> > >> >
> > >> > >> > - Romain
> > >> > >> >
> > >> > >> > ---------- Message transféré ----------
> > >> > >> > De : <jg...@apache.org>
> > >> > >> > Date : 27 oct. 2011 01:08
> > >> > >> > Objet : svn commit: r1189526 - in
> > /openejb/trunk/arquillian-tomee:
> > >> ./
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
> > >> > >> > arquillian-tomee-remote/
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
> > >> > >> > arquillian-to...
> > >> > >> > À : <co...@openejb.apache.org>
> > >> > >> >
> > >> > >> > Author: jgallimore
> > >> > >> > Date: Wed Oct 26 23:08:05 2011
> > >> > >> > New Revision: 1189526
> > >> > >> >
> > >> > >> > URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
> > >> > >> > Log:
> > >> > >> > Progress on supporting enriching tests with @EJB fields
> > >> > >> >
> > >> > >> > Added:
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > >> > Removed:
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
> > >> > >> > Modified:
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> > >> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> > >> >
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> > >> >   openejb/trunk/arquillian-tomee/pom.xml
> > >> > >> >
> > >> > >> > Modified:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> > >> > (original)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
> > >> > >> >  import
> > >> > >> >
> > >> org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
> > >> > >> >  import org.jboss.shrinkwrap.api.Archive;
> > >> > >> >  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
> > >> > >> > +import org.jboss.shrinkwrap.api.spec.WebArchive;
> > >> > >> >  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
> > >> > >> >
> > >> > >> >  public abstract class TomEEContainer implements
> > >> > >> > DeployableContainer<TomEEConfiguration> {
> > >> > >> > @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
> > >> > >> >    }
> > >> > >> >
> > >> > >> >    public ProtocolDescription getDefaultProtocol() {
> > >> > >> > -        return new ProtocolDescription("Servlet 3.0");
> > >> > >> > +        return new ProtocolDescription("Servlet 2.5");
> > >> > >> >    }
> > >> > >> >
> > >> > >> >    public ProtocolMetaData deploy(Archive<?> archive) throws
> > >> > >> > DeploymentException {
> > >> > >> > @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
> > >> > >> >            moduleIds.put(archive.getName(),
> > >> file.getAbsolutePath());
> > >> > >> >
> > >> > >> >            HTTPContext httpContext = new HTTPContext("0.0.0.0",
> > >> > >> > configuration.getHttpPort());
> > >> > >> > -            httpContext.add(new
> > Servlet("ArquillianServletRunner",
> > >> > "/"
> > >> > >> +
> > >> > >> > getArchiveNameWithoutExtension(archive)));
> > >> > >> > +            if (archive instanceof WebArchive) {
> > >> > >> > +               httpContext.add(new
> > >> Servlet("ArquillianServletRunner",
> > >> > >> "/"
> > >> > >> > +
> > >> > >> > getArchiveNameWithoutExtension(archive)));
> > >> > >> > +            } else {
> > >> > >> > +               httpContext.add(new
> > >> Servlet("ArquillianServletRunner",
> > >> > >> > "/arquillian-protocol"));
> > >> > >> > +            }
> > >> > >> > +
> > >> > >> >            // we should probably get all servlets and add them
> to
> > >> the
> > >> > >> > context
> > >> > >> >            return new
> ProtocolMetaData().addContext(httpContext);
> > >> > >> >        } catch (Exception e) {
> > >> > >> >
> > >> > >> > Modified:
> > >> > openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > >> > >> > (original)
> > >> > >> > +++
> > openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > >> Wed
> > >> > >> Oct
> > >> > >> > 26 23:08:05 2011
> > >> > >> > @@ -333,5 +333,12 @@
> > >> > >> >       <artifactId>swizzle-stream</artifactId>
> > >> > >> >       <version>1.0.2</version>
> > >> > >> >    </dependency>
> > >> > >> > +    <dependency>
> > >> > >> > +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
> > >> > >> > +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
> > >> > >> > +       <version>1.1.0-alpha-2</version>
> > >> > >> > +       <type>jar</type>
> > >> > >> > +       <scope>compile</scope>
> > >> > >> > +    </dependency>
> > >> > >> >  </dependencies>
> > >> > >> >  </project>
> > >> > >> >
> > >> > >> > Modified:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> > >> > (original)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
> > >> > >> >
> > >> > >> >                   System.setProperty("catalina.home",
> > >> > >> > openejbHome.getAbsolutePath());
> > >> > >> >                           System.setProperty("catalina.base",
> > >> > >> > openejbHome.getAbsolutePath());
> > >> > >> > +
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
> > >> > >> >                           Paths paths = new Paths(new
> > >> > >> > File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
> > >> > >> >                           Installer installer = new
> > >> Installer(paths,
> > >> > >> true);
> > >> > >> >                           installer.installAll();
> > >> > >> >
> > >> > >> > Added:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> > >> > (added)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -0,0 +1,18 @@
> > >> > >> > +package org.apache.openejb.arquillian.remote;
> > >> > >> > +
> > >> > >> > +import
> > >> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> > >> > >> > +import
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> > >> > >> > +import org.jboss.shrinkwrap.api.Archive;
> > >> > >> > +import org.jboss.shrinkwrap.api.ShrinkWrap;
> > >> > >> > +import org.jboss.shrinkwrap.api.spec.JavaArchive;
> > >> > >> > +
> > >> > >> > +public class RemoteTomEEEJBEnricherArchiveAppender implements
> > >> > >> > AuxiliaryArchiveAppender
> > >> > >> > +{
> > >> > >> > +          @Override
> > >> > >> > +          public Archive<?> createAuxiliaryArchive()
> > >> > >> > +          {
> > >> > >> > +             return ShrinkWrap.create(JavaArchive.class,
> > >> > >> > "arquillian-tomee-testenricher-ejb.jar")
> > >> > >> > +
> .addClasses(RemoteTomEEEnricher.class,
> > >> > >> > RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
> > >> > >> > +
> > >> > >> > .addAsServiceProvider(RemoteLoadableExtension.class,
> > >> > >> > RemoteTomEEEJBEnricherExtension.class);
> > >> > >> > +          }
> > >> > >> > +       }
> > >> > >> > \ No newline at end of file
> > >> > >> >
> > >> > >> > Added:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> > >> > (added)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -0,0 +1,13 @@
> > >> > >> > +package org.apache.openejb.arquillian.remote;
> > >> > >> > +
> > >> > >> > +import
> > >> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> > >> > >> > +import org.jboss.arquillian.test.spi.TestEnricher;
> > >> > >> > +
> > >> > >> > +public class RemoteTomEEEJBEnricherExtension implements
> > >> > >> > RemoteLoadableExtension {
> > >> > >> > +    @Override public void register(ExtensionBuilder builder) {
> > >> > >> > +       // only load if EJB is on ClassPath
> > >> > >> > +        if(Validate.classExists("javax.ejb.EJB")) {
> > >> > >> > +           builder.service(TestEnricher.class,
> > >> > >> >
> org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
> > >> > >> > +        }
> > >> > >> > +    }
> > >> > >> > +}
> > >> > >> >
> > >> > >> > Modified:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> > >> > (original)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
> > >> > >> >  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
> > >> > >> >  import org.jboss.arquillian.test.spi.TestEnricher;
> > >> > >> >
> > >> > >> > +import javax.ejb.EJB;
> > >> > >> >  import javax.enterprise.context.spi.CreationalContext;
> > >> > >> >  import javax.enterprise.inject.spi.AnnotatedType;
> > >> > >> >  import javax.enterprise.inject.spi.BeanManager;
> > >> > >> >  import javax.enterprise.inject.spi.InjectionTarget;
> > >> > >> > +import javax.naming.Context;
> > >> > >> > +import javax.naming.InitialContext;
> > >> > >> > +import javax.naming.NamingException;
> > >> > >> > +
> > >> > >> > +import java.lang.annotation.Annotation;
> > >> > >> > +import java.lang.reflect.Field;
> > >> > >> >  import java.lang.reflect.Method;
> > >> > >> > +import java.util.List;
> > >> > >> >
> > >> > >> >  public class RemoteTomEEEnricher implements TestEnricher {
> > >> > >> > -    @Override public void enrich(Object testCase) {
> > >> > >> > -//        BeanManager mgr = getBeanManager();
> > >> > >> > -//        if (mgr != null) {
> > >> > >> > -//            AnnotatedType<?> type =
> > >> > >> >  mgr.createAnnotatedType(getClass());
> > >> > >> > -//            InjectionTarget<Object> injectionTarget =
> > >> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> > >> > >> > -//            CreationalContext<Object> context =
> > >> > >> > mgr.createCreationalContext(null);
> > >> > >> > -//
> > >> > >> > -//            injectionTarget.inject(testCase, context);
> > >> > >> > -//            injectionTarget.postConstruct(this);
> > >> > >> > -//        } else {
> > >> > >> > -//            throw new NullPointerException("bean manager is
> > >> null");
> > >> > >> > -//        }
> > >> > >> > -
> > >> > >> > -        /* TODO: see if this code could be called after tests
> > >> > >> > -                *
> > >> > >> > -                * if (injectionTarget != null) {
> > >> > >> > -                *        injectionTarget.preDestroy(this);
> > >> > >> > -                *    }
> > >> > >> > -                *   if (context != null) {
> > >> > >> > -                *        context.release();
> > >> > >> > -                *    }
> > >> > >> > -                *
> > >> > >> > -                *   injectionTarget = null;
> > >> > >> > -                *   context = null;
> > >> > >> > -                */
> > >> > >> > -    }
> > >> > >> > -
> > >> > >> > -    @Override public Object[] resolve(Method method) {
> > >> > >> > -        return new Object[method.getParameterTypes().length];
> > >> > >> > -    }
> > >> > >> > -
> > >> > >> > -    public BeanManager getBeanManager() {
> > >> > >> > -        return
> > >> ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> > >> > >> > -    }
> > >> > >> > +
> > >> > >> > +       private static final String ANNOTATION_NAME =
> > >> "javax.ejb.EJB";
> > >> > >> > +
> > >> > >> > +       public void enrich(Object testCase) {
> > >> > >> > +               BeanManager mgr = getBeanManager();
> > >> > >> > +               if (mgr != null) {
> > >> > >> > +                       AnnotatedType<?> type =
> > >> > >> > mgr.createAnnotatedType(getClass());
> > >> > >> > +                       InjectionTarget<Object> injectionTarget
> =
> > >> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> > >> > >> > +                       CreationalContext<Object> context =
> > >> > >> > mgr.createCreationalContext(null);
> > >> > >> > +
> > >> > >> > +                       injectionTarget.inject(testCase,
> > context);
> > >> > >> > +                       injectionTarget.postConstruct(this);
> > >> > >> > +               }
> > >> > >> > +
> > >> > >> > +               try {
> > >> > >> > +                       if
> > >> > >> > (SecurityActions.isClassPresent(ANNOTATION_NAME))
> > >> > >> > {
> > >> > >> > +                               @SuppressWarnings("unchecked")
> > >> > >> > +                               Class<? extends Annotation>
> > >> > >> ejbAnnotation =
> > >> > >> > (Class<? extends Annotation>)
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> > SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
> > >> > >> > +
> > >> > >> > +                               List<Field> annotatedFields =
> > >> > >> > SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
> > >> > >> > ejbAnnotation);
> > >> > >> > +
> > >> > >> > +                               for (Field field :
> > annotatedFields)
> > >> {
> > >> > >> > +                                       if (field.get(testCase)
> > ==
> > >> > null)
> > >> > >> {
> > >> > >> > +                                               EJB
> > fieldAnnotation
> > >> =
> > >> > >> (EJB)
> > >> > >> > field.getAnnotation(ejbAnnotation);
> > >> > >> > +                                               Object ejb =
> > >> > >> > lookupEJB(field.getType(), fieldAnnotation.mappedName());
> > >> > >> > +
> > field.set(testCase,
> > >> > >> ejb);
> > >> > >> > +                                       }
> > >> > >> > +                               }
> > >> > >> > +
> > >> > >> > +                               List<Method> methods =
> > >> > >> > SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
> > >> > >> > ejbAnnotation);
> > >> > >> > +
> > >> > >> > +                               for (Method method : methods) {
> > >> > >> > +                                       if
> > >> > >> > (method.getParameterTypes().length != 1) {
> > >> > >> > +                                               throw new
> > >> > >> > RuntimeException("@EJB only allowed on single argument
> methods");
> > >> > >> > +                                       }
> > >> > >> > +                                       if
> > >> > >> > (!method.getName().startsWith("set")) {
> > >> > >> > +                                               throw new
> > >> > >> > RuntimeException("@EJB only allowed on 'set' methods");
> > >> > >> > +                                       }
> > >> > >> > +                                       EJB parameterAnnotation
> =
> > >> > null;
> > >> > >> //
> > >> > >> > method.getParameterAnnotations()[0]
> > >> > >> > +                                       for (Annotation
> > annotation
> > >> :
> > >> > >> > method.getParameterAnnotations()[0]) {
> > >> > >> > +                                               if
> > >> > >> > (EJB.class.isAssignableFrom(annotation.annotationType())) {
> > >> > >> > +
> > >> > >> parameterAnnotation
> > >> > >> > = (EJB) annotation;
> > >> > >> > +                                               }
> > >> > >> > +                                       }
> > >> > >> > +                                       String mappedName =
> > >> > >> > parameterAnnotation == null ? null :
> > >> parameterAnnotation.mappedName();
> > >> > >> > +                                       Object ejb =
> > >> > >> > lookupEJB(method.getParameterTypes()[0], mappedName);
> > >> > >> > +                                       method.invoke(testCase,
> > >> ejb);
> > >> > >> > +                               }
> > >> > >> > +
> > >> > >> > +                       }
> > >> > >> > +               } catch (Exception e) {
> > >> > >> > +
> > >> > >> > +               }
> > >> > >> > +
> > >> > >> > +       }
> > >> > >> > +
> > >> > >> > +       protected Object lookupEJB(Class<?> fieldType, String
> > >> > >> mappedName)
> > >> > >> > throws Exception {
> > >> > >> > +               // TODO: figure out test context ?
> > >> > >> > +               Context initcontext = new InitialContext();
> > >> > >> > +
> > >> > >> > +               // TODO: These names are not spec compliant;
> > >> fieldType
> > >> > >> > needs
> > >> > >> > to be a
> > >> > >> > +               // bean type here,
> > >> > >> > +               // but usually is just an interface of a bean.
> > >> These
> > >> > >> seldom
> > >> > >> > work.
> > >> > >> > +               String[] jndiNames = {
> > >> > >> > "openejb:global/global/test/test.jar/" +
> > fieldType.getSimpleName()
> > >> +
> > >> > >> > "Bean",
> > >> > >> > +
> > >> "openejb:global/global/test/test.jar/"
> > >> > +
> > >> > >> > fieldType.getSimpleName(),
> > >> > >> > +                               "java:global/test/test.jar/" +
> > >> > >> > fieldType.getSimpleName() + "Bean",
> > >> > >> > +                               "java:global/test/test.jar/" +
> > >> > >> > fieldType.getSimpleName(),
> > >> > >> > +                               "java:global/test.ear/test/" +
> > >> > >> > fieldType.getSimpleName() + "Bean",
> > >> > >> > +                               "java:global/test.ear/test/" +
> > >> > >> > fieldType.getSimpleName(),
> > >> > >> > +                               "java:global/test/" +
> > >> > >> > fieldType.getSimpleName(),
> > >> > >> > +                               "java:global/test/" +
> > >> > >> > fieldType.getSimpleName() + "Bean",
> > >> > >> > +                               "java:global/test/" +
> > >> > >> > fieldType.getSimpleName() + "/no-interface",
> > >> > >> > +                               "test/" +
> > fieldType.getSimpleName()
> > >> +
> > >> > >> > "Bean/local",
> > >> > >> > +                               "test/" +
> > fieldType.getSimpleName()
> > >> +
> > >> > >> > "Bean/remote",
> > >> > >> > +                               "test/" +
> > fieldType.getSimpleName()
> > >> +
> > >> > >> > "/no-interface",
> > >> > >> > +                               fieldType.getSimpleName() +
> > >> > >> "Bean/local",
> > >> > >> > +                               fieldType.getSimpleName() +
> > >> > >> "Bean/remote",
> > >> > >> > +                               fieldType.getSimpleName() +
> > >> > >> > "/no-interface",
> > >> > >> > +                               "ejblocal:" +
> > >> > >> fieldType.getCanonicalName(),
> > >> > >> > +                               fieldType.getCanonicalName() };
> > >> > >> > +               if ((mappedName != null) &&
> > >> (!mappedName.equals("")))
> > >> > {
> > >> > >> > +                       // Use only the mapped name to lookup
> > this
> > >> EJB
> > >> > >> > +                       jndiNames = new String[] { mappedName
> };
> > >> > >> > +               }
> > >> > >> > +
> > >> > >> > +               for (String jndiName : jndiNames) {
> > >> > >> > +                       try {
> > >> > >> > +                               return
> > >> initcontext.lookup(jndiName);
> > >> > >> > +                       } catch (NamingException e) {
> > >> > >> > +                               // no-op, try next
> > >> > >> > +                       }
> > >> > >> > +               }
> > >> > >> > +               throw new NamingException("No EJB found in
> > JNDI");
> > >> > >> > +       }
> > >> > >> > +
> > >> > >> > +       @Override
> > >> > >> > +       public Object[] resolve(Method method) {
> > >> > >> > +               return new
> > >> Object[method.getParameterTypes().length];
> > >> > >> > +       }
> > >> > >> > +
> > >> > >> > +       public BeanManager getBeanManager() {
> > >> > >> > +               return
> > >> > >> > ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> > >> > >> > +       }
> > >> > >> >  }
> > >> > >> >
> > >> > >> > Modified:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> > >> > (original)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -1,12 +1,12 @@
> > >> > >> >  package org.apache.openejb.arquillian.remote;
> > >> > >> >
> > >> > >> >  import
> > >> > >> >
> > >> >
> > org.jboss.arquillian.container.spi.client.container.DeployableContainer;
> > >> > >> > +import
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> > >> > >> >  import org.jboss.arquillian.core.spi.LoadableExtension;
> > >> > >> > -import org.jboss.arquillian.test.spi.TestEnricher;
> > >> > >> >
> > >> > >> >  public class RemoteTomEEExtension implements LoadableExtension
> {
> > >> > >> >    @Override public void register(ExtensionBuilder builder) {
> > >> > >> >        builder.service(DeployableContainer.class,
> > >> > >> > RemoteTomEEContainer.class)
> > >> > >> > -            .service(TestEnricher.class,
> > >> RemoteTomEEEnricher.class);
> > >> > >> > +            .service(AuxiliaryArchiveAppender.class,
> > >> > >> > RemoteTomEEEJBEnricherArchiveAppender.class);
> > >> > >> >    }
> > >> > >> >  }
> > >> > >> >
> > >> > >> > Added:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > >> > (added)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -0,0 +1,249 @@
> > >> > >> > +/*
> > >> > >> > + * JBoss, Home of Professional Open Source
> > >> > >> > + * Copyright 2009, Red Hat Middleware LLC, and individual
> > >> > contributors
> > >> > >> > + * by the @authors tag. See the copyright.txt in the
> > distribution
> > >> for
> > >> > a
> > >> > >> > + * full listing of individual contributors.
> > >> > >> > + *
> > >> > >> > + * 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.openejb.arquillian.remote;
> > >> > >> > +
> > >> > >> > +import java.lang.annotation.Annotation;
> > >> > >> > +import java.lang.reflect.Constructor;
> > >> > >> > +import java.lang.reflect.Field;
> > >> > >> > +import java.lang.reflect.Method;
> > >> > >> > +import java.security.AccessController;
> > >> > >> > +import java.security.PrivilegedAction;
> > >> > >> > +import java.security.PrivilegedActionException;
> > >> > >> > +import java.security.PrivilegedExceptionAction;
> > >> > >> > +import java.util.ArrayList;
> > >> > >> > +import java.util.List;
> > >> > >> > +
> > >> > >> > +/**
> > >> > >> > + * SecurityActions
> > >> > >> > + *
> > >> > >> > + * A set of privileged actions that are not to leak out
> > >> > >> > + * of this package
> > >> > >> > + *
> > >> > >> > + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> > >> > >> > + * @version $Revision: $
> > >> > >> > + */
> > >> > >> > +final class SecurityActions
> > >> > >> > +{
> > >> > >> > +
> > >> > >> > +
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > >> > +   // Constructor
> > >> > >> >
> > >> ------------------------------------------------------------------||
> > >> > >> > +
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > >> > +
> > >> > >> > +   /**
> > >> > >> > +    * No instantiation
> > >> > >> > +    */
> > >> > >> > +   private SecurityActions()
> > >> > >> > +   {
> > >> > >> > +      throw new UnsupportedOperationException("No
> > instantiation");
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > >> > +   // Utility Methods
> > >> > >> >
> --------------------------------------------------------------||
> > >> > >> > +
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > >> > +
> > >> > >> > +   /**
> > >> > >> > +    * Obtains the Thread Context ClassLoader
> > >> > >> > +    */
> > >> > >> > +   static ClassLoader getThreadContextClassLoader()
> > >> > >> > +   {
> > >> > >> > +      return
> > >> AccessController.doPrivileged(GetTcclAction.INSTANCE);
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +   /**
> > >> > >> > +    * Obtains the Constructor specified from the given Class
> and
> > >> > >> argument
> > >> > >> > types
> > >> > >> > +    * @param clazz
> > >> > >> > +    * @param argumentTypes
> > >> > >> > +    * @return
> > >> > >> > +    * @throws NoSuchMethodException
> > >> > >> > +    */
> > >> > >> > +   static Constructor<?> getConstructor(final Class<?> clazz,
> > >> final
> > >> > >> > Class<?>... argumentTypes)
> > >> > >> > +         throws NoSuchMethodException
> > >> > >> > +   {
> > >> > >> > +      try
> > >> > >> > +      {
> > >> > >> > +         return AccessController.doPrivileged(new
> > >> > >> > PrivilegedExceptionAction<Constructor<?>>()
> > >> > >> > +         {
> > >> > >> > +            public Constructor<?> run() throws
> > >> NoSuchMethodException
> > >> > >> > +            {
> > >> > >> > +               return clazz.getConstructor(argumentTypes);
> > >> > >> > +            }
> > >> > >> > +         });
> > >> > >> > +      }
> > >> > >> > +      // Unwrap
> > >> > >> > +      catch (final PrivilegedActionException pae)
> > >> > >> > +      {
> > >> > >> > +         final Throwable t = pae.getCause();
> > >> > >> > +         // Rethrow
> > >> > >> > +         if (t instanceof NoSuchMethodException)
> > >> > >> > +         {
> > >> > >> > +            throw (NoSuchMethodException) t;
> > >> > >> > +         }
> > >> > >> > +         else
> > >> > >> > +         {
> > >> > >> > +            // No other checked Exception thrown by
> > >> > >> Class.getConstructor
> > >> > >> > +            try
> > >> > >> > +            {
> > >> > >> > +               throw (RuntimeException) t;
> > >> > >> > +            }
> > >> > >> > +            // Just in case we've really messed up
> > >> > >> > +            catch (final ClassCastException cce)
> > >> > >> > +            {
> > >> > >> > +               throw new RuntimeException("Obtained unchecked
> > >> > >> Exception;
> > >> > >> > this code should never be reached", t);
> > >> > >> > +            }
> > >> > >> > +         }
> > >> > >> > +      }
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +   /**
> > >> > >> > +    * Create a new instance by finding a constructor that
> > matches
> > >> the
> > >> > >> > argumentTypes signature
> > >> > >> > +    * using the arguments for instantiation.
> > >> > >> > +    *
> > >> > >> > +    * @param className Full classname of class to create
> > >> > >> > +    * @param argumentTypes The constructor argument types
> > >> > >> > +    * @param arguments The constructor arguments
> > >> > >> > +    * @return a new instance
> > >> > >> > +    * @throws IllegalArgumentException if className,
> > >> argumentTypes,
> > >> > or
> > >> > >> > arguments are null
> > >> > >> > +    * @throws RuntimeException if any exceptions during
> creation
> > >> > >> > +    * @author <a href="mailto:aslak@conduct.no">Aslak
> > Knutsen</a>
> > >> > >> > +    * @author <a href="mailto:andrew.rubinger@jboss.org
> > ">ALR</a>
> > >> > >> > +    */
> > >> > >> > +   static <T> T newInstance(final String className, final
> > >> Class<?>[]
> > >> > >> > argumentTypes, final Object[] arguments,
> > >> > >> > +         final Class<T> expectedType)
> > >> > >> > +   {
> > >> > >> > +      if (className == null)
> > >> > >> > +      {
> > >> > >> > +         throw new IllegalArgumentException("ClassName must be
> > >> > >> > specified");
> > >> > >> > +      }
> > >> > >> > +      if (argumentTypes == null)
> > >> > >> > +      {
> > >> > >> > +         throw new IllegalArgumentException("ArgumentTypes
> must
> > be
> > >> > >> > specified. Use empty array if no arguments");
> > >> > >> > +      }
> > >> > >> > +      if (arguments == null)
> > >> > >> > +      {
> > >> > >> > +         throw new IllegalArgumentException("Arguments must be
> > >> > >> specified.
> > >> > >> > Use empty array if no arguments");
> > >> > >> > +      }
> > >> > >> > +      final Object obj;
> > >> > >> > +      try
> > >> > >> > +      {
> > >> > >> > +         final ClassLoader tccl =
> getThreadContextClassLoader();
> > >> > >> > +         final Class<?> implClass = Class.forName(className,
> > >> false,
> > >> > >> tccl);
> > >> > >> > +         Constructor<?> constructor =
> getConstructor(implClass,
> > >> > >> > argumentTypes);
> > >> > >> > +         obj = constructor.newInstance(arguments);
> > >> > >> > +      }
> > >> > >> > +      catch (Exception e)
> > >> > >> > +      {
> > >> > >> > +         throw new RuntimeException("Could not create new
> > instance
> > >> of
> > >> > "
> > >> > >> +
> > >> > >> > className
> > >> > >> > +               + ", missing package from classpath?", e);
> > >> > >> > +      }
> > >> > >> > +
> > >> > >> > +      // Cast
> > >> > >> > +      try
> > >> > >> > +      {
> > >> > >> > +         return expectedType.cast(obj);
> > >> > >> > +      }
> > >> > >> > +      catch (final ClassCastException cce)
> > >> > >> > +      {
> > >> > >> > +         // Reconstruct so we get some useful information
> > >> > >> > +         throw new ClassCastException("Incorrect expected
> type,
> > "
> > >> +
> > >> > >> > expectedType.getName() + ", defined for "
> > >> > >> > +               + obj.getClass().getName());
> > >> > >> > +      }
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +   public static boolean isClassPresent(String name)
> > >> > >> > +   {
> > >> > >> > +      try
> > >> > >> > +      {
> > >> > >> > +         ClassLoader classLoader =
> > getThreadContextClassLoader();
> > >> > >> > +         classLoader.loadClass(name);
> > >> > >> > +         return true;
> > >> > >> > +      }
> > >> > >> > +      catch (ClassNotFoundException e)
> > >> > >> > +      {
> > >> > >> > +         return false;
> > >> > >> > +      }
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +   public static List<Field> getFieldsWithAnnotation(final
> > >> Class<?>
> > >> > >> > source,
> > >> > >> > final Class<? extends Annotation> annotationClass)
> > >> > >> > +   {
> > >> > >> > +      List<Field> declaredAccessableFields =
> > >> > >> > AccessController.doPrivileged(new
> PrivilegedAction<List<Field>>()
> > >> > >> > +      {
> > >> > >> > +         public List<Field> run()
> > >> > >> > +         {
> > >> > >> > +            List<Field> foundFields = new ArrayList<Field>();
> > >> > >> > +            Class<?> nextSource = source;
> > >> > >> > +            while (nextSource != Object.class) {
> > >> > >> > +               for(Field field :
> nextSource.getDeclaredFields())
> > >> > >> > +               {
> > >> > >> > +
>  if(field.isAnnotationPresent(annotationClass))
> > >> > >> > +                  {
> > >> > >> > +                     if(!field.isAccessible())
> > >> > >> > +                     {
> > >> > >> > +                        field.setAccessible(true);
> > >> > >> > +                     }
> > >> > >> > +                     foundFields.add(field);
> > >> > >> > +                  }
> > >> > >> > +               }
> > >> > >> > +               nextSource = nextSource.getSuperclass();
> > >> > >> > +            }
> > >> > >> > +            return foundFields;
> > >> > >> > +         }
> > >> > >> > +      });
> > >> > >> > +      return declaredAccessableFields;
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +   public static List<Method> getMethodsWithAnnotation(final
> > >> Class<?>
> > >> > >> > source, final Class<? extends Annotation> annotationClass)
> > >> > >> > +   {
> > >> > >> > +      List<Method> declaredAccessableMethods =
> > >> > >> > AccessController.doPrivileged(new
> > PrivilegedAction<List<Method>>()
> > >> > >> > +      {
> > >> > >> > +         public List<Method> run()
> > >> > >> > +         {
> > >> > >> > +            List<Method> foundMethods = new
> ArrayList<Method>();
> > >> > >> > +            for(Method method : source.getDeclaredMethods())
> > >> > >> > +            {
> > >> > >> > +               if(method.isAnnotationPresent(annotationClass))
> > >> > >> > +               {
> > >> > >> > +                  if(!method.isAccessible())
> > >> > >> > +                  {
> > >> > >> > +                     method.setAccessible(true);
> > >> > >> > +                  }
> > >> > >> > +                  foundMethods.add(method);
> > >> > >> > +               }
> > >> > >> > +            }
> > >> > >> > +            return foundMethods;
> > >> > >> > +         }
> > >> > >> > +      });
> > >> > >> > +      return declaredAccessableMethods;
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > >> > +   // Inner Classes
> > >> > >> >
> > ----------------------------------------------------------------||
> > >> > >> > +
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > >> > +
> > >> > >> > +   /**
> > >> > >> > +    * Single instance to get the TCCL
> > >> > >> > +    */
> > >> > >> > +   private enum GetTcclAction implements
> > >> > PrivilegedAction<ClassLoader>
> > >> > >> {
> > >> > >> > +      INSTANCE;
> > >> > >> > +
> > >> > >> > +      public ClassLoader run()
> > >> > >> > +      {
> > >> > >> > +         return
> Thread.currentThread().getContextClassLoader();
> > >> > >> > +      }
> > >> > >> > +
> > >> > >> > +   }
> > >> > >> > +
> > >> > >> > +}
> > >> > >> >
> > >> > >> > Modified:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > ---
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> > >> > (original)
> > >> > >> > +++
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> > >> > Wed Oct 26 23:08:05 2011
> > >> > >> > @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
> > >> > >> >  import java.io.InputStream;
> > >> > >> >  import java.net.URL;
> > >> > >> >
> > >> > >> > +import javax.ejb.EJB;
> > >> > >> > +
> > >> > >> >  import junit.framework.Assert;
> > >> > >> >
> > >> > >> >  import org.jboss.arquillian.container.test.api.Deployment;
> > >> > >> > @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
> > >> > >> >  @RunWith(Arquillian.class)
> > >> > >> >  public class TomEEContainerTest {
> > >> > >> >
> > >> > >> > -    @Deployment(testable = false)
> > >> > >> > +    @Deployment
> > >> > >> >    public static WebArchive createDeployment() {
> > >> > >> > -        return ShrinkWrap.create(WebArchive.class,
> > >> > >> > "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
> > >> > >> > +        return ShrinkWrap.create(WebArchive.class,
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
> > >> > >> >                .setWebXML(new
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
> > >> > >> > "/Test").exportAsString()));
> > >> > >> >    }
> > >> > >> >
> > >> > >> > -    @Test
> > >> > >> > -    public void nothing(){}
> > >> > >> > +    @EJB
> > >> > >> > +    private TestEjb ejb;
> > >> > >> > +
> > >> > >> > +    @Test
> > >> > >> > +    public void testEjbIsNotNull() throws Exception {
> > >> > >> > +       Assert.assertNotNull(ejb);
> > >> > >> > +    }
> > >> > >> >
> > >> > >> > +    @Test
> > >> > >> >    public void testShouldBeAbleToAccessServletAndEjb() throws
> > >> > Exception
> > >> > >> {
> > >> > >> >        InputStream is = new URL("
> http://localhost:9080/test/Test
> > >> > >> > ").openStream();
> > >> > >> >        ByteArrayOutputStream os = new ByteArrayOutputStream();
> > >> > >> >
> > >> > >> > Modified: openejb/trunk/arquillian-tomee/pom.xml
> > >> > >> > URL:
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> > >> >
> > >> > >> >
> > >> > >>
> > >> >
> > >>
> >
> ==============================================================================
> > >> > >> > --- openejb/trunk/arquillian-tomee/pom.xml (original)
> > >> > >> > +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05
> > 2011
> > >> > >> > @@ -49,7 +49,7 @@
> > >> > >> >
> > >> > >> >  <properties>
> > >> > >> >
> > >>  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> > >> > >> > -    <version.arquillian>1.0.0.CR1</version.arquillian>
> > >> > >> > +    <version.arquillian>1.0.0.CR4</version.arquillian>
> > >> > >> >    <version.cdi-api>1.0</version.cdi-api>
> > >> > >> >    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
> > >> > >> >
>  <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
> > >> > >> >
> > >> > >>
> > >> > >
> > >> >
> > >>
> > >
> > >
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Jonathan Gallimore <jo...@gmail.com>.
Hi Romain,

Thanks for the commit. Your test does work for me, but I still can't run the
ejb tests in the Arquillian showcase, and your test doesn't work if I remove
the @RunAsClient annotation (i.e. running the test in the container with the
app). The tests in the showcase do (or at least should) work with other
containers, so my view is that they should work with TomEE just by adding
the profiles for our adapters to the pom.xml and the settings to
arquillian.xml.

Do you any objection if we use the EJB/CDI enricher code I put in the remote
adapter the other day in both adapters?

I'm presenting at JAX on Tuesday, and it would be great if this
functionality works in both the Remote and Embedded adapters - I think the
Arquillian demo will be a bit disappointing without it. Obviously I'm happy
to carry on looking for a better long-term solution for getting the
injections working with the tests running on the server.

Jon

On Fri, Oct 28, 2011 at 9:03 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Note: David spoke about adding the class test in the application deployed
> as
> a managed bean...it is probably the best solution from an injection point
> of
> view but the test class is not instantiated by us so the managed stuff is
> useless out of the box...i'm not sure how good is this solution since it
> can
> make us rewrite all (almost ;)) the arquillian stuff
>
> - Romain
>
>
> 2011/10/28 Romain Manni-Bucau <rm...@gmail.com>
>
> > i looked testenricher implementation from jboss and...the cdi one is
> almost
> > the same than mine so i guess mine is useless
> >
> > i made the ejb injection for the embedded case working.
> >
> > i think it is just a bit more complicated for the remote case but almost
> > the same philosophy.
> >
> > you can have a look, i added a test case to make it work.
> >
> > - Romain
> >
> >
> >
> > 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
> >
> >> Neither the arquillian-showcase-ejb example, nor my own test in the
> >> moviefun
> >> example for testing ejbs work with the embedded adapter as it stands
> >> either
> >> - the ejb isn't getting injected.
> >>
> >> I'd be grateful if you could give it a try with the latest code.
> >>
> >> I'm afraid I don't understand your last point about @DeploymentScoped.
> >> Where
> >> does that need to go? Do I have to change the showcase code beyond
> >> referencing the adapters in the pom? I'm not sure I like that.
> >>
> >> There does seem to be an issue where the default ejbenricher with
> >> arquillian
> >> would work, except 1. it can't lookup Java:global. I've created an ear
> and
> >> confirmed I can't look it up from a servlet either, and 2. the global
> >> individual names it uses are slightly different to ours:
> >> Java:global/test.ear/test vs Java:global/test/test.jar.
> >>
> >> The first issue really doesn't seem right to me and I think we'll need
> to
> >> solve that.
> >>
> >> Jon
> >> On Oct 27, 2011 11:45 PM, "Romain Manni-Bucau" <rm...@gmail.com>
> >> wrote:
> >>
> >> > i don't get why it doesn't work since everything is in the same
> webapp?
> >> >
> >> > Note: the ejbenricher needs the context to use to lookup, it can be
> set
> >> > using @Inject @DeployementScoped private Instance<Context> context;
> then
> >> > context.set(new InitialContext()) (in the container)
> >> >
> >> > - Romain
> >> >
> >> >
> >> > 2011/10/27 Romain Manni-Bucau <rm...@gmail.com>
> >> >
> >> > > Weird, it seems to work in embedded case.
> >> > >
> >> > > Le 27 oct. 2011 13:29, "Jonathan Gallimore" <
> >> > jonathan.gallimore@gmail.com>
> >> > > a écrit :
> >> > >
> >> > >  When I first saw your email, I did wonder whether the bean manager
> >> code
> >> > >> would be enough, and maybe I was just missing the ArchiveAppender
> >> stuff
> >> > to
> >> > >> get the Enricher over to the server side. I've retested with the
> EJB
> >> > >> lookup
> >> > >> commented out, and unfortunately, It didn't work without my change
> >> for
> >> > the
> >> > >> test case I was using (arquillian-showcase-ejb).
> >> > >>
> >> > >> Jon
> >> > >>
> >> > >> On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
> >> > >> <rm...@gmail.com>wrote:
> >> > >>
> >> > >> > Hi,
> >> > >> >
> >> > >> > Why beanmanager stuff is not enough?
> >> > >> >
> >> > >> > - Romain
> >> > >> >
> >> > >> > ---------- Message transféré ----------
> >> > >> > De : <jg...@apache.org>
> >> > >> > Date : 27 oct. 2011 01:08
> >> > >> > Objet : svn commit: r1189526 - in
> /openejb/trunk/arquillian-tomee:
> >> ./
> >> > >> >
> >> > >>
> >> >
> >>
> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
> >> > >> > arquillian-tomee-remote/
> >> > >> >
> >> > >>
> >> >
> >>
> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
> >> > >> > arquillian-to...
> >> > >> > À : <co...@openejb.apache.org>
> >> > >> >
> >> > >> > Author: jgallimore
> >> > >> > Date: Wed Oct 26 23:08:05 2011
> >> > >> > New Revision: 1189526
> >> > >> >
> >> > >> > URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
> >> > >> > Log:
> >> > >> > Progress on supporting enriching tests with @EJB fields
> >> > >> >
> >> > >> > Added:
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > >> > Removed:
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
> >> > >> > Modified:
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> > >> >   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> > >> >
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> > >> >   openejb/trunk/arquillian-tomee/pom.xml
> >> > >> >
> >> > >> > Modified:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> > >> > (original)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
> >> > >> >  import
> >> > >> >
> >> org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
> >> > >> >  import org.jboss.shrinkwrap.api.Archive;
> >> > >> >  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
> >> > >> > +import org.jboss.shrinkwrap.api.spec.WebArchive;
> >> > >> >  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
> >> > >> >
> >> > >> >  public abstract class TomEEContainer implements
> >> > >> > DeployableContainer<TomEEConfiguration> {
> >> > >> > @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
> >> > >> >    }
> >> > >> >
> >> > >> >    public ProtocolDescription getDefaultProtocol() {
> >> > >> > -        return new ProtocolDescription("Servlet 3.0");
> >> > >> > +        return new ProtocolDescription("Servlet 2.5");
> >> > >> >    }
> >> > >> >
> >> > >> >    public ProtocolMetaData deploy(Archive<?> archive) throws
> >> > >> > DeploymentException {
> >> > >> > @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
> >> > >> >            moduleIds.put(archive.getName(),
> >> file.getAbsolutePath());
> >> > >> >
> >> > >> >            HTTPContext httpContext = new HTTPContext("0.0.0.0",
> >> > >> > configuration.getHttpPort());
> >> > >> > -            httpContext.add(new
> Servlet("ArquillianServletRunner",
> >> > "/"
> >> > >> +
> >> > >> > getArchiveNameWithoutExtension(archive)));
> >> > >> > +            if (archive instanceof WebArchive) {
> >> > >> > +               httpContext.add(new
> >> Servlet("ArquillianServletRunner",
> >> > >> "/"
> >> > >> > +
> >> > >> > getArchiveNameWithoutExtension(archive)));
> >> > >> > +            } else {
> >> > >> > +               httpContext.add(new
> >> Servlet("ArquillianServletRunner",
> >> > >> > "/arquillian-protocol"));
> >> > >> > +            }
> >> > >> > +
> >> > >> >            // we should probably get all servlets and add them to
> >> the
> >> > >> > context
> >> > >> >            return new ProtocolMetaData().addContext(httpContext);
> >> > >> >        } catch (Exception e) {
> >> > >> >
> >> > >> > Modified:
> >> > openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >> > >> > (original)
> >> > >> > +++
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >> Wed
> >> > >> Oct
> >> > >> > 26 23:08:05 2011
> >> > >> > @@ -333,5 +333,12 @@
> >> > >> >       <artifactId>swizzle-stream</artifactId>
> >> > >> >       <version>1.0.2</version>
> >> > >> >    </dependency>
> >> > >> > +    <dependency>
> >> > >> > +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
> >> > >> > +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
> >> > >> > +       <version>1.1.0-alpha-2</version>
> >> > >> > +       <type>jar</type>
> >> > >> > +       <scope>compile</scope>
> >> > >> > +    </dependency>
> >> > >> >  </dependencies>
> >> > >> >  </project>
> >> > >> >
> >> > >> > Modified:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> > >> > (original)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
> >> > >> >
> >> > >> >                   System.setProperty("catalina.home",
> >> > >> > openejbHome.getAbsolutePath());
> >> > >> >                           System.setProperty("catalina.base",
> >> > >> > openejbHome.getAbsolutePath());
> >> > >> > +
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
> >> > >> >                           Paths paths = new Paths(new
> >> > >> > File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
> >> > >> >                           Installer installer = new
> >> Installer(paths,
> >> > >> true);
> >> > >> >                           installer.installAll();
> >> > >> >
> >> > >> > Added:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> > >> > (added)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -0,0 +1,18 @@
> >> > >> > +package org.apache.openejb.arquillian.remote;
> >> > >> > +
> >> > >> > +import
> >> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> >> > >> > +import
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> >> > >> > +import org.jboss.shrinkwrap.api.Archive;
> >> > >> > +import org.jboss.shrinkwrap.api.ShrinkWrap;
> >> > >> > +import org.jboss.shrinkwrap.api.spec.JavaArchive;
> >> > >> > +
> >> > >> > +public class RemoteTomEEEJBEnricherArchiveAppender implements
> >> > >> > AuxiliaryArchiveAppender
> >> > >> > +{
> >> > >> > +          @Override
> >> > >> > +          public Archive<?> createAuxiliaryArchive()
> >> > >> > +          {
> >> > >> > +             return ShrinkWrap.create(JavaArchive.class,
> >> > >> > "arquillian-tomee-testenricher-ejb.jar")
> >> > >> > +                         .addClasses(RemoteTomEEEnricher.class,
> >> > >> > RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
> >> > >> > +
> >> > >> > .addAsServiceProvider(RemoteLoadableExtension.class,
> >> > >> > RemoteTomEEEJBEnricherExtension.class);
> >> > >> > +          }
> >> > >> > +       }
> >> > >> > \ No newline at end of file
> >> > >> >
> >> > >> > Added:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> > >> > (added)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -0,0 +1,13 @@
> >> > >> > +package org.apache.openejb.arquillian.remote;
> >> > >> > +
> >> > >> > +import
> >> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> >> > >> > +import org.jboss.arquillian.test.spi.TestEnricher;
> >> > >> > +
> >> > >> > +public class RemoteTomEEEJBEnricherExtension implements
> >> > >> > RemoteLoadableExtension {
> >> > >> > +    @Override public void register(ExtensionBuilder builder) {
> >> > >> > +       // only load if EJB is on ClassPath
> >> > >> > +        if(Validate.classExists("javax.ejb.EJB")) {
> >> > >> > +           builder.service(TestEnricher.class,
> >> > >> > org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
> >> > >> > +        }
> >> > >> > +    }
> >> > >> > +}
> >> > >> >
> >> > >> > Modified:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> > >> > (original)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
> >> > >> >  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
> >> > >> >  import org.jboss.arquillian.test.spi.TestEnricher;
> >> > >> >
> >> > >> > +import javax.ejb.EJB;
> >> > >> >  import javax.enterprise.context.spi.CreationalContext;
> >> > >> >  import javax.enterprise.inject.spi.AnnotatedType;
> >> > >> >  import javax.enterprise.inject.spi.BeanManager;
> >> > >> >  import javax.enterprise.inject.spi.InjectionTarget;
> >> > >> > +import javax.naming.Context;
> >> > >> > +import javax.naming.InitialContext;
> >> > >> > +import javax.naming.NamingException;
> >> > >> > +
> >> > >> > +import java.lang.annotation.Annotation;
> >> > >> > +import java.lang.reflect.Field;
> >> > >> >  import java.lang.reflect.Method;
> >> > >> > +import java.util.List;
> >> > >> >
> >> > >> >  public class RemoteTomEEEnricher implements TestEnricher {
> >> > >> > -    @Override public void enrich(Object testCase) {
> >> > >> > -//        BeanManager mgr = getBeanManager();
> >> > >> > -//        if (mgr != null) {
> >> > >> > -//            AnnotatedType<?> type =
> >> > >> >  mgr.createAnnotatedType(getClass());
> >> > >> > -//            InjectionTarget<Object> injectionTarget =
> >> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> >> > >> > -//            CreationalContext<Object> context =
> >> > >> > mgr.createCreationalContext(null);
> >> > >> > -//
> >> > >> > -//            injectionTarget.inject(testCase, context);
> >> > >> > -//            injectionTarget.postConstruct(this);
> >> > >> > -//        } else {
> >> > >> > -//            throw new NullPointerException("bean manager is
> >> null");
> >> > >> > -//        }
> >> > >> > -
> >> > >> > -        /* TODO: see if this code could be called after tests
> >> > >> > -                *
> >> > >> > -                * if (injectionTarget != null) {
> >> > >> > -                *        injectionTarget.preDestroy(this);
> >> > >> > -                *    }
> >> > >> > -                *   if (context != null) {
> >> > >> > -                *        context.release();
> >> > >> > -                *    }
> >> > >> > -                *
> >> > >> > -                *   injectionTarget = null;
> >> > >> > -                *   context = null;
> >> > >> > -                */
> >> > >> > -    }
> >> > >> > -
> >> > >> > -    @Override public Object[] resolve(Method method) {
> >> > >> > -        return new Object[method.getParameterTypes().length];
> >> > >> > -    }
> >> > >> > -
> >> > >> > -    public BeanManager getBeanManager() {
> >> > >> > -        return
> >> ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> >> > >> > -    }
> >> > >> > +
> >> > >> > +       private static final String ANNOTATION_NAME =
> >> "javax.ejb.EJB";
> >> > >> > +
> >> > >> > +       public void enrich(Object testCase) {
> >> > >> > +               BeanManager mgr = getBeanManager();
> >> > >> > +               if (mgr != null) {
> >> > >> > +                       AnnotatedType<?> type =
> >> > >> > mgr.createAnnotatedType(getClass());
> >> > >> > +                       InjectionTarget<Object> injectionTarget =
> >> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> >> > >> > +                       CreationalContext<Object> context =
> >> > >> > mgr.createCreationalContext(null);
> >> > >> > +
> >> > >> > +                       injectionTarget.inject(testCase,
> context);
> >> > >> > +                       injectionTarget.postConstruct(this);
> >> > >> > +               }
> >> > >> > +
> >> > >> > +               try {
> >> > >> > +                       if
> >> > >> > (SecurityActions.isClassPresent(ANNOTATION_NAME))
> >> > >> > {
> >> > >> > +                               @SuppressWarnings("unchecked")
> >> > >> > +                               Class<? extends Annotation>
> >> > >> ejbAnnotation =
> >> > >> > (Class<? extends Annotation>)
> >> > >> >
> >> > >>
> >> >
> >>
> SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
> >> > >> > +
> >> > >> > +                               List<Field> annotatedFields =
> >> > >> > SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
> >> > >> > ejbAnnotation);
> >> > >> > +
> >> > >> > +                               for (Field field :
> annotatedFields)
> >> {
> >> > >> > +                                       if (field.get(testCase)
> ==
> >> > null)
> >> > >> {
> >> > >> > +                                               EJB
> fieldAnnotation
> >> =
> >> > >> (EJB)
> >> > >> > field.getAnnotation(ejbAnnotation);
> >> > >> > +                                               Object ejb =
> >> > >> > lookupEJB(field.getType(), fieldAnnotation.mappedName());
> >> > >> > +
> field.set(testCase,
> >> > >> ejb);
> >> > >> > +                                       }
> >> > >> > +                               }
> >> > >> > +
> >> > >> > +                               List<Method> methods =
> >> > >> > SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
> >> > >> > ejbAnnotation);
> >> > >> > +
> >> > >> > +                               for (Method method : methods) {
> >> > >> > +                                       if
> >> > >> > (method.getParameterTypes().length != 1) {
> >> > >> > +                                               throw new
> >> > >> > RuntimeException("@EJB only allowed on single argument methods");
> >> > >> > +                                       }
> >> > >> > +                                       if
> >> > >> > (!method.getName().startsWith("set")) {
> >> > >> > +                                               throw new
> >> > >> > RuntimeException("@EJB only allowed on 'set' methods");
> >> > >> > +                                       }
> >> > >> > +                                       EJB parameterAnnotation =
> >> > null;
> >> > >> //
> >> > >> > method.getParameterAnnotations()[0]
> >> > >> > +                                       for (Annotation
> annotation
> >> :
> >> > >> > method.getParameterAnnotations()[0]) {
> >> > >> > +                                               if
> >> > >> > (EJB.class.isAssignableFrom(annotation.annotationType())) {
> >> > >> > +
> >> > >> parameterAnnotation
> >> > >> > = (EJB) annotation;
> >> > >> > +                                               }
> >> > >> > +                                       }
> >> > >> > +                                       String mappedName =
> >> > >> > parameterAnnotation == null ? null :
> >> parameterAnnotation.mappedName();
> >> > >> > +                                       Object ejb =
> >> > >> > lookupEJB(method.getParameterTypes()[0], mappedName);
> >> > >> > +                                       method.invoke(testCase,
> >> ejb);
> >> > >> > +                               }
> >> > >> > +
> >> > >> > +                       }
> >> > >> > +               } catch (Exception e) {
> >> > >> > +
> >> > >> > +               }
> >> > >> > +
> >> > >> > +       }
> >> > >> > +
> >> > >> > +       protected Object lookupEJB(Class<?> fieldType, String
> >> > >> mappedName)
> >> > >> > throws Exception {
> >> > >> > +               // TODO: figure out test context ?
> >> > >> > +               Context initcontext = new InitialContext();
> >> > >> > +
> >> > >> > +               // TODO: These names are not spec compliant;
> >> fieldType
> >> > >> > needs
> >> > >> > to be a
> >> > >> > +               // bean type here,
> >> > >> > +               // but usually is just an interface of a bean.
> >> These
> >> > >> seldom
> >> > >> > work.
> >> > >> > +               String[] jndiNames = {
> >> > >> > "openejb:global/global/test/test.jar/" +
> fieldType.getSimpleName()
> >> +
> >> > >> > "Bean",
> >> > >> > +
> >> "openejb:global/global/test/test.jar/"
> >> > +
> >> > >> > fieldType.getSimpleName(),
> >> > >> > +                               "java:global/test/test.jar/" +
> >> > >> > fieldType.getSimpleName() + "Bean",
> >> > >> > +                               "java:global/test/test.jar/" +
> >> > >> > fieldType.getSimpleName(),
> >> > >> > +                               "java:global/test.ear/test/" +
> >> > >> > fieldType.getSimpleName() + "Bean",
> >> > >> > +                               "java:global/test.ear/test/" +
> >> > >> > fieldType.getSimpleName(),
> >> > >> > +                               "java:global/test/" +
> >> > >> > fieldType.getSimpleName(),
> >> > >> > +                               "java:global/test/" +
> >> > >> > fieldType.getSimpleName() + "Bean",
> >> > >> > +                               "java:global/test/" +
> >> > >> > fieldType.getSimpleName() + "/no-interface",
> >> > >> > +                               "test/" +
> fieldType.getSimpleName()
> >> +
> >> > >> > "Bean/local",
> >> > >> > +                               "test/" +
> fieldType.getSimpleName()
> >> +
> >> > >> > "Bean/remote",
> >> > >> > +                               "test/" +
> fieldType.getSimpleName()
> >> +
> >> > >> > "/no-interface",
> >> > >> > +                               fieldType.getSimpleName() +
> >> > >> "Bean/local",
> >> > >> > +                               fieldType.getSimpleName() +
> >> > >> "Bean/remote",
> >> > >> > +                               fieldType.getSimpleName() +
> >> > >> > "/no-interface",
> >> > >> > +                               "ejblocal:" +
> >> > >> fieldType.getCanonicalName(),
> >> > >> > +                               fieldType.getCanonicalName() };
> >> > >> > +               if ((mappedName != null) &&
> >> (!mappedName.equals("")))
> >> > {
> >> > >> > +                       // Use only the mapped name to lookup
> this
> >> EJB
> >> > >> > +                       jndiNames = new String[] { mappedName };
> >> > >> > +               }
> >> > >> > +
> >> > >> > +               for (String jndiName : jndiNames) {
> >> > >> > +                       try {
> >> > >> > +                               return
> >> initcontext.lookup(jndiName);
> >> > >> > +                       } catch (NamingException e) {
> >> > >> > +                               // no-op, try next
> >> > >> > +                       }
> >> > >> > +               }
> >> > >> > +               throw new NamingException("No EJB found in
> JNDI");
> >> > >> > +       }
> >> > >> > +
> >> > >> > +       @Override
> >> > >> > +       public Object[] resolve(Method method) {
> >> > >> > +               return new
> >> Object[method.getParameterTypes().length];
> >> > >> > +       }
> >> > >> > +
> >> > >> > +       public BeanManager getBeanManager() {
> >> > >> > +               return
> >> > >> > ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> >> > >> > +       }
> >> > >> >  }
> >> > >> >
> >> > >> > Modified:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> > >> > (original)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -1,12 +1,12 @@
> >> > >> >  package org.apache.openejb.arquillian.remote;
> >> > >> >
> >> > >> >  import
> >> > >> >
> >> >
> org.jboss.arquillian.container.spi.client.container.DeployableContainer;
> >> > >> > +import
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> >> > >> >  import org.jboss.arquillian.core.spi.LoadableExtension;
> >> > >> > -import org.jboss.arquillian.test.spi.TestEnricher;
> >> > >> >
> >> > >> >  public class RemoteTomEEExtension implements LoadableExtension {
> >> > >> >    @Override public void register(ExtensionBuilder builder) {
> >> > >> >        builder.service(DeployableContainer.class,
> >> > >> > RemoteTomEEContainer.class)
> >> > >> > -            .service(TestEnricher.class,
> >> RemoteTomEEEnricher.class);
> >> > >> > +            .service(AuxiliaryArchiveAppender.class,
> >> > >> > RemoteTomEEEJBEnricherArchiveAppender.class);
> >> > >> >    }
> >> > >> >  }
> >> > >> >
> >> > >> > Added:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > >> > (added)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -0,0 +1,249 @@
> >> > >> > +/*
> >> > >> > + * JBoss, Home of Professional Open Source
> >> > >> > + * Copyright 2009, Red Hat Middleware LLC, and individual
> >> > contributors
> >> > >> > + * by the @authors tag. See the copyright.txt in the
> distribution
> >> for
> >> > a
> >> > >> > + * full listing of individual contributors.
> >> > >> > + *
> >> > >> > + * 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.openejb.arquillian.remote;
> >> > >> > +
> >> > >> > +import java.lang.annotation.Annotation;
> >> > >> > +import java.lang.reflect.Constructor;
> >> > >> > +import java.lang.reflect.Field;
> >> > >> > +import java.lang.reflect.Method;
> >> > >> > +import java.security.AccessController;
> >> > >> > +import java.security.PrivilegedAction;
> >> > >> > +import java.security.PrivilegedActionException;
> >> > >> > +import java.security.PrivilegedExceptionAction;
> >> > >> > +import java.util.ArrayList;
> >> > >> > +import java.util.List;
> >> > >> > +
> >> > >> > +/**
> >> > >> > + * SecurityActions
> >> > >> > + *
> >> > >> > + * A set of privileged actions that are not to leak out
> >> > >> > + * of this package
> >> > >> > + *
> >> > >> > + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> >> > >> > + * @version $Revision: $
> >> > >> > + */
> >> > >> > +final class SecurityActions
> >> > >> > +{
> >> > >> > +
> >> > >> > +
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > >> > +   // Constructor
> >> > >> >
> >> ------------------------------------------------------------------||
> >> > >> > +
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > >> > +
> >> > >> > +   /**
> >> > >> > +    * No instantiation
> >> > >> > +    */
> >> > >> > +   private SecurityActions()
> >> > >> > +   {
> >> > >> > +      throw new UnsupportedOperationException("No
> instantiation");
> >> > >> > +   }
> >> > >> > +
> >> > >> > +
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > >> > +   // Utility Methods
> >> > >> > --------------------------------------------------------------||
> >> > >> > +
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > >> > +
> >> > >> > +   /**
> >> > >> > +    * Obtains the Thread Context ClassLoader
> >> > >> > +    */
> >> > >> > +   static ClassLoader getThreadContextClassLoader()
> >> > >> > +   {
> >> > >> > +      return
> >> AccessController.doPrivileged(GetTcclAction.INSTANCE);
> >> > >> > +   }
> >> > >> > +
> >> > >> > +   /**
> >> > >> > +    * Obtains the Constructor specified from the given Class and
> >> > >> argument
> >> > >> > types
> >> > >> > +    * @param clazz
> >> > >> > +    * @param argumentTypes
> >> > >> > +    * @return
> >> > >> > +    * @throws NoSuchMethodException
> >> > >> > +    */
> >> > >> > +   static Constructor<?> getConstructor(final Class<?> clazz,
> >> final
> >> > >> > Class<?>... argumentTypes)
> >> > >> > +         throws NoSuchMethodException
> >> > >> > +   {
> >> > >> > +      try
> >> > >> > +      {
> >> > >> > +         return AccessController.doPrivileged(new
> >> > >> > PrivilegedExceptionAction<Constructor<?>>()
> >> > >> > +         {
> >> > >> > +            public Constructor<?> run() throws
> >> NoSuchMethodException
> >> > >> > +            {
> >> > >> > +               return clazz.getConstructor(argumentTypes);
> >> > >> > +            }
> >> > >> > +         });
> >> > >> > +      }
> >> > >> > +      // Unwrap
> >> > >> > +      catch (final PrivilegedActionException pae)
> >> > >> > +      {
> >> > >> > +         final Throwable t = pae.getCause();
> >> > >> > +         // Rethrow
> >> > >> > +         if (t instanceof NoSuchMethodException)
> >> > >> > +         {
> >> > >> > +            throw (NoSuchMethodException) t;
> >> > >> > +         }
> >> > >> > +         else
> >> > >> > +         {
> >> > >> > +            // No other checked Exception thrown by
> >> > >> Class.getConstructor
> >> > >> > +            try
> >> > >> > +            {
> >> > >> > +               throw (RuntimeException) t;
> >> > >> > +            }
> >> > >> > +            // Just in case we've really messed up
> >> > >> > +            catch (final ClassCastException cce)
> >> > >> > +            {
> >> > >> > +               throw new RuntimeException("Obtained unchecked
> >> > >> Exception;
> >> > >> > this code should never be reached", t);
> >> > >> > +            }
> >> > >> > +         }
> >> > >> > +      }
> >> > >> > +   }
> >> > >> > +
> >> > >> > +   /**
> >> > >> > +    * Create a new instance by finding a constructor that
> matches
> >> the
> >> > >> > argumentTypes signature
> >> > >> > +    * using the arguments for instantiation.
> >> > >> > +    *
> >> > >> > +    * @param className Full classname of class to create
> >> > >> > +    * @param argumentTypes The constructor argument types
> >> > >> > +    * @param arguments The constructor arguments
> >> > >> > +    * @return a new instance
> >> > >> > +    * @throws IllegalArgumentException if className,
> >> argumentTypes,
> >> > or
> >> > >> > arguments are null
> >> > >> > +    * @throws RuntimeException if any exceptions during creation
> >> > >> > +    * @author <a href="mailto:aslak@conduct.no">Aslak
> Knutsen</a>
> >> > >> > +    * @author <a href="mailto:andrew.rubinger@jboss.org
> ">ALR</a>
> >> > >> > +    */
> >> > >> > +   static <T> T newInstance(final String className, final
> >> Class<?>[]
> >> > >> > argumentTypes, final Object[] arguments,
> >> > >> > +         final Class<T> expectedType)
> >> > >> > +   {
> >> > >> > +      if (className == null)
> >> > >> > +      {
> >> > >> > +         throw new IllegalArgumentException("ClassName must be
> >> > >> > specified");
> >> > >> > +      }
> >> > >> > +      if (argumentTypes == null)
> >> > >> > +      {
> >> > >> > +         throw new IllegalArgumentException("ArgumentTypes must
> be
> >> > >> > specified. Use empty array if no arguments");
> >> > >> > +      }
> >> > >> > +      if (arguments == null)
> >> > >> > +      {
> >> > >> > +         throw new IllegalArgumentException("Arguments must be
> >> > >> specified.
> >> > >> > Use empty array if no arguments");
> >> > >> > +      }
> >> > >> > +      final Object obj;
> >> > >> > +      try
> >> > >> > +      {
> >> > >> > +         final ClassLoader tccl = getThreadContextClassLoader();
> >> > >> > +         final Class<?> implClass = Class.forName(className,
> >> false,
> >> > >> tccl);
> >> > >> > +         Constructor<?> constructor = getConstructor(implClass,
> >> > >> > argumentTypes);
> >> > >> > +         obj = constructor.newInstance(arguments);
> >> > >> > +      }
> >> > >> > +      catch (Exception e)
> >> > >> > +      {
> >> > >> > +         throw new RuntimeException("Could not create new
> instance
> >> of
> >> > "
> >> > >> +
> >> > >> > className
> >> > >> > +               + ", missing package from classpath?", e);
> >> > >> > +      }
> >> > >> > +
> >> > >> > +      // Cast
> >> > >> > +      try
> >> > >> > +      {
> >> > >> > +         return expectedType.cast(obj);
> >> > >> > +      }
> >> > >> > +      catch (final ClassCastException cce)
> >> > >> > +      {
> >> > >> > +         // Reconstruct so we get some useful information
> >> > >> > +         throw new ClassCastException("Incorrect expected type,
> "
> >> +
> >> > >> > expectedType.getName() + ", defined for "
> >> > >> > +               + obj.getClass().getName());
> >> > >> > +      }
> >> > >> > +   }
> >> > >> > +
> >> > >> > +   public static boolean isClassPresent(String name)
> >> > >> > +   {
> >> > >> > +      try
> >> > >> > +      {
> >> > >> > +         ClassLoader classLoader =
> getThreadContextClassLoader();
> >> > >> > +         classLoader.loadClass(name);
> >> > >> > +         return true;
> >> > >> > +      }
> >> > >> > +      catch (ClassNotFoundException e)
> >> > >> > +      {
> >> > >> > +         return false;
> >> > >> > +      }
> >> > >> > +   }
> >> > >> > +
> >> > >> > +   public static List<Field> getFieldsWithAnnotation(final
> >> Class<?>
> >> > >> > source,
> >> > >> > final Class<? extends Annotation> annotationClass)
> >> > >> > +   {
> >> > >> > +      List<Field> declaredAccessableFields =
> >> > >> > AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
> >> > >> > +      {
> >> > >> > +         public List<Field> run()
> >> > >> > +         {
> >> > >> > +            List<Field> foundFields = new ArrayList<Field>();
> >> > >> > +            Class<?> nextSource = source;
> >> > >> > +            while (nextSource != Object.class) {
> >> > >> > +               for(Field field : nextSource.getDeclaredFields())
> >> > >> > +               {
> >> > >> > +                  if(field.isAnnotationPresent(annotationClass))
> >> > >> > +                  {
> >> > >> > +                     if(!field.isAccessible())
> >> > >> > +                     {
> >> > >> > +                        field.setAccessible(true);
> >> > >> > +                     }
> >> > >> > +                     foundFields.add(field);
> >> > >> > +                  }
> >> > >> > +               }
> >> > >> > +               nextSource = nextSource.getSuperclass();
> >> > >> > +            }
> >> > >> > +            return foundFields;
> >> > >> > +         }
> >> > >> > +      });
> >> > >> > +      return declaredAccessableFields;
> >> > >> > +   }
> >> > >> > +
> >> > >> > +   public static List<Method> getMethodsWithAnnotation(final
> >> Class<?>
> >> > >> > source, final Class<? extends Annotation> annotationClass)
> >> > >> > +   {
> >> > >> > +      List<Method> declaredAccessableMethods =
> >> > >> > AccessController.doPrivileged(new
> PrivilegedAction<List<Method>>()
> >> > >> > +      {
> >> > >> > +         public List<Method> run()
> >> > >> > +         {
> >> > >> > +            List<Method> foundMethods = new ArrayList<Method>();
> >> > >> > +            for(Method method : source.getDeclaredMethods())
> >> > >> > +            {
> >> > >> > +               if(method.isAnnotationPresent(annotationClass))
> >> > >> > +               {
> >> > >> > +                  if(!method.isAccessible())
> >> > >> > +                  {
> >> > >> > +                     method.setAccessible(true);
> >> > >> > +                  }
> >> > >> > +                  foundMethods.add(method);
> >> > >> > +               }
> >> > >> > +            }
> >> > >> > +            return foundMethods;
> >> > >> > +         }
> >> > >> > +      });
> >> > >> > +      return declaredAccessableMethods;
> >> > >> > +   }
> >> > >> > +
> >> > >> > +
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > >> > +   // Inner Classes
> >> > >> >
> ----------------------------------------------------------------||
> >> > >> > +
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > >> > +
> >> > >> > +   /**
> >> > >> > +    * Single instance to get the TCCL
> >> > >> > +    */
> >> > >> > +   private enum GetTcclAction implements
> >> > PrivilegedAction<ClassLoader>
> >> > >> {
> >> > >> > +      INSTANCE;
> >> > >> > +
> >> > >> > +      public ClassLoader run()
> >> > >> > +      {
> >> > >> > +         return Thread.currentThread().getContextClassLoader();
> >> > >> > +      }
> >> > >> > +
> >> > >> > +   }
> >> > >> > +
> >> > >> > +}
> >> > >> >
> >> > >> > Modified:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > ---
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> > >> > (original)
> >> > >> > +++
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> > >> > Wed Oct 26 23:08:05 2011
> >> > >> > @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
> >> > >> >  import java.io.InputStream;
> >> > >> >  import java.net.URL;
> >> > >> >
> >> > >> > +import javax.ejb.EJB;
> >> > >> > +
> >> > >> >  import junit.framework.Assert;
> >> > >> >
> >> > >> >  import org.jboss.arquillian.container.test.api.Deployment;
> >> > >> > @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
> >> > >> >  @RunWith(Arquillian.class)
> >> > >> >  public class TomEEContainerTest {
> >> > >> >
> >> > >> > -    @Deployment(testable = false)
> >> > >> > +    @Deployment
> >> > >> >    public static WebArchive createDeployment() {
> >> > >> > -        return ShrinkWrap.create(WebArchive.class,
> >> > >> > "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
> >> > >> > +        return ShrinkWrap.create(WebArchive.class,
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
> >> > >> >                .setWebXML(new
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
> >> > >> > "/Test").exportAsString()));
> >> > >> >    }
> >> > >> >
> >> > >> > -    @Test
> >> > >> > -    public void nothing(){}
> >> > >> > +    @EJB
> >> > >> > +    private TestEjb ejb;
> >> > >> > +
> >> > >> > +    @Test
> >> > >> > +    public void testEjbIsNotNull() throws Exception {
> >> > >> > +       Assert.assertNotNull(ejb);
> >> > >> > +    }
> >> > >> >
> >> > >> > +    @Test
> >> > >> >    public void testShouldBeAbleToAccessServletAndEjb() throws
> >> > Exception
> >> > >> {
> >> > >> >        InputStream is = new URL("http://localhost:9080/test/Test
> >> > >> > ").openStream();
> >> > >> >        ByteArrayOutputStream os = new ByteArrayOutputStream();
> >> > >> >
> >> > >> > Modified: openejb/trunk/arquillian-tomee/pom.xml
> >> > >> > URL:
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> > >> >
> >> > >> >
> >> > >>
> >> >
> >>
> ==============================================================================
> >> > >> > --- openejb/trunk/arquillian-tomee/pom.xml (original)
> >> > >> > +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05
> 2011
> >> > >> > @@ -49,7 +49,7 @@
> >> > >> >
> >> > >> >  <properties>
> >> > >> >
> >>  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> >> > >> > -    <version.arquillian>1.0.0.CR1</version.arquillian>
> >> > >> > +    <version.arquillian>1.0.0.CR4</version.arquillian>
> >> > >> >    <version.cdi-api>1.0</version.cdi-api>
> >> > >> >    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
> >> > >> >    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
> >> > >> >
> >> > >>
> >> > >
> >> >
> >>
> >
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Note: David spoke about adding the class test in the application deployed as
a managed bean...it is probably the best solution from an injection point of
view but the test class is not instantiated by us so the managed stuff is
useless out of the box...i'm not sure how good is this solution since it can
make us rewrite all (almost ;)) the arquillian stuff

- Romain


2011/10/28 Romain Manni-Bucau <rm...@gmail.com>

> i looked testenricher implementation from jboss and...the cdi one is almost
> the same than mine so i guess mine is useless
>
> i made the ejb injection for the embedded case working.
>
> i think it is just a bit more complicated for the remote case but almost
> the same philosophy.
>
> you can have a look, i added a test case to make it work.
>
> - Romain
>
>
>
> 2011/10/28 Jonathan Gallimore <jo...@gmail.com>
>
>> Neither the arquillian-showcase-ejb example, nor my own test in the
>> moviefun
>> example for testing ejbs work with the embedded adapter as it stands
>> either
>> - the ejb isn't getting injected.
>>
>> I'd be grateful if you could give it a try with the latest code.
>>
>> I'm afraid I don't understand your last point about @DeploymentScoped.
>> Where
>> does that need to go? Do I have to change the showcase code beyond
>> referencing the adapters in the pom? I'm not sure I like that.
>>
>> There does seem to be an issue where the default ejbenricher with
>> arquillian
>> would work, except 1. it can't lookup Java:global. I've created an ear and
>> confirmed I can't look it up from a servlet either, and 2. the global
>> individual names it uses are slightly different to ours:
>> Java:global/test.ear/test vs Java:global/test/test.jar.
>>
>> The first issue really doesn't seem right to me and I think we'll need to
>> solve that.
>>
>> Jon
>> On Oct 27, 2011 11:45 PM, "Romain Manni-Bucau" <rm...@gmail.com>
>> wrote:
>>
>> > i don't get why it doesn't work since everything is in the same webapp?
>> >
>> > Note: the ejbenricher needs the context to use to lookup, it can be set
>> > using @Inject @DeployementScoped private Instance<Context> context; then
>> > context.set(new InitialContext()) (in the container)
>> >
>> > - Romain
>> >
>> >
>> > 2011/10/27 Romain Manni-Bucau <rm...@gmail.com>
>> >
>> > > Weird, it seems to work in embedded case.
>> > >
>> > > Le 27 oct. 2011 13:29, "Jonathan Gallimore" <
>> > jonathan.gallimore@gmail.com>
>> > > a écrit :
>> > >
>> > >  When I first saw your email, I did wonder whether the bean manager
>> code
>> > >> would be enough, and maybe I was just missing the ArchiveAppender
>> stuff
>> > to
>> > >> get the Enricher over to the server side. I've retested with the EJB
>> > >> lookup
>> > >> commented out, and unfortunately, It didn't work without my change
>> for
>> > the
>> > >> test case I was using (arquillian-showcase-ejb).
>> > >>
>> > >> Jon
>> > >>
>> > >> On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
>> > >> <rm...@gmail.com>wrote:
>> > >>
>> > >> > Hi,
>> > >> >
>> > >> > Why beanmanager stuff is not enough?
>> > >> >
>> > >> > - Romain
>> > >> >
>> > >> > ---------- Message transféré ----------
>> > >> > De : <jg...@apache.org>
>> > >> > Date : 27 oct. 2011 01:08
>> > >> > Objet : svn commit: r1189526 - in /openejb/trunk/arquillian-tomee:
>> ./
>> > >> >
>> > >>
>> >
>> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
>> > >> > arquillian-tomee-remote/
>> > >> >
>> > >>
>> >
>> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
>> > >> > arquillian-to...
>> > >> > À : <co...@openejb.apache.org>
>> > >> >
>> > >> > Author: jgallimore
>> > >> > Date: Wed Oct 26 23:08:05 2011
>> > >> > New Revision: 1189526
>> > >> >
>> > >> > URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
>> > >> > Log:
>> > >> > Progress on supporting enriching tests with @EJB fields
>> > >> >
>> > >> > Added:
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > >> > Removed:
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
>> > >> > Modified:
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> > >> >   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> > >> >
>> > >> >
>> > >> >
>> > >>
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> > >> >   openejb/trunk/arquillian-tomee/pom.xml
>> > >> >
>> > >> > Modified:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> > >> > (original)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
>> > >> >  import
>> > >> >
>> org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
>> > >> >  import org.jboss.shrinkwrap.api.Archive;
>> > >> >  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
>> > >> > +import org.jboss.shrinkwrap.api.spec.WebArchive;
>> > >> >  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
>> > >> >
>> > >> >  public abstract class TomEEContainer implements
>> > >> > DeployableContainer<TomEEConfiguration> {
>> > >> > @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
>> > >> >    }
>> > >> >
>> > >> >    public ProtocolDescription getDefaultProtocol() {
>> > >> > -        return new ProtocolDescription("Servlet 3.0");
>> > >> > +        return new ProtocolDescription("Servlet 2.5");
>> > >> >    }
>> > >> >
>> > >> >    public ProtocolMetaData deploy(Archive<?> archive) throws
>> > >> > DeploymentException {
>> > >> > @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
>> > >> >            moduleIds.put(archive.getName(),
>> file.getAbsolutePath());
>> > >> >
>> > >> >            HTTPContext httpContext = new HTTPContext("0.0.0.0",
>> > >> > configuration.getHttpPort());
>> > >> > -            httpContext.add(new Servlet("ArquillianServletRunner",
>> > "/"
>> > >> +
>> > >> > getArchiveNameWithoutExtension(archive)));
>> > >> > +            if (archive instanceof WebArchive) {
>> > >> > +               httpContext.add(new
>> Servlet("ArquillianServletRunner",
>> > >> "/"
>> > >> > +
>> > >> > getArchiveNameWithoutExtension(archive)));
>> > >> > +            } else {
>> > >> > +               httpContext.add(new
>> Servlet("ArquillianServletRunner",
>> > >> > "/arquillian-protocol"));
>> > >> > +            }
>> > >> > +
>> > >> >            // we should probably get all servlets and add them to
>> the
>> > >> > context
>> > >> >            return new ProtocolMetaData().addContext(httpContext);
>> > >> >        } catch (Exception e) {
>> > >> >
>> > >> > Modified:
>> > openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > --- openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>> > >> > (original)
>> > >> > +++ openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>> Wed
>> > >> Oct
>> > >> > 26 23:08:05 2011
>> > >> > @@ -333,5 +333,12 @@
>> > >> >       <artifactId>swizzle-stream</artifactId>
>> > >> >       <version>1.0.2</version>
>> > >> >    </dependency>
>> > >> > +    <dependency>
>> > >> > +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
>> > >> > +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
>> > >> > +       <version>1.1.0-alpha-2</version>
>> > >> > +       <type>jar</type>
>> > >> > +       <scope>compile</scope>
>> > >> > +    </dependency>
>> > >> >  </dependencies>
>> > >> >  </project>
>> > >> >
>> > >> > Modified:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> > >> > (original)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
>> > >> >
>> > >> >                   System.setProperty("catalina.home",
>> > >> > openejbHome.getAbsolutePath());
>> > >> >                           System.setProperty("catalina.base",
>> > >> > openejbHome.getAbsolutePath());
>> > >> > +
>> > >> >
>> > >> >
>> > >>
>> >
>> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
>> > >> >                           Paths paths = new Paths(new
>> > >> > File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
>> > >> >                           Installer installer = new
>> Installer(paths,
>> > >> true);
>> > >> >                           installer.installAll();
>> > >> >
>> > >> > Added:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> > >> > (added)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -0,0 +1,18 @@
>> > >> > +package org.apache.openejb.arquillian.remote;
>> > >> > +
>> > >> > +import
>> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
>> > >> > +import
>> > >> >
>> > >> >
>> > >>
>> >
>> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
>> > >> > +import org.jboss.shrinkwrap.api.Archive;
>> > >> > +import org.jboss.shrinkwrap.api.ShrinkWrap;
>> > >> > +import org.jboss.shrinkwrap.api.spec.JavaArchive;
>> > >> > +
>> > >> > +public class RemoteTomEEEJBEnricherArchiveAppender implements
>> > >> > AuxiliaryArchiveAppender
>> > >> > +{
>> > >> > +          @Override
>> > >> > +          public Archive<?> createAuxiliaryArchive()
>> > >> > +          {
>> > >> > +             return ShrinkWrap.create(JavaArchive.class,
>> > >> > "arquillian-tomee-testenricher-ejb.jar")
>> > >> > +                         .addClasses(RemoteTomEEEnricher.class,
>> > >> > RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
>> > >> > +
>> > >> > .addAsServiceProvider(RemoteLoadableExtension.class,
>> > >> > RemoteTomEEEJBEnricherExtension.class);
>> > >> > +          }
>> > >> > +       }
>> > >> > \ No newline at end of file
>> > >> >
>> > >> > Added:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> > >> > (added)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -0,0 +1,13 @@
>> > >> > +package org.apache.openejb.arquillian.remote;
>> > >> > +
>> > >> > +import
>> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
>> > >> > +import org.jboss.arquillian.test.spi.TestEnricher;
>> > >> > +
>> > >> > +public class RemoteTomEEEJBEnricherExtension implements
>> > >> > RemoteLoadableExtension {
>> > >> > +    @Override public void register(ExtensionBuilder builder) {
>> > >> > +       // only load if EJB is on ClassPath
>> > >> > +        if(Validate.classExists("javax.ejb.EJB")) {
>> > >> > +           builder.service(TestEnricher.class,
>> > >> > org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
>> > >> > +        }
>> > >> > +    }
>> > >> > +}
>> > >> >
>> > >> > Modified:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> > >> > (original)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
>> > >> >  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
>> > >> >  import org.jboss.arquillian.test.spi.TestEnricher;
>> > >> >
>> > >> > +import javax.ejb.EJB;
>> > >> >  import javax.enterprise.context.spi.CreationalContext;
>> > >> >  import javax.enterprise.inject.spi.AnnotatedType;
>> > >> >  import javax.enterprise.inject.spi.BeanManager;
>> > >> >  import javax.enterprise.inject.spi.InjectionTarget;
>> > >> > +import javax.naming.Context;
>> > >> > +import javax.naming.InitialContext;
>> > >> > +import javax.naming.NamingException;
>> > >> > +
>> > >> > +import java.lang.annotation.Annotation;
>> > >> > +import java.lang.reflect.Field;
>> > >> >  import java.lang.reflect.Method;
>> > >> > +import java.util.List;
>> > >> >
>> > >> >  public class RemoteTomEEEnricher implements TestEnricher {
>> > >> > -    @Override public void enrich(Object testCase) {
>> > >> > -//        BeanManager mgr = getBeanManager();
>> > >> > -//        if (mgr != null) {
>> > >> > -//            AnnotatedType<?> type =
>> > >> >  mgr.createAnnotatedType(getClass());
>> > >> > -//            InjectionTarget<Object> injectionTarget =
>> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
>> > >> > -//            CreationalContext<Object> context =
>> > >> > mgr.createCreationalContext(null);
>> > >> > -//
>> > >> > -//            injectionTarget.inject(testCase, context);
>> > >> > -//            injectionTarget.postConstruct(this);
>> > >> > -//        } else {
>> > >> > -//            throw new NullPointerException("bean manager is
>> null");
>> > >> > -//        }
>> > >> > -
>> > >> > -        /* TODO: see if this code could be called after tests
>> > >> > -                *
>> > >> > -                * if (injectionTarget != null) {
>> > >> > -                *        injectionTarget.preDestroy(this);
>> > >> > -                *    }
>> > >> > -                *   if (context != null) {
>> > >> > -                *        context.release();
>> > >> > -                *    }
>> > >> > -                *
>> > >> > -                *   injectionTarget = null;
>> > >> > -                *   context = null;
>> > >> > -                */
>> > >> > -    }
>> > >> > -
>> > >> > -    @Override public Object[] resolve(Method method) {
>> > >> > -        return new Object[method.getParameterTypes().length];
>> > >> > -    }
>> > >> > -
>> > >> > -    public BeanManager getBeanManager() {
>> > >> > -        return
>> ThreadSingletonServiceImpl.get().getBeanManagerImpl();
>> > >> > -    }
>> > >> > +
>> > >> > +       private static final String ANNOTATION_NAME =
>> "javax.ejb.EJB";
>> > >> > +
>> > >> > +       public void enrich(Object testCase) {
>> > >> > +               BeanManager mgr = getBeanManager();
>> > >> > +               if (mgr != null) {
>> > >> > +                       AnnotatedType<?> type =
>> > >> > mgr.createAnnotatedType(getClass());
>> > >> > +                       InjectionTarget<Object> injectionTarget =
>> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
>> > >> > +                       CreationalContext<Object> context =
>> > >> > mgr.createCreationalContext(null);
>> > >> > +
>> > >> > +                       injectionTarget.inject(testCase, context);
>> > >> > +                       injectionTarget.postConstruct(this);
>> > >> > +               }
>> > >> > +
>> > >> > +               try {
>> > >> > +                       if
>> > >> > (SecurityActions.isClassPresent(ANNOTATION_NAME))
>> > >> > {
>> > >> > +                               @SuppressWarnings("unchecked")
>> > >> > +                               Class<? extends Annotation>
>> > >> ejbAnnotation =
>> > >> > (Class<? extends Annotation>)
>> > >> >
>> > >>
>> >
>> SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
>> > >> > +
>> > >> > +                               List<Field> annotatedFields =
>> > >> > SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
>> > >> > ejbAnnotation);
>> > >> > +
>> > >> > +                               for (Field field : annotatedFields)
>> {
>> > >> > +                                       if (field.get(testCase) ==
>> > null)
>> > >> {
>> > >> > +                                               EJB fieldAnnotation
>> =
>> > >> (EJB)
>> > >> > field.getAnnotation(ejbAnnotation);
>> > >> > +                                               Object ejb =
>> > >> > lookupEJB(field.getType(), fieldAnnotation.mappedName());
>> > >> > +                                               field.set(testCase,
>> > >> ejb);
>> > >> > +                                       }
>> > >> > +                               }
>> > >> > +
>> > >> > +                               List<Method> methods =
>> > >> > SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
>> > >> > ejbAnnotation);
>> > >> > +
>> > >> > +                               for (Method method : methods) {
>> > >> > +                                       if
>> > >> > (method.getParameterTypes().length != 1) {
>> > >> > +                                               throw new
>> > >> > RuntimeException("@EJB only allowed on single argument methods");
>> > >> > +                                       }
>> > >> > +                                       if
>> > >> > (!method.getName().startsWith("set")) {
>> > >> > +                                               throw new
>> > >> > RuntimeException("@EJB only allowed on 'set' methods");
>> > >> > +                                       }
>> > >> > +                                       EJB parameterAnnotation =
>> > null;
>> > >> //
>> > >> > method.getParameterAnnotations()[0]
>> > >> > +                                       for (Annotation annotation
>> :
>> > >> > method.getParameterAnnotations()[0]) {
>> > >> > +                                               if
>> > >> > (EJB.class.isAssignableFrom(annotation.annotationType())) {
>> > >> > +
>> > >> parameterAnnotation
>> > >> > = (EJB) annotation;
>> > >> > +                                               }
>> > >> > +                                       }
>> > >> > +                                       String mappedName =
>> > >> > parameterAnnotation == null ? null :
>> parameterAnnotation.mappedName();
>> > >> > +                                       Object ejb =
>> > >> > lookupEJB(method.getParameterTypes()[0], mappedName);
>> > >> > +                                       method.invoke(testCase,
>> ejb);
>> > >> > +                               }
>> > >> > +
>> > >> > +                       }
>> > >> > +               } catch (Exception e) {
>> > >> > +
>> > >> > +               }
>> > >> > +
>> > >> > +       }
>> > >> > +
>> > >> > +       protected Object lookupEJB(Class<?> fieldType, String
>> > >> mappedName)
>> > >> > throws Exception {
>> > >> > +               // TODO: figure out test context ?
>> > >> > +               Context initcontext = new InitialContext();
>> > >> > +
>> > >> > +               // TODO: These names are not spec compliant;
>> fieldType
>> > >> > needs
>> > >> > to be a
>> > >> > +               // bean type here,
>> > >> > +               // but usually is just an interface of a bean.
>> These
>> > >> seldom
>> > >> > work.
>> > >> > +               String[] jndiNames = {
>> > >> > "openejb:global/global/test/test.jar/" + fieldType.getSimpleName()
>> +
>> > >> > "Bean",
>> > >> > +
>> "openejb:global/global/test/test.jar/"
>> > +
>> > >> > fieldType.getSimpleName(),
>> > >> > +                               "java:global/test/test.jar/" +
>> > >> > fieldType.getSimpleName() + "Bean",
>> > >> > +                               "java:global/test/test.jar/" +
>> > >> > fieldType.getSimpleName(),
>> > >> > +                               "java:global/test.ear/test/" +
>> > >> > fieldType.getSimpleName() + "Bean",
>> > >> > +                               "java:global/test.ear/test/" +
>> > >> > fieldType.getSimpleName(),
>> > >> > +                               "java:global/test/" +
>> > >> > fieldType.getSimpleName(),
>> > >> > +                               "java:global/test/" +
>> > >> > fieldType.getSimpleName() + "Bean",
>> > >> > +                               "java:global/test/" +
>> > >> > fieldType.getSimpleName() + "/no-interface",
>> > >> > +                               "test/" + fieldType.getSimpleName()
>> +
>> > >> > "Bean/local",
>> > >> > +                               "test/" + fieldType.getSimpleName()
>> +
>> > >> > "Bean/remote",
>> > >> > +                               "test/" + fieldType.getSimpleName()
>> +
>> > >> > "/no-interface",
>> > >> > +                               fieldType.getSimpleName() +
>> > >> "Bean/local",
>> > >> > +                               fieldType.getSimpleName() +
>> > >> "Bean/remote",
>> > >> > +                               fieldType.getSimpleName() +
>> > >> > "/no-interface",
>> > >> > +                               "ejblocal:" +
>> > >> fieldType.getCanonicalName(),
>> > >> > +                               fieldType.getCanonicalName() };
>> > >> > +               if ((mappedName != null) &&
>> (!mappedName.equals("")))
>> > {
>> > >> > +                       // Use only the mapped name to lookup this
>> EJB
>> > >> > +                       jndiNames = new String[] { mappedName };
>> > >> > +               }
>> > >> > +
>> > >> > +               for (String jndiName : jndiNames) {
>> > >> > +                       try {
>> > >> > +                               return
>> initcontext.lookup(jndiName);
>> > >> > +                       } catch (NamingException e) {
>> > >> > +                               // no-op, try next
>> > >> > +                       }
>> > >> > +               }
>> > >> > +               throw new NamingException("No EJB found in JNDI");
>> > >> > +       }
>> > >> > +
>> > >> > +       @Override
>> > >> > +       public Object[] resolve(Method method) {
>> > >> > +               return new
>> Object[method.getParameterTypes().length];
>> > >> > +       }
>> > >> > +
>> > >> > +       public BeanManager getBeanManager() {
>> > >> > +               return
>> > >> > ThreadSingletonServiceImpl.get().getBeanManagerImpl();
>> > >> > +       }
>> > >> >  }
>> > >> >
>> > >> > Modified:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> > >> > (original)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -1,12 +1,12 @@
>> > >> >  package org.apache.openejb.arquillian.remote;
>> > >> >
>> > >> >  import
>> > >> >
>> > org.jboss.arquillian.container.spi.client.container.DeployableContainer;
>> > >> > +import
>> > >> >
>> > >> >
>> > >>
>> >
>> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
>> > >> >  import org.jboss.arquillian.core.spi.LoadableExtension;
>> > >> > -import org.jboss.arquillian.test.spi.TestEnricher;
>> > >> >
>> > >> >  public class RemoteTomEEExtension implements LoadableExtension {
>> > >> >    @Override public void register(ExtensionBuilder builder) {
>> > >> >        builder.service(DeployableContainer.class,
>> > >> > RemoteTomEEContainer.class)
>> > >> > -            .service(TestEnricher.class,
>> RemoteTomEEEnricher.class);
>> > >> > +            .service(AuxiliaryArchiveAppender.class,
>> > >> > RemoteTomEEEJBEnricherArchiveAppender.class);
>> > >> >    }
>> > >> >  }
>> > >> >
>> > >> > Added:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > >> > (added)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -0,0 +1,249 @@
>> > >> > +/*
>> > >> > + * JBoss, Home of Professional Open Source
>> > >> > + * Copyright 2009, Red Hat Middleware LLC, and individual
>> > contributors
>> > >> > + * by the @authors tag. See the copyright.txt in the distribution
>> for
>> > a
>> > >> > + * full listing of individual contributors.
>> > >> > + *
>> > >> > + * 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.openejb.arquillian.remote;
>> > >> > +
>> > >> > +import java.lang.annotation.Annotation;
>> > >> > +import java.lang.reflect.Constructor;
>> > >> > +import java.lang.reflect.Field;
>> > >> > +import java.lang.reflect.Method;
>> > >> > +import java.security.AccessController;
>> > >> > +import java.security.PrivilegedAction;
>> > >> > +import java.security.PrivilegedActionException;
>> > >> > +import java.security.PrivilegedExceptionAction;
>> > >> > +import java.util.ArrayList;
>> > >> > +import java.util.List;
>> > >> > +
>> > >> > +/**
>> > >> > + * SecurityActions
>> > >> > + *
>> > >> > + * A set of privileged actions that are not to leak out
>> > >> > + * of this package
>> > >> > + *
>> > >> > + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
>> > >> > + * @version $Revision: $
>> > >> > + */
>> > >> > +final class SecurityActions
>> > >> > +{
>> > >> > +
>> > >> > +
>> > >> >
>> > >> >
>> > >>
>> >
>> //-------------------------------------------------------------------------------||
>> > >> > +   // Constructor
>> > >> >
>> ------------------------------------------------------------------||
>> > >> > +
>> > >> >
>> > >> >
>> > >>
>> >
>> //-------------------------------------------------------------------------------||
>> > >> > +
>> > >> > +   /**
>> > >> > +    * No instantiation
>> > >> > +    */
>> > >> > +   private SecurityActions()
>> > >> > +   {
>> > >> > +      throw new UnsupportedOperationException("No instantiation");
>> > >> > +   }
>> > >> > +
>> > >> > +
>> > >> >
>> > >> >
>> > >>
>> >
>> //-------------------------------------------------------------------------------||
>> > >> > +   // Utility Methods
>> > >> > --------------------------------------------------------------||
>> > >> > +
>> > >> >
>> > >> >
>> > >>
>> >
>> //-------------------------------------------------------------------------------||
>> > >> > +
>> > >> > +   /**
>> > >> > +    * Obtains the Thread Context ClassLoader
>> > >> > +    */
>> > >> > +   static ClassLoader getThreadContextClassLoader()
>> > >> > +   {
>> > >> > +      return
>> AccessController.doPrivileged(GetTcclAction.INSTANCE);
>> > >> > +   }
>> > >> > +
>> > >> > +   /**
>> > >> > +    * Obtains the Constructor specified from the given Class and
>> > >> argument
>> > >> > types
>> > >> > +    * @param clazz
>> > >> > +    * @param argumentTypes
>> > >> > +    * @return
>> > >> > +    * @throws NoSuchMethodException
>> > >> > +    */
>> > >> > +   static Constructor<?> getConstructor(final Class<?> clazz,
>> final
>> > >> > Class<?>... argumentTypes)
>> > >> > +         throws NoSuchMethodException
>> > >> > +   {
>> > >> > +      try
>> > >> > +      {
>> > >> > +         return AccessController.doPrivileged(new
>> > >> > PrivilegedExceptionAction<Constructor<?>>()
>> > >> > +         {
>> > >> > +            public Constructor<?> run() throws
>> NoSuchMethodException
>> > >> > +            {
>> > >> > +               return clazz.getConstructor(argumentTypes);
>> > >> > +            }
>> > >> > +         });
>> > >> > +      }
>> > >> > +      // Unwrap
>> > >> > +      catch (final PrivilegedActionException pae)
>> > >> > +      {
>> > >> > +         final Throwable t = pae.getCause();
>> > >> > +         // Rethrow
>> > >> > +         if (t instanceof NoSuchMethodException)
>> > >> > +         {
>> > >> > +            throw (NoSuchMethodException) t;
>> > >> > +         }
>> > >> > +         else
>> > >> > +         {
>> > >> > +            // No other checked Exception thrown by
>> > >> Class.getConstructor
>> > >> > +            try
>> > >> > +            {
>> > >> > +               throw (RuntimeException) t;
>> > >> > +            }
>> > >> > +            // Just in case we've really messed up
>> > >> > +            catch (final ClassCastException cce)
>> > >> > +            {
>> > >> > +               throw new RuntimeException("Obtained unchecked
>> > >> Exception;
>> > >> > this code should never be reached", t);
>> > >> > +            }
>> > >> > +         }
>> > >> > +      }
>> > >> > +   }
>> > >> > +
>> > >> > +   /**
>> > >> > +    * Create a new instance by finding a constructor that matches
>> the
>> > >> > argumentTypes signature
>> > >> > +    * using the arguments for instantiation.
>> > >> > +    *
>> > >> > +    * @param className Full classname of class to create
>> > >> > +    * @param argumentTypes The constructor argument types
>> > >> > +    * @param arguments The constructor arguments
>> > >> > +    * @return a new instance
>> > >> > +    * @throws IllegalArgumentException if className,
>> argumentTypes,
>> > or
>> > >> > arguments are null
>> > >> > +    * @throws RuntimeException if any exceptions during creation
>> > >> > +    * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
>> > >> > +    * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
>> > >> > +    */
>> > >> > +   static <T> T newInstance(final String className, final
>> Class<?>[]
>> > >> > argumentTypes, final Object[] arguments,
>> > >> > +         final Class<T> expectedType)
>> > >> > +   {
>> > >> > +      if (className == null)
>> > >> > +      {
>> > >> > +         throw new IllegalArgumentException("ClassName must be
>> > >> > specified");
>> > >> > +      }
>> > >> > +      if (argumentTypes == null)
>> > >> > +      {
>> > >> > +         throw new IllegalArgumentException("ArgumentTypes must be
>> > >> > specified. Use empty array if no arguments");
>> > >> > +      }
>> > >> > +      if (arguments == null)
>> > >> > +      {
>> > >> > +         throw new IllegalArgumentException("Arguments must be
>> > >> specified.
>> > >> > Use empty array if no arguments");
>> > >> > +      }
>> > >> > +      final Object obj;
>> > >> > +      try
>> > >> > +      {
>> > >> > +         final ClassLoader tccl = getThreadContextClassLoader();
>> > >> > +         final Class<?> implClass = Class.forName(className,
>> false,
>> > >> tccl);
>> > >> > +         Constructor<?> constructor = getConstructor(implClass,
>> > >> > argumentTypes);
>> > >> > +         obj = constructor.newInstance(arguments);
>> > >> > +      }
>> > >> > +      catch (Exception e)
>> > >> > +      {
>> > >> > +         throw new RuntimeException("Could not create new instance
>> of
>> > "
>> > >> +
>> > >> > className
>> > >> > +               + ", missing package from classpath?", e);
>> > >> > +      }
>> > >> > +
>> > >> > +      // Cast
>> > >> > +      try
>> > >> > +      {
>> > >> > +         return expectedType.cast(obj);
>> > >> > +      }
>> > >> > +      catch (final ClassCastException cce)
>> > >> > +      {
>> > >> > +         // Reconstruct so we get some useful information
>> > >> > +         throw new ClassCastException("Incorrect expected type, "
>> +
>> > >> > expectedType.getName() + ", defined for "
>> > >> > +               + obj.getClass().getName());
>> > >> > +      }
>> > >> > +   }
>> > >> > +
>> > >> > +   public static boolean isClassPresent(String name)
>> > >> > +   {
>> > >> > +      try
>> > >> > +      {
>> > >> > +         ClassLoader classLoader = getThreadContextClassLoader();
>> > >> > +         classLoader.loadClass(name);
>> > >> > +         return true;
>> > >> > +      }
>> > >> > +      catch (ClassNotFoundException e)
>> > >> > +      {
>> > >> > +         return false;
>> > >> > +      }
>> > >> > +   }
>> > >> > +
>> > >> > +   public static List<Field> getFieldsWithAnnotation(final
>> Class<?>
>> > >> > source,
>> > >> > final Class<? extends Annotation> annotationClass)
>> > >> > +   {
>> > >> > +      List<Field> declaredAccessableFields =
>> > >> > AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
>> > >> > +      {
>> > >> > +         public List<Field> run()
>> > >> > +         {
>> > >> > +            List<Field> foundFields = new ArrayList<Field>();
>> > >> > +            Class<?> nextSource = source;
>> > >> > +            while (nextSource != Object.class) {
>> > >> > +               for(Field field : nextSource.getDeclaredFields())
>> > >> > +               {
>> > >> > +                  if(field.isAnnotationPresent(annotationClass))
>> > >> > +                  {
>> > >> > +                     if(!field.isAccessible())
>> > >> > +                     {
>> > >> > +                        field.setAccessible(true);
>> > >> > +                     }
>> > >> > +                     foundFields.add(field);
>> > >> > +                  }
>> > >> > +               }
>> > >> > +               nextSource = nextSource.getSuperclass();
>> > >> > +            }
>> > >> > +            return foundFields;
>> > >> > +         }
>> > >> > +      });
>> > >> > +      return declaredAccessableFields;
>> > >> > +   }
>> > >> > +
>> > >> > +   public static List<Method> getMethodsWithAnnotation(final
>> Class<?>
>> > >> > source, final Class<? extends Annotation> annotationClass)
>> > >> > +   {
>> > >> > +      List<Method> declaredAccessableMethods =
>> > >> > AccessController.doPrivileged(new PrivilegedAction<List<Method>>()
>> > >> > +      {
>> > >> > +         public List<Method> run()
>> > >> > +         {
>> > >> > +            List<Method> foundMethods = new ArrayList<Method>();
>> > >> > +            for(Method method : source.getDeclaredMethods())
>> > >> > +            {
>> > >> > +               if(method.isAnnotationPresent(annotationClass))
>> > >> > +               {
>> > >> > +                  if(!method.isAccessible())
>> > >> > +                  {
>> > >> > +                     method.setAccessible(true);
>> > >> > +                  }
>> > >> > +                  foundMethods.add(method);
>> > >> > +               }
>> > >> > +            }
>> > >> > +            return foundMethods;
>> > >> > +         }
>> > >> > +      });
>> > >> > +      return declaredAccessableMethods;
>> > >> > +   }
>> > >> > +
>> > >> > +
>> > >> >
>> > >> >
>> > >>
>> >
>> //-------------------------------------------------------------------------------||
>> > >> > +   // Inner Classes
>> > >> > ----------------------------------------------------------------||
>> > >> > +
>> > >> >
>> > >> >
>> > >>
>> >
>> //-------------------------------------------------------------------------------||
>> > >> > +
>> > >> > +   /**
>> > >> > +    * Single instance to get the TCCL
>> > >> > +    */
>> > >> > +   private enum GetTcclAction implements
>> > PrivilegedAction<ClassLoader>
>> > >> {
>> > >> > +      INSTANCE;
>> > >> > +
>> > >> > +      public ClassLoader run()
>> > >> > +      {
>> > >> > +         return Thread.currentThread().getContextClassLoader();
>> > >> > +      }
>> > >> > +
>> > >> > +   }
>> > >> > +
>> > >> > +}
>> > >> >
>> > >> > Modified:
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > ---
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> > >> > (original)
>> > >> > +++
>> > >> >
>> > >> >
>> > >>
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> > >> > Wed Oct 26 23:08:05 2011
>> > >> > @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
>> > >> >  import java.io.InputStream;
>> > >> >  import java.net.URL;
>> > >> >
>> > >> > +import javax.ejb.EJB;
>> > >> > +
>> > >> >  import junit.framework.Assert;
>> > >> >
>> > >> >  import org.jboss.arquillian.container.test.api.Deployment;
>> > >> > @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
>> > >> >  @RunWith(Arquillian.class)
>> > >> >  public class TomEEContainerTest {
>> > >> >
>> > >> > -    @Deployment(testable = false)
>> > >> > +    @Deployment
>> > >> >    public static WebArchive createDeployment() {
>> > >> > -        return ShrinkWrap.create(WebArchive.class,
>> > >> > "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
>> > >> > +        return ShrinkWrap.create(WebArchive.class,
>> > >> >
>> > >> >
>> > >>
>> >
>> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
>> > >> >                .setWebXML(new
>> > >> >
>> > >> >
>> > >>
>> >
>> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
>> > >> > "/Test").exportAsString()));
>> > >> >    }
>> > >> >
>> > >> > -    @Test
>> > >> > -    public void nothing(){}
>> > >> > +    @EJB
>> > >> > +    private TestEjb ejb;
>> > >> > +
>> > >> > +    @Test
>> > >> > +    public void testEjbIsNotNull() throws Exception {
>> > >> > +       Assert.assertNotNull(ejb);
>> > >> > +    }
>> > >> >
>> > >> > +    @Test
>> > >> >    public void testShouldBeAbleToAccessServletAndEjb() throws
>> > Exception
>> > >> {
>> > >> >        InputStream is = new URL("http://localhost:9080/test/Test
>> > >> > ").openStream();
>> > >> >        ByteArrayOutputStream os = new ByteArrayOutputStream();
>> > >> >
>> > >> > Modified: openejb/trunk/arquillian-tomee/pom.xml
>> > >> > URL:
>> > >> >
>> > >> >
>> > >>
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
>> > >> >
>> > >> >
>> > >>
>> >
>> ==============================================================================
>> > >> > --- openejb/trunk/arquillian-tomee/pom.xml (original)
>> > >> > +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05 2011
>> > >> > @@ -49,7 +49,7 @@
>> > >> >
>> > >> >  <properties>
>> > >> >
>>  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>> > >> > -    <version.arquillian>1.0.0.CR1</version.arquillian>
>> > >> > +    <version.arquillian>1.0.0.CR4</version.arquillian>
>> > >> >    <version.cdi-api>1.0</version.cdi-api>
>> > >> >    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
>> > >> >    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
>> > >> >
>> > >>
>> > >
>> >
>>
>
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
i looked testenricher implementation from jboss and...the cdi one is almost
the same than mine so i guess mine is useless

i made the ejb injection for the embedded case working.

i think it is just a bit more complicated for the remote case but almost the
same philosophy.

you can have a look, i added a test case to make it work.

- Romain


2011/10/28 Jonathan Gallimore <jo...@gmail.com>

> Neither the arquillian-showcase-ejb example, nor my own test in the
> moviefun
> example for testing ejbs work with the embedded adapter as it stands either
> - the ejb isn't getting injected.
>
> I'd be grateful if you could give it a try with the latest code.
>
> I'm afraid I don't understand your last point about @DeploymentScoped.
> Where
> does that need to go? Do I have to change the showcase code beyond
> referencing the adapters in the pom? I'm not sure I like that.
>
> There does seem to be an issue where the default ejbenricher with
> arquillian
> would work, except 1. it can't lookup Java:global. I've created an ear and
> confirmed I can't look it up from a servlet either, and 2. the global
> individual names it uses are slightly different to ours:
> Java:global/test.ear/test vs Java:global/test/test.jar.
>
> The first issue really doesn't seem right to me and I think we'll need to
> solve that.
>
> Jon
> On Oct 27, 2011 11:45 PM, "Romain Manni-Bucau" <rm...@gmail.com>
> wrote:
>
> > i don't get why it doesn't work since everything is in the same webapp?
> >
> > Note: the ejbenricher needs the context to use to lookup, it can be set
> > using @Inject @DeployementScoped private Instance<Context> context; then
> > context.set(new InitialContext()) (in the container)
> >
> > - Romain
> >
> >
> > 2011/10/27 Romain Manni-Bucau <rm...@gmail.com>
> >
> > > Weird, it seems to work in embedded case.
> > >
> > > Le 27 oct. 2011 13:29, "Jonathan Gallimore" <
> > jonathan.gallimore@gmail.com>
> > > a écrit :
> > >
> > >  When I first saw your email, I did wonder whether the bean manager
> code
> > >> would be enough, and maybe I was just missing the ArchiveAppender
> stuff
> > to
> > >> get the Enricher over to the server side. I've retested with the EJB
> > >> lookup
> > >> commented out, and unfortunately, It didn't work without my change for
> > the
> > >> test case I was using (arquillian-showcase-ejb).
> > >>
> > >> Jon
> > >>
> > >> On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
> > >> <rm...@gmail.com>wrote:
> > >>
> > >> > Hi,
> > >> >
> > >> > Why beanmanager stuff is not enough?
> > >> >
> > >> > - Romain
> > >> >
> > >> > ---------- Message transféré ----------
> > >> > De : <jg...@apache.org>
> > >> > Date : 27 oct. 2011 01:08
> > >> > Objet : svn commit: r1189526 - in /openejb/trunk/arquillian-tomee:
> ./
> > >> >
> > >>
> >
> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
> > >> > arquillian-tomee-remote/
> > >> >
> > >>
> >
> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
> > >> > arquillian-to...
> > >> > À : <co...@openejb.apache.org>
> > >> >
> > >> > Author: jgallimore
> > >> > Date: Wed Oct 26 23:08:05 2011
> > >> > New Revision: 1189526
> > >> >
> > >> > URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
> > >> > Log:
> > >> > Progress on supporting enriching tests with @EJB fields
> > >> >
> > >> > Added:
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > Removed:
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
> > >> > Modified:
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> >   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> >
> > >> >
> > >> >
> > >>
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> >   openejb/trunk/arquillian-tomee/pom.xml
> > >> >
> > >> > Modified:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> > (original)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
> > >> >  import
> > >> > org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
> > >> >  import org.jboss.shrinkwrap.api.Archive;
> > >> >  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
> > >> > +import org.jboss.shrinkwrap.api.spec.WebArchive;
> > >> >  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
> > >> >
> > >> >  public abstract class TomEEContainer implements
> > >> > DeployableContainer<TomEEConfiguration> {
> > >> > @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
> > >> >    }
> > >> >
> > >> >    public ProtocolDescription getDefaultProtocol() {
> > >> > -        return new ProtocolDescription("Servlet 3.0");
> > >> > +        return new ProtocolDescription("Servlet 2.5");
> > >> >    }
> > >> >
> > >> >    public ProtocolMetaData deploy(Archive<?> archive) throws
> > >> > DeploymentException {
> > >> > @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
> > >> >            moduleIds.put(archive.getName(), file.getAbsolutePath());
> > >> >
> > >> >            HTTPContext httpContext = new HTTPContext("0.0.0.0",
> > >> > configuration.getHttpPort());
> > >> > -            httpContext.add(new Servlet("ArquillianServletRunner",
> > "/"
> > >> +
> > >> > getArchiveNameWithoutExtension(archive)));
> > >> > +            if (archive instanceof WebArchive) {
> > >> > +               httpContext.add(new
> Servlet("ArquillianServletRunner",
> > >> "/"
> > >> > +
> > >> > getArchiveNameWithoutExtension(archive)));
> > >> > +            } else {
> > >> > +               httpContext.add(new
> Servlet("ArquillianServletRunner",
> > >> > "/arquillian-protocol"));
> > >> > +            }
> > >> > +
> > >> >            // we should probably get all servlets and add them to
> the
> > >> > context
> > >> >            return new ProtocolMetaData().addContext(httpContext);
> > >> >        } catch (Exception e) {
> > >> >
> > >> > Modified:
> > openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > --- openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > >> > (original)
> > >> > +++ openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> Wed
> > >> Oct
> > >> > 26 23:08:05 2011
> > >> > @@ -333,5 +333,12 @@
> > >> >       <artifactId>swizzle-stream</artifactId>
> > >> >       <version>1.0.2</version>
> > >> >    </dependency>
> > >> > +    <dependency>
> > >> > +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
> > >> > +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
> > >> > +       <version>1.1.0-alpha-2</version>
> > >> > +       <type>jar</type>
> > >> > +       <scope>compile</scope>
> > >> > +    </dependency>
> > >> >  </dependencies>
> > >> >  </project>
> > >> >
> > >> > Modified:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> > (original)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
> > >> >
> > >> >                   System.setProperty("catalina.home",
> > >> > openejbHome.getAbsolutePath());
> > >> >                           System.setProperty("catalina.base",
> > >> > openejbHome.getAbsolutePath());
> > >> > +
> > >> >
> > >> >
> > >>
> >
> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
> > >> >                           Paths paths = new Paths(new
> > >> > File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
> > >> >                           Installer installer = new Installer(paths,
> > >> true);
> > >> >                           installer.installAll();
> > >> >
> > >> > Added:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> > (added)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -0,0 +1,18 @@
> > >> > +package org.apache.openejb.arquillian.remote;
> > >> > +
> > >> > +import
> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> > >> > +import
> > >> >
> > >> >
> > >>
> >
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> > >> > +import org.jboss.shrinkwrap.api.Archive;
> > >> > +import org.jboss.shrinkwrap.api.ShrinkWrap;
> > >> > +import org.jboss.shrinkwrap.api.spec.JavaArchive;
> > >> > +
> > >> > +public class RemoteTomEEEJBEnricherArchiveAppender implements
> > >> > AuxiliaryArchiveAppender
> > >> > +{
> > >> > +          @Override
> > >> > +          public Archive<?> createAuxiliaryArchive()
> > >> > +          {
> > >> > +             return ShrinkWrap.create(JavaArchive.class,
> > >> > "arquillian-tomee-testenricher-ejb.jar")
> > >> > +                         .addClasses(RemoteTomEEEnricher.class,
> > >> > RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
> > >> > +
> > >> > .addAsServiceProvider(RemoteLoadableExtension.class,
> > >> > RemoteTomEEEJBEnricherExtension.class);
> > >> > +          }
> > >> > +       }
> > >> > \ No newline at end of file
> > >> >
> > >> > Added:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> > (added)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -0,0 +1,13 @@
> > >> > +package org.apache.openejb.arquillian.remote;
> > >> > +
> > >> > +import
> > org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> > >> > +import org.jboss.arquillian.test.spi.TestEnricher;
> > >> > +
> > >> > +public class RemoteTomEEEJBEnricherExtension implements
> > >> > RemoteLoadableExtension {
> > >> > +    @Override public void register(ExtensionBuilder builder) {
> > >> > +       // only load if EJB is on ClassPath
> > >> > +        if(Validate.classExists("javax.ejb.EJB")) {
> > >> > +           builder.service(TestEnricher.class,
> > >> > org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
> > >> > +        }
> > >> > +    }
> > >> > +}
> > >> >
> > >> > Modified:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> > (original)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
> > >> >  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
> > >> >  import org.jboss.arquillian.test.spi.TestEnricher;
> > >> >
> > >> > +import javax.ejb.EJB;
> > >> >  import javax.enterprise.context.spi.CreationalContext;
> > >> >  import javax.enterprise.inject.spi.AnnotatedType;
> > >> >  import javax.enterprise.inject.spi.BeanManager;
> > >> >  import javax.enterprise.inject.spi.InjectionTarget;
> > >> > +import javax.naming.Context;
> > >> > +import javax.naming.InitialContext;
> > >> > +import javax.naming.NamingException;
> > >> > +
> > >> > +import java.lang.annotation.Annotation;
> > >> > +import java.lang.reflect.Field;
> > >> >  import java.lang.reflect.Method;
> > >> > +import java.util.List;
> > >> >
> > >> >  public class RemoteTomEEEnricher implements TestEnricher {
> > >> > -    @Override public void enrich(Object testCase) {
> > >> > -//        BeanManager mgr = getBeanManager();
> > >> > -//        if (mgr != null) {
> > >> > -//            AnnotatedType<?> type =
> > >> >  mgr.createAnnotatedType(getClass());
> > >> > -//            InjectionTarget<Object> injectionTarget =
> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> > >> > -//            CreationalContext<Object> context =
> > >> > mgr.createCreationalContext(null);
> > >> > -//
> > >> > -//            injectionTarget.inject(testCase, context);
> > >> > -//            injectionTarget.postConstruct(this);
> > >> > -//        } else {
> > >> > -//            throw new NullPointerException("bean manager is
> null");
> > >> > -//        }
> > >> > -
> > >> > -        /* TODO: see if this code could be called after tests
> > >> > -                *
> > >> > -                * if (injectionTarget != null) {
> > >> > -                *        injectionTarget.preDestroy(this);
> > >> > -                *    }
> > >> > -                *   if (context != null) {
> > >> > -                *        context.release();
> > >> > -                *    }
> > >> > -                *
> > >> > -                *   injectionTarget = null;
> > >> > -                *   context = null;
> > >> > -                */
> > >> > -    }
> > >> > -
> > >> > -    @Override public Object[] resolve(Method method) {
> > >> > -        return new Object[method.getParameterTypes().length];
> > >> > -    }
> > >> > -
> > >> > -    public BeanManager getBeanManager() {
> > >> > -        return
> ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> > >> > -    }
> > >> > +
> > >> > +       private static final String ANNOTATION_NAME =
> "javax.ejb.EJB";
> > >> > +
> > >> > +       public void enrich(Object testCase) {
> > >> > +               BeanManager mgr = getBeanManager();
> > >> > +               if (mgr != null) {
> > >> > +                       AnnotatedType<?> type =
> > >> > mgr.createAnnotatedType(getClass());
> > >> > +                       InjectionTarget<Object> injectionTarget =
> > >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> > >> > +                       CreationalContext<Object> context =
> > >> > mgr.createCreationalContext(null);
> > >> > +
> > >> > +                       injectionTarget.inject(testCase, context);
> > >> > +                       injectionTarget.postConstruct(this);
> > >> > +               }
> > >> > +
> > >> > +               try {
> > >> > +                       if
> > >> > (SecurityActions.isClassPresent(ANNOTATION_NAME))
> > >> > {
> > >> > +                               @SuppressWarnings("unchecked")
> > >> > +                               Class<? extends Annotation>
> > >> ejbAnnotation =
> > >> > (Class<? extends Annotation>)
> > >> >
> > >>
> > SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
> > >> > +
> > >> > +                               List<Field> annotatedFields =
> > >> > SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
> > >> > ejbAnnotation);
> > >> > +
> > >> > +                               for (Field field : annotatedFields)
> {
> > >> > +                                       if (field.get(testCase) ==
> > null)
> > >> {
> > >> > +                                               EJB fieldAnnotation
> =
> > >> (EJB)
> > >> > field.getAnnotation(ejbAnnotation);
> > >> > +                                               Object ejb =
> > >> > lookupEJB(field.getType(), fieldAnnotation.mappedName());
> > >> > +                                               field.set(testCase,
> > >> ejb);
> > >> > +                                       }
> > >> > +                               }
> > >> > +
> > >> > +                               List<Method> methods =
> > >> > SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
> > >> > ejbAnnotation);
> > >> > +
> > >> > +                               for (Method method : methods) {
> > >> > +                                       if
> > >> > (method.getParameterTypes().length != 1) {
> > >> > +                                               throw new
> > >> > RuntimeException("@EJB only allowed on single argument methods");
> > >> > +                                       }
> > >> > +                                       if
> > >> > (!method.getName().startsWith("set")) {
> > >> > +                                               throw new
> > >> > RuntimeException("@EJB only allowed on 'set' methods");
> > >> > +                                       }
> > >> > +                                       EJB parameterAnnotation =
> > null;
> > >> //
> > >> > method.getParameterAnnotations()[0]
> > >> > +                                       for (Annotation annotation :
> > >> > method.getParameterAnnotations()[0]) {
> > >> > +                                               if
> > >> > (EJB.class.isAssignableFrom(annotation.annotationType())) {
> > >> > +
> > >> parameterAnnotation
> > >> > = (EJB) annotation;
> > >> > +                                               }
> > >> > +                                       }
> > >> > +                                       String mappedName =
> > >> > parameterAnnotation == null ? null :
> parameterAnnotation.mappedName();
> > >> > +                                       Object ejb =
> > >> > lookupEJB(method.getParameterTypes()[0], mappedName);
> > >> > +                                       method.invoke(testCase,
> ejb);
> > >> > +                               }
> > >> > +
> > >> > +                       }
> > >> > +               } catch (Exception e) {
> > >> > +
> > >> > +               }
> > >> > +
> > >> > +       }
> > >> > +
> > >> > +       protected Object lookupEJB(Class<?> fieldType, String
> > >> mappedName)
> > >> > throws Exception {
> > >> > +               // TODO: figure out test context ?
> > >> > +               Context initcontext = new InitialContext();
> > >> > +
> > >> > +               // TODO: These names are not spec compliant;
> fieldType
> > >> > needs
> > >> > to be a
> > >> > +               // bean type here,
> > >> > +               // but usually is just an interface of a bean. These
> > >> seldom
> > >> > work.
> > >> > +               String[] jndiNames = {
> > >> > "openejb:global/global/test/test.jar/" + fieldType.getSimpleName() +
> > >> > "Bean",
> > >> > +
> "openejb:global/global/test/test.jar/"
> > +
> > >> > fieldType.getSimpleName(),
> > >> > +                               "java:global/test/test.jar/" +
> > >> > fieldType.getSimpleName() + "Bean",
> > >> > +                               "java:global/test/test.jar/" +
> > >> > fieldType.getSimpleName(),
> > >> > +                               "java:global/test.ear/test/" +
> > >> > fieldType.getSimpleName() + "Bean",
> > >> > +                               "java:global/test.ear/test/" +
> > >> > fieldType.getSimpleName(),
> > >> > +                               "java:global/test/" +
> > >> > fieldType.getSimpleName(),
> > >> > +                               "java:global/test/" +
> > >> > fieldType.getSimpleName() + "Bean",
> > >> > +                               "java:global/test/" +
> > >> > fieldType.getSimpleName() + "/no-interface",
> > >> > +                               "test/" + fieldType.getSimpleName()
> +
> > >> > "Bean/local",
> > >> > +                               "test/" + fieldType.getSimpleName()
> +
> > >> > "Bean/remote",
> > >> > +                               "test/" + fieldType.getSimpleName()
> +
> > >> > "/no-interface",
> > >> > +                               fieldType.getSimpleName() +
> > >> "Bean/local",
> > >> > +                               fieldType.getSimpleName() +
> > >> "Bean/remote",
> > >> > +                               fieldType.getSimpleName() +
> > >> > "/no-interface",
> > >> > +                               "ejblocal:" +
> > >> fieldType.getCanonicalName(),
> > >> > +                               fieldType.getCanonicalName() };
> > >> > +               if ((mappedName != null) &&
> (!mappedName.equals("")))
> > {
> > >> > +                       // Use only the mapped name to lookup this
> EJB
> > >> > +                       jndiNames = new String[] { mappedName };
> > >> > +               }
> > >> > +
> > >> > +               for (String jndiName : jndiNames) {
> > >> > +                       try {
> > >> > +                               return initcontext.lookup(jndiName);
> > >> > +                       } catch (NamingException e) {
> > >> > +                               // no-op, try next
> > >> > +                       }
> > >> > +               }
> > >> > +               throw new NamingException("No EJB found in JNDI");
> > >> > +       }
> > >> > +
> > >> > +       @Override
> > >> > +       public Object[] resolve(Method method) {
> > >> > +               return new
> Object[method.getParameterTypes().length];
> > >> > +       }
> > >> > +
> > >> > +       public BeanManager getBeanManager() {
> > >> > +               return
> > >> > ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> > >> > +       }
> > >> >  }
> > >> >
> > >> > Modified:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> > (original)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -1,12 +1,12 @@
> > >> >  package org.apache.openejb.arquillian.remote;
> > >> >
> > >> >  import
> > >> >
> > org.jboss.arquillian.container.spi.client.container.DeployableContainer;
> > >> > +import
> > >> >
> > >> >
> > >>
> >
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> > >> >  import org.jboss.arquillian.core.spi.LoadableExtension;
> > >> > -import org.jboss.arquillian.test.spi.TestEnricher;
> > >> >
> > >> >  public class RemoteTomEEExtension implements LoadableExtension {
> > >> >    @Override public void register(ExtensionBuilder builder) {
> > >> >        builder.service(DeployableContainer.class,
> > >> > RemoteTomEEContainer.class)
> > >> > -            .service(TestEnricher.class,
> RemoteTomEEEnricher.class);
> > >> > +            .service(AuxiliaryArchiveAppender.class,
> > >> > RemoteTomEEEJBEnricherArchiveAppender.class);
> > >> >    }
> > >> >  }
> > >> >
> > >> > Added:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > (added)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -0,0 +1,249 @@
> > >> > +/*
> > >> > + * JBoss, Home of Professional Open Source
> > >> > + * Copyright 2009, Red Hat Middleware LLC, and individual
> > contributors
> > >> > + * by the @authors tag. See the copyright.txt in the distribution
> for
> > a
> > >> > + * full listing of individual contributors.
> > >> > + *
> > >> > + * 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.openejb.arquillian.remote;
> > >> > +
> > >> > +import java.lang.annotation.Annotation;
> > >> > +import java.lang.reflect.Constructor;
> > >> > +import java.lang.reflect.Field;
> > >> > +import java.lang.reflect.Method;
> > >> > +import java.security.AccessController;
> > >> > +import java.security.PrivilegedAction;
> > >> > +import java.security.PrivilegedActionException;
> > >> > +import java.security.PrivilegedExceptionAction;
> > >> > +import java.util.ArrayList;
> > >> > +import java.util.List;
> > >> > +
> > >> > +/**
> > >> > + * SecurityActions
> > >> > + *
> > >> > + * A set of privileged actions that are not to leak out
> > >> > + * of this package
> > >> > + *
> > >> > + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> > >> > + * @version $Revision: $
> > >> > + */
> > >> > +final class SecurityActions
> > >> > +{
> > >> > +
> > >> > +
> > >> >
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > +   // Constructor
> > >> > ------------------------------------------------------------------||
> > >> > +
> > >> >
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > +
> > >> > +   /**
> > >> > +    * No instantiation
> > >> > +    */
> > >> > +   private SecurityActions()
> > >> > +   {
> > >> > +      throw new UnsupportedOperationException("No instantiation");
> > >> > +   }
> > >> > +
> > >> > +
> > >> >
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > +   // Utility Methods
> > >> > --------------------------------------------------------------||
> > >> > +
> > >> >
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > +
> > >> > +   /**
> > >> > +    * Obtains the Thread Context ClassLoader
> > >> > +    */
> > >> > +   static ClassLoader getThreadContextClassLoader()
> > >> > +   {
> > >> > +      return AccessController.doPrivileged(GetTcclAction.INSTANCE);
> > >> > +   }
> > >> > +
> > >> > +   /**
> > >> > +    * Obtains the Constructor specified from the given Class and
> > >> argument
> > >> > types
> > >> > +    * @param clazz
> > >> > +    * @param argumentTypes
> > >> > +    * @return
> > >> > +    * @throws NoSuchMethodException
> > >> > +    */
> > >> > +   static Constructor<?> getConstructor(final Class<?> clazz, final
> > >> > Class<?>... argumentTypes)
> > >> > +         throws NoSuchMethodException
> > >> > +   {
> > >> > +      try
> > >> > +      {
> > >> > +         return AccessController.doPrivileged(new
> > >> > PrivilegedExceptionAction<Constructor<?>>()
> > >> > +         {
> > >> > +            public Constructor<?> run() throws
> NoSuchMethodException
> > >> > +            {
> > >> > +               return clazz.getConstructor(argumentTypes);
> > >> > +            }
> > >> > +         });
> > >> > +      }
> > >> > +      // Unwrap
> > >> > +      catch (final PrivilegedActionException pae)
> > >> > +      {
> > >> > +         final Throwable t = pae.getCause();
> > >> > +         // Rethrow
> > >> > +         if (t instanceof NoSuchMethodException)
> > >> > +         {
> > >> > +            throw (NoSuchMethodException) t;
> > >> > +         }
> > >> > +         else
> > >> > +         {
> > >> > +            // No other checked Exception thrown by
> > >> Class.getConstructor
> > >> > +            try
> > >> > +            {
> > >> > +               throw (RuntimeException) t;
> > >> > +            }
> > >> > +            // Just in case we've really messed up
> > >> > +            catch (final ClassCastException cce)
> > >> > +            {
> > >> > +               throw new RuntimeException("Obtained unchecked
> > >> Exception;
> > >> > this code should never be reached", t);
> > >> > +            }
> > >> > +         }
> > >> > +      }
> > >> > +   }
> > >> > +
> > >> > +   /**
> > >> > +    * Create a new instance by finding a constructor that matches
> the
> > >> > argumentTypes signature
> > >> > +    * using the arguments for instantiation.
> > >> > +    *
> > >> > +    * @param className Full classname of class to create
> > >> > +    * @param argumentTypes The constructor argument types
> > >> > +    * @param arguments The constructor arguments
> > >> > +    * @return a new instance
> > >> > +    * @throws IllegalArgumentException if className, argumentTypes,
> > or
> > >> > arguments are null
> > >> > +    * @throws RuntimeException if any exceptions during creation
> > >> > +    * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
> > >> > +    * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> > >> > +    */
> > >> > +   static <T> T newInstance(final String className, final
> Class<?>[]
> > >> > argumentTypes, final Object[] arguments,
> > >> > +         final Class<T> expectedType)
> > >> > +   {
> > >> > +      if (className == null)
> > >> > +      {
> > >> > +         throw new IllegalArgumentException("ClassName must be
> > >> > specified");
> > >> > +      }
> > >> > +      if (argumentTypes == null)
> > >> > +      {
> > >> > +         throw new IllegalArgumentException("ArgumentTypes must be
> > >> > specified. Use empty array if no arguments");
> > >> > +      }
> > >> > +      if (arguments == null)
> > >> > +      {
> > >> > +         throw new IllegalArgumentException("Arguments must be
> > >> specified.
> > >> > Use empty array if no arguments");
> > >> > +      }
> > >> > +      final Object obj;
> > >> > +      try
> > >> > +      {
> > >> > +         final ClassLoader tccl = getThreadContextClassLoader();
> > >> > +         final Class<?> implClass = Class.forName(className, false,
> > >> tccl);
> > >> > +         Constructor<?> constructor = getConstructor(implClass,
> > >> > argumentTypes);
> > >> > +         obj = constructor.newInstance(arguments);
> > >> > +      }
> > >> > +      catch (Exception e)
> > >> > +      {
> > >> > +         throw new RuntimeException("Could not create new instance
> of
> > "
> > >> +
> > >> > className
> > >> > +               + ", missing package from classpath?", e);
> > >> > +      }
> > >> > +
> > >> > +      // Cast
> > >> > +      try
> > >> > +      {
> > >> > +         return expectedType.cast(obj);
> > >> > +      }
> > >> > +      catch (final ClassCastException cce)
> > >> > +      {
> > >> > +         // Reconstruct so we get some useful information
> > >> > +         throw new ClassCastException("Incorrect expected type, " +
> > >> > expectedType.getName() + ", defined for "
> > >> > +               + obj.getClass().getName());
> > >> > +      }
> > >> > +   }
> > >> > +
> > >> > +   public static boolean isClassPresent(String name)
> > >> > +   {
> > >> > +      try
> > >> > +      {
> > >> > +         ClassLoader classLoader = getThreadContextClassLoader();
> > >> > +         classLoader.loadClass(name);
> > >> > +         return true;
> > >> > +      }
> > >> > +      catch (ClassNotFoundException e)
> > >> > +      {
> > >> > +         return false;
> > >> > +      }
> > >> > +   }
> > >> > +
> > >> > +   public static List<Field> getFieldsWithAnnotation(final Class<?>
> > >> > source,
> > >> > final Class<? extends Annotation> annotationClass)
> > >> > +   {
> > >> > +      List<Field> declaredAccessableFields =
> > >> > AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
> > >> > +      {
> > >> > +         public List<Field> run()
> > >> > +         {
> > >> > +            List<Field> foundFields = new ArrayList<Field>();
> > >> > +            Class<?> nextSource = source;
> > >> > +            while (nextSource != Object.class) {
> > >> > +               for(Field field : nextSource.getDeclaredFields())
> > >> > +               {
> > >> > +                  if(field.isAnnotationPresent(annotationClass))
> > >> > +                  {
> > >> > +                     if(!field.isAccessible())
> > >> > +                     {
> > >> > +                        field.setAccessible(true);
> > >> > +                     }
> > >> > +                     foundFields.add(field);
> > >> > +                  }
> > >> > +               }
> > >> > +               nextSource = nextSource.getSuperclass();
> > >> > +            }
> > >> > +            return foundFields;
> > >> > +         }
> > >> > +      });
> > >> > +      return declaredAccessableFields;
> > >> > +   }
> > >> > +
> > >> > +   public static List<Method> getMethodsWithAnnotation(final
> Class<?>
> > >> > source, final Class<? extends Annotation> annotationClass)
> > >> > +   {
> > >> > +      List<Method> declaredAccessableMethods =
> > >> > AccessController.doPrivileged(new PrivilegedAction<List<Method>>()
> > >> > +      {
> > >> > +         public List<Method> run()
> > >> > +         {
> > >> > +            List<Method> foundMethods = new ArrayList<Method>();
> > >> > +            for(Method method : source.getDeclaredMethods())
> > >> > +            {
> > >> > +               if(method.isAnnotationPresent(annotationClass))
> > >> > +               {
> > >> > +                  if(!method.isAccessible())
> > >> > +                  {
> > >> > +                     method.setAccessible(true);
> > >> > +                  }
> > >> > +                  foundMethods.add(method);
> > >> > +               }
> > >> > +            }
> > >> > +            return foundMethods;
> > >> > +         }
> > >> > +      });
> > >> > +      return declaredAccessableMethods;
> > >> > +   }
> > >> > +
> > >> > +
> > >> >
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > +   // Inner Classes
> > >> > ----------------------------------------------------------------||
> > >> > +
> > >> >
> > >> >
> > >>
> >
> //-------------------------------------------------------------------------------||
> > >> > +
> > >> > +   /**
> > >> > +    * Single instance to get the TCCL
> > >> > +    */
> > >> > +   private enum GetTcclAction implements
> > PrivilegedAction<ClassLoader>
> > >> {
> > >> > +      INSTANCE;
> > >> > +
> > >> > +      public ClassLoader run()
> > >> > +      {
> > >> > +         return Thread.currentThread().getContextClassLoader();
> > >> > +      }
> > >> > +
> > >> > +   }
> > >> > +
> > >> > +}
> > >> >
> > >> > Modified:
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > ---
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> > (original)
> > >> > +++
> > >> >
> > >> >
> > >>
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > >> > Wed Oct 26 23:08:05 2011
> > >> > @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
> > >> >  import java.io.InputStream;
> > >> >  import java.net.URL;
> > >> >
> > >> > +import javax.ejb.EJB;
> > >> > +
> > >> >  import junit.framework.Assert;
> > >> >
> > >> >  import org.jboss.arquillian.container.test.api.Deployment;
> > >> > @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
> > >> >  @RunWith(Arquillian.class)
> > >> >  public class TomEEContainerTest {
> > >> >
> > >> > -    @Deployment(testable = false)
> > >> > +    @Deployment
> > >> >    public static WebArchive createDeployment() {
> > >> > -        return ShrinkWrap.create(WebArchive.class,
> > >> > "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
> > >> > +        return ShrinkWrap.create(WebArchive.class,
> > >> >
> > >> >
> > >>
> >
> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
> > >> >                .setWebXML(new
> > >> >
> > >> >
> > >>
> >
> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
> > >> > "/Test").exportAsString()));
> > >> >    }
> > >> >
> > >> > -    @Test
> > >> > -    public void nothing(){}
> > >> > +    @EJB
> > >> > +    private TestEjb ejb;
> > >> > +
> > >> > +    @Test
> > >> > +    public void testEjbIsNotNull() throws Exception {
> > >> > +       Assert.assertNotNull(ejb);
> > >> > +    }
> > >> >
> > >> > +    @Test
> > >> >    public void testShouldBeAbleToAccessServletAndEjb() throws
> > Exception
> > >> {
> > >> >        InputStream is = new URL("http://localhost:9080/test/Test
> > >> > ").openStream();
> > >> >        ByteArrayOutputStream os = new ByteArrayOutputStream();
> > >> >
> > >> > Modified: openejb/trunk/arquillian-tomee/pom.xml
> > >> > URL:
> > >> >
> > >> >
> > >>
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> > >> >
> > >> >
> > >>
> >
> ==============================================================================
> > >> > --- openejb/trunk/arquillian-tomee/pom.xml (original)
> > >> > +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05 2011
> > >> > @@ -49,7 +49,7 @@
> > >> >
> > >> >  <properties>
> > >> >
>  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> > >> > -    <version.arquillian>1.0.0.CR1</version.arquillian>
> > >> > +    <version.arquillian>1.0.0.CR4</version.arquillian>
> > >> >    <version.cdi-api>1.0</version.cdi-api>
> > >> >    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
> > >> >    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
> > >> >
> > >>
> > >
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Jonathan Gallimore <jo...@gmail.com>.
Neither the arquillian-showcase-ejb example, nor my own test in the moviefun
example for testing ejbs work with the embedded adapter as it stands either
- the ejb isn't getting injected.

I'd be grateful if you could give it a try with the latest code.

I'm afraid I don't understand your last point about @DeploymentScoped. Where
does that need to go? Do I have to change the showcase code beyond
referencing the adapters in the pom? I'm not sure I like that.

There does seem to be an issue where the default ejbenricher with arquillian
would work, except 1. it can't lookup Java:global. I've created an ear and
confirmed I can't look it up from a servlet either, and 2. the global
individual names it uses are slightly different to ours:
Java:global/test.ear/test vs Java:global/test/test.jar.

The first issue really doesn't seem right to me and I think we'll need to
solve that.

Jon
On Oct 27, 2011 11:45 PM, "Romain Manni-Bucau" <rm...@gmail.com>
wrote:

> i don't get why it doesn't work since everything is in the same webapp?
>
> Note: the ejbenricher needs the context to use to lookup, it can be set
> using @Inject @DeployementScoped private Instance<Context> context; then
> context.set(new InitialContext()) (in the container)
>
> - Romain
>
>
> 2011/10/27 Romain Manni-Bucau <rm...@gmail.com>
>
> > Weird, it seems to work in embedded case.
> >
> > Le 27 oct. 2011 13:29, "Jonathan Gallimore" <
> jonathan.gallimore@gmail.com>
> > a écrit :
> >
> >  When I first saw your email, I did wonder whether the bean manager code
> >> would be enough, and maybe I was just missing the ArchiveAppender stuff
> to
> >> get the Enricher over to the server side. I've retested with the EJB
> >> lookup
> >> commented out, and unfortunately, It didn't work without my change for
> the
> >> test case I was using (arquillian-showcase-ejb).
> >>
> >> Jon
> >>
> >> On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
> >> <rm...@gmail.com>wrote:
> >>
> >> > Hi,
> >> >
> >> > Why beanmanager stuff is not enough?
> >> >
> >> > - Romain
> >> >
> >> > ---------- Message transféré ----------
> >> > De : <jg...@apache.org>
> >> > Date : 27 oct. 2011 01:08
> >> > Objet : svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./
> >> >
> >>
> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
> >> > arquillian-tomee-remote/
> >> >
> >>
> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
> >> > arquillian-to...
> >> > À : <co...@openejb.apache.org>
> >> >
> >> > Author: jgallimore
> >> > Date: Wed Oct 26 23:08:05 2011
> >> > New Revision: 1189526
> >> >
> >> > URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
> >> > Log:
> >> > Progress on supporting enriching tests with @EJB fields
> >> >
> >> > Added:
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > Removed:
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
> >> > Modified:
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> >   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> >
> >> >
> >> >
> >>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> >   openejb/trunk/arquillian-tomee/pom.xml
> >> >
> >> > Modified:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> > (original)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
> >> >  import
> >> > org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
> >> >  import org.jboss.shrinkwrap.api.Archive;
> >> >  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
> >> > +import org.jboss.shrinkwrap.api.spec.WebArchive;
> >> >  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
> >> >
> >> >  public abstract class TomEEContainer implements
> >> > DeployableContainer<TomEEConfiguration> {
> >> > @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
> >> >    }
> >> >
> >> >    public ProtocolDescription getDefaultProtocol() {
> >> > -        return new ProtocolDescription("Servlet 3.0");
> >> > +        return new ProtocolDescription("Servlet 2.5");
> >> >    }
> >> >
> >> >    public ProtocolMetaData deploy(Archive<?> archive) throws
> >> > DeploymentException {
> >> > @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
> >> >            moduleIds.put(archive.getName(), file.getAbsolutePath());
> >> >
> >> >            HTTPContext httpContext = new HTTPContext("0.0.0.0",
> >> > configuration.getHttpPort());
> >> > -            httpContext.add(new Servlet("ArquillianServletRunner",
> "/"
> >> +
> >> > getArchiveNameWithoutExtension(archive)));
> >> > +            if (archive instanceof WebArchive) {
> >> > +               httpContext.add(new Servlet("ArquillianServletRunner",
> >> "/"
> >> > +
> >> > getArchiveNameWithoutExtension(archive)));
> >> > +            } else {
> >> > +               httpContext.add(new Servlet("ArquillianServletRunner",
> >> > "/arquillian-protocol"));
> >> > +            }
> >> > +
> >> >            // we should probably get all servlets and add them to the
> >> > context
> >> >            return new ProtocolMetaData().addContext(httpContext);
> >> >        } catch (Exception e) {
> >> >
> >> > Modified:
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> >
> >> >
> >>
> ==============================================================================
> >> > --- openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >> > (original)
> >> > +++ openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml Wed
> >> Oct
> >> > 26 23:08:05 2011
> >> > @@ -333,5 +333,12 @@
> >> >       <artifactId>swizzle-stream</artifactId>
> >> >       <version>1.0.2</version>
> >> >    </dependency>
> >> > +    <dependency>
> >> > +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
> >> > +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
> >> > +       <version>1.1.0-alpha-2</version>
> >> > +       <type>jar</type>
> >> > +       <scope>compile</scope>
> >> > +    </dependency>
> >> >  </dependencies>
> >> >  </project>
> >> >
> >> > Modified:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> > (original)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
> >> >
> >> >                   System.setProperty("catalina.home",
> >> > openejbHome.getAbsolutePath());
> >> >                           System.setProperty("catalina.base",
> >> > openejbHome.getAbsolutePath());
> >> > +
> >> >
> >> >
> >>
> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
> >> >                           Paths paths = new Paths(new
> >> > File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
> >> >                           Installer installer = new Installer(paths,
> >> true);
> >> >                           installer.installAll();
> >> >
> >> > Added:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> > (added)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -0,0 +1,18 @@
> >> > +package org.apache.openejb.arquillian.remote;
> >> > +
> >> > +import
> org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> >> > +import
> >> >
> >> >
> >>
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> >> > +import org.jboss.shrinkwrap.api.Archive;
> >> > +import org.jboss.shrinkwrap.api.ShrinkWrap;
> >> > +import org.jboss.shrinkwrap.api.spec.JavaArchive;
> >> > +
> >> > +public class RemoteTomEEEJBEnricherArchiveAppender implements
> >> > AuxiliaryArchiveAppender
> >> > +{
> >> > +          @Override
> >> > +          public Archive<?> createAuxiliaryArchive()
> >> > +          {
> >> > +             return ShrinkWrap.create(JavaArchive.class,
> >> > "arquillian-tomee-testenricher-ejb.jar")
> >> > +                         .addClasses(RemoteTomEEEnricher.class,
> >> > RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
> >> > +
> >> > .addAsServiceProvider(RemoteLoadableExtension.class,
> >> > RemoteTomEEEJBEnricherExtension.class);
> >> > +          }
> >> > +       }
> >> > \ No newline at end of file
> >> >
> >> > Added:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> > (added)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -0,0 +1,13 @@
> >> > +package org.apache.openejb.arquillian.remote;
> >> > +
> >> > +import
> org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> >> > +import org.jboss.arquillian.test.spi.TestEnricher;
> >> > +
> >> > +public class RemoteTomEEEJBEnricherExtension implements
> >> > RemoteLoadableExtension {
> >> > +    @Override public void register(ExtensionBuilder builder) {
> >> > +       // only load if EJB is on ClassPath
> >> > +        if(Validate.classExists("javax.ejb.EJB")) {
> >> > +           builder.service(TestEnricher.class,
> >> > org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
> >> > +        }
> >> > +    }
> >> > +}
> >> >
> >> > Modified:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> > (original)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
> >> >  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
> >> >  import org.jboss.arquillian.test.spi.TestEnricher;
> >> >
> >> > +import javax.ejb.EJB;
> >> >  import javax.enterprise.context.spi.CreationalContext;
> >> >  import javax.enterprise.inject.spi.AnnotatedType;
> >> >  import javax.enterprise.inject.spi.BeanManager;
> >> >  import javax.enterprise.inject.spi.InjectionTarget;
> >> > +import javax.naming.Context;
> >> > +import javax.naming.InitialContext;
> >> > +import javax.naming.NamingException;
> >> > +
> >> > +import java.lang.annotation.Annotation;
> >> > +import java.lang.reflect.Field;
> >> >  import java.lang.reflect.Method;
> >> > +import java.util.List;
> >> >
> >> >  public class RemoteTomEEEnricher implements TestEnricher {
> >> > -    @Override public void enrich(Object testCase) {
> >> > -//        BeanManager mgr = getBeanManager();
> >> > -//        if (mgr != null) {
> >> > -//            AnnotatedType<?> type =
> >> >  mgr.createAnnotatedType(getClass());
> >> > -//            InjectionTarget<Object> injectionTarget =
> >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> >> > -//            CreationalContext<Object> context =
> >> > mgr.createCreationalContext(null);
> >> > -//
> >> > -//            injectionTarget.inject(testCase, context);
> >> > -//            injectionTarget.postConstruct(this);
> >> > -//        } else {
> >> > -//            throw new NullPointerException("bean manager is null");
> >> > -//        }
> >> > -
> >> > -        /* TODO: see if this code could be called after tests
> >> > -                *
> >> > -                * if (injectionTarget != null) {
> >> > -                *        injectionTarget.preDestroy(this);
> >> > -                *    }
> >> > -                *   if (context != null) {
> >> > -                *        context.release();
> >> > -                *    }
> >> > -                *
> >> > -                *   injectionTarget = null;
> >> > -                *   context = null;
> >> > -                */
> >> > -    }
> >> > -
> >> > -    @Override public Object[] resolve(Method method) {
> >> > -        return new Object[method.getParameterTypes().length];
> >> > -    }
> >> > -
> >> > -    public BeanManager getBeanManager() {
> >> > -        return ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> >> > -    }
> >> > +
> >> > +       private static final String ANNOTATION_NAME = "javax.ejb.EJB";
> >> > +
> >> > +       public void enrich(Object testCase) {
> >> > +               BeanManager mgr = getBeanManager();
> >> > +               if (mgr != null) {
> >> > +                       AnnotatedType<?> type =
> >> > mgr.createAnnotatedType(getClass());
> >> > +                       InjectionTarget<Object> injectionTarget =
> >> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> >> > +                       CreationalContext<Object> context =
> >> > mgr.createCreationalContext(null);
> >> > +
> >> > +                       injectionTarget.inject(testCase, context);
> >> > +                       injectionTarget.postConstruct(this);
> >> > +               }
> >> > +
> >> > +               try {
> >> > +                       if
> >> > (SecurityActions.isClassPresent(ANNOTATION_NAME))
> >> > {
> >> > +                               @SuppressWarnings("unchecked")
> >> > +                               Class<? extends Annotation>
> >> ejbAnnotation =
> >> > (Class<? extends Annotation>)
> >> >
> >>
> SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
> >> > +
> >> > +                               List<Field> annotatedFields =
> >> > SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
> >> > ejbAnnotation);
> >> > +
> >> > +                               for (Field field : annotatedFields) {
> >> > +                                       if (field.get(testCase) ==
> null)
> >> {
> >> > +                                               EJB fieldAnnotation =
> >> (EJB)
> >> > field.getAnnotation(ejbAnnotation);
> >> > +                                               Object ejb =
> >> > lookupEJB(field.getType(), fieldAnnotation.mappedName());
> >> > +                                               field.set(testCase,
> >> ejb);
> >> > +                                       }
> >> > +                               }
> >> > +
> >> > +                               List<Method> methods =
> >> > SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
> >> > ejbAnnotation);
> >> > +
> >> > +                               for (Method method : methods) {
> >> > +                                       if
> >> > (method.getParameterTypes().length != 1) {
> >> > +                                               throw new
> >> > RuntimeException("@EJB only allowed on single argument methods");
> >> > +                                       }
> >> > +                                       if
> >> > (!method.getName().startsWith("set")) {
> >> > +                                               throw new
> >> > RuntimeException("@EJB only allowed on 'set' methods");
> >> > +                                       }
> >> > +                                       EJB parameterAnnotation =
> null;
> >> //
> >> > method.getParameterAnnotations()[0]
> >> > +                                       for (Annotation annotation :
> >> > method.getParameterAnnotations()[0]) {
> >> > +                                               if
> >> > (EJB.class.isAssignableFrom(annotation.annotationType())) {
> >> > +
> >> parameterAnnotation
> >> > = (EJB) annotation;
> >> > +                                               }
> >> > +                                       }
> >> > +                                       String mappedName =
> >> > parameterAnnotation == null ? null : parameterAnnotation.mappedName();
> >> > +                                       Object ejb =
> >> > lookupEJB(method.getParameterTypes()[0], mappedName);
> >> > +                                       method.invoke(testCase, ejb);
> >> > +                               }
> >> > +
> >> > +                       }
> >> > +               } catch (Exception e) {
> >> > +
> >> > +               }
> >> > +
> >> > +       }
> >> > +
> >> > +       protected Object lookupEJB(Class<?> fieldType, String
> >> mappedName)
> >> > throws Exception {
> >> > +               // TODO: figure out test context ?
> >> > +               Context initcontext = new InitialContext();
> >> > +
> >> > +               // TODO: These names are not spec compliant; fieldType
> >> > needs
> >> > to be a
> >> > +               // bean type here,
> >> > +               // but usually is just an interface of a bean. These
> >> seldom
> >> > work.
> >> > +               String[] jndiNames = {
> >> > "openejb:global/global/test/test.jar/" + fieldType.getSimpleName() +
> >> > "Bean",
> >> > +                               "openejb:global/global/test/test.jar/"
> +
> >> > fieldType.getSimpleName(),
> >> > +                               "java:global/test/test.jar/" +
> >> > fieldType.getSimpleName() + "Bean",
> >> > +                               "java:global/test/test.jar/" +
> >> > fieldType.getSimpleName(),
> >> > +                               "java:global/test.ear/test/" +
> >> > fieldType.getSimpleName() + "Bean",
> >> > +                               "java:global/test.ear/test/" +
> >> > fieldType.getSimpleName(),
> >> > +                               "java:global/test/" +
> >> > fieldType.getSimpleName(),
> >> > +                               "java:global/test/" +
> >> > fieldType.getSimpleName() + "Bean",
> >> > +                               "java:global/test/" +
> >> > fieldType.getSimpleName() + "/no-interface",
> >> > +                               "test/" + fieldType.getSimpleName() +
> >> > "Bean/local",
> >> > +                               "test/" + fieldType.getSimpleName() +
> >> > "Bean/remote",
> >> > +                               "test/" + fieldType.getSimpleName() +
> >> > "/no-interface",
> >> > +                               fieldType.getSimpleName() +
> >> "Bean/local",
> >> > +                               fieldType.getSimpleName() +
> >> "Bean/remote",
> >> > +                               fieldType.getSimpleName() +
> >> > "/no-interface",
> >> > +                               "ejblocal:" +
> >> fieldType.getCanonicalName(),
> >> > +                               fieldType.getCanonicalName() };
> >> > +               if ((mappedName != null) && (!mappedName.equals("")))
> {
> >> > +                       // Use only the mapped name to lookup this EJB
> >> > +                       jndiNames = new String[] { mappedName };
> >> > +               }
> >> > +
> >> > +               for (String jndiName : jndiNames) {
> >> > +                       try {
> >> > +                               return initcontext.lookup(jndiName);
> >> > +                       } catch (NamingException e) {
> >> > +                               // no-op, try next
> >> > +                       }
> >> > +               }
> >> > +               throw new NamingException("No EJB found in JNDI");
> >> > +       }
> >> > +
> >> > +       @Override
> >> > +       public Object[] resolve(Method method) {
> >> > +               return new Object[method.getParameterTypes().length];
> >> > +       }
> >> > +
> >> > +       public BeanManager getBeanManager() {
> >> > +               return
> >> > ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> >> > +       }
> >> >  }
> >> >
> >> > Modified:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> > (original)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -1,12 +1,12 @@
> >> >  package org.apache.openejb.arquillian.remote;
> >> >
> >> >  import
> >> >
> org.jboss.arquillian.container.spi.client.container.DeployableContainer;
> >> > +import
> >> >
> >> >
> >>
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> >> >  import org.jboss.arquillian.core.spi.LoadableExtension;
> >> > -import org.jboss.arquillian.test.spi.TestEnricher;
> >> >
> >> >  public class RemoteTomEEExtension implements LoadableExtension {
> >> >    @Override public void register(ExtensionBuilder builder) {
> >> >        builder.service(DeployableContainer.class,
> >> > RemoteTomEEContainer.class)
> >> > -            .service(TestEnricher.class, RemoteTomEEEnricher.class);
> >> > +            .service(AuxiliaryArchiveAppender.class,
> >> > RemoteTomEEEJBEnricherArchiveAppender.class);
> >> >    }
> >> >  }
> >> >
> >> > Added:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > (added)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -0,0 +1,249 @@
> >> > +/*
> >> > + * JBoss, Home of Professional Open Source
> >> > + * Copyright 2009, Red Hat Middleware LLC, and individual
> contributors
> >> > + * by the @authors tag. See the copyright.txt in the distribution for
> a
> >> > + * full listing of individual contributors.
> >> > + *
> >> > + * 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.openejb.arquillian.remote;
> >> > +
> >> > +import java.lang.annotation.Annotation;
> >> > +import java.lang.reflect.Constructor;
> >> > +import java.lang.reflect.Field;
> >> > +import java.lang.reflect.Method;
> >> > +import java.security.AccessController;
> >> > +import java.security.PrivilegedAction;
> >> > +import java.security.PrivilegedActionException;
> >> > +import java.security.PrivilegedExceptionAction;
> >> > +import java.util.ArrayList;
> >> > +import java.util.List;
> >> > +
> >> > +/**
> >> > + * SecurityActions
> >> > + *
> >> > + * A set of privileged actions that are not to leak out
> >> > + * of this package
> >> > + *
> >> > + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> >> > + * @version $Revision: $
> >> > + */
> >> > +final class SecurityActions
> >> > +{
> >> > +
> >> > +
> >> >
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > +   // Constructor
> >> > ------------------------------------------------------------------||
> >> > +
> >> >
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > +
> >> > +   /**
> >> > +    * No instantiation
> >> > +    */
> >> > +   private SecurityActions()
> >> > +   {
> >> > +      throw new UnsupportedOperationException("No instantiation");
> >> > +   }
> >> > +
> >> > +
> >> >
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > +   // Utility Methods
> >> > --------------------------------------------------------------||
> >> > +
> >> >
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > +
> >> > +   /**
> >> > +    * Obtains the Thread Context ClassLoader
> >> > +    */
> >> > +   static ClassLoader getThreadContextClassLoader()
> >> > +   {
> >> > +      return AccessController.doPrivileged(GetTcclAction.INSTANCE);
> >> > +   }
> >> > +
> >> > +   /**
> >> > +    * Obtains the Constructor specified from the given Class and
> >> argument
> >> > types
> >> > +    * @param clazz
> >> > +    * @param argumentTypes
> >> > +    * @return
> >> > +    * @throws NoSuchMethodException
> >> > +    */
> >> > +   static Constructor<?> getConstructor(final Class<?> clazz, final
> >> > Class<?>... argumentTypes)
> >> > +         throws NoSuchMethodException
> >> > +   {
> >> > +      try
> >> > +      {
> >> > +         return AccessController.doPrivileged(new
> >> > PrivilegedExceptionAction<Constructor<?>>()
> >> > +         {
> >> > +            public Constructor<?> run() throws NoSuchMethodException
> >> > +            {
> >> > +               return clazz.getConstructor(argumentTypes);
> >> > +            }
> >> > +         });
> >> > +      }
> >> > +      // Unwrap
> >> > +      catch (final PrivilegedActionException pae)
> >> > +      {
> >> > +         final Throwable t = pae.getCause();
> >> > +         // Rethrow
> >> > +         if (t instanceof NoSuchMethodException)
> >> > +         {
> >> > +            throw (NoSuchMethodException) t;
> >> > +         }
> >> > +         else
> >> > +         {
> >> > +            // No other checked Exception thrown by
> >> Class.getConstructor
> >> > +            try
> >> > +            {
> >> > +               throw (RuntimeException) t;
> >> > +            }
> >> > +            // Just in case we've really messed up
> >> > +            catch (final ClassCastException cce)
> >> > +            {
> >> > +               throw new RuntimeException("Obtained unchecked
> >> Exception;
> >> > this code should never be reached", t);
> >> > +            }
> >> > +         }
> >> > +      }
> >> > +   }
> >> > +
> >> > +   /**
> >> > +    * Create a new instance by finding a constructor that matches the
> >> > argumentTypes signature
> >> > +    * using the arguments for instantiation.
> >> > +    *
> >> > +    * @param className Full classname of class to create
> >> > +    * @param argumentTypes The constructor argument types
> >> > +    * @param arguments The constructor arguments
> >> > +    * @return a new instance
> >> > +    * @throws IllegalArgumentException if className, argumentTypes,
> or
> >> > arguments are null
> >> > +    * @throws RuntimeException if any exceptions during creation
> >> > +    * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
> >> > +    * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> >> > +    */
> >> > +   static <T> T newInstance(final String className, final Class<?>[]
> >> > argumentTypes, final Object[] arguments,
> >> > +         final Class<T> expectedType)
> >> > +   {
> >> > +      if (className == null)
> >> > +      {
> >> > +         throw new IllegalArgumentException("ClassName must be
> >> > specified");
> >> > +      }
> >> > +      if (argumentTypes == null)
> >> > +      {
> >> > +         throw new IllegalArgumentException("ArgumentTypes must be
> >> > specified. Use empty array if no arguments");
> >> > +      }
> >> > +      if (arguments == null)
> >> > +      {
> >> > +         throw new IllegalArgumentException("Arguments must be
> >> specified.
> >> > Use empty array if no arguments");
> >> > +      }
> >> > +      final Object obj;
> >> > +      try
> >> > +      {
> >> > +         final ClassLoader tccl = getThreadContextClassLoader();
> >> > +         final Class<?> implClass = Class.forName(className, false,
> >> tccl);
> >> > +         Constructor<?> constructor = getConstructor(implClass,
> >> > argumentTypes);
> >> > +         obj = constructor.newInstance(arguments);
> >> > +      }
> >> > +      catch (Exception e)
> >> > +      {
> >> > +         throw new RuntimeException("Could not create new instance of
> "
> >> +
> >> > className
> >> > +               + ", missing package from classpath?", e);
> >> > +      }
> >> > +
> >> > +      // Cast
> >> > +      try
> >> > +      {
> >> > +         return expectedType.cast(obj);
> >> > +      }
> >> > +      catch (final ClassCastException cce)
> >> > +      {
> >> > +         // Reconstruct so we get some useful information
> >> > +         throw new ClassCastException("Incorrect expected type, " +
> >> > expectedType.getName() + ", defined for "
> >> > +               + obj.getClass().getName());
> >> > +      }
> >> > +   }
> >> > +
> >> > +   public static boolean isClassPresent(String name)
> >> > +   {
> >> > +      try
> >> > +      {
> >> > +         ClassLoader classLoader = getThreadContextClassLoader();
> >> > +         classLoader.loadClass(name);
> >> > +         return true;
> >> > +      }
> >> > +      catch (ClassNotFoundException e)
> >> > +      {
> >> > +         return false;
> >> > +      }
> >> > +   }
> >> > +
> >> > +   public static List<Field> getFieldsWithAnnotation(final Class<?>
> >> > source,
> >> > final Class<? extends Annotation> annotationClass)
> >> > +   {
> >> > +      List<Field> declaredAccessableFields =
> >> > AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
> >> > +      {
> >> > +         public List<Field> run()
> >> > +         {
> >> > +            List<Field> foundFields = new ArrayList<Field>();
> >> > +            Class<?> nextSource = source;
> >> > +            while (nextSource != Object.class) {
> >> > +               for(Field field : nextSource.getDeclaredFields())
> >> > +               {
> >> > +                  if(field.isAnnotationPresent(annotationClass))
> >> > +                  {
> >> > +                     if(!field.isAccessible())
> >> > +                     {
> >> > +                        field.setAccessible(true);
> >> > +                     }
> >> > +                     foundFields.add(field);
> >> > +                  }
> >> > +               }
> >> > +               nextSource = nextSource.getSuperclass();
> >> > +            }
> >> > +            return foundFields;
> >> > +         }
> >> > +      });
> >> > +      return declaredAccessableFields;
> >> > +   }
> >> > +
> >> > +   public static List<Method> getMethodsWithAnnotation(final Class<?>
> >> > source, final Class<? extends Annotation> annotationClass)
> >> > +   {
> >> > +      List<Method> declaredAccessableMethods =
> >> > AccessController.doPrivileged(new PrivilegedAction<List<Method>>()
> >> > +      {
> >> > +         public List<Method> run()
> >> > +         {
> >> > +            List<Method> foundMethods = new ArrayList<Method>();
> >> > +            for(Method method : source.getDeclaredMethods())
> >> > +            {
> >> > +               if(method.isAnnotationPresent(annotationClass))
> >> > +               {
> >> > +                  if(!method.isAccessible())
> >> > +                  {
> >> > +                     method.setAccessible(true);
> >> > +                  }
> >> > +                  foundMethods.add(method);
> >> > +               }
> >> > +            }
> >> > +            return foundMethods;
> >> > +         }
> >> > +      });
> >> > +      return declaredAccessableMethods;
> >> > +   }
> >> > +
> >> > +
> >> >
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > +   // Inner Classes
> >> > ----------------------------------------------------------------||
> >> > +
> >> >
> >> >
> >>
> //-------------------------------------------------------------------------------||
> >> > +
> >> > +   /**
> >> > +    * Single instance to get the TCCL
> >> > +    */
> >> > +   private enum GetTcclAction implements
> PrivilegedAction<ClassLoader>
> >> {
> >> > +      INSTANCE;
> >> > +
> >> > +      public ClassLoader run()
> >> > +      {
> >> > +         return Thread.currentThread().getContextClassLoader();
> >> > +      }
> >> > +
> >> > +   }
> >> > +
> >> > +}
> >> >
> >> > Modified:
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> >
> >> >
> >>
> ==============================================================================
> >> > ---
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> > (original)
> >> > +++
> >> >
> >> >
> >>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >> > Wed Oct 26 23:08:05 2011
> >> > @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
> >> >  import java.io.InputStream;
> >> >  import java.net.URL;
> >> >
> >> > +import javax.ejb.EJB;
> >> > +
> >> >  import junit.framework.Assert;
> >> >
> >> >  import org.jboss.arquillian.container.test.api.Deployment;
> >> > @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
> >> >  @RunWith(Arquillian.class)
> >> >  public class TomEEContainerTest {
> >> >
> >> > -    @Deployment(testable = false)
> >> > +    @Deployment
> >> >    public static WebArchive createDeployment() {
> >> > -        return ShrinkWrap.create(WebArchive.class,
> >> > "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
> >> > +        return ShrinkWrap.create(WebArchive.class,
> >> >
> >> >
> >>
> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
> >> >                .setWebXML(new
> >> >
> >> >
> >>
> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
> >> > "/Test").exportAsString()));
> >> >    }
> >> >
> >> > -    @Test
> >> > -    public void nothing(){}
> >> > +    @EJB
> >> > +    private TestEjb ejb;
> >> > +
> >> > +    @Test
> >> > +    public void testEjbIsNotNull() throws Exception {
> >> > +       Assert.assertNotNull(ejb);
> >> > +    }
> >> >
> >> > +    @Test
> >> >    public void testShouldBeAbleToAccessServletAndEjb() throws
> Exception
> >> {
> >> >        InputStream is = new URL("http://localhost:9080/test/Test
> >> > ").openStream();
> >> >        ByteArrayOutputStream os = new ByteArrayOutputStream();
> >> >
> >> > Modified: openejb/trunk/arquillian-tomee/pom.xml
> >> > URL:
> >> >
> >> >
> >>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> >> >
> >> >
> >>
> ==============================================================================
> >> > --- openejb/trunk/arquillian-tomee/pom.xml (original)
> >> > +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05 2011
> >> > @@ -49,7 +49,7 @@
> >> >
> >> >  <properties>
> >> >    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> >> > -    <version.arquillian>1.0.0.CR1</version.arquillian>
> >> > +    <version.arquillian>1.0.0.CR4</version.arquillian>
> >> >    <version.cdi-api>1.0</version.cdi-api>
> >> >    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
> >> >    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
> >> >
> >>
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
i don't get why it doesn't work since everything is in the same webapp?

Note: the ejbenricher needs the context to use to lookup, it can be set
using @Inject @DeployementScoped private Instance<Context> context; then
context.set(new InitialContext()) (in the container)

- Romain


2011/10/27 Romain Manni-Bucau <rm...@gmail.com>

> Weird, it seems to work in embedded case.
>
> Le 27 oct. 2011 13:29, "Jonathan Gallimore" <jo...@gmail.com>
> a écrit :
>
>  When I first saw your email, I did wonder whether the bean manager code
>> would be enough, and maybe I was just missing the ArchiveAppender stuff to
>> get the Enricher over to the server side. I've retested with the EJB
>> lookup
>> commented out, and unfortunately, It didn't work without my change for the
>> test case I was using (arquillian-showcase-ejb).
>>
>> Jon
>>
>> On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
>> <rm...@gmail.com>wrote:
>>
>> > Hi,
>> >
>> > Why beanmanager stuff is not enough?
>> >
>> > - Romain
>> >
>> > ---------- Message transféré ----------
>> > De : <jg...@apache.org>
>> > Date : 27 oct. 2011 01:08
>> > Objet : svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./
>> >
>> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
>> > arquillian-tomee-remote/
>> >
>> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
>> > arquillian-to...
>> > À : <co...@openejb.apache.org>
>> >
>> > Author: jgallimore
>> > Date: Wed Oct 26 23:08:05 2011
>> > New Revision: 1189526
>> >
>> > URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
>> > Log:
>> > Progress on supporting enriching tests with @EJB fields
>> >
>> > Added:
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > Removed:
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
>> > Modified:
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> >   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> >
>> >
>> >
>>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> >   openejb/trunk/arquillian-tomee/pom.xml
>> >
>> > Modified:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> > (original)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
>> >  import
>> > org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
>> >  import org.jboss.shrinkwrap.api.Archive;
>> >  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
>> > +import org.jboss.shrinkwrap.api.spec.WebArchive;
>> >  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
>> >
>> >  public abstract class TomEEContainer implements
>> > DeployableContainer<TomEEConfiguration> {
>> > @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
>> >    }
>> >
>> >    public ProtocolDescription getDefaultProtocol() {
>> > -        return new ProtocolDescription("Servlet 3.0");
>> > +        return new ProtocolDescription("Servlet 2.5");
>> >    }
>> >
>> >    public ProtocolMetaData deploy(Archive<?> archive) throws
>> > DeploymentException {
>> > @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
>> >            moduleIds.put(archive.getName(), file.getAbsolutePath());
>> >
>> >            HTTPContext httpContext = new HTTPContext("0.0.0.0",
>> > configuration.getHttpPort());
>> > -            httpContext.add(new Servlet("ArquillianServletRunner", "/"
>> +
>> > getArchiveNameWithoutExtension(archive)));
>> > +            if (archive instanceof WebArchive) {
>> > +               httpContext.add(new Servlet("ArquillianServletRunner",
>> "/"
>> > +
>> > getArchiveNameWithoutExtension(archive)));
>> > +            } else {
>> > +               httpContext.add(new Servlet("ArquillianServletRunner",
>> > "/arquillian-protocol"));
>> > +            }
>> > +
>> >            // we should probably get all servlets and add them to the
>> > context
>> >            return new ProtocolMetaData().addContext(httpContext);
>> >        } catch (Exception e) {
>> >
>> > Modified: openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
>> >
>> >
>> ==============================================================================
>> > --- openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>> > (original)
>> > +++ openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml Wed
>> Oct
>> > 26 23:08:05 2011
>> > @@ -333,5 +333,12 @@
>> >       <artifactId>swizzle-stream</artifactId>
>> >       <version>1.0.2</version>
>> >    </dependency>
>> > +    <dependency>
>> > +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
>> > +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
>> > +       <version>1.1.0-alpha-2</version>
>> > +       <type>jar</type>
>> > +       <scope>compile</scope>
>> > +    </dependency>
>> >  </dependencies>
>> >  </project>
>> >
>> > Modified:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> > (original)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
>> >
>> >                   System.setProperty("catalina.home",
>> > openejbHome.getAbsolutePath());
>> >                           System.setProperty("catalina.base",
>> > openejbHome.getAbsolutePath());
>> > +
>> >
>> >
>> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
>> >                           Paths paths = new Paths(new
>> > File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
>> >                           Installer installer = new Installer(paths,
>> true);
>> >                           installer.installAll();
>> >
>> > Added:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> > (added)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -0,0 +1,18 @@
>> > +package org.apache.openejb.arquillian.remote;
>> > +
>> > +import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
>> > +import
>> >
>> >
>> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
>> > +import org.jboss.shrinkwrap.api.Archive;
>> > +import org.jboss.shrinkwrap.api.ShrinkWrap;
>> > +import org.jboss.shrinkwrap.api.spec.JavaArchive;
>> > +
>> > +public class RemoteTomEEEJBEnricherArchiveAppender implements
>> > AuxiliaryArchiveAppender
>> > +{
>> > +          @Override
>> > +          public Archive<?> createAuxiliaryArchive()
>> > +          {
>> > +             return ShrinkWrap.create(JavaArchive.class,
>> > "arquillian-tomee-testenricher-ejb.jar")
>> > +                         .addClasses(RemoteTomEEEnricher.class,
>> > RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
>> > +
>> > .addAsServiceProvider(RemoteLoadableExtension.class,
>> > RemoteTomEEEJBEnricherExtension.class);
>> > +          }
>> > +       }
>> > \ No newline at end of file
>> >
>> > Added:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> > (added)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -0,0 +1,13 @@
>> > +package org.apache.openejb.arquillian.remote;
>> > +
>> > +import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
>> > +import org.jboss.arquillian.test.spi.TestEnricher;
>> > +
>> > +public class RemoteTomEEEJBEnricherExtension implements
>> > RemoteLoadableExtension {
>> > +    @Override public void register(ExtensionBuilder builder) {
>> > +       // only load if EJB is on ClassPath
>> > +        if(Validate.classExists("javax.ejb.EJB")) {
>> > +           builder.service(TestEnricher.class,
>> > org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
>> > +        }
>> > +    }
>> > +}
>> >
>> > Modified:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> > (original)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
>> >  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
>> >  import org.jboss.arquillian.test.spi.TestEnricher;
>> >
>> > +import javax.ejb.EJB;
>> >  import javax.enterprise.context.spi.CreationalContext;
>> >  import javax.enterprise.inject.spi.AnnotatedType;
>> >  import javax.enterprise.inject.spi.BeanManager;
>> >  import javax.enterprise.inject.spi.InjectionTarget;
>> > +import javax.naming.Context;
>> > +import javax.naming.InitialContext;
>> > +import javax.naming.NamingException;
>> > +
>> > +import java.lang.annotation.Annotation;
>> > +import java.lang.reflect.Field;
>> >  import java.lang.reflect.Method;
>> > +import java.util.List;
>> >
>> >  public class RemoteTomEEEnricher implements TestEnricher {
>> > -    @Override public void enrich(Object testCase) {
>> > -//        BeanManager mgr = getBeanManager();
>> > -//        if (mgr != null) {
>> > -//            AnnotatedType<?> type =
>> >  mgr.createAnnotatedType(getClass());
>> > -//            InjectionTarget<Object> injectionTarget =
>> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
>> > -//            CreationalContext<Object> context =
>> > mgr.createCreationalContext(null);
>> > -//
>> > -//            injectionTarget.inject(testCase, context);
>> > -//            injectionTarget.postConstruct(this);
>> > -//        } else {
>> > -//            throw new NullPointerException("bean manager is null");
>> > -//        }
>> > -
>> > -        /* TODO: see if this code could be called after tests
>> > -                *
>> > -                * if (injectionTarget != null) {
>> > -                *        injectionTarget.preDestroy(this);
>> > -                *    }
>> > -                *   if (context != null) {
>> > -                *        context.release();
>> > -                *    }
>> > -                *
>> > -                *   injectionTarget = null;
>> > -                *   context = null;
>> > -                */
>> > -    }
>> > -
>> > -    @Override public Object[] resolve(Method method) {
>> > -        return new Object[method.getParameterTypes().length];
>> > -    }
>> > -
>> > -    public BeanManager getBeanManager() {
>> > -        return ThreadSingletonServiceImpl.get().getBeanManagerImpl();
>> > -    }
>> > +
>> > +       private static final String ANNOTATION_NAME = "javax.ejb.EJB";
>> > +
>> > +       public void enrich(Object testCase) {
>> > +               BeanManager mgr = getBeanManager();
>> > +               if (mgr != null) {
>> > +                       AnnotatedType<?> type =
>> > mgr.createAnnotatedType(getClass());
>> > +                       InjectionTarget<Object> injectionTarget =
>> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
>> > +                       CreationalContext<Object> context =
>> > mgr.createCreationalContext(null);
>> > +
>> > +                       injectionTarget.inject(testCase, context);
>> > +                       injectionTarget.postConstruct(this);
>> > +               }
>> > +
>> > +               try {
>> > +                       if
>> > (SecurityActions.isClassPresent(ANNOTATION_NAME))
>> > {
>> > +                               @SuppressWarnings("unchecked")
>> > +                               Class<? extends Annotation>
>> ejbAnnotation =
>> > (Class<? extends Annotation>)
>> >
>> SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
>> > +
>> > +                               List<Field> annotatedFields =
>> > SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
>> > ejbAnnotation);
>> > +
>> > +                               for (Field field : annotatedFields) {
>> > +                                       if (field.get(testCase) == null)
>> {
>> > +                                               EJB fieldAnnotation =
>> (EJB)
>> > field.getAnnotation(ejbAnnotation);
>> > +                                               Object ejb =
>> > lookupEJB(field.getType(), fieldAnnotation.mappedName());
>> > +                                               field.set(testCase,
>> ejb);
>> > +                                       }
>> > +                               }
>> > +
>> > +                               List<Method> methods =
>> > SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
>> > ejbAnnotation);
>> > +
>> > +                               for (Method method : methods) {
>> > +                                       if
>> > (method.getParameterTypes().length != 1) {
>> > +                                               throw new
>> > RuntimeException("@EJB only allowed on single argument methods");
>> > +                                       }
>> > +                                       if
>> > (!method.getName().startsWith("set")) {
>> > +                                               throw new
>> > RuntimeException("@EJB only allowed on 'set' methods");
>> > +                                       }
>> > +                                       EJB parameterAnnotation = null;
>> //
>> > method.getParameterAnnotations()[0]
>> > +                                       for (Annotation annotation :
>> > method.getParameterAnnotations()[0]) {
>> > +                                               if
>> > (EJB.class.isAssignableFrom(annotation.annotationType())) {
>> > +
>> parameterAnnotation
>> > = (EJB) annotation;
>> > +                                               }
>> > +                                       }
>> > +                                       String mappedName =
>> > parameterAnnotation == null ? null : parameterAnnotation.mappedName();
>> > +                                       Object ejb =
>> > lookupEJB(method.getParameterTypes()[0], mappedName);
>> > +                                       method.invoke(testCase, ejb);
>> > +                               }
>> > +
>> > +                       }
>> > +               } catch (Exception e) {
>> > +
>> > +               }
>> > +
>> > +       }
>> > +
>> > +       protected Object lookupEJB(Class<?> fieldType, String
>> mappedName)
>> > throws Exception {
>> > +               // TODO: figure out test context ?
>> > +               Context initcontext = new InitialContext();
>> > +
>> > +               // TODO: These names are not spec compliant; fieldType
>> > needs
>> > to be a
>> > +               // bean type here,
>> > +               // but usually is just an interface of a bean. These
>> seldom
>> > work.
>> > +               String[] jndiNames = {
>> > "openejb:global/global/test/test.jar/" + fieldType.getSimpleName() +
>> > "Bean",
>> > +                               "openejb:global/global/test/test.jar/" +
>> > fieldType.getSimpleName(),
>> > +                               "java:global/test/test.jar/" +
>> > fieldType.getSimpleName() + "Bean",
>> > +                               "java:global/test/test.jar/" +
>> > fieldType.getSimpleName(),
>> > +                               "java:global/test.ear/test/" +
>> > fieldType.getSimpleName() + "Bean",
>> > +                               "java:global/test.ear/test/" +
>> > fieldType.getSimpleName(),
>> > +                               "java:global/test/" +
>> > fieldType.getSimpleName(),
>> > +                               "java:global/test/" +
>> > fieldType.getSimpleName() + "Bean",
>> > +                               "java:global/test/" +
>> > fieldType.getSimpleName() + "/no-interface",
>> > +                               "test/" + fieldType.getSimpleName() +
>> > "Bean/local",
>> > +                               "test/" + fieldType.getSimpleName() +
>> > "Bean/remote",
>> > +                               "test/" + fieldType.getSimpleName() +
>> > "/no-interface",
>> > +                               fieldType.getSimpleName() +
>> "Bean/local",
>> > +                               fieldType.getSimpleName() +
>> "Bean/remote",
>> > +                               fieldType.getSimpleName() +
>> > "/no-interface",
>> > +                               "ejblocal:" +
>> fieldType.getCanonicalName(),
>> > +                               fieldType.getCanonicalName() };
>> > +               if ((mappedName != null) && (!mappedName.equals(""))) {
>> > +                       // Use only the mapped name to lookup this EJB
>> > +                       jndiNames = new String[] { mappedName };
>> > +               }
>> > +
>> > +               for (String jndiName : jndiNames) {
>> > +                       try {
>> > +                               return initcontext.lookup(jndiName);
>> > +                       } catch (NamingException e) {
>> > +                               // no-op, try next
>> > +                       }
>> > +               }
>> > +               throw new NamingException("No EJB found in JNDI");
>> > +       }
>> > +
>> > +       @Override
>> > +       public Object[] resolve(Method method) {
>> > +               return new Object[method.getParameterTypes().length];
>> > +       }
>> > +
>> > +       public BeanManager getBeanManager() {
>> > +               return
>> > ThreadSingletonServiceImpl.get().getBeanManagerImpl();
>> > +       }
>> >  }
>> >
>> > Modified:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> > (original)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -1,12 +1,12 @@
>> >  package org.apache.openejb.arquillian.remote;
>> >
>> >  import
>> > org.jboss.arquillian.container.spi.client.container.DeployableContainer;
>> > +import
>> >
>> >
>> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
>> >  import org.jboss.arquillian.core.spi.LoadableExtension;
>> > -import org.jboss.arquillian.test.spi.TestEnricher;
>> >
>> >  public class RemoteTomEEExtension implements LoadableExtension {
>> >    @Override public void register(ExtensionBuilder builder) {
>> >        builder.service(DeployableContainer.class,
>> > RemoteTomEEContainer.class)
>> > -            .service(TestEnricher.class, RemoteTomEEEnricher.class);
>> > +            .service(AuxiliaryArchiveAppender.class,
>> > RemoteTomEEEJBEnricherArchiveAppender.class);
>> >    }
>> >  }
>> >
>> > Added:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > (added)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -0,0 +1,249 @@
>> > +/*
>> > + * JBoss, Home of Professional Open Source
>> > + * Copyright 2009, Red Hat Middleware LLC, and individual contributors
>> > + * by the @authors tag. See the copyright.txt in the distribution for a
>> > + * full listing of individual contributors.
>> > + *
>> > + * 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.openejb.arquillian.remote;
>> > +
>> > +import java.lang.annotation.Annotation;
>> > +import java.lang.reflect.Constructor;
>> > +import java.lang.reflect.Field;
>> > +import java.lang.reflect.Method;
>> > +import java.security.AccessController;
>> > +import java.security.PrivilegedAction;
>> > +import java.security.PrivilegedActionException;
>> > +import java.security.PrivilegedExceptionAction;
>> > +import java.util.ArrayList;
>> > +import java.util.List;
>> > +
>> > +/**
>> > + * SecurityActions
>> > + *
>> > + * A set of privileged actions that are not to leak out
>> > + * of this package
>> > + *
>> > + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
>> > + * @version $Revision: $
>> > + */
>> > +final class SecurityActions
>> > +{
>> > +
>> > +
>> >
>> >
>> //-------------------------------------------------------------------------------||
>> > +   // Constructor
>> > ------------------------------------------------------------------||
>> > +
>> >
>> >
>> //-------------------------------------------------------------------------------||
>> > +
>> > +   /**
>> > +    * No instantiation
>> > +    */
>> > +   private SecurityActions()
>> > +   {
>> > +      throw new UnsupportedOperationException("No instantiation");
>> > +   }
>> > +
>> > +
>> >
>> >
>> //-------------------------------------------------------------------------------||
>> > +   // Utility Methods
>> > --------------------------------------------------------------||
>> > +
>> >
>> >
>> //-------------------------------------------------------------------------------||
>> > +
>> > +   /**
>> > +    * Obtains the Thread Context ClassLoader
>> > +    */
>> > +   static ClassLoader getThreadContextClassLoader()
>> > +   {
>> > +      return AccessController.doPrivileged(GetTcclAction.INSTANCE);
>> > +   }
>> > +
>> > +   /**
>> > +    * Obtains the Constructor specified from the given Class and
>> argument
>> > types
>> > +    * @param clazz
>> > +    * @param argumentTypes
>> > +    * @return
>> > +    * @throws NoSuchMethodException
>> > +    */
>> > +   static Constructor<?> getConstructor(final Class<?> clazz, final
>> > Class<?>... argumentTypes)
>> > +         throws NoSuchMethodException
>> > +   {
>> > +      try
>> > +      {
>> > +         return AccessController.doPrivileged(new
>> > PrivilegedExceptionAction<Constructor<?>>()
>> > +         {
>> > +            public Constructor<?> run() throws NoSuchMethodException
>> > +            {
>> > +               return clazz.getConstructor(argumentTypes);
>> > +            }
>> > +         });
>> > +      }
>> > +      // Unwrap
>> > +      catch (final PrivilegedActionException pae)
>> > +      {
>> > +         final Throwable t = pae.getCause();
>> > +         // Rethrow
>> > +         if (t instanceof NoSuchMethodException)
>> > +         {
>> > +            throw (NoSuchMethodException) t;
>> > +         }
>> > +         else
>> > +         {
>> > +            // No other checked Exception thrown by
>> Class.getConstructor
>> > +            try
>> > +            {
>> > +               throw (RuntimeException) t;
>> > +            }
>> > +            // Just in case we've really messed up
>> > +            catch (final ClassCastException cce)
>> > +            {
>> > +               throw new RuntimeException("Obtained unchecked
>> Exception;
>> > this code should never be reached", t);
>> > +            }
>> > +         }
>> > +      }
>> > +   }
>> > +
>> > +   /**
>> > +    * Create a new instance by finding a constructor that matches the
>> > argumentTypes signature
>> > +    * using the arguments for instantiation.
>> > +    *
>> > +    * @param className Full classname of class to create
>> > +    * @param argumentTypes The constructor argument types
>> > +    * @param arguments The constructor arguments
>> > +    * @return a new instance
>> > +    * @throws IllegalArgumentException if className, argumentTypes, or
>> > arguments are null
>> > +    * @throws RuntimeException if any exceptions during creation
>> > +    * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
>> > +    * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
>> > +    */
>> > +   static <T> T newInstance(final String className, final Class<?>[]
>> > argumentTypes, final Object[] arguments,
>> > +         final Class<T> expectedType)
>> > +   {
>> > +      if (className == null)
>> > +      {
>> > +         throw new IllegalArgumentException("ClassName must be
>> > specified");
>> > +      }
>> > +      if (argumentTypes == null)
>> > +      {
>> > +         throw new IllegalArgumentException("ArgumentTypes must be
>> > specified. Use empty array if no arguments");
>> > +      }
>> > +      if (arguments == null)
>> > +      {
>> > +         throw new IllegalArgumentException("Arguments must be
>> specified.
>> > Use empty array if no arguments");
>> > +      }
>> > +      final Object obj;
>> > +      try
>> > +      {
>> > +         final ClassLoader tccl = getThreadContextClassLoader();
>> > +         final Class<?> implClass = Class.forName(className, false,
>> tccl);
>> > +         Constructor<?> constructor = getConstructor(implClass,
>> > argumentTypes);
>> > +         obj = constructor.newInstance(arguments);
>> > +      }
>> > +      catch (Exception e)
>> > +      {
>> > +         throw new RuntimeException("Could not create new instance of "
>> +
>> > className
>> > +               + ", missing package from classpath?", e);
>> > +      }
>> > +
>> > +      // Cast
>> > +      try
>> > +      {
>> > +         return expectedType.cast(obj);
>> > +      }
>> > +      catch (final ClassCastException cce)
>> > +      {
>> > +         // Reconstruct so we get some useful information
>> > +         throw new ClassCastException("Incorrect expected type, " +
>> > expectedType.getName() + ", defined for "
>> > +               + obj.getClass().getName());
>> > +      }
>> > +   }
>> > +
>> > +   public static boolean isClassPresent(String name)
>> > +   {
>> > +      try
>> > +      {
>> > +         ClassLoader classLoader = getThreadContextClassLoader();
>> > +         classLoader.loadClass(name);
>> > +         return true;
>> > +      }
>> > +      catch (ClassNotFoundException e)
>> > +      {
>> > +         return false;
>> > +      }
>> > +   }
>> > +
>> > +   public static List<Field> getFieldsWithAnnotation(final Class<?>
>> > source,
>> > final Class<? extends Annotation> annotationClass)
>> > +   {
>> > +      List<Field> declaredAccessableFields =
>> > AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
>> > +      {
>> > +         public List<Field> run()
>> > +         {
>> > +            List<Field> foundFields = new ArrayList<Field>();
>> > +            Class<?> nextSource = source;
>> > +            while (nextSource != Object.class) {
>> > +               for(Field field : nextSource.getDeclaredFields())
>> > +               {
>> > +                  if(field.isAnnotationPresent(annotationClass))
>> > +                  {
>> > +                     if(!field.isAccessible())
>> > +                     {
>> > +                        field.setAccessible(true);
>> > +                     }
>> > +                     foundFields.add(field);
>> > +                  }
>> > +               }
>> > +               nextSource = nextSource.getSuperclass();
>> > +            }
>> > +            return foundFields;
>> > +         }
>> > +      });
>> > +      return declaredAccessableFields;
>> > +   }
>> > +
>> > +   public static List<Method> getMethodsWithAnnotation(final Class<?>
>> > source, final Class<? extends Annotation> annotationClass)
>> > +   {
>> > +      List<Method> declaredAccessableMethods =
>> > AccessController.doPrivileged(new PrivilegedAction<List<Method>>()
>> > +      {
>> > +         public List<Method> run()
>> > +         {
>> > +            List<Method> foundMethods = new ArrayList<Method>();
>> > +            for(Method method : source.getDeclaredMethods())
>> > +            {
>> > +               if(method.isAnnotationPresent(annotationClass))
>> > +               {
>> > +                  if(!method.isAccessible())
>> > +                  {
>> > +                     method.setAccessible(true);
>> > +                  }
>> > +                  foundMethods.add(method);
>> > +               }
>> > +            }
>> > +            return foundMethods;
>> > +         }
>> > +      });
>> > +      return declaredAccessableMethods;
>> > +   }
>> > +
>> > +
>> >
>> >
>> //-------------------------------------------------------------------------------||
>> > +   // Inner Classes
>> > ----------------------------------------------------------------||
>> > +
>> >
>> >
>> //-------------------------------------------------------------------------------||
>> > +
>> > +   /**
>> > +    * Single instance to get the TCCL
>> > +    */
>> > +   private enum GetTcclAction implements PrivilegedAction<ClassLoader>
>> {
>> > +      INSTANCE;
>> > +
>> > +      public ClassLoader run()
>> > +      {
>> > +         return Thread.currentThread().getContextClassLoader();
>> > +      }
>> > +
>> > +   }
>> > +
>> > +}
>> >
>> > Modified:
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>> >
>> >
>> ==============================================================================
>> > ---
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> > (original)
>> > +++
>> >
>> >
>> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>> > Wed Oct 26 23:08:05 2011
>> > @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
>> >  import java.io.InputStream;
>> >  import java.net.URL;
>> >
>> > +import javax.ejb.EJB;
>> > +
>> >  import junit.framework.Assert;
>> >
>> >  import org.jboss.arquillian.container.test.api.Deployment;
>> > @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
>> >  @RunWith(Arquillian.class)
>> >  public class TomEEContainerTest {
>> >
>> > -    @Deployment(testable = false)
>> > +    @Deployment
>> >    public static WebArchive createDeployment() {
>> > -        return ShrinkWrap.create(WebArchive.class,
>> > "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
>> > +        return ShrinkWrap.create(WebArchive.class,
>> >
>> >
>> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
>> >                .setWebXML(new
>> >
>> >
>> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
>> > "/Test").exportAsString()));
>> >    }
>> >
>> > -    @Test
>> > -    public void nothing(){}
>> > +    @EJB
>> > +    private TestEjb ejb;
>> > +
>> > +    @Test
>> > +    public void testEjbIsNotNull() throws Exception {
>> > +       Assert.assertNotNull(ejb);
>> > +    }
>> >
>> > +    @Test
>> >    public void testShouldBeAbleToAccessServletAndEjb() throws Exception
>> {
>> >        InputStream is = new URL("http://localhost:9080/test/Test
>> > ").openStream();
>> >        ByteArrayOutputStream os = new ByteArrayOutputStream();
>> >
>> > Modified: openejb/trunk/arquillian-tomee/pom.xml
>> > URL:
>> >
>> >
>> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
>> >
>> >
>> ==============================================================================
>> > --- openejb/trunk/arquillian-tomee/pom.xml (original)
>> > +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05 2011
>> > @@ -49,7 +49,7 @@
>> >
>> >  <properties>
>> >    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>> > -    <version.arquillian>1.0.0.CR1</version.arquillian>
>> > +    <version.arquillian>1.0.0.CR4</version.arquillian>
>> >    <version.cdi-api>1.0</version.cdi-api>
>> >    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
>> >    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
>> >
>>
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Weird, it seems to work in embedded case.

Le 27 oct. 2011 13:29, "Jonathan Gallimore" <jo...@gmail.com> a
écrit :

> When I first saw your email, I did wonder whether the bean manager code
> would be enough, and maybe I was just missing the ArchiveAppender stuff to
> get the Enricher over to the server side. I've retested with the EJB lookup
> commented out, and unfortunately, It didn't work without my change for the
> test case I was using (arquillian-showcase-ejb).
>
> Jon
>
> On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
> <rm...@gmail.com>wrote:
>
> > Hi,
> >
> > Why beanmanager stuff is not enough?
> >
> > - Romain
> >
> > ---------- Message transféré ----------
> > De : <jg...@apache.org>
> > Date : 27 oct. 2011 01:08
> > Objet : svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./
> >
> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
> > arquillian-tomee-remote/
> >
> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
> > arquillian-to...
> > À : <co...@openejb.apache.org>
> >
> > Author: jgallimore
> > Date: Wed Oct 26 23:08:05 2011
> > New Revision: 1189526
> >
> > URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
> > Log:
> > Progress on supporting enriching tests with @EJB fields
> >
> > Added:
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > Removed:
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
> > Modified:
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> >   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> >
> >
> >
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> >   openejb/trunk/arquillian-tomee/pom.xml
> >
> > Modified:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > (original)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> > Wed Oct 26 23:08:05 2011
> > @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
> >  import
> > org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
> >  import org.jboss.shrinkwrap.api.Archive;
> >  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
> > +import org.jboss.shrinkwrap.api.spec.WebArchive;
> >  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
> >
> >  public abstract class TomEEContainer implements
> > DeployableContainer<TomEEConfiguration> {
> > @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
> >    }
> >
> >    public ProtocolDescription getDefaultProtocol() {
> > -        return new ProtocolDescription("Servlet 3.0");
> > +        return new ProtocolDescription("Servlet 2.5");
> >    }
> >
> >    public ProtocolMetaData deploy(Archive<?> archive) throws
> > DeploymentException {
> > @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
> >            moduleIds.put(archive.getName(), file.getAbsolutePath());
> >
> >            HTTPContext httpContext = new HTTPContext("0.0.0.0",
> > configuration.getHttpPort());
> > -            httpContext.add(new Servlet("ArquillianServletRunner", "/" +
> > getArchiveNameWithoutExtension(archive)));
> > +            if (archive instanceof WebArchive) {
> > +               httpContext.add(new Servlet("ArquillianServletRunner",
> "/"
> > +
> > getArchiveNameWithoutExtension(archive)));
> > +            } else {
> > +               httpContext.add(new Servlet("ArquillianServletRunner",
> > "/arquillian-protocol"));
> > +            }
> > +
> >            // we should probably get all servlets and add them to the
> > context
> >            return new ProtocolMetaData().addContext(httpContext);
> >        } catch (Exception e) {
> >
> > Modified: openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> >
> >
> ==============================================================================
> > --- openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> > (original)
> > +++ openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml Wed
> Oct
> > 26 23:08:05 2011
> > @@ -333,5 +333,12 @@
> >       <artifactId>swizzle-stream</artifactId>
> >       <version>1.0.2</version>
> >    </dependency>
> > +    <dependency>
> > +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
> > +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
> > +       <version>1.1.0-alpha-2</version>
> > +       <type>jar</type>
> > +       <scope>compile</scope>
> > +    </dependency>
> >  </dependencies>
> >  </project>
> >
> > Modified:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > (original)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> > Wed Oct 26 23:08:05 2011
> > @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
> >
> >                   System.setProperty("catalina.home",
> > openejbHome.getAbsolutePath());
> >                           System.setProperty("catalina.base",
> > openejbHome.getAbsolutePath());
> > +
> >
> >
> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
> >                           Paths paths = new Paths(new
> > File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
> >                           Installer installer = new Installer(paths,
> true);
> >                           installer.installAll();
> >
> > Added:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > (added)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> > Wed Oct 26 23:08:05 2011
> > @@ -0,0 +1,18 @@
> > +package org.apache.openejb.arquillian.remote;
> > +
> > +import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> > +import
> >
> >
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> > +import org.jboss.shrinkwrap.api.Archive;
> > +import org.jboss.shrinkwrap.api.ShrinkWrap;
> > +import org.jboss.shrinkwrap.api.spec.JavaArchive;
> > +
> > +public class RemoteTomEEEJBEnricherArchiveAppender implements
> > AuxiliaryArchiveAppender
> > +{
> > +          @Override
> > +          public Archive<?> createAuxiliaryArchive()
> > +          {
> > +             return ShrinkWrap.create(JavaArchive.class,
> > "arquillian-tomee-testenricher-ejb.jar")
> > +                         .addClasses(RemoteTomEEEnricher.class,
> > RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
> > +
> > .addAsServiceProvider(RemoteLoadableExtension.class,
> > RemoteTomEEEJBEnricherExtension.class);
> > +          }
> > +       }
> > \ No newline at end of file
> >
> > Added:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > (added)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> > Wed Oct 26 23:08:05 2011
> > @@ -0,0 +1,13 @@
> > +package org.apache.openejb.arquillian.remote;
> > +
> > +import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> > +import org.jboss.arquillian.test.spi.TestEnricher;
> > +
> > +public class RemoteTomEEEJBEnricherExtension implements
> > RemoteLoadableExtension {
> > +    @Override public void register(ExtensionBuilder builder) {
> > +       // only load if EJB is on ClassPath
> > +        if(Validate.classExists("javax.ejb.EJB")) {
> > +           builder.service(TestEnricher.class,
> > org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
> > +        }
> > +    }
> > +}
> >
> > Modified:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > (original)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> > Wed Oct 26 23:08:05 2011
> > @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
> >  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
> >  import org.jboss.arquillian.test.spi.TestEnricher;
> >
> > +import javax.ejb.EJB;
> >  import javax.enterprise.context.spi.CreationalContext;
> >  import javax.enterprise.inject.spi.AnnotatedType;
> >  import javax.enterprise.inject.spi.BeanManager;
> >  import javax.enterprise.inject.spi.InjectionTarget;
> > +import javax.naming.Context;
> > +import javax.naming.InitialContext;
> > +import javax.naming.NamingException;
> > +
> > +import java.lang.annotation.Annotation;
> > +import java.lang.reflect.Field;
> >  import java.lang.reflect.Method;
> > +import java.util.List;
> >
> >  public class RemoteTomEEEnricher implements TestEnricher {
> > -    @Override public void enrich(Object testCase) {
> > -//        BeanManager mgr = getBeanManager();
> > -//        if (mgr != null) {
> > -//            AnnotatedType<?> type =
> >  mgr.createAnnotatedType(getClass());
> > -//            InjectionTarget<Object> injectionTarget =
> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> > -//            CreationalContext<Object> context =
> > mgr.createCreationalContext(null);
> > -//
> > -//            injectionTarget.inject(testCase, context);
> > -//            injectionTarget.postConstruct(this);
> > -//        } else {
> > -//            throw new NullPointerException("bean manager is null");
> > -//        }
> > -
> > -        /* TODO: see if this code could be called after tests
> > -                *
> > -                * if (injectionTarget != null) {
> > -                *        injectionTarget.preDestroy(this);
> > -                *    }
> > -                *   if (context != null) {
> > -                *        context.release();
> > -                *    }
> > -                *
> > -                *   injectionTarget = null;
> > -                *   context = null;
> > -                */
> > -    }
> > -
> > -    @Override public Object[] resolve(Method method) {
> > -        return new Object[method.getParameterTypes().length];
> > -    }
> > -
> > -    public BeanManager getBeanManager() {
> > -        return ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> > -    }
> > +
> > +       private static final String ANNOTATION_NAME = "javax.ejb.EJB";
> > +
> > +       public void enrich(Object testCase) {
> > +               BeanManager mgr = getBeanManager();
> > +               if (mgr != null) {
> > +                       AnnotatedType<?> type =
> > mgr.createAnnotatedType(getClass());
> > +                       InjectionTarget<Object> injectionTarget =
> > (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> > +                       CreationalContext<Object> context =
> > mgr.createCreationalContext(null);
> > +
> > +                       injectionTarget.inject(testCase, context);
> > +                       injectionTarget.postConstruct(this);
> > +               }
> > +
> > +               try {
> > +                       if
> > (SecurityActions.isClassPresent(ANNOTATION_NAME))
> > {
> > +                               @SuppressWarnings("unchecked")
> > +                               Class<? extends Annotation> ejbAnnotation
> =
> > (Class<? extends Annotation>)
> > SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
> > +
> > +                               List<Field> annotatedFields =
> > SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
> > ejbAnnotation);
> > +
> > +                               for (Field field : annotatedFields) {
> > +                                       if (field.get(testCase) == null)
> {
> > +                                               EJB fieldAnnotation =
> (EJB)
> > field.getAnnotation(ejbAnnotation);
> > +                                               Object ejb =
> > lookupEJB(field.getType(), fieldAnnotation.mappedName());
> > +                                               field.set(testCase, ejb);
> > +                                       }
> > +                               }
> > +
> > +                               List<Method> methods =
> > SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
> > ejbAnnotation);
> > +
> > +                               for (Method method : methods) {
> > +                                       if
> > (method.getParameterTypes().length != 1) {
> > +                                               throw new
> > RuntimeException("@EJB only allowed on single argument methods");
> > +                                       }
> > +                                       if
> > (!method.getName().startsWith("set")) {
> > +                                               throw new
> > RuntimeException("@EJB only allowed on 'set' methods");
> > +                                       }
> > +                                       EJB parameterAnnotation = null;
> //
> > method.getParameterAnnotations()[0]
> > +                                       for (Annotation annotation :
> > method.getParameterAnnotations()[0]) {
> > +                                               if
> > (EJB.class.isAssignableFrom(annotation.annotationType())) {
> > +
> parameterAnnotation
> > = (EJB) annotation;
> > +                                               }
> > +                                       }
> > +                                       String mappedName =
> > parameterAnnotation == null ? null : parameterAnnotation.mappedName();
> > +                                       Object ejb =
> > lookupEJB(method.getParameterTypes()[0], mappedName);
> > +                                       method.invoke(testCase, ejb);
> > +                               }
> > +
> > +                       }
> > +               } catch (Exception e) {
> > +
> > +               }
> > +
> > +       }
> > +
> > +       protected Object lookupEJB(Class<?> fieldType, String mappedName)
> > throws Exception {
> > +               // TODO: figure out test context ?
> > +               Context initcontext = new InitialContext();
> > +
> > +               // TODO: These names are not spec compliant; fieldType
> > needs
> > to be a
> > +               // bean type here,
> > +               // but usually is just an interface of a bean. These
> seldom
> > work.
> > +               String[] jndiNames = {
> > "openejb:global/global/test/test.jar/" + fieldType.getSimpleName() +
> > "Bean",
> > +                               "openejb:global/global/test/test.jar/" +
> > fieldType.getSimpleName(),
> > +                               "java:global/test/test.jar/" +
> > fieldType.getSimpleName() + "Bean",
> > +                               "java:global/test/test.jar/" +
> > fieldType.getSimpleName(),
> > +                               "java:global/test.ear/test/" +
> > fieldType.getSimpleName() + "Bean",
> > +                               "java:global/test.ear/test/" +
> > fieldType.getSimpleName(),
> > +                               "java:global/test/" +
> > fieldType.getSimpleName(),
> > +                               "java:global/test/" +
> > fieldType.getSimpleName() + "Bean",
> > +                               "java:global/test/" +
> > fieldType.getSimpleName() + "/no-interface",
> > +                               "test/" + fieldType.getSimpleName() +
> > "Bean/local",
> > +                               "test/" + fieldType.getSimpleName() +
> > "Bean/remote",
> > +                               "test/" + fieldType.getSimpleName() +
> > "/no-interface",
> > +                               fieldType.getSimpleName() + "Bean/local",
> > +                               fieldType.getSimpleName() +
> "Bean/remote",
> > +                               fieldType.getSimpleName() +
> > "/no-interface",
> > +                               "ejblocal:" +
> fieldType.getCanonicalName(),
> > +                               fieldType.getCanonicalName() };
> > +               if ((mappedName != null) && (!mappedName.equals(""))) {
> > +                       // Use only the mapped name to lookup this EJB
> > +                       jndiNames = new String[] { mappedName };
> > +               }
> > +
> > +               for (String jndiName : jndiNames) {
> > +                       try {
> > +                               return initcontext.lookup(jndiName);
> > +                       } catch (NamingException e) {
> > +                               // no-op, try next
> > +                       }
> > +               }
> > +               throw new NamingException("No EJB found in JNDI");
> > +       }
> > +
> > +       @Override
> > +       public Object[] resolve(Method method) {
> > +               return new Object[method.getParameterTypes().length];
> > +       }
> > +
> > +       public BeanManager getBeanManager() {
> > +               return
> > ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> > +       }
> >  }
> >
> > Modified:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > (original)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> > Wed Oct 26 23:08:05 2011
> > @@ -1,12 +1,12 @@
> >  package org.apache.openejb.arquillian.remote;
> >
> >  import
> > org.jboss.arquillian.container.spi.client.container.DeployableContainer;
> > +import
> >
> >
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> >  import org.jboss.arquillian.core.spi.LoadableExtension;
> > -import org.jboss.arquillian.test.spi.TestEnricher;
> >
> >  public class RemoteTomEEExtension implements LoadableExtension {
> >    @Override public void register(ExtensionBuilder builder) {
> >        builder.service(DeployableContainer.class,
> > RemoteTomEEContainer.class)
> > -            .service(TestEnricher.class, RemoteTomEEEnricher.class);
> > +            .service(AuxiliaryArchiveAppender.class,
> > RemoteTomEEEJBEnricherArchiveAppender.class);
> >    }
> >  }
> >
> > Added:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > (added)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> > Wed Oct 26 23:08:05 2011
> > @@ -0,0 +1,249 @@
> > +/*
> > + * JBoss, Home of Professional Open Source
> > + * Copyright 2009, Red Hat Middleware LLC, and individual contributors
> > + * by the @authors tag. See the copyright.txt in the distribution for a
> > + * full listing of individual contributors.
> > + *
> > + * 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.openejb.arquillian.remote;
> > +
> > +import java.lang.annotation.Annotation;
> > +import java.lang.reflect.Constructor;
> > +import java.lang.reflect.Field;
> > +import java.lang.reflect.Method;
> > +import java.security.AccessController;
> > +import java.security.PrivilegedAction;
> > +import java.security.PrivilegedActionException;
> > +import java.security.PrivilegedExceptionAction;
> > +import java.util.ArrayList;
> > +import java.util.List;
> > +
> > +/**
> > + * SecurityActions
> > + *
> > + * A set of privileged actions that are not to leak out
> > + * of this package
> > + *
> > + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> > + * @version $Revision: $
> > + */
> > +final class SecurityActions
> > +{
> > +
> > +
> >
> >
> //-------------------------------------------------------------------------------||
> > +   // Constructor
> > ------------------------------------------------------------------||
> > +
> >
> >
> //-------------------------------------------------------------------------------||
> > +
> > +   /**
> > +    * No instantiation
> > +    */
> > +   private SecurityActions()
> > +   {
> > +      throw new UnsupportedOperationException("No instantiation");
> > +   }
> > +
> > +
> >
> >
> //-------------------------------------------------------------------------------||
> > +   // Utility Methods
> > --------------------------------------------------------------||
> > +
> >
> >
> //-------------------------------------------------------------------------------||
> > +
> > +   /**
> > +    * Obtains the Thread Context ClassLoader
> > +    */
> > +   static ClassLoader getThreadContextClassLoader()
> > +   {
> > +      return AccessController.doPrivileged(GetTcclAction.INSTANCE);
> > +   }
> > +
> > +   /**
> > +    * Obtains the Constructor specified from the given Class and
> argument
> > types
> > +    * @param clazz
> > +    * @param argumentTypes
> > +    * @return
> > +    * @throws NoSuchMethodException
> > +    */
> > +   static Constructor<?> getConstructor(final Class<?> clazz, final
> > Class<?>... argumentTypes)
> > +         throws NoSuchMethodException
> > +   {
> > +      try
> > +      {
> > +         return AccessController.doPrivileged(new
> > PrivilegedExceptionAction<Constructor<?>>()
> > +         {
> > +            public Constructor<?> run() throws NoSuchMethodException
> > +            {
> > +               return clazz.getConstructor(argumentTypes);
> > +            }
> > +         });
> > +      }
> > +      // Unwrap
> > +      catch (final PrivilegedActionException pae)
> > +      {
> > +         final Throwable t = pae.getCause();
> > +         // Rethrow
> > +         if (t instanceof NoSuchMethodException)
> > +         {
> > +            throw (NoSuchMethodException) t;
> > +         }
> > +         else
> > +         {
> > +            // No other checked Exception thrown by Class.getConstructor
> > +            try
> > +            {
> > +               throw (RuntimeException) t;
> > +            }
> > +            // Just in case we've really messed up
> > +            catch (final ClassCastException cce)
> > +            {
> > +               throw new RuntimeException("Obtained unchecked Exception;
> > this code should never be reached", t);
> > +            }
> > +         }
> > +      }
> > +   }
> > +
> > +   /**
> > +    * Create a new instance by finding a constructor that matches the
> > argumentTypes signature
> > +    * using the arguments for instantiation.
> > +    *
> > +    * @param className Full classname of class to create
> > +    * @param argumentTypes The constructor argument types
> > +    * @param arguments The constructor arguments
> > +    * @return a new instance
> > +    * @throws IllegalArgumentException if className, argumentTypes, or
> > arguments are null
> > +    * @throws RuntimeException if any exceptions during creation
> > +    * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
> > +    * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> > +    */
> > +   static <T> T newInstance(final String className, final Class<?>[]
> > argumentTypes, final Object[] arguments,
> > +         final Class<T> expectedType)
> > +   {
> > +      if (className == null)
> > +      {
> > +         throw new IllegalArgumentException("ClassName must be
> > specified");
> > +      }
> > +      if (argumentTypes == null)
> > +      {
> > +         throw new IllegalArgumentException("ArgumentTypes must be
> > specified. Use empty array if no arguments");
> > +      }
> > +      if (arguments == null)
> > +      {
> > +         throw new IllegalArgumentException("Arguments must be
> specified.
> > Use empty array if no arguments");
> > +      }
> > +      final Object obj;
> > +      try
> > +      {
> > +         final ClassLoader tccl = getThreadContextClassLoader();
> > +         final Class<?> implClass = Class.forName(className, false,
> tccl);
> > +         Constructor<?> constructor = getConstructor(implClass,
> > argumentTypes);
> > +         obj = constructor.newInstance(arguments);
> > +      }
> > +      catch (Exception e)
> > +      {
> > +         throw new RuntimeException("Could not create new instance of "
> +
> > className
> > +               + ", missing package from classpath?", e);
> > +      }
> > +
> > +      // Cast
> > +      try
> > +      {
> > +         return expectedType.cast(obj);
> > +      }
> > +      catch (final ClassCastException cce)
> > +      {
> > +         // Reconstruct so we get some useful information
> > +         throw new ClassCastException("Incorrect expected type, " +
> > expectedType.getName() + ", defined for "
> > +               + obj.getClass().getName());
> > +      }
> > +   }
> > +
> > +   public static boolean isClassPresent(String name)
> > +   {
> > +      try
> > +      {
> > +         ClassLoader classLoader = getThreadContextClassLoader();
> > +         classLoader.loadClass(name);
> > +         return true;
> > +      }
> > +      catch (ClassNotFoundException e)
> > +      {
> > +         return false;
> > +      }
> > +   }
> > +
> > +   public static List<Field> getFieldsWithAnnotation(final Class<?>
> > source,
> > final Class<? extends Annotation> annotationClass)
> > +   {
> > +      List<Field> declaredAccessableFields =
> > AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
> > +      {
> > +         public List<Field> run()
> > +         {
> > +            List<Field> foundFields = new ArrayList<Field>();
> > +            Class<?> nextSource = source;
> > +            while (nextSource != Object.class) {
> > +               for(Field field : nextSource.getDeclaredFields())
> > +               {
> > +                  if(field.isAnnotationPresent(annotationClass))
> > +                  {
> > +                     if(!field.isAccessible())
> > +                     {
> > +                        field.setAccessible(true);
> > +                     }
> > +                     foundFields.add(field);
> > +                  }
> > +               }
> > +               nextSource = nextSource.getSuperclass();
> > +            }
> > +            return foundFields;
> > +         }
> > +      });
> > +      return declaredAccessableFields;
> > +   }
> > +
> > +   public static List<Method> getMethodsWithAnnotation(final Class<?>
> > source, final Class<? extends Annotation> annotationClass)
> > +   {
> > +      List<Method> declaredAccessableMethods =
> > AccessController.doPrivileged(new PrivilegedAction<List<Method>>()
> > +      {
> > +         public List<Method> run()
> > +         {
> > +            List<Method> foundMethods = new ArrayList<Method>();
> > +            for(Method method : source.getDeclaredMethods())
> > +            {
> > +               if(method.isAnnotationPresent(annotationClass))
> > +               {
> > +                  if(!method.isAccessible())
> > +                  {
> > +                     method.setAccessible(true);
> > +                  }
> > +                  foundMethods.add(method);
> > +               }
> > +            }
> > +            return foundMethods;
> > +         }
> > +      });
> > +      return declaredAccessableMethods;
> > +   }
> > +
> > +
> >
> >
> //-------------------------------------------------------------------------------||
> > +   // Inner Classes
> > ----------------------------------------------------------------||
> > +
> >
> >
> //-------------------------------------------------------------------------------||
> > +
> > +   /**
> > +    * Single instance to get the TCCL
> > +    */
> > +   private enum GetTcclAction implements PrivilegedAction<ClassLoader> {
> > +      INSTANCE;
> > +
> > +      public ClassLoader run()
> > +      {
> > +         return Thread.currentThread().getContextClassLoader();
> > +      }
> > +
> > +   }
> > +
> > +}
> >
> > Modified:
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
> >
> >
> ==============================================================================
> > ---
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > (original)
> > +++
> >
> >
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> > Wed Oct 26 23:08:05 2011
> > @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
> >  import java.io.InputStream;
> >  import java.net.URL;
> >
> > +import javax.ejb.EJB;
> > +
> >  import junit.framework.Assert;
> >
> >  import org.jboss.arquillian.container.test.api.Deployment;
> > @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
> >  @RunWith(Arquillian.class)
> >  public class TomEEContainerTest {
> >
> > -    @Deployment(testable = false)
> > +    @Deployment
> >    public static WebArchive createDeployment() {
> > -        return ShrinkWrap.create(WebArchive.class,
> > "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
> > +        return ShrinkWrap.create(WebArchive.class,
> >
> >
> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
> >                .setWebXML(new
> >
> >
> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
> > "/Test").exportAsString()));
> >    }
> >
> > -    @Test
> > -    public void nothing(){}
> > +    @EJB
> > +    private TestEjb ejb;
> > +
> > +    @Test
> > +    public void testEjbIsNotNull() throws Exception {
> > +       Assert.assertNotNull(ejb);
> > +    }
> >
> > +    @Test
> >    public void testShouldBeAbleToAccessServletAndEjb() throws Exception {
> >        InputStream is = new URL("http://localhost:9080/test/Test
> > ").openStream();
> >        ByteArrayOutputStream os = new ByteArrayOutputStream();
> >
> > Modified: openejb/trunk/arquillian-tomee/pom.xml
> > URL:
> >
> >
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
> >
> >
> ==============================================================================
> > --- openejb/trunk/arquillian-tomee/pom.xml (original)
> > +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05 2011
> > @@ -49,7 +49,7 @@
> >
> >  <properties>
> >    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> > -    <version.arquillian>1.0.0.CR1</version.arquillian>
> > +    <version.arquillian>1.0.0.CR4</version.arquillian>
> >    <version.cdi-api>1.0</version.cdi-api>
> >    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
> >    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
> >
>

Re: svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./ arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee-remote/ arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/ arquil

Posted by Jonathan Gallimore <jo...@gmail.com>.
When I first saw your email, I did wonder whether the bean manager code
would be enough, and maybe I was just missing the ArchiveAppender stuff to
get the Enricher over to the server side. I've retested with the EJB lookup
commented out, and unfortunately, It didn't work without my change for the
test case I was using (arquillian-showcase-ejb).

Jon

On Thu, Oct 27, 2011 at 5:29 AM, Romain Manni-Bucau
<rm...@gmail.com>wrote:

> Hi,
>
> Why beanmanager stuff is not enough?
>
> - Romain
>
> ---------- Message transféré ----------
> De : <jg...@apache.org>
> Date : 27 oct. 2011 01:08
> Objet : svn commit: r1189526 - in /openejb/trunk/arquillian-tomee: ./
> arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
> arquillian-tomee-remote/
> arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
> arquillian-to...
> À : <co...@openejb.apache.org>
>
> Author: jgallimore
> Date: Wed Oct 26 23:08:05 2011
> New Revision: 1189526
>
> URL: http://svn.apache.org/viewvc?rev=1189526&view=rev
> Log:
> Progress on supporting enriching tests with @EJB fields
>
> Added:
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> Removed:
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestEnricher
> Modified:
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
>   openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
>
>
>  openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
>   openejb/trunk/arquillian-tomee/pom.xml
>
> Modified:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> (original)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/TomEEContainer.java
> Wed Oct 26 23:08:05 2011
> @@ -36,6 +36,7 @@ import org.jboss.arquillian.container.sp
>  import
> org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
>  import org.jboss.shrinkwrap.api.Archive;
>  import org.jboss.shrinkwrap.api.exporter.ZipExporter;
> +import org.jboss.shrinkwrap.api.spec.WebArchive;
>  import org.jboss.shrinkwrap.descriptor.api.Descriptor;
>
>  public abstract class TomEEContainer implements
> DeployableContainer<TomEEConfiguration> {
> @@ -86,7 +87,7 @@ public abstract class TomEEContainer imp
>    }
>
>    public ProtocolDescription getDefaultProtocol() {
> -        return new ProtocolDescription("Servlet 3.0");
> +        return new ProtocolDescription("Servlet 2.5");
>    }
>
>    public ProtocolMetaData deploy(Archive<?> archive) throws
> DeploymentException {
> @@ -107,7 +108,12 @@ public abstract class TomEEContainer imp
>            moduleIds.put(archive.getName(), file.getAbsolutePath());
>
>            HTTPContext httpContext = new HTTPContext("0.0.0.0",
> configuration.getHttpPort());
> -            httpContext.add(new Servlet("ArquillianServletRunner", "/" +
> getArchiveNameWithoutExtension(archive)));
> +            if (archive instanceof WebArchive) {
> +               httpContext.add(new Servlet("ArquillianServletRunner", "/"
> +
> getArchiveNameWithoutExtension(archive)));
> +            } else {
> +               httpContext.add(new Servlet("ArquillianServletRunner",
> "/arquillian-protocol"));
> +            }
> +
>            // we should probably get all servlets and add them to the
> context
>            return new ProtocolMetaData().addContext(httpContext);
>        } catch (Exception e) {
>
> Modified: openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
>
> ==============================================================================
> --- openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml
> (original)
> +++ openejb/trunk/arquillian-tomee/arquillian-tomee-remote/pom.xml Wed Oct
> 26 23:08:05 2011
> @@ -333,5 +333,12 @@
>       <artifactId>swizzle-stream</artifactId>
>       <version>1.0.2</version>
>    </dependency>
> +    <dependency>
> +       <groupId>org.jboss.shrinkwrap.descriptors</groupId>
> +       <artifactId>shrinkwrap-descriptors-impl</artifactId>
> +       <version>1.1.0-alpha-2</version>
> +       <type>jar</type>
> +       <scope>compile</scope>
> +    </dependency>
>  </dependencies>
>  </project>
>
> Modified:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> (original)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEContainer.java
> Wed Oct 26 23:08:05 2011
> @@ -77,6 +77,7 @@ public class RemoteTomEEContainer extend
>
>                   System.setProperty("catalina.home",
> openejbHome.getAbsolutePath());
>                           System.setProperty("catalina.base",
> openejbHome.getAbsolutePath());
> +
>
> System.setProperty("openejb.deploymentId.format","{appId}/{ejbJarId}/{ejbName}");
>                           Paths paths = new Paths(new
> File(openejbHome.getAbsolutePath(), "/webapps/openejb"));
>                           Installer installer = new Installer(paths, true);
>                           installer.installAll();
>
> Added:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java?rev=1189526&view=auto
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> (added)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherArchiveAppender.java
> Wed Oct 26 23:08:05 2011
> @@ -0,0 +1,18 @@
> +package org.apache.openejb.arquillian.remote;
> +
> +import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> +import
>
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
> +import org.jboss.shrinkwrap.api.Archive;
> +import org.jboss.shrinkwrap.api.ShrinkWrap;
> +import org.jboss.shrinkwrap.api.spec.JavaArchive;
> +
> +public class RemoteTomEEEJBEnricherArchiveAppender implements
> AuxiliaryArchiveAppender
> +{
> +          @Override
> +          public Archive<?> createAuxiliaryArchive()
> +          {
> +             return ShrinkWrap.create(JavaArchive.class,
> "arquillian-tomee-testenricher-ejb.jar")
> +                         .addClasses(RemoteTomEEEnricher.class,
> RemoteTomEEEJBEnricherExtension.class, SecurityActions.class)
> +
> .addAsServiceProvider(RemoteLoadableExtension.class,
> RemoteTomEEEJBEnricherExtension.class);
> +          }
> +       }
> \ No newline at end of file
>
> Added:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java?rev=1189526&view=auto
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> (added)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEJBEnricherExtension.java
> Wed Oct 26 23:08:05 2011
> @@ -0,0 +1,13 @@
> +package org.apache.openejb.arquillian.remote;
> +
> +import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
> +import org.jboss.arquillian.test.spi.TestEnricher;
> +
> +public class RemoteTomEEEJBEnricherExtension implements
> RemoteLoadableExtension {
> +    @Override public void register(ExtensionBuilder builder) {
> +       // only load if EJB is on ClassPath
> +        if(Validate.classExists("javax.ejb.EJB")) {
> +           builder.service(TestEnricher.class,
> org.apache.openejb.arquillian.remote.RemoteTomEEEnricher.class);
> +        }
> +    }
> +}
>
> Modified:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> (original)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEEnricher.java
> Wed Oct 26 23:08:05 2011
> @@ -3,45 +3,122 @@ package org.apache.openejb.arquillian.re
>  import org.apache.openejb.cdi.ThreadSingletonServiceImpl;
>  import org.jboss.arquillian.test.spi.TestEnricher;
>
> +import javax.ejb.EJB;
>  import javax.enterprise.context.spi.CreationalContext;
>  import javax.enterprise.inject.spi.AnnotatedType;
>  import javax.enterprise.inject.spi.BeanManager;
>  import javax.enterprise.inject.spi.InjectionTarget;
> +import javax.naming.Context;
> +import javax.naming.InitialContext;
> +import javax.naming.NamingException;
> +
> +import java.lang.annotation.Annotation;
> +import java.lang.reflect.Field;
>  import java.lang.reflect.Method;
> +import java.util.List;
>
>  public class RemoteTomEEEnricher implements TestEnricher {
> -    @Override public void enrich(Object testCase) {
> -//        BeanManager mgr = getBeanManager();
> -//        if (mgr != null) {
> -//            AnnotatedType<?> type =
>  mgr.createAnnotatedType(getClass());
> -//            InjectionTarget<Object> injectionTarget =
> (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> -//            CreationalContext<Object> context =
> mgr.createCreationalContext(null);
> -//
> -//            injectionTarget.inject(testCase, context);
> -//            injectionTarget.postConstruct(this);
> -//        } else {
> -//            throw new NullPointerException("bean manager is null");
> -//        }
> -
> -        /* TODO: see if this code could be called after tests
> -                *
> -                * if (injectionTarget != null) {
> -                *        injectionTarget.preDestroy(this);
> -                *    }
> -                *   if (context != null) {
> -                *        context.release();
> -                *    }
> -                *
> -                *   injectionTarget = null;
> -                *   context = null;
> -                */
> -    }
> -
> -    @Override public Object[] resolve(Method method) {
> -        return new Object[method.getParameterTypes().length];
> -    }
> -
> -    public BeanManager getBeanManager() {
> -        return ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> -    }
> +
> +       private static final String ANNOTATION_NAME = "javax.ejb.EJB";
> +
> +       public void enrich(Object testCase) {
> +               BeanManager mgr = getBeanManager();
> +               if (mgr != null) {
> +                       AnnotatedType<?> type =
> mgr.createAnnotatedType(getClass());
> +                       InjectionTarget<Object> injectionTarget =
> (InjectionTarget<Object>) mgr.createInjectionTarget(type);
> +                       CreationalContext<Object> context =
> mgr.createCreationalContext(null);
> +
> +                       injectionTarget.inject(testCase, context);
> +                       injectionTarget.postConstruct(this);
> +               }
> +
> +               try {
> +                       if
> (SecurityActions.isClassPresent(ANNOTATION_NAME))
> {
> +                               @SuppressWarnings("unchecked")
> +                               Class<? extends Annotation> ejbAnnotation =
> (Class<? extends Annotation>)
> SecurityActions.getThreadContextClassLoader().loadClass(ANNOTATION_NAME);
> +
> +                               List<Field> annotatedFields =
> SecurityActions.getFieldsWithAnnotation(testCase.getClass(),
> ejbAnnotation);
> +
> +                               for (Field field : annotatedFields) {
> +                                       if (field.get(testCase) == null) {
> +                                               EJB fieldAnnotation = (EJB)
> field.getAnnotation(ejbAnnotation);
> +                                               Object ejb =
> lookupEJB(field.getType(), fieldAnnotation.mappedName());
> +                                               field.set(testCase, ejb);
> +                                       }
> +                               }
> +
> +                               List<Method> methods =
> SecurityActions.getMethodsWithAnnotation(testCase.getClass(),
> ejbAnnotation);
> +
> +                               for (Method method : methods) {
> +                                       if
> (method.getParameterTypes().length != 1) {
> +                                               throw new
> RuntimeException("@EJB only allowed on single argument methods");
> +                                       }
> +                                       if
> (!method.getName().startsWith("set")) {
> +                                               throw new
> RuntimeException("@EJB only allowed on 'set' methods");
> +                                       }
> +                                       EJB parameterAnnotation = null; //
> method.getParameterAnnotations()[0]
> +                                       for (Annotation annotation :
> method.getParameterAnnotations()[0]) {
> +                                               if
> (EJB.class.isAssignableFrom(annotation.annotationType())) {
> +                                                       parameterAnnotation
> = (EJB) annotation;
> +                                               }
> +                                       }
> +                                       String mappedName =
> parameterAnnotation == null ? null : parameterAnnotation.mappedName();
> +                                       Object ejb =
> lookupEJB(method.getParameterTypes()[0], mappedName);
> +                                       method.invoke(testCase, ejb);
> +                               }
> +
> +                       }
> +               } catch (Exception e) {
> +
> +               }
> +
> +       }
> +
> +       protected Object lookupEJB(Class<?> fieldType, String mappedName)
> throws Exception {
> +               // TODO: figure out test context ?
> +               Context initcontext = new InitialContext();
> +
> +               // TODO: These names are not spec compliant; fieldType
> needs
> to be a
> +               // bean type here,
> +               // but usually is just an interface of a bean. These seldom
> work.
> +               String[] jndiNames = {
> "openejb:global/global/test/test.jar/" + fieldType.getSimpleName() +
> "Bean",
> +                               "openejb:global/global/test/test.jar/" +
> fieldType.getSimpleName(),
> +                               "java:global/test/test.jar/" +
> fieldType.getSimpleName() + "Bean",
> +                               "java:global/test/test.jar/" +
> fieldType.getSimpleName(),
> +                               "java:global/test.ear/test/" +
> fieldType.getSimpleName() + "Bean",
> +                               "java:global/test.ear/test/" +
> fieldType.getSimpleName(),
> +                               "java:global/test/" +
> fieldType.getSimpleName(),
> +                               "java:global/test/" +
> fieldType.getSimpleName() + "Bean",
> +                               "java:global/test/" +
> fieldType.getSimpleName() + "/no-interface",
> +                               "test/" + fieldType.getSimpleName() +
> "Bean/local",
> +                               "test/" + fieldType.getSimpleName() +
> "Bean/remote",
> +                               "test/" + fieldType.getSimpleName() +
> "/no-interface",
> +                               fieldType.getSimpleName() + "Bean/local",
> +                               fieldType.getSimpleName() + "Bean/remote",
> +                               fieldType.getSimpleName() +
> "/no-interface",
> +                               "ejblocal:" + fieldType.getCanonicalName(),
> +                               fieldType.getCanonicalName() };
> +               if ((mappedName != null) && (!mappedName.equals(""))) {
> +                       // Use only the mapped name to lookup this EJB
> +                       jndiNames = new String[] { mappedName };
> +               }
> +
> +               for (String jndiName : jndiNames) {
> +                       try {
> +                               return initcontext.lookup(jndiName);
> +                       } catch (NamingException e) {
> +                               // no-op, try next
> +                       }
> +               }
> +               throw new NamingException("No EJB found in JNDI");
> +       }
> +
> +       @Override
> +       public Object[] resolve(Method method) {
> +               return new Object[method.getParameterTypes().length];
> +       }
> +
> +       public BeanManager getBeanManager() {
> +               return
> ThreadSingletonServiceImpl.get().getBeanManagerImpl();
> +       }
>  }
>
> Modified:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> (original)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/RemoteTomEEExtension.java
> Wed Oct 26 23:08:05 2011
> @@ -1,12 +1,12 @@
>  package org.apache.openejb.arquillian.remote;
>
>  import
> org.jboss.arquillian.container.spi.client.container.DeployableContainer;
> +import
>
> org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
>  import org.jboss.arquillian.core.spi.LoadableExtension;
> -import org.jboss.arquillian.test.spi.TestEnricher;
>
>  public class RemoteTomEEExtension implements LoadableExtension {
>    @Override public void register(ExtensionBuilder builder) {
>        builder.service(DeployableContainer.class,
> RemoteTomEEContainer.class)
> -            .service(TestEnricher.class, RemoteTomEEEnricher.class);
> +            .service(AuxiliaryArchiveAppender.class,
> RemoteTomEEEJBEnricherArchiveAppender.class);
>    }
>  }
>
> Added:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java?rev=1189526&view=auto
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> (added)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/SecurityActions.java
> Wed Oct 26 23:08:05 2011
> @@ -0,0 +1,249 @@
> +/*
> + * JBoss, Home of Professional Open Source
> + * Copyright 2009, Red Hat Middleware LLC, and individual contributors
> + * by the @authors tag. See the copyright.txt in the distribution for a
> + * full listing of individual contributors.
> + *
> + * 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.openejb.arquillian.remote;
> +
> +import java.lang.annotation.Annotation;
> +import java.lang.reflect.Constructor;
> +import java.lang.reflect.Field;
> +import java.lang.reflect.Method;
> +import java.security.AccessController;
> +import java.security.PrivilegedAction;
> +import java.security.PrivilegedActionException;
> +import java.security.PrivilegedExceptionAction;
> +import java.util.ArrayList;
> +import java.util.List;
> +
> +/**
> + * SecurityActions
> + *
> + * A set of privileged actions that are not to leak out
> + * of this package
> + *
> + * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> + * @version $Revision: $
> + */
> +final class SecurityActions
> +{
> +
> +
>
> //-------------------------------------------------------------------------------||
> +   // Constructor
> ------------------------------------------------------------------||
> +
>
> //-------------------------------------------------------------------------------||
> +
> +   /**
> +    * No instantiation
> +    */
> +   private SecurityActions()
> +   {
> +      throw new UnsupportedOperationException("No instantiation");
> +   }
> +
> +
>
> //-------------------------------------------------------------------------------||
> +   // Utility Methods
> --------------------------------------------------------------||
> +
>
> //-------------------------------------------------------------------------------||
> +
> +   /**
> +    * Obtains the Thread Context ClassLoader
> +    */
> +   static ClassLoader getThreadContextClassLoader()
> +   {
> +      return AccessController.doPrivileged(GetTcclAction.INSTANCE);
> +   }
> +
> +   /**
> +    * Obtains the Constructor specified from the given Class and argument
> types
> +    * @param clazz
> +    * @param argumentTypes
> +    * @return
> +    * @throws NoSuchMethodException
> +    */
> +   static Constructor<?> getConstructor(final Class<?> clazz, final
> Class<?>... argumentTypes)
> +         throws NoSuchMethodException
> +   {
> +      try
> +      {
> +         return AccessController.doPrivileged(new
> PrivilegedExceptionAction<Constructor<?>>()
> +         {
> +            public Constructor<?> run() throws NoSuchMethodException
> +            {
> +               return clazz.getConstructor(argumentTypes);
> +            }
> +         });
> +      }
> +      // Unwrap
> +      catch (final PrivilegedActionException pae)
> +      {
> +         final Throwable t = pae.getCause();
> +         // Rethrow
> +         if (t instanceof NoSuchMethodException)
> +         {
> +            throw (NoSuchMethodException) t;
> +         }
> +         else
> +         {
> +            // No other checked Exception thrown by Class.getConstructor
> +            try
> +            {
> +               throw (RuntimeException) t;
> +            }
> +            // Just in case we've really messed up
> +            catch (final ClassCastException cce)
> +            {
> +               throw new RuntimeException("Obtained unchecked Exception;
> this code should never be reached", t);
> +            }
> +         }
> +      }
> +   }
> +
> +   /**
> +    * Create a new instance by finding a constructor that matches the
> argumentTypes signature
> +    * using the arguments for instantiation.
> +    *
> +    * @param className Full classname of class to create
> +    * @param argumentTypes The constructor argument types
> +    * @param arguments The constructor arguments
> +    * @return a new instance
> +    * @throws IllegalArgumentException if className, argumentTypes, or
> arguments are null
> +    * @throws RuntimeException if any exceptions during creation
> +    * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
> +    * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a>
> +    */
> +   static <T> T newInstance(final String className, final Class<?>[]
> argumentTypes, final Object[] arguments,
> +         final Class<T> expectedType)
> +   {
> +      if (className == null)
> +      {
> +         throw new IllegalArgumentException("ClassName must be
> specified");
> +      }
> +      if (argumentTypes == null)
> +      {
> +         throw new IllegalArgumentException("ArgumentTypes must be
> specified. Use empty array if no arguments");
> +      }
> +      if (arguments == null)
> +      {
> +         throw new IllegalArgumentException("Arguments must be specified.
> Use empty array if no arguments");
> +      }
> +      final Object obj;
> +      try
> +      {
> +         final ClassLoader tccl = getThreadContextClassLoader();
> +         final Class<?> implClass = Class.forName(className, false, tccl);
> +         Constructor<?> constructor = getConstructor(implClass,
> argumentTypes);
> +         obj = constructor.newInstance(arguments);
> +      }
> +      catch (Exception e)
> +      {
> +         throw new RuntimeException("Could not create new instance of " +
> className
> +               + ", missing package from classpath?", e);
> +      }
> +
> +      // Cast
> +      try
> +      {
> +         return expectedType.cast(obj);
> +      }
> +      catch (final ClassCastException cce)
> +      {
> +         // Reconstruct so we get some useful information
> +         throw new ClassCastException("Incorrect expected type, " +
> expectedType.getName() + ", defined for "
> +               + obj.getClass().getName());
> +      }
> +   }
> +
> +   public static boolean isClassPresent(String name)
> +   {
> +      try
> +      {
> +         ClassLoader classLoader = getThreadContextClassLoader();
> +         classLoader.loadClass(name);
> +         return true;
> +      }
> +      catch (ClassNotFoundException e)
> +      {
> +         return false;
> +      }
> +   }
> +
> +   public static List<Field> getFieldsWithAnnotation(final Class<?>
> source,
> final Class<? extends Annotation> annotationClass)
> +   {
> +      List<Field> declaredAccessableFields =
> AccessController.doPrivileged(new PrivilegedAction<List<Field>>()
> +      {
> +         public List<Field> run()
> +         {
> +            List<Field> foundFields = new ArrayList<Field>();
> +            Class<?> nextSource = source;
> +            while (nextSource != Object.class) {
> +               for(Field field : nextSource.getDeclaredFields())
> +               {
> +                  if(field.isAnnotationPresent(annotationClass))
> +                  {
> +                     if(!field.isAccessible())
> +                     {
> +                        field.setAccessible(true);
> +                     }
> +                     foundFields.add(field);
> +                  }
> +               }
> +               nextSource = nextSource.getSuperclass();
> +            }
> +            return foundFields;
> +         }
> +      });
> +      return declaredAccessableFields;
> +   }
> +
> +   public static List<Method> getMethodsWithAnnotation(final Class<?>
> source, final Class<? extends Annotation> annotationClass)
> +   {
> +      List<Method> declaredAccessableMethods =
> AccessController.doPrivileged(new PrivilegedAction<List<Method>>()
> +      {
> +         public List<Method> run()
> +         {
> +            List<Method> foundMethods = new ArrayList<Method>();
> +            for(Method method : source.getDeclaredMethods())
> +            {
> +               if(method.isAnnotationPresent(annotationClass))
> +               {
> +                  if(!method.isAccessible())
> +                  {
> +                     method.setAccessible(true);
> +                  }
> +                  foundMethods.add(method);
> +               }
> +            }
> +            return foundMethods;
> +         }
> +      });
> +      return declaredAccessableMethods;
> +   }
> +
> +
>
> //-------------------------------------------------------------------------------||
> +   // Inner Classes
> ----------------------------------------------------------------||
> +
>
> //-------------------------------------------------------------------------------||
> +
> +   /**
> +    * Single instance to get the TCCL
> +    */
> +   private enum GetTcclAction implements PrivilegedAction<ClassLoader> {
> +      INSTANCE;
> +
> +      public ClassLoader run()
> +      {
> +         return Thread.currentThread().getContextClassLoader();
> +      }
> +
> +   }
> +
> +}
>
> Modified:
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java?rev=1189526&r1=1189525&r2=1189526&view=diff
>
> ==============================================================================
> ---
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> (original)
> +++
>
> openejb/trunk/arquillian-tomee/arquillian-tomee-remote/src/test/java/org/apache/openejb/arquillian/TomEEContainerTest.java
> Wed Oct 26 23:08:05 2011
> @@ -20,6 +20,8 @@ import java.io.ByteArrayOutputStream;
>  import java.io.InputStream;
>  import java.net.URL;
>
> +import javax.ejb.EJB;
> +
>  import junit.framework.Assert;
>
>  import org.jboss.arquillian.container.test.api.Deployment;
> @@ -35,15 +37,21 @@ import org.junit.runner.RunWith;
>  @RunWith(Arquillian.class)
>  public class TomEEContainerTest {
>
> -    @Deployment(testable = false)
> +    @Deployment
>    public static WebArchive createDeployment() {
> -        return ShrinkWrap.create(WebArchive.class,
> "test.war").addClass(TestServlet.class).addClass(TestEjb.class)
> +        return ShrinkWrap.create(WebArchive.class,
>
> "test.war").addClass(TestServlet.class).addClass(TestEjb.class).addClass(TomEEContainerTest.class)
>                .setWebXML(new
>
> StringAsset(Descriptors.create(WebAppDescriptor.class).version("3.0").servlet(TestServlet.class,
> "/Test").exportAsString()));
>    }
>
> -    @Test
> -    public void nothing(){}
> +    @EJB
> +    private TestEjb ejb;
> +
> +    @Test
> +    public void testEjbIsNotNull() throws Exception {
> +       Assert.assertNotNull(ejb);
> +    }
>
> +    @Test
>    public void testShouldBeAbleToAccessServletAndEjb() throws Exception {
>        InputStream is = new URL("http://localhost:9080/test/Test
> ").openStream();
>        ByteArrayOutputStream os = new ByteArrayOutputStream();
>
> Modified: openejb/trunk/arquillian-tomee/pom.xml
> URL:
>
> http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/pom.xml?rev=1189526&r1=1189525&r2=1189526&view=diff
>
> ==============================================================================
> --- openejb/trunk/arquillian-tomee/pom.xml (original)
> +++ openejb/trunk/arquillian-tomee/pom.xml Wed Oct 26 23:08:05 2011
> @@ -49,7 +49,7 @@
>
>  <properties>
>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> -    <version.arquillian>1.0.0.CR1</version.arquillian>
> +    <version.arquillian>1.0.0.CR4</version.arquillian>
>    <version.cdi-api>1.0</version.cdi-api>
>    <version.openejb>4.0.0-beta-2-SNAPSHOT</version.openejb>
>    <version.org.apache.tomcat>7.0.21</version.org.apache.tomcat>
>