package org.jboss.webbeans.test.unit.implementation.event;

import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.AnnotationLiteral;
import javax.enterprise.inject.Any;

import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.webbeans.BeanManagerImpl;
import org.jboss.webbeans.test.AbstractWebBeansTest;
import org.testng.annotations.Test;

@Artifact 
public class SimpleEventTest extends AbstractWebBeansTest
{
   private static boolean RECEIVE_1_OBSERVED;
   private static boolean RECEIVE_2_OBSERVED;
   
   private static void initFlags() {
      RECEIVE_1_OBSERVED = false;
      RECEIVE_2_OBSERVED = false;
   }
   
   @Test
   public void testFireEventOnManager()
   {
      BeanManagerImpl manager = getCurrentManager();
      
      initFlags();

      manager.fireEvent("Fired using Manager Interface with AnnotationLiteral.", new AnnotationLiteral<Updated>(){});

      assert RECEIVE_2_OBSERVED == true;
      assert RECEIVE_1_OBSERVED == true;
      
      initFlags();
      
      manager.fireEvent("Fired using Manager Interface.");
      
      assert RECEIVE_2_OBSERVED == true;
      assert RECEIVE_1_OBSERVED == false; // not called
   }
   
   @Test
   public void testFireEventOnEvent()
   {
      BeanManagerImpl manager = getCurrentManager();

      App app = createContextualInstance(App.class);
      
      initFlags();
      
      app.fireEventByBindingDeclaredAtInjectionPoint();

      assert RECEIVE_1_OBSERVED == true;
      assert RECEIVE_2_OBSERVED == true;
      
      initFlags();
      
      app.fireEventByAnnotationLiteral();
      
      assert RECEIVE_2_OBSERVED == true;
      assert RECEIVE_1_OBSERVED == true;
      
      initFlags();
      
      app.fireEventViaAny();
      
      assert RECEIVE_2_OBSERVED == true;
      assert RECEIVE_1_OBSERVED == false; // not called
   }

   public static class App
   {
      @Any
      Event<String> event1;
      
      @Updated
      Event<String> event2;

      @Any
      Event<String> event3;

      public void fireEventByAnnotationLiteral()
      {
         event1.select(new AnnotationLiteral<Updated>(){}).fire("Fired using Event Interface with AnnotationLiteral.");
      }
      
      public void fireEventByBindingDeclaredAtInjectionPoint()
      {
         event2.fire("Fired using Event Interface with Binding Declared.");
      }
      
      public void fireEventViaAny()
      {
         event3.fire("Fired using Event Interface with Non-BindingType.");
      }
   }

   public static class Receiver
   {
      public void receive1(@Observes @Updated String s)
      {
         RECEIVE_1_OBSERVED = true;
      }

      public void receive2(@Any @Observes String s)
      {
         RECEIVE_2_OBSERVED = true;
      }
   }
}
@@ -215,16 +215,56 @@
 ect.Any;
+%0Aimport javax.enterprise.inject.Current;
 %0A%0Aimport
@@ -607,16 +607,62 @@
 SERVED;%0A
+   private static boolean RECEIVE_3_OBSERVED;%0A
    %0A   p
@@ -762,16 +762,50 @@
  false;%0A
+      RECEIVE_3_OBSERVED = false;%0A
    %7D%0A   
@@ -1132,32 +1132,74 @@
 SERVED == true;%0A
+      assert RECEIVE_3_OBSERVED == false;%0A
       %0A      ini
@@ -1374,24 +1374,65 @@
  not called%0A
+      assert RECEIVE_3_OBSERVED == true;%0A
    %7D%0A   %0A   
@@ -1751,32 +1751,74 @@
 SERVED == true;%0A
+      assert RECEIVE_3_OBSERVED == false;%0A
       %0A      ini
@@ -1961,24 +1961,66 @@
 ED == true;%0A
+      assert RECEIVE_3_OBSERVED == false;%0A
       %0A     
@@ -2173,16 +2173,269 @@
  called%0A
+      assert RECEIVE_3_OBSERVED == false;%0A      %0A      initFlags();%0A      %0A      app.fireEventViaCurrent();%0A      %0A      assert RECEIVE_2_OBSERVED == true;%0A      assert RECEIVE_1_OBSERVED == false; // not called%0A      assert RECEIVE_3_OBSERVED == true;%0A
    %7D%0A%0A  
@@ -2592,16 +2592,66 @@
  event3;
+%0A      %0A      @Current%0A      Event%3CString%3E event4;
 %0A%0A      
@@ -3121,24 +3121,154 @@
 %22);%0A      %7D%0A
+      %0A      public void fireEventViaCurrent()%0A      %7B%0A         event4.fire(%22Fired using Event Interface with @Current%22);%0A      %7D%0A
    %7D%0A%0A   pub
@@ -3459,32 +3459,32 @@
 ring s)%0A      %7B%0A
-
          RECEIVE
@@ -3507,18 +3507,124 @@
 ue;%0A      %7D%0A
+      %0A      public void receive3(@Observes String s)%0A      %7B%0A         RECEIVE_3_OBSERVED = true;%0A      %7D%0A
    %7D%0A%7D

Add a @Current test