[jboss-cvs] JBossAS SVN: r77154 - in projects/ejb3/trunk/core/src/test/java/org/jboss: injection and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Aug 18 08:43:40 EDT 2008


Author: wolfc
Date: 2008-08-18 08:43:40 -0400 (Mon, 18 Aug 2008)
New Revision: 77154

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/MyClass.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/unit/
   projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/unit/InjectResourceRefTestCase.java
Log:
EJBTHREE-1465: unit test

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/common/DummyInjectionContainer.java	2008-08-18 12:43:40 UTC (rev 77154)
@@ -0,0 +1,169 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection.test.common;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+
+import org.jboss.ejb3.Container;
+import org.jboss.ejb3.DependencyPolicy;
+import org.jboss.ejb3.entity.PersistenceUnitDeployment;
+import org.jboss.injection.EncInjector;
+import org.jboss.injection.InjectionContainer;
+import org.jboss.injection.Injector;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DummyInjectionContainer implements InjectionContainer
+{
+   private Context enc;
+   private Map<String, Map<AccessibleObject, Injector>> encInjections = new HashMap<String, Map<AccessibleObject, Injector>>();
+   private Map<String, EncInjector> encInjectors = new HashMap<String, EncInjector>();
+   
+   public DummyInjectionContainer(Context enc)
+   {
+      this.enc = enc;
+   }
+   
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz)
+   {
+      return null;
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Method method)
+   {
+      return null;
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Method method)
+   {
+      return null;
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Class<?> clazz, Field field)
+   {
+      return null;
+   }
+
+   public <T extends Annotation> T getAnnotation(Class<T> annotationType, Field field)
+   {
+      return null;
+   }
+
+   public ClassLoader getClassloader()
+   {
+      return Thread.currentThread().getContextClassLoader();
+   }
+
+   public DependencyPolicy getDependencyPolicy()
+   {
+      return null;
+   }
+
+   public String getDeploymentDescriptorType()
+   {
+      return null;
+   }
+
+   public String getEjbJndiName(Class<?> businessInterface) throws NameNotFoundException
+   {
+      return null;
+   }
+
+   public String getEjbJndiName(String link, Class<?> businessInterface)
+   {
+      return null;
+   }
+
+   public Context getEnc()
+   {
+      return enc;
+   }
+
+   public Map<String, Map<AccessibleObject, Injector>> getEncInjections()
+   {
+      return encInjections;
+   }
+
+   public Map<String, EncInjector> getEncInjectors()
+   {
+      return encInjectors;
+   }
+
+   public RemoteEnvironment getEnvironmentRefGroup()
+   {
+      return null;
+   }
+
+   public String getIdentifier()
+   {
+      return null;
+   }
+
+   public List<Injector> getInjectors()
+   {
+      return null;
+   }
+
+   public PersistenceUnitDeployment getPersistenceUnitDeployment(String unitName) throws NameNotFoundException
+   {
+      return null;
+   }
+
+   public VirtualFile getRootFile()
+   {
+      return null;
+   }
+
+   public boolean hasJNDIBinding(String jndiName)
+   {
+      return false;
+   }
+
+   public Container resolveEjbContainer(String link, Class<?> businessIntf)
+   {
+      return null;
+   }
+
+   public Container resolveEjbContainer(Class<?> businessIntf) throws NameNotFoundException
+   {
+      return null;
+   }
+
+   public String resolveMessageDestination(String link)
+   {
+      return null;
+   }
+
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/MyClass.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/MyClass.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/MyClass.java	2008-08-18 12:43:40 UTC (rev 77154)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection.test.ejbthree1465;
+
+import org.omg.CORBA.ORB;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MyClass
+{
+   private ORB orb;
+   
+   public ORB getORB()
+   {
+      return orb;
+   }
+}

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/unit/InjectResourceRefTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/unit/InjectResourceRefTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/injection/test/ejbthree1465/unit/InjectResourceRefTestCase.java	2008-08-18 12:43:40 UTC (rev 77154)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.injection.test.ejbthree1465.unit;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.lang.reflect.AccessibleObject;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.ejb3.NonSerializableFactory;
+import org.jboss.injection.EncInjector;
+import org.jboss.injection.InjectionHandler;
+import org.jboss.injection.InjectionUtil;
+import org.jboss.injection.Injector;
+import org.jboss.injection.ResourceHandler;
+import org.jboss.injection.test.common.DummyInjectionContainer;
+import org.jboss.injection.test.ejbthree1465.MyClass;
+import org.jboss.metadata.javaee.jboss.JBossRemoteEnvironmentRefsGroupMetaData;
+import org.jboss.metadata.javaee.spec.RemoteEnvironment;
+import org.jboss.metadata.javaee.spec.ResourceAuthorityType;
+import org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData;
+import org.jboss.metadata.javaee.spec.ResourceReferenceMetaData;
+import org.jboss.metadata.javaee.spec.ResourceReferencesMetaData;
+import org.jboss.metadata.javaee.spec.ResourceSharingScopeType;
+import org.jnp.server.SingletonNamingServer;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.omg.CORBA.ORB;
+
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InjectResourceRefTestCase
+{
+   private static SingletonNamingServer naming;
+   private static InitialContext ctx;
+   
+   @AfterClass
+   public static void afterClass() throws NamingException
+   {
+      ctx.close();
+      
+      naming.destroy();
+      naming = null;
+   }
+   
+   @BeforeClass
+   public static void beforeClass() throws NamingException
+   {
+      naming = new SingletonNamingServer();
+      
+      ctx = new InitialContext();
+   }
+   
+   @Test
+   public void test1() throws NamingException
+   {
+      Context enc = ((Context) ctx.lookup("java:")).createSubcontext("comp");
+      NonSerializableFactory.bind(enc, "ORB", ORB.init());
+      
+      ResourceInjectionTargetMetaData injectionTarget = new ResourceInjectionTargetMetaData();
+      injectionTarget.setInjectionTargetClass(MyClass.class.getName());
+      injectionTarget.setInjectionTargetName("orb");
+      
+      Set<ResourceInjectionTargetMetaData> injectionTargets = new HashSet<ResourceInjectionTargetMetaData>();
+      injectionTargets.add(injectionTarget);
+      
+      ResourceReferenceMetaData resourceReference = new ResourceReferenceMetaData();
+      resourceReference.setResourceRefName("orb");
+      resourceReference.setType(ORB.class.getName());
+      resourceReference.setResAuth(ResourceAuthorityType.Container);
+      resourceReference.setResSharingScope(ResourceSharingScopeType.Shareable);
+      resourceReference.setInjectionTargets(injectionTargets);
+      
+      ResourceReferencesMetaData resourceReferences = new ResourceReferencesMetaData();
+      resourceReferences.add(resourceReference);
+      
+      JBossRemoteEnvironmentRefsGroupMetaData xml = new JBossRemoteEnvironmentRefsGroupMetaData();
+      xml.setResourceReferences(resourceReferences);
+      
+      DummyInjectionContainer container = new DummyInjectionContainer(enc);
+      
+      ResourceHandler<RemoteEnvironment> handler = new ResourceHandler<RemoteEnvironment>();
+      
+      Collection<InjectionHandler<RemoteEnvironment>> handlers = new HashSet<InjectionHandler<RemoteEnvironment>>();
+      handlers.add(handler);
+
+      for(InjectionHandler<RemoteEnvironment> h : handlers) h.loadXml(xml, container);
+      
+      Map<AccessibleObject, Injector> tmp = InjectionUtil.processAnnotations(container, handlers, MyClass.class);
+
+      for(EncInjector encInjector : container.getEncInjectors().values())
+         encInjector.inject(container);
+      
+      MyClass instance = new MyClass();
+      
+      for(Injector injector : tmp.values())
+         injector.inject(instance);
+      
+      assertNotNull(instance.getORB());
+   }
+}




More information about the jboss-cvs-commits mailing list