[webbeans-commits] Webbeans SVN: r534 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/bootstrap and 3 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Dec 16 13:36:27 EST 2008


Author: dallen6
Date: 2008-12-16 13:36:27 -0500 (Tue, 16 Dec 2008)
New Revision: 534

Added:
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BirdCage.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BlueFacedParrotFinch.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FinchKeeper.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/StarFinch.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OwlFinch.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/SweeWaxbill.java
Removed:
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SweeWaxbill.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
Log:
New test implementations and fixes for Observable event beans.

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java	2008-12-16 18:09:58 UTC (rev 533)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractFacadeBean.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -18,9 +18,6 @@
 package org.jboss.webbeans.bean;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-
-import javax.webbeans.DefinitionException;
 import javax.webbeans.Dependent;
 import javax.webbeans.Production;
 import javax.webbeans.Standard;
@@ -55,33 +52,6 @@
       init();
    }
 
-   /**
-    * Initializes the bean
-    * 
-    * Calls super method and validates the annotated item
-    */
-   protected void init()
-   {
-      super.init();
-      checkAnnotatedItem();
-   }
-
-   /**
-    * Validates the annotated item
-    */
-   private void checkAnnotatedItem()
-   {
-      Type[] actualTypeArguments = annotatedItem.getActualTypeArguments();
-      if (actualTypeArguments.length != 1)
-      {
-         throw new DefinitionException("Event must have type arguments");
-      }
-      if (!(actualTypeArguments[0] instanceof Class))
-      {
-         throw new DefinitionException("Event must have concrete type argument");
-      }
-   }
-
    /*
     * Gets the binding type as an array
     * 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java	2008-12-16 18:09:58 UTC (rev 533)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -18,12 +18,16 @@
 package org.jboss.webbeans.bean;
 
 
+import java.lang.reflect.Type;
+
+import javax.webbeans.DefinitionException;
 import javax.webbeans.Event;
 
 import org.jboss.webbeans.ManagerImpl;
 import org.jboss.webbeans.contexts.DependentContext;
 import org.jboss.webbeans.event.EventImpl;
 import org.jboss.webbeans.introspector.AnnotatedItem;
+import org.jboss.webbeans.introspector.AnnotatedParameter;
 import org.jboss.webbeans.util.Names;
 
 /**
@@ -49,17 +53,58 @@
    }
 
    /**
+    * Initializes the bean
+    * 
+    * Calls super method and validates the annotated item
+    */
+   protected void init()
+   {
+      super.init();
+      checkAnnotatedItem();
+   }
+
+   /**
+    * Validates the annotated item
+    */
+   private void checkAnnotatedItem()
+   {
+      // Only check the type arguments if this is for a field.  Parameters
+      // do not have access to the type arguments in Java 6.
+      if (!(this.annotatedItem instanceof AnnotatedParameter))
+      {
+         Type[] actualTypeArguments = annotatedItem.getActualTypeArguments();
+         if (actualTypeArguments.length != 1)
+         {
+            throw new DefinitionException("Event must have type arguments");
+         }
+         if (!(actualTypeArguments[0] instanceof Class))
+         {
+            throw new DefinitionException("Event must have concrete type argument");
+         }
+      }
+   }
+
+   /**
     * Creates an instance
     * 
     * @return an event instance
     */
+   @SuppressWarnings("unchecked")
    @Override
    public Event<T> create()
    {
       try
       {
          DependentContext.INSTANCE.setActive(true);
-         return new EventImpl<T>(getTypeParameter(), manager, getBindingTypesArray());
+         Class eventType = null;
+         if (this.getAnnotatedItem() instanceof AnnotatedParameter)
+         {
+            eventType = Object.class;
+         } else
+         {
+            eventType = (Class<T>) getAnnotatedItem().getActualTypeArguments()[0];         
+         }
+         return new EventImpl(eventType, manager, getBindingTypesArray());
       }
       finally
       {

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2008-12-16 18:09:58 UTC (rev 533)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -34,6 +34,7 @@
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -160,7 +161,7 @@
       return beans;
    }
    
-
+   @SuppressWarnings("unchecked")
    protected void createBean(AbstractClassBean<?> bean, Set<AbstractBean<?, ?>> beans)
    {
       beans.add(bean);
@@ -170,6 +171,15 @@
          ProducerMethodBean<?> producerMethodBean = createProducerMethodBean(producerMethod, bean, manager);
          beans.add(producerMethodBean);
          manager.getResolver().addInjectionPoints(producerMethodBean.getInjectionPoints());
+         for (AnnotatedItem injectionPoint : producerMethodBean.getInjectionPoints())
+         {
+            if ( injectionPoint.isAnnotationPresent(Observable.class) )
+            {
+               EventBean<Object, Method> eventBean = createEventBean(injectionPoint, manager);
+               beans.add(eventBean);
+               log.info("Web Bean: " + eventBean);
+            }
+         }
          log.info("Web Bean: " + producerMethodBean);
       }
       for (AnnotatedField<Object> producerField : bean.getProducerFields())

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java	2008-12-16 18:09:58 UTC (rev 533)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -20,9 +20,14 @@
 import org.jboss.webbeans.contexts.DependentContext;
 import org.jboss.webbeans.introspector.AnnotatedField;
 import org.jboss.webbeans.test.beans.BananaSpider;
+import org.jboss.webbeans.test.beans.BirdCage;
+import org.jboss.webbeans.test.beans.BlueFacedParrotFinch;
+import org.jboss.webbeans.test.beans.FinchKeeper;
 import org.jboss.webbeans.test.beans.RecluseSpider;
-import org.jboss.webbeans.test.beans.SweeWaxbill;
+import org.jboss.webbeans.test.beans.StarFinch;
 import org.jboss.webbeans.test.beans.TeaCupPomeranian;
+import org.jboss.webbeans.test.beans.broken.OwlFinch;
+import org.jboss.webbeans.test.beans.broken.SweeWaxbill;
 import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
 import org.jboss.webbeans.test.bindings.RoleBinding;
 import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
@@ -619,32 +624,80 @@
       }
    }
 
-   @Test(groups = { "stub", "events" })
+   @Test(groups = { "events" }, expectedExceptions = { IllegalArgumentException.class })
    @SpecAssertion(section = "8.6")
    public void testNonBindingTypePassedToFireFails()
    {
-      assert false;
+      webBeansBootstrap.boot(new MockWebBeanDiscovery(OwlFinch.class));
+      try
+      {
+         DependentContext.INSTANCE.setActive(true);
+         OwlFinch bean = manager.getInstanceByType(OwlFinch.class);
+         bean.methodThatFiresEvent();
+      }
+      finally
+      {
+         DependentContext.INSTANCE.setActive(false);
+      }
    }
 
-   @Test(groups = { "stub", "events" })
+   @Test(groups = { "events" }, expectedExceptions = { IllegalArgumentException.class })
    @SpecAssertion(section = "8.6")
    public void testNonBindingTypePassedToObservesFails()
    {
-      assert false;
+      webBeansBootstrap.boot(new MockWebBeanDiscovery(OwlFinch.class));
+      try
+      {
+         DependentContext.INSTANCE.setActive(true);
+         OwlFinch bean = manager.getInstanceByType(OwlFinch.class);
+         bean.methodThatRegistersObserver();
+      }
+      finally
+      {
+         DependentContext.INSTANCE.setActive(false);
+      }
    }
 
-   @Test(groups = { "stub", "events" })
+   @Test(groups = { "events" })
    @SpecAssertion(section = "8.6")
    public void testObservableAnnotationOnField()
    {
-      assert false;
+      webBeansBootstrap.boot(new MockWebBeanDiscovery(BlueFacedParrotFinch.class));
+      try
+      {
+         DependentContext.INSTANCE.setActive(true);
+         BlueFacedParrotFinch bean = manager.getInstanceByType(BlueFacedParrotFinch.class);
+         bean.methodThatRegistersObserver();
+
+         Set<Observer<String>> observers = manager.resolveObservers("String type event");
+         assert observers.size() == 1;
+      }
+      finally
+      {
+         DependentContext.INSTANCE.setActive(false);
+      }
    }
 
-   @Test(groups = { "stub", "events" })
+   @Test(groups = { "broken", "events" })
    @SpecAssertion(section = "8.6")
    public void testObservableAnnotationOnParameterOfProducerMethod()
    {
-      assert false;
+      webBeansBootstrap.boot(new MockWebBeanDiscovery(StarFinch.class, FinchKeeper.class, BirdCage.class));
+      try
+      {
+         DependentContext.INSTANCE.setActive(true);
+         StarFinch starFinch = manager.getInstanceByType(StarFinch.class);
+         FinchKeeper birdKeeper = manager.getInstanceByType(FinchKeeper.class);
+         BirdCage birdCage = manager.getInstanceByType(BirdCage.class);
+         assert starFinch != null;
+         assert birdCage != null;
+         assert birdCage.someMess != null;
+         assert birdKeeper.newMessDetected;
+      }
+      finally
+      {
+         DependentContext.INSTANCE.setActive(false);
+      }
    }
 
    @Test(groups = { "stub", "events" })

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BirdCage.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BirdCage.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BirdCage.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Current;
+import javax.webbeans.RequestScoped;
+
+import org.jboss.webbeans.test.beans.StarFinch.Mess;
+
+ at RequestScoped
+public class BirdCage
+{
+   @Current
+   public Mess someMess;
+
+   public BirdCage()
+   {
+   }
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BirdCage.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BlueFacedParrotFinch.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BlueFacedParrotFinch.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BlueFacedParrotFinch.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -0,0 +1,26 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Event;
+import javax.webbeans.Observable;
+import javax.webbeans.Observer;
+
+public class BlueFacedParrotFinch
+{
+   @Observable
+   private Event<String> simpleEvent;
+
+   public void methodThatFiresEvent()
+   {
+      simpleEvent.fire("An event");
+   }
+
+   public void methodThatRegistersObserver()
+   {
+      simpleEvent.observe(new Observer<String>()
+      {
+         public void notify(String event)
+         {
+         }
+      });
+   }
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/BlueFacedParrotFinch.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FinchKeeper.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FinchKeeper.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FinchKeeper.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -0,0 +1,21 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Observes;
+import javax.webbeans.RequestScoped;
+
+import org.jboss.webbeans.test.beans.StarFinch.Mess;
+
+ at RequestScoped
+public class FinchKeeper
+{
+   public FinchKeeper()
+   {
+   }
+
+   public boolean newMessDetected = false;
+
+   public void observesMesses(@Observes Mess aNewMess)
+   {
+      newMessDetected = true;
+   }
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FinchKeeper.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/StarFinch.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/StarFinch.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/StarFinch.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -0,0 +1,26 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Event;
+import javax.webbeans.Observable;
+import javax.webbeans.Produces;
+import javax.webbeans.RequestScoped;
+
+ at RequestScoped
+public class StarFinch
+{
+   public static class Mess
+   {
+   }
+
+   public StarFinch()
+   {
+   }
+
+   @Produces
+   public Mess producerOfMesses(@Observable Event<Mess> messEvent)
+   {
+      Mess newMess = new Mess();
+      messEvent.fire(newMess);
+      return newMess;
+   }
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/StarFinch.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SweeWaxbill.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SweeWaxbill.java	2008-12-16 18:09:58 UTC (rev 533)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SweeWaxbill.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -1,30 +0,0 @@
-package org.jboss.webbeans.test.beans;
-
-import javax.webbeans.Event;
-import javax.webbeans.Observable;
-import javax.webbeans.Observer;
-
-import org.jboss.webbeans.test.annotations.Role;
-import org.jboss.webbeans.test.bindings.RoleBinding;
-
-public class SweeWaxbill
-{
-   @Observable @Role("Admin")
-   private Event<String> simpleEvent;
-
-   public void methodThatFiresEvent()
-   {
-      simpleEvent.fire("An event", new RoleBinding("Admin"));
-   }
-
-   public void methodThatRegistersObserver()
-   {
-      simpleEvent.observe(new Observer<String>()
-      {
-
-         public void notify(String event)
-         {
-         }
-      }, new RoleBinding("Admin"));
-   }
-}

Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OwlFinch.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OwlFinch.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OwlFinch.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -0,0 +1,28 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.webbeans.Event;
+import javax.webbeans.Observable;
+import javax.webbeans.Observer;
+
+import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
+
+public class OwlFinch
+{
+   @Observable
+   private Event<String> simpleEvent;
+
+   public void methodThatFiresEvent()
+   {
+      simpleEvent.fire("An event", new AnimalStereotypeAnnotationLiteral());
+   }
+
+   public void methodThatRegistersObserver()
+   {
+      simpleEvent.observe(new Observer<String>()
+      {
+         public void notify(String event)
+         {
+         }
+      }, new AnimalStereotypeAnnotationLiteral());
+   }
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/OwlFinch.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/SweeWaxbill.java (from rev 526, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SweeWaxbill.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/SweeWaxbill.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/SweeWaxbill.java	2008-12-16 18:36:27 UTC (rev 534)
@@ -0,0 +1,30 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import javax.webbeans.Event;
+import javax.webbeans.Observable;
+import javax.webbeans.Observer;
+
+import org.jboss.webbeans.test.annotations.Role;
+import org.jboss.webbeans.test.bindings.RoleBinding;
+
+public class SweeWaxbill
+{
+   @Observable @Role("Admin")
+   private Event<String> simpleEvent;
+
+   public void methodThatFiresEvent()
+   {
+      simpleEvent.fire("An event", new RoleBinding("Admin"));
+   }
+
+   public void methodThatRegistersObserver()
+   {
+      simpleEvent.observe(new Observer<String>()
+      {
+
+         public void notify(String event)
+         {
+         }
+      }, new RoleBinding("Admin"));
+   }
+}


Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/SweeWaxbill.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the weld-commits mailing list