[jboss-cvs] JBossAS SVN: r59078 - in projects/ejb3/trunk/injection/src: main/java/org/jboss/injection main/java/org/jboss/injection/aop test/java/org/jboss/injection/test test/java/org/jboss/injection/test/annotated test/java/org/jboss/injection/test/annotated/unit test/java/org/jboss/injection/test/appclient test/java/org/jboss/injection/test/appclient/unit test/java/org/jboss/injection/test/common test/java/org/jboss/injection/test/programatically test/java/org/jboss/injection/test/programatically/unit test/java/org/jboss/injection/test/simple test/java/org/jboss/injection/test/simple/unit

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Dec 18 09:11:21 EST 2006


Author: wolfc
Date: 2006-12-18 09:10:38 -0500 (Mon, 18 Dec 2006)
New Revision: 59078

Added:
   projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedMethodFinder.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/HelloWorldClient.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/unit/
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/unit/AppClientTestCase.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/Counter.java
Removed:
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/Counter.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/Counter.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/Counter.java
Modified:
   projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedPropertyProcessor.java
   projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/ClassPropertyProcessor.java
   projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/InjectorProcessor.java
   projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/PostConstructProcessor.java
   projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/Processor.java
   projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/InjectedBean.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/unit/AnnotatedTestCase.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/InjectedBean.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/unit/InjectorProcessorTestCase.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java
   projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java
Log:
app client unit test

Added: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedMethodFinder.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedMethodFinder.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedMethodFinder.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * Finds all methods annotation with a certain annotation.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AnnotatedMethodFinder<T extends Annotation> implements Processor<Class<?>, Collection<Method>>
+{
+   private Class<T> annotationClass;
+   
+   public AnnotatedMethodFinder(Class<T> annotationClass)
+   {
+      assert annotationClass != null : "annotationClass is null";
+      
+      this.annotationClass = annotationClass;
+   }
+   
+   public Collection<Method> process(Class<?> cls)
+   {
+      Collection<Method> list = new ArrayList<Method>();
+      if(cls == null) return list;
+      
+      Method methods[] = cls.getDeclaredMethods();
+      for(Method method : methods)
+      {
+         T annotation = method.getAnnotation(annotationClass);
+         if(annotation != null)
+         {
+            list.add(method);
+         }
+      }
+      
+      list.addAll(process(cls.getSuperclass()));
+      
+      return list;
+   }
+}

Modified: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedPropertyProcessor.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedPropertyProcessor.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/AnnotatedPropertyProcessor.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -30,25 +30,26 @@
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision: $
- * @deprecated NYI
  */
-public class AnnotatedPropertyProcessor<FactoryType extends InjectorFactory, AnnotationType extends Annotation> extends AbstractProcessor<BeanProperty>
+public class AnnotatedPropertyProcessor<FactoryType extends InjectorFactory<AnnotationType>, AnnotationType extends Annotation> extends AbstractProcessor<BeanProperty>
 {
    private FactoryType factory;
+   private Class<AnnotationType> annotationClass;
    
-   protected AnnotatedPropertyProcessor(FactoryType factory)
+   protected AnnotatedPropertyProcessor(FactoryType factory, Class<AnnotationType> annotationClass)
    {
       assert factory != null;
+      assert annotationClass != null;
       
       this.factory = factory;
+      this.annotationClass = annotationClass;
    }
    
    public Injector processOne(BeanProperty property)
    {
-      throw new RuntimeException("NYI");
-//      AnnotationType resource = property.getAnnotation(AnnotationType);
-//      if(resource == null) return null;
-//      
-//      return factory.create(property, resource);
+      AnnotationType resource = property.getAnnotation(annotationClass);
+      if(resource == null) return null;
+      
+      return factory.create(property, resource);
    }
 }

Modified: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/ClassPropertyProcessor.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/ClassPropertyProcessor.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/ClassPropertyProcessor.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -57,6 +57,10 @@
     */
    public Collection<Injector> process(Class<?> cls)
    {
+      // TODO: I don't like that BeanProperty is first instantiated and then checked
+      // for annotations, it's slower.
+      // Maybe we should first check the AccessibleObject and then create a BeanProperty.
+      
       Collection<Injector> list = new ArrayList<Injector>();
       
       Field fields[] = cls.getDeclaredFields();
@@ -69,6 +73,8 @@
       Method methods[] = cls.getDeclaredMethods();
       for(Method method : methods)
       {
+         // TODO: this I don't like. I want to scan for annotation first and then verify the method,
+         // so I can properly inform users of errors.
          if(MethodBeanProperty.isValid(method))
          {
             BeanProperty property = new MethodBeanProperty(method);

Modified: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/InjectorProcessor.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/InjectorProcessor.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/InjectorProcessor.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -23,6 +23,7 @@
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.Collection;
 
 /**
@@ -33,21 +34,33 @@
  */
 public class InjectorProcessor
 {
-   public static void process(Object instance, Collection<Injector> injectors, Collection<Method> postConstructs)
+   public static void destroy(Collection<Method> preDestroys)
    {
-      assert instance != null;
-      assert injectors != null;
-      assert postConstructs != null : "postConstructs is null";
+      destroy(null, preDestroys);
+   }
+   
+   /**
+    * Run the pre-destroys on an instance.
+    * 
+    * @param instance       either an instance or null for static pre-destroys
+    * @param preDestroys
+    */
+   public static void destroy(Object instance, Collection<Method> preDestroys)
+   {
+      assert preDestroys != null : "preDestroys is null";
       
-      for(Injector injector : injectors)
+      for(Method method : preDestroys)
       {
-         injector.inject(instance);
+         invoke(instance, method);
       }
-      
-      Class<?> cls = instance.getClass();
-      for(Method method : postConstructs)
+   }
+   
+   private static void invoke(Object instance, Method method)
+   {
+      Object obj = null;
+      if(instance != null)
       {
-         Object obj;
+         Class<?> cls = instance.getClass();
          if(cls.isAssignableFrom(method.getDeclaringClass()))
          {
             obj = instance;
@@ -68,26 +81,63 @@
                throw new RuntimeException(e);
             }
          }
-         Object args[] = null;
-         method.setAccessible(true);
-         try
-         {
-            method.invoke(obj, args);
-         }
-         catch (IllegalAccessException e)
-         {
-            // should not happen
-            throw new RuntimeException(e);
-         }
-         catch (InvocationTargetException e)
-         {
-            Throwable t = e.getCause();
-            if(t instanceof Error)
-               throw (Error) t;
-            if(t instanceof RuntimeException)
-               throw (RuntimeException) t;
-            throw new RuntimeException(t);
-         }
       }
+      if(obj == null && !Modifier.isStatic(method.getModifiers()))
+      {
+         throw new IllegalArgumentException("Can't run non-static " + method + ", there is no instance");
+      }
+      Object args[] = null;
+      method.setAccessible(true);
+      try
+      {
+         method.invoke(obj, args);
+      }
+      catch (IllegalAccessException e)
+      {
+         // should not happen
+         throw new RuntimeException(e);
+      }
+      catch (InvocationTargetException e)
+      {
+         Throwable t = e.getCause();
+         if(t instanceof Error)
+            throw (Error) t;
+         if(t instanceof RuntimeException)
+            throw (RuntimeException) t;
+         throw new RuntimeException(t);
+      }
    }
+   
+   /**
+    * Convinience method for static injection.
+    * 
+    * @param injectors
+    * @param postConstructs
+    */
+   public static void process(Collection<Injector> injectors, Collection<Method> postConstructs)
+   {
+      process(null, injectors, postConstructs);
+   }
+   
+   /**
+    * 
+    * @param instance       either an object or null for static injection
+    * @param injectors
+    * @param postConstructs
+    */
+   public static void process(Object instance, Collection<Injector> injectors, Collection<Method> postConstructs)
+   {
+      assert injectors != null : "injectors is null";
+      assert postConstructs != null : "postConstructs is null";
+      
+      for(Injector injector : injectors)
+      {
+         injector.inject(instance);
+      }
+      
+      for(Method method : postConstructs)
+      {
+         invoke(instance, method);
+      }
+   }
 }

Modified: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/PostConstructProcessor.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/PostConstructProcessor.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/PostConstructProcessor.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -21,10 +21,6 @@
  */
 package org.jboss.injection;
 
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Collection;
-
 import javax.annotation.PostConstruct;
 
 /**
@@ -33,25 +29,10 @@
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
-public class PostConstructProcessor implements Processor<Class<?>, Collection<Method>>
+public class PostConstructProcessor extends AnnotatedMethodFinder<PostConstruct>
 {
-   public Collection<Method> process(Class<?> cls)
+   public PostConstructProcessor()
    {
-      Collection<Method> list = new ArrayList<Method>();
-      if(cls == null) return list;
-      
-      Method methods[] = cls.getDeclaredMethods();
-      for(Method method : methods)
-      {
-         PostConstruct pc = method.getAnnotation(PostConstruct.class);
-         if(pc != null)
-         {
-            list.add(method);
-         }
-      }
-      
-      list.addAll(process(cls.getSuperclass()));
-      
-      return list;
+      super(PostConstruct.class);
    }
 }

Modified: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/Processor.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/Processor.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/Processor.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -23,11 +23,20 @@
 
 /**
  * Processes an object to produce something.
+ * 
+ * This is an extreme abstraction of a processor which produces something.
+ * T1 is the subject type, T2 is the resultant type.
  *
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
 public interface Processor<T1, T2>
 {
-   T2 process(T1 t);
+   /**
+    * Process an object to produce something.
+    * 
+    * @param subject    the object on which the processing takes place
+    * @return           the result
+    */
+   T2 process(T1 subject);
 }

Modified: projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java
===================================================================
--- projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/main/java/org/jboss/injection/aop/ConstructorInterceptor.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -23,7 +23,6 @@
 
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.injection.InjectorProcessor;
 
 /**
  * Intercepts construction of new objects and fires up injection.

Deleted: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/Counter.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/Counter.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/Counter.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.annotated;
-
-/**
- * Comment
- *
- * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class Counter
-{
-   public static int postConstructs;
-   public static int preDestroys;
-   
-   public static void reset()
-   {
-      postConstructs = 0;
-      preDestroys = 0;
-   }
-}

Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/InjectedBean.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/InjectedBean.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/InjectedBean.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -25,6 +25,8 @@
 import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
 
+import org.jboss.injection.test.common.Counter;
+
 /**
  * Do injection based on annotation.
  *

Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/unit/AnnotatedTestCase.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/unit/AnnotatedTestCase.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/annotated/unit/AnnotatedTestCase.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -37,9 +37,9 @@
 import org.jboss.injection.PostConstructProcessor;
 import org.jboss.injection.Processor;
 import org.jboss.injection.ResourceClassProcessor;
-import org.jboss.injection.test.annotated.Counter;
 import org.jboss.injection.test.annotated.InjectedBean;
 import org.jboss.injection.test.annotated.SimplePropertyProcessor;
+import org.jboss.injection.test.common.Counter;
 
 /**
  * Comment

Added: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/HelloWorldClient.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/HelloWorldClient.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/HelloWorldClient.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.appclient;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+
+import org.jboss.injection.test.common.Counter;
+
+/**
+ * The app client differs from other injections, that all
+ * is static. And thus usable from the main method.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class HelloWorldClient
+{
+   @Resource
+   private static String value;
+   
+   public static void check()
+   {
+      if(value == null)
+         throw new IllegalStateException("value must not be null");
+   }
+   
+   @PostConstruct
+   public static void postConstruct()
+   {
+      if(value == null)
+         throw new IllegalStateException("value must not be null");
+      Counter.postConstructs++;
+   }
+   
+   @PreDestroy
+   public static void preDestroy()
+   {
+      Counter.preDestroys++;
+   }
+}

Added: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/unit/AppClientTestCase.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/unit/AppClientTestCase.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/appclient/unit/AppClientTestCase.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.appclient.unit;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.PreDestroy;
+
+import junit.framework.TestCase;
+
+import org.jboss.injection.AnnotatedMethodFinder;
+import org.jboss.injection.Injection;
+import org.jboss.injection.Injector;
+import org.jboss.injection.InjectorProcessor;
+import org.jboss.injection.MapInjectorFactory;
+import org.jboss.injection.PostConstructProcessor;
+import org.jboss.injection.Processor;
+import org.jboss.injection.ResourceClassProcessor;
+import org.jboss.injection.test.appclient.HelloWorldClient;
+import org.jboss.injection.test.common.Counter;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class AppClientTestCase extends TestCase
+{
+   public void test1() throws Exception
+   {
+      Counter.reset();
+      
+      // There are multiple ways to initialize the injectors, annotation
+      // is one of them.
+      
+      //
+      // the environment to use
+      //
+      
+      Map<String, Object> env = new HashMap<String, Object>();
+      env.put(HelloWorldClient.class.getName() + "/value", "Hello world");
+      
+      //
+      // the setup of injectors
+      //
+      
+      // TODO: weird, shouldn't this work?
+      //Collection<InjectionProcessor<Class<?>>> handlers = new ArrayList<InjectionProcessor<Class<?>>>();
+      Collection<Processor<Class<?>, Collection<Injector>>> handlers = new ArrayList<Processor<Class<?>, Collection<Injector>>>();
+      handlers.add(new ResourceClassProcessor(new MapInjectorFactory(env)));
+      Collection<Injector> injectors = Injection.doIt(HelloWorldClient.class, handlers);
+      
+      assertEquals("Wrong number of injectors", 1, injectors.size());
+      
+      Collection<Processor<Class<?>, Collection<Method>>> postConstructProcessors = new ArrayList<Processor<Class<?>, Collection<Method>>>();
+      postConstructProcessors.add(new PostConstructProcessor());
+      Collection<Method> postConstructs = Injection.doIt(HelloWorldClient.class, postConstructProcessors);
+      
+      assertEquals("Wrong number of post-constructs", 1, postConstructs.size());
+      
+      Collection<Processor<Class<?>, Collection<Method>>> preDestroyProcessors = new ArrayList<Processor<Class<?>, Collection<Method>>>();
+      preDestroyProcessors.add(new AnnotatedMethodFinder<PreDestroy>(PreDestroy.class));
+      Collection<Method> preDestroys = Injection.doIt(HelloWorldClient.class, preDestroyProcessors);
+      
+      assertEquals("Wrong number of pre-destroys", 1, preDestroys.size());
+      
+      //
+      // the target
+      //
+      
+      // With app client there is no target instance.
+      
+      //
+      // the injection
+      //
+      
+      InjectorProcessor.process(injectors, postConstructs);
+      
+      //
+      // do some business
+      //
+      
+      HelloWorldClient.check();
+      
+      assertEquals("postConstruct should have been called once", 1, Counter.postConstructs);
+      
+      //
+      // destroy phase
+      //
+      
+      InjectorProcessor.destroy(preDestroys);
+      
+      assertEquals("preDestroy should have been called once", 1, Counter.preDestroys);
+   }
+}

Copied: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/Counter.java (from rev 59010, projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/Counter.java)
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/Counter.java	2006-12-13 11:12:42 UTC (rev 59010)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/common/Counter.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class Counter
+{
+   public static int postConstructs;
+   public static int preDestroys;
+   
+   public static void reset()
+   {
+      postConstructs = 0;
+      preDestroys = 0;
+   }
+}

Deleted: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/Counter.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/Counter.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/Counter.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.programatically;
-
-/**
- * Comment
- *
- * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class Counter
-{
-   public static int postConstructs;
-   public static int preDestroys;
-   
-   public static void reset()
-   {
-      postConstructs = 0;
-      preDestroys = 0;
-   }
-}

Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/InjectedBean.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/InjectedBean.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/InjectedBean.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -21,6 +21,8 @@
  */
 package org.jboss.injection.test.programatically;
 
+import org.jboss.injection.test.common.Counter;
+
 /**
  * Comment
  *

Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/unit/InjectorProcessorTestCase.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/unit/InjectorProcessorTestCase.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/programatically/unit/InjectorProcessorTestCase.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -32,7 +32,7 @@
 import org.jboss.injection.SimpleValueInjector;
 import org.jboss.injection.lang.reflect.BeanProperty;
 import org.jboss.injection.lang.reflect.FieldBeanProperty;
-import org.jboss.injection.test.programatically.Counter;
+import org.jboss.injection.test.common.Counter;
 import org.jboss.injection.test.programatically.InjectedBean;
 
 /**

Deleted: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/Counter.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/Counter.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/Counter.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -1,40 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt 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.simple;
-
-/**
- * Comment
- *
- * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
- * @version $Revision: $
- */
-public class Counter
-{
-   public static int postConstructs;
-   public static int preDestroys;
-   
-   public static void reset()
-   {
-      postConstructs = 0;
-      preDestroys = 0;
-   }
-}

Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/InjectedBean.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -21,6 +21,8 @@
  */
 package org.jboss.injection.test.simple;
 
+import org.jboss.injection.test.common.Counter;
+
 /**
  * Comment
  *

Modified: projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java
===================================================================
--- projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java	2006-12-18 14:05:09 UTC (rev 59077)
+++ projects/ejb3/trunk/injection/src/test/java/org/jboss/injection/test/simple/unit/SimpleTestCase.java	2006-12-18 14:10:38 UTC (rev 59078)
@@ -28,7 +28,7 @@
 import junit.framework.TestSuite;
 
 import org.jboss.aop.AspectXmlLoader;
-import org.jboss.injection.test.simple.Counter;
+import org.jboss.injection.test.common.Counter;
 import org.jboss.injection.test.simple.InjectedBean;
 
 /**




More information about the jboss-cvs-commits mailing list