Author: dallen6
Date: 2008-12-08 16:46:17 -0500 (Mon, 08 Dec 2008)
New Revision: 486
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/TeaCupPomeranian.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/DefaultEnterpriseBeanLookup.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.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/valid/Pomeranian.java
Log:
Added some more event test implementations and modifications to event bus to support
latest specs.
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/DefaultEnterpriseBeanLookup.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/DefaultEnterpriseBeanLookup.java 2008-12-08
19:24:01 UTC (rev 485)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ejb/DefaultEnterpriseBeanLookup.java 2008-12-08
21:46:17 UTC (rev 486)
@@ -77,6 +77,8 @@
*/
public Object lookup(String ejbName)
{
+ if (ejbName == null)
+ throw new NullPointerException("No EJB name supplied for lookup");
return lookup(ejbMetaDataMap.get(ejbName));
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-08
19:24:01 UTC (rev 485)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-08
21:46:17 UTC (rev 486)
@@ -23,6 +23,7 @@
import static
org.jboss.webbeans.event.EventManager.TransactionObservationPhase.BEFORE_COMPLETION;
import static org.jboss.webbeans.event.EventManager.TransactionObservationPhase.NONE;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
@@ -33,9 +34,11 @@
import javax.webbeans.DefinitionException;
import javax.webbeans.Destructor;
import javax.webbeans.Disposes;
+import javax.webbeans.ExecutionException;
import javax.webbeans.IfExists;
import javax.webbeans.Initializer;
import javax.webbeans.Observer;
+import javax.webbeans.ObserverException;
import javax.webbeans.Observes;
import javax.webbeans.Produces;
import javax.webbeans.manager.Bean;
@@ -171,9 +174,26 @@
if (instance != null)
{
// TODO replace event parameter
- observerMethod.invokeWithSpecialValue(manager, instance, Observes.class,
event);
+ try
+ {
+ observerMethod.invokeWithSpecialValue(manager, instance, Observes.class,
event);
+ }
+ catch (ExecutionException e)
+ {
+ if ((e.getCause() != null) && (e.getCause() instanceof
InvocationTargetException))
+ {
+ InvocationTargetException wrappedException = (InvocationTargetException)
e.getCause();
+ if ((wrappedException.getCause() != null) &&
(RuntimeException.class.isAssignableFrom(wrappedException.getCause().getClass())))
+ {
+ throw (RuntimeException) wrappedException.getCause();
+ }
+ else
+ {
+ throw new ObserverException(wrappedException.getCause().getMessage(),
wrappedException.getCause());
+ }
+ }
+ }
}
-
}
/**
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
19:24:01 UTC (rev 485)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java 2008-12-08
21:46:17 UTC (rev 486)
@@ -8,6 +8,7 @@
import javax.webbeans.Event;
import javax.webbeans.Observable;
import javax.webbeans.Observer;
+import javax.webbeans.ObserverException;
import javax.webbeans.TypeLiteral;
import org.jboss.webbeans.bean.AbstractBean;
@@ -17,6 +18,7 @@
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.test.beans.BananaSpider;
import org.jboss.webbeans.test.beans.RecluseSpider;
+import org.jboss.webbeans.test.beans.TeaCupPomeranian;
import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.RoleBinding;
import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
@@ -434,20 +436,20 @@
}
- // @Test(groups = { "stub", "events" })
- // @SpecAssertion(section = "8.5.3")
- // public void testXMLDefinedObserverMethodIgnoresBindingAnnotations()
- // {
- // assert false;
- // }
- //
- // @Test(groups = { "stub", "events" })
- // @SpecAssertion(section = "8.5.3")
- // public void testXMLDefinedObserverNotFindingImplementationMethodFails()
- // {
- // assert false;
- // }
- //
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "8.5.3")
+ public void testXMLDefinedObserverMethodIgnoresBindingAnnotations()
+ {
+ assert false;
+ }
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "8.5.3")
+ public void testXMLDefinedObserverNotFindingImplementationMethodFails()
+ {
+ assert false;
+ }
+
@Test(groups = { "events" })
@SpecAssertion(section = "8.5.4")
public void testObserverMethodReceivesInjectionsOnNonObservesParameters()
@@ -515,18 +517,29 @@
assert false;
}
- @Test(groups = { "stub", "events" })
+ @Test(groups = { "events" })
@SpecAssertion(section = "8.5.7")
public void testObserverMethodRegistration()
{
- assert false;
+ // For now, this test is checking the registration of methods
+ testObserverMethodOnEnterpriseBeanIsBusinessMethodOrStatic();
}
- @Test(groups = { "stub", "events" })
+ /**
+ *
+ */
+ @Test(groups = { "broken", "events" })
@SpecAssertion(section = "8.5.7")
public void testEnterpriseBeanObserverMethodCalledWithCallerContext()
{
- assert false;
+ Set<AbstractBean<?, ?>> beans =
webBeansBootstrap.createBeans(Pomeranian.class);
+ assert beans.size() == 1;
+ String event = "A new event";
+ Set<Observer<String>> observers = manager.resolveObservers(event);
+ assert observers.size() == 1;
+
+ manager.fireEvent(event);
+ assert Thread.currentThread().equals(Pomeranian.notificationThread);
}
@Test(groups = { "stub", "events" })
@@ -536,18 +549,22 @@
assert false;
}
- @Test(groups = { "stub", "events" })
+ @Test(groups = { "events" }, expectedExceptions={
TeaCupPomeranian.OversizedException.class })
@SpecAssertion(section = "8.5.7")
public void testNonTransactionalObserverThrownNonCheckedExceptionIsRethrown()
{
- assert false;
+ Set<AbstractBean<?, ?>> beans =
webBeansBootstrap.createBeans(TeaCupPomeranian.class);
+ assert beans.size() == 1;
+ manager.fireEvent("Another event");
}
- @Test(groups = { "stub", "events" })
+ @Test(groups = { "events" }, expectedExceptions={ ObserverException.class
})
@SpecAssertion(section = "8.5.7")
public void testNonTransactionalObserverThrownCheckedExceptionIsWrappedAndRethrown()
{
- assert false;
+ Set<AbstractBean<?, ?>> beans =
webBeansBootstrap.createBeans(TeaCupPomeranian.class);
+ assert beans.size() == 1;
+ manager.fireEvent(new Integer(1));
}
@Test(groups = { "stub", "events" })
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/TeaCupPomeranian.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/TeaCupPomeranian.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/TeaCupPomeranian.java 2008-12-08
21:46:17 UTC (rev 486)
@@ -0,0 +1,32 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Named;
+import javax.webbeans.Observes;
+
+import org.jboss.webbeans.test.annotations.Tame;
+
+@Tame
+@Named("Ted")
+public class TeaCupPomeranian
+{
+ public static class OversizedException extends RuntimeException
+ {
+ private static final long serialVersionUID = 1L;
+
+ }
+
+ public static class TooSmallException extends Exception
+ {
+ private static final long serialVersionUID = 1L;
+ }
+
+ public void observeSimpleEvent(@Observes String someEvent)
+ {
+ throw new OversizedException();
+ }
+
+ public void observeAnotherSimpleEvent(@Observes Integer someEvent) throws
TooSmallException
+ {
+ throw new TooSmallException();
+ }
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/TeaCupPomeranian.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/valid/Pomeranian.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/valid/Pomeranian.java 2008-12-08
19:24:01 UTC (rev 485)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/valid/Pomeranian.java 2008-12-08
21:46:17 UTC (rev 486)
@@ -13,12 +13,15 @@
@Named("Teddy")
public class Pomeranian
{
+ public static Thread notificationThread;
+
public void observeInitialized(@Observes @Initialized Manager manager)
{
}
public void observeSimpleEvent(@Observes String someEvent)
{
+ notificationThread = Thread.currentThread();
}
public static void staticallyObserveInitialized(@Observes @Initialized Manager
manager)