Author: dallen6
Date: 2009-07-22 10:31:32 -0400 (Wed, 22 Jul 2009)
New Revision: 3135
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisobedientDog.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/LargeDog.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/ShowDog.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SmallDog.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/TransactionalObservers.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverMethodImpl.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java
tck/trunk/impl/src/main/resources/tck-audit.xml
Log:
Added new tests for ObserverMethod and fixed related bugs.
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverMethodImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverMethodImpl.java 2009-07-22
14:01:07 UTC (rev 3134)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverMethodImpl.java 2009-07-22
14:31:32 UTC (rev 3135)
@@ -43,6 +43,7 @@
import org.jboss.webbeans.injection.MethodInjectionPoint;
import org.jboss.webbeans.introspector.WBMethod;
import org.jboss.webbeans.introspector.WBParameter;
+import org.jboss.webbeans.literal.AnyLiteral;
import org.jboss.webbeans.util.Names;
/**
@@ -83,6 +84,7 @@
this.eventType =
observerMethod.getAnnotatedParameters(Observes.class).get(0).getBaseType();
this.bindings = new
HashSet<Annotation>(Arrays.asList(observerMethod.getAnnotatedParameters(Observes.class).get(0).getBindingsAsArray()));
+ this.bindings.add(new AnyLiteral()); // Always add the Any annotation in case it
is not there yet
Observes observesAnnotation =
observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class);
this.notifyType = observesAnnotation.notifyObserver();
transactionPhase = TransactionPhase.IN_PROGRESS;
@@ -172,7 +174,7 @@
public TransactionPhase getTransactionPhase()
{
- return TransactionPhase.IN_PROGRESS;
+ return transactionPhase;
}
/**
Copied: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisobedientDog.java
(from rev 3123,
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/transactionalObservers/DisobedientDog.java)
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisobedientDog.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisobedientDog.java 2009-07-22
14:31:32 UTC (rev 3135)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.event;
+
+class DisobedientDog
+{
+
+}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java 2009-07-22
14:01:07 UTC (rev 3134)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java 2009-07-22
14:31:32 UTC (rev 3135)
@@ -4,6 +4,8 @@
import java.util.ArrayList;
import java.util.Set;
+import javax.enterprise.event.Notify;
+import javax.enterprise.event.TransactionPhase;
import javax.enterprise.inject.AnnotationLiteral;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.ObserverMethod;
@@ -11,6 +13,8 @@
import org.hibernate.tck.annotations.SpecAssertion;
import org.hibernate.tck.annotations.SpecAssertions;
import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.jsr299.tck.literals.AnyLiteral;
+import org.jboss.jsr299.tck.literals.CurrentLiteral;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.jsr299.BeansXml;
import org.testng.annotations.Test;
@@ -233,7 +237,7 @@
@SpecAssertion(section = "10.4.4", id = "a"),
@SpecAssertion(section = "5.6.8", id = "b")
} )
- public void testConditionalObserver() throws Exception
+ public void testConditionalObserver()
{
RecluseSpider.reset();
getCurrentManager().fireEvent(new ConditionalEvent());
@@ -241,21 +245,13 @@
assert !RecluseSpider.isNotified();
// Now instantiate the bean and fire another event
- new RunInDependentContext()
- {
- @Override
- protected void execute() throws Exception
- {
- RecluseSpider bean = getInstanceByType(RecluseSpider.class);
- assert bean != null;
- // Must invoke a method to really create the instance
- assert !bean.isInstanceNotified();
- getCurrentManager().fireEvent(new ConditionalEvent());
- assert RecluseSpider.isNotified() && bean.isInstanceNotified();
- }
+ RecluseSpider bean = getInstanceByType(RecluseSpider.class);
+ assert bean != null;
+ // Must invoke a method to really create the instance
+ assert !bean.isInstanceNotified();
+ getCurrentManager().fireEvent(new ConditionalEvent());
+ assert RecluseSpider.isNotified() && bean.isInstanceNotified();
- }.run();
-
RecluseSpider.reset();
}
@@ -272,19 +268,11 @@
@SpecAssertion(section = "10.5", id = "review"), // was b
@SpecAssertion(section = "10.5", id = "review") // was h
})
- public void testObserverMethodCalledImmediately() throws Exception
+ public void testObserverMethodCalledImmediately()
{
StaticObserver.reset();
- new RunInDependentContext()
- {
- @Override
- protected void execute() throws Exception
- {
- getCurrentManager().fireEvent(new Delivery());
- assert StaticObserver.isDeliveryReceived() &&
StaticObserver.getThreadObservingEvent().equals(Thread.currentThread());
- }
-
- }.run();
+ getCurrentManager().fireEvent(new Delivery());
+ assert StaticObserver.isDeliveryReceived() &&
StaticObserver.getThreadObservingEvent().equals(Thread.currentThread());
StaticObserver.reset();
}
@@ -297,7 +285,7 @@
@SpecAssertion(section = "10.4", id = "c"),
@SpecAssertion(section = "5.6.8", id = "a")
})
- public void testStaticObserverMethodInvoked() throws Exception
+ public void testStaticObserverMethodInvoked()
{
try
{
@@ -339,20 +327,11 @@
@Test(groups = { "events", "stub" })
@SpecAssertion(section = "10.5", id = "ca")
- public void testAsynchronousObserverThrowsExceptionIsLogged() throws Exception
+ public void testAsynchronousObserverThrowsExceptionIsLogged() throws
InterruptedException
{
- new RunInDependentContext()
- {
-
- @Override
- protected void execute() throws Exception
- {
- getCurrentManager().fireEvent('a');
- Thread.sleep(200);
- //TODO How can we assert that the exception was logged?
- }
-
- }.run();
+ getCurrentManager().fireEvent('a');
+ Thread.sleep(200);
+ //TODO How can we assert that the exception was logged?
}
@Test(groups = { "events", "stub" })
@@ -364,18 +343,10 @@
@Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class })
@SpecAssertion(section = "11.3.10", id = "d")
- public void testDuplicateBindingsToFireFails() throws Exception
+ public void testDuplicateBindingsToFireFails()
{
- new RunInDependentContext()
- {
- @Override
- protected void execute() throws Exception
- {
- SweeWaxbill bean = getInstanceByType(SweeWaxbill.class);
- bean.methodThatFiresEvent();
- }
-
- }.run();
+ SweeWaxbill bean = getInstanceByType(SweeWaxbill.class);
+ bean.methodThatFiresEvent();
}
@Test(groups = { "events" })
@@ -506,49 +477,102 @@
*/
@Test(groups = { "events", "inheritance" })
@SpecAssertion(section = "4.2", id = "dc")
- public void testNonStaticObserverMethodNotInherited() throws Exception
+ public void testNonStaticObserverMethodNotInherited()
{
- new RunInDependentContext()
- {
- @Override
- protected void execute() throws Exception
- {
- Egg egg = new Egg();
- Set<ObserverMethod<?, Egg>> observers =
getCurrentManager().resolveObserverMethods(egg);
- assert observers.size() == 1;
+ Egg egg = new Egg();
+ Set<ObserverMethod<?, Egg>> observers =
getCurrentManager().resolveObserverMethods(egg);
+ assert observers.size() == 1;
- // Notify the observer so we can confirm that it
- // is a method only on Farmer, and not LazyFarmer
- observers.iterator().next().notify(egg);
- assert egg.getClassesVisited().size() == 1;
- assert egg.getClassesVisited().iterator().next().equals(Farmer.class);
- }
-
- }.run();
+ // Notify the observer so we can confirm that it
+ // is a method only on Farmer, and not LazyFarmer
+ observers.iterator().next().notify(egg);
+ assert egg.getClassesVisited().size() == 1;
+ assert egg.getClassesVisited().iterator().next().equals(Farmer.class);
}
@Test(groups = { "events", "inheritance" })
- @SpecAssertion(section = "4.2", id = "di")
- public void testNonStaticObserverMethodNotIndirectlyInherited() throws Exception
+ @SpecAssertions({
+ @SpecAssertion(section = "4.2", id = "di"),
+ @SpecAssertion(section = "11.1.3", id = "f")
+ })
+ public void testNonStaticObserverMethodNotIndirectlyInherited()
{
- new RunInDependentContext()
- {
- @Override
- protected void execute() throws Exception
- {
- StockPrice price = new StockPrice();
- Set<ObserverMethod<?, StockPrice>> observers =
getCurrentManager().resolveObserverMethods(price);
- assert observers.size() == 1;
+ StockPrice price = new StockPrice();
+ Set<ObserverMethod<?, StockPrice>> observers =
getCurrentManager().resolveObserverMethods(price);
+ assert observers.size() == 1;
- // Notify the observer so we can confirm that it
- // is a method only on StockWatcher, and not IntermediateStockWatcher
- // or IndirectStockWatcher
- observers.iterator().next().notify(price);
- assert price.getClassesVisited().size() == 1;
- assert
price.getClassesVisited().iterator().next().equals(StockWatcher.class);
- }
+ // Notify the observer so we can confirm that it
+ // is a method only on StockWatcher, and not IntermediateStockWatcher
+ // or IndirectStockWatcher
+ observers.iterator().next().notify(price);
+ assert price.getClassesVisited().size() == 1;
+ assert price.getClassesVisited().iterator().next().equals(StockWatcher.class);
+ }
- }.run();
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "11.1.3", id = "b")
+ public void testGetBeanOnObserverMethod()
+ {
+ Set<ObserverMethod<?, StockPrice>> observers =
getCurrentManager().resolveObserverMethods(new StockPrice());
+ assert observers.size() == 1;
+ ObserverMethod<?, StockPrice> observerMethod = observers.iterator().next();
+ assert observerMethod.getBean().getBeanClass().equals(StockWatcher.class);
}
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "11.1.3", id = "c")
+ public void testGetObservedTypeOnObserverMethod()
+ {
+ Set<ObserverMethod<?, StockPrice>> observers =
getCurrentManager().resolveObserverMethods(new StockPrice());
+ assert observers.size() == 1;
+ ObserverMethod<?, ?> observerMethod = observers.iterator().next();
+ assert observerMethod.getObservedType().equals(StockPrice.class);
+ }
+
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "11.1.3", id = "c")
+ public void testGetObservedBindingsOnObserverMethod()
+ {
+ Set<ObserverMethod<?, StockPrice>> observers =
getCurrentManager().resolveObserverMethods(new StockPrice());
+ assert observers.size() == 1;
+ ObserverMethod<?, ?> observerMethod = observers.iterator().next();
+ assert observerMethod.getObservedBindings().size() == 2;
+ assert observerMethod.getObservedBindings().contains(new CurrentLiteral());
+ assert observerMethod.getObservedBindings().contains(new AnyLiteral());
+ }
+
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "11.1.3", id = "d")
+ public void testGetNotifyOnObserverMethod()
+ {
+ Set<ObserverMethod<?, StockPrice>> observers =
getCurrentManager().resolveObserverMethods(new StockPrice());
+ assert observers.size() == 1;
+ assert observers.iterator().next().getNotify().equals(Notify.ALWAYS);
+
+ Set<ObserverMethod<?, ConditionalEvent>> conditionalObservers =
getCurrentManager().resolveObserverMethods(new ConditionalEvent());
+ assert !conditionalObservers.isEmpty();
+ assert
conditionalObservers.iterator().next().getNotify().equals(Notify.IF_EXISTS);
+ }
+
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "11.1.3", id = "e")
+ public void testGetTransactionPhaseOnObserverMethod()
+ {
+ assert getCurrentManager().resolveObserverMethods(new
StockPrice()).iterator().next().getTransactionPhase().equals(TransactionPhase.IN_PROGRESS);
+ assert getCurrentManager().resolveObserverMethods(new
DisobedientDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.BEFORE_COMPLETION);
+ assert getCurrentManager().resolveObserverMethods(new
ShowDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.AFTER_COMPLETION);
+ assert getCurrentManager().resolveObserverMethods(new
SmallDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.AFTER_FAILURE);
+ assert getCurrentManager().resolveObserverMethods(new
LargeDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.AFTER_SUCCESS);
+ }
+
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "11.1.3", id = "g")
+ public void testInstanceOfBeanForEveryEnabledObserverMethod()
+ {
+ assert getCurrentManager().resolveObserverMethods(new
StockPrice()).iterator().next().getTransactionPhase().equals(TransactionPhase.IN_PROGRESS);
+ assert getCurrentManager().resolveObserverMethods(new
DisobedientDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.BEFORE_COMPLETION);
+ assert getCurrentManager().resolveObserverMethods(new
ShowDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.AFTER_COMPLETION);
+ assert getCurrentManager().resolveObserverMethods(new
SmallDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.AFTER_FAILURE);
+ assert getCurrentManager().resolveObserverMethods(new
LargeDog()).iterator().next().getTransactionPhase().equals(TransactionPhase.AFTER_SUCCESS);
+ }
}
Copied: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/LargeDog.java (from
rev 3123,
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/transactionalObservers/LargeDog.java)
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/LargeDog.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/LargeDog.java 2009-07-22
14:31:32 UTC (rev 3135)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.event;
+
+public class LargeDog
+{
+
+}
Copied: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/ShowDog.java (from
rev 3123,
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/transactionalObservers/ShowDog.java)
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/ShowDog.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/ShowDog.java 2009-07-22
14:31:32 UTC (rev 3135)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.event;
+
+public class ShowDog
+{
+
+}
Copied: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SmallDog.java (from
rev 3123,
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/transactionalObservers/SmallDog.java)
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SmallDog.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SmallDog.java 2009-07-22
14:31:32 UTC (rev 3135)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.event;
+
+public class SmallDog
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/TransactionalObservers.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/TransactionalObservers.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/TransactionalObservers.java 2009-07-22
14:31:32 UTC (rev 3135)
@@ -0,0 +1,28 @@
+package org.jboss.jsr299.tck.tests.event;
+
+import static javax.enterprise.event.TransactionPhase.BEFORE_COMPLETION;
+import static javax.enterprise.event.TransactionPhase.AFTER_COMPLETION;
+import static javax.enterprise.event.TransactionPhase.AFTER_FAILURE;
+import static javax.enterprise.event.TransactionPhase.AFTER_SUCCESS;
+
+import javax.enterprise.event.Observes;
+
+public class TransactionalObservers
+{
+ public void train(@Observes(during=BEFORE_COMPLETION) DisobedientDog dog)
+ {
+ }
+
+ public void trainNewTricks(@Observes(during=AFTER_COMPLETION) ShowDog dog)
+ {
+ }
+
+ public void trainCompanion(@Observes(during=AFTER_FAILURE) SmallDog dog)
+ {
+ }
+
+ public void trainSightSeeing(@Observes(during=AFTER_SUCCESS) LargeDog dog)
+ {
+ }
+
+}
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/TransactionalObservers.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: tck/trunk/impl/src/main/resources/tck-audit.xml
===================================================================
--- tck/trunk/impl/src/main/resources/tck-audit.xml 2009-07-22 14:01:07 UTC (rev 3134)
+++ tck/trunk/impl/src/main/resources/tck-audit.xml 2009-07-22 14:31:32 UTC (rev 3135)
@@ -3897,7 +3897,7 @@
</section>
<section id="11.1.3" title="The ObserverMethod interface">
- <assertion id="a">
+ <assertion id="a" testable="false">
<text>The interface |javax.enterprise.inject.spi.ObserverMethod| defines
everything the container needs to know about an observer method.</text>
</assertion>