[webbeans-commits] Webbeans SVN: r472 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Dec 8 07:17:28 EST 2008
Author: dallen6
Date: 2008-12-08 07:17:28 -0500 (Mon, 08 Dec 2008)
New Revision: 472
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/BullTerrier.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java
Log:
Fixed some more bugs with observer methods and implemented the tests through 8.5.2 for events.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-12-08 11:15:09 UTC (rev 471)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-12-08 12:17:28 UTC (rev 472)
@@ -18,11 +18,10 @@
package org.jboss.webbeans.event;
import java.lang.annotation.Annotation;
-import java.util.Arrays;
-import java.util.HashSet;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
+import javax.webbeans.Current;
import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Observer;
@@ -61,31 +60,33 @@
{
this.observer = observer;
this.eventType = eventType;
- this.eventBindings = Arrays.asList(eventBindings);
+ this.eventBindings = new ArrayList<Annotation>();
checkEventBindings(eventBindings);
}
/**
* Checks that each event binding specified on the observer is indeed a
* binding type (annotated with @BindingType) and that there are no duplicate
- * bindings specified.
- *
- * @param observerEventBindings The list of event bindings for the observer
+ * bindings specified. If the @Current binding type is found, it is removed
+ * since this is only a default supplied by the container but no applicable
+ * for the actual event objects which get fired.
*/
- private void checkEventBindings(Annotation[] observerEventBindings)
+ private void checkEventBindings(Annotation[] bindingAnnotations)
{
- Set<Annotation> checkedBindings = new HashSet<Annotation>();
- for (Annotation annotation : observerEventBindings)
+ for (Annotation annotation : bindingAnnotations)
{
if (!Reflections.isBindingType(annotation))
{
throw new IllegalArgumentException(annotation + " is not a binding type for " + this);
}
- if (checkedBindings.contains(annotation))
+ if (eventBindings.contains(annotation))
{
throw new DuplicateBindingTypeException(annotation + " is already present in the bindings list for " + this);
}
- checkedBindings.add(annotation);
+ if (!annotation.annotationType().equals(Current.class))
+ {
+ eventBindings.add(annotation);
+ }
}
}
@@ -162,6 +163,7 @@
return result;
}
+ @SuppressWarnings("unchecked")
@Override
public boolean equals(Object other)
{
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-08 11:15:09 UTC (rev 471)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java 2008-12-08 12:17:28 UTC (rev 472)
@@ -25,6 +25,7 @@
import org.jboss.webbeans.test.ejb.model.invalid.FoxTerrier;
import org.jboss.webbeans.test.ejb.model.invalid.TibetanTerrier;
import org.jboss.webbeans.test.ejb.model.invalid.YorkshireTerrier;
+import org.jboss.webbeans.test.ejb.model.valid.BullTerrier;
import org.jboss.webbeans.test.ejb.model.valid.Pomeranian;
import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.jboss.webbeans.util.BeanFactory;
@@ -76,8 +77,9 @@
{
SimpleBean<MyTest> myTestBean = BeanFactory.createSimpleBean(MyTest.class);
boolean found = false;
- for (AnnotatedField field : myTestBean.getInjectableFields()) {
- if ( field.isAnnotationPresent(Observable.class) )
+ for (AnnotatedField field : myTestBean.getInjectableFields())
+ {
+ if (field.isAnnotationPresent(Observable.class))
{
EventBean eventBean = BeanFactory.createEventBean(field);
Event<Param> event = eventBean.create();
@@ -439,6 +441,20 @@
}
@Test(groups = { "events" })
+ @SpecAssertion(section = "8.5.1")
+ public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
+ {
+ // This observer has no binding types specified
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(Pomeranian.class);
+ assert beans.size() == 1;
+
+ // Resolve registered observers with an event containing no binding types
+ Set<Observer<String>> resolvedObservers = manager.resolveObservers("A new event");
+ assert !resolvedObservers.isEmpty();
+ assert resolvedObservers.size() == 1;
+ }
+
+ @Test(groups = { "events" })
@SpecAssertion(section = "8.5.2")
public void testObserverMethodAnnotatedProducesFails()
{
@@ -506,11 +522,18 @@
assert definitionException;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "8.5.1")
- public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5.2")
+ public void testObserverMethodMayHaveMultipleBindingTypes()
{
- assert false;
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(BullTerrier.class);
+ assert beans != null;
+ // If we can resolve the observer with the two binding types,
+ // then it worked
+ Set<Observer<String>> resolvedObservers = manager.resolveObservers("An event object", new RoleBinding("Admin"), new TameAnnotationLiteral());
+ assert !resolvedObservers.isEmpty();
+ assert resolvedObservers.size() == 1;
+
}
@Test(groups = { "stub", "events" })
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/BullTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/BullTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/BullTerrier.java 2008-12-08 12:17:28 UTC (rev 472)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.test.ejb.model.valid;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Observes;
+
+import org.jboss.webbeans.test.annotations.Role;
+import org.jboss.webbeans.test.annotations.Tame;
+
+ at Stateless
+public class BullTerrier
+{
+ public void observesBadEvent(@Observes @Role("Admin") @Tame String someEvent)
+ {
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/BullTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java 2008-12-08 11:15:09 UTC (rev 471)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java 2008-12-08 12:17:28 UTC (rev 472)
@@ -17,6 +17,10 @@
{
}
+ public void observeSimpleString(@Observes String someString)
+ {
+ }
+
public static void staticallyObserveInitialized(@Observes @Initialized Manager manager)
{
}
More information about the weld-commits
mailing list