Author: dan.j.allen
Date: 2009-06-22 22:41:14 -0400 (Mon, 22 Jun 2009)
New Revision: 2861
Added:
ri/trunk/api/src/main/java/javax/event/Notify.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingTypeNotRuntime.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledDeploymentType.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledStringObserver.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DogWhisperer.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingEvent.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Spun.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Web.java
Removed:
ri/trunk/api/src/main/java/javax/event/Asynchronously.java
ri/trunk/api/src/main/java/javax/event/IfExists.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingNotRuntime.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingType.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/AsynchronousConditionalObserverTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/Terrier.java
Modified:
ri/trunk/api/src/main/java/javax/event/Observes.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBMethod.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/standalone/TcasDisplay.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/AsynchronousObserver.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BananaSpider.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BullTerrier.java
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/Pomeranian.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/RecluseSpider.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/StaticObserver.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SweeWaxbill.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/event1/FiresOnNonEventTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/AsynchronousBeforeCompletionObserverTest.java
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/Terrier.java
Log:
Refactor @IfExists and @Asynchronously as Notify annotation attributes on @Observes
Update tests in the EventTest class to the 20090519 spec (actually a bit beyond that)
Deleted: ri/trunk/api/src/main/java/javax/event/Asynchronously.java
===================================================================
--- ri/trunk/api/src/main/java/javax/event/Asynchronously.java 2009-06-23 02:38:25 UTC
(rev 2860)
+++ ri/trunk/api/src/main/java/javax/event/Asynchronously.java 2009-06-23 02:41:14 UTC
(rev 2861)
@@ -1,38 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package javax.event;
-
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Specifies that an observer method is to be notified asynchronously
- * with respect to the firing of the event.
- *
- * @author Gavin King
- * @author David Allen
- *
- */
-@Retention(RUNTIME)
-@Target(PARAMETER)
-public @interface Asynchronously
-{
-}
Deleted: ri/trunk/api/src/main/java/javax/event/IfExists.java
===================================================================
--- ri/trunk/api/src/main/java/javax/event/IfExists.java 2009-06-23 02:38:25 UTC (rev
2860)
+++ ri/trunk/api/src/main/java/javax/event/IfExists.java 2009-06-23 02:41:14 UTC (rev
2861)
@@ -1,40 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-package javax.event;
-
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-/**
- * Specifies that an observer method is only called if the current instance of
- * the bean declaring the observer method already exists.
- *
- * @author Gavin King
- * @author Pete Muir
- */
-
-@Target(PARAMETER)
-@Retention(RUNTIME)
-@Documented
-public @interface IfExists
-{
-}
Added: ri/trunk/api/src/main/java/javax/event/Notify.java
===================================================================
--- ri/trunk/api/src/main/java/javax/event/Notify.java (rev 0)
+++ ri/trunk/api/src/main/java/javax/event/Notify.java 2009-06-23 02:41:14 UTC (rev 2861)
@@ -0,0 +1,28 @@
+package javax.event;
+
+/**
+ * An enumeration that is used to declare the condition under which an
+ * observer method should be called. The default behavior is to
+ * create the bean and invoke the observer method synchronously.
+ *
+ * @author Gavin King
+ * @author Dan Allen
+ */
+public enum Notify {
+ /**
+ * Specifies that an observer method is only called if the current instance of
+ * the bean declaring the observer method already exists.
+ */
+ IF_EXISTS,
+
+ /**
+ * Specifies that an observer method is called synchronously.
+ */
+ SYNCHRONOUSLY,
+
+ /**
+ * Specifies that an observer method receives the event notifications
+ * asynchronously.
+ */
+ ASYNCHRONOUSLY
+}
\ No newline at end of file
Modified: ri/trunk/api/src/main/java/javax/event/Observes.java
===================================================================
--- ri/trunk/api/src/main/java/javax/event/Observes.java 2009-06-23 02:38:25 UTC (rev
2860)
+++ ri/trunk/api/src/main/java/javax/event/Observes.java 2009-06-23 02:41:14 UTC (rev
2861)
@@ -9,7 +9,7 @@
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
+* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
@@ -25,8 +25,8 @@
import java.lang.annotation.Target;
/**
- * Specifies that a parameter of a method of a bean
- * implementation class is the event parameter
+ * Specifies that a parameter of a method of a bean
+ * implementation class is the event parameter
* of an observer method.
*
* @author Gavin King
@@ -38,4 +38,5 @@
@Documented
public @interface Observes
{
+ public Notify notifyObserver() default Notify.SYNCHRONOUSLY;
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-06-23
02:38:25 UTC (rev 2860)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -9,7 +9,7 @@
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
@@ -27,8 +27,7 @@
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Initializer;
import javax.enterprise.inject.Produces;
-import javax.event.Asynchronously;
-import javax.event.IfExists;
+import javax.event.Notify;
import javax.event.Observer;
import javax.event.ObserverException;
import javax.event.Observes;
@@ -82,8 +81,9 @@
this.eventType =
observerMethod.getAnnotatedParameters(Observes.class).get(0).getBaseType();
this.bindings =
observerMethod.getAnnotatedParameters(Observes.class).get(0).getBindingsAsArray();
- this.conditional =
!observerMethod.getAnnotatedParameters(IfExists.class).isEmpty();
- this.asynchronous =
!observerMethod.getAnnotatedParameters(Asynchronously.class).isEmpty();
+ Observes observesAnnotation =
observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class);
+ this.conditional = observesAnnotation.notifyObserver().equals(Notify.IF_EXISTS);
+ this.asynchronous =
observesAnnotation.notifyObserver().equals(Notify.ASYNCHRONOUSLY);
}
/**
@@ -204,7 +204,7 @@
}
/**
- * Queues the event for later execution
+ * Queues the event for later execution
* @param event
*/
protected void sendEventAsynchronously(final T event)
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/event/TransactionalObserverImpl.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -9,7 +9,7 @@
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
@@ -22,8 +22,9 @@
import javax.event.AfterTransactionCompletion;
import javax.event.AfterTransactionFailure;
import javax.event.AfterTransactionSuccess;
-import javax.event.Asynchronously;
import javax.event.BeforeTransactionCompletion;
+import javax.event.Notify;
+import javax.event.Observes;
import javax.transaction.Synchronization;
import org.jboss.webbeans.BeanManagerImpl;
@@ -104,9 +105,9 @@
if
(!observerMethod.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty())
{
observationPhases.add(TransactionObservationPhase.BEFORE_COMPLETION);
- if (!observerMethod.getAnnotatedParameters(Asynchronously.class).isEmpty())
+ if
(observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class).notifyObserver().equals(Notify.ASYNCHRONOUSLY))
{
- throw new DefinitionException("@BeforeTransactionCompletion cannot be
used with @Asynchronously on " + observerMethod);
+ throw new DefinitionException("@BeforeTransactionCompletion cannot be
used on an asynchronous observer on " + observerMethod);
}
}
if
(!observerMethod.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty())
@@ -144,7 +145,7 @@
private void deferEvent(T event)
{
DeferredEventNotification<T> deferredEvent = null;
- if (this.observerMethod.getAnnotatedParameters(Asynchronously.class).isEmpty())
+ if
(this.observerMethod.getAnnotatedParameters(Observes.class).get(0).getAnnotation(Observes.class).notifyObserver().equals(Notify.ASYNCHRONOUSLY))
{
deferredEvent = new DeferredEventNotification<T>(event, this);
}
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBMethod.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBMethod.java 2009-06-23
02:38:25 UTC (rev 2860)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/introspector/WBMethod.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -9,7 +9,7 @@
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
@@ -28,9 +28,7 @@
import javax.event.AfterTransactionCompletion;
import javax.event.AfterTransactionFailure;
import javax.event.AfterTransactionSuccess;
-import javax.event.Asynchronously;
import javax.event.BeforeTransactionCompletion;
-import javax.event.IfExists;
import javax.event.Observes;
/**
@@ -43,7 +41,7 @@
public interface WBMethod<T> extends WBMember<T, Method>
{
@SuppressWarnings("unchecked")
- public static final Set<Class<? extends Annotation>>
MAPPED_PARAMETER_ANNOTATIONS = new HashSet<Class<? extends
Annotation>>(Arrays.asList(Disposes.class, Observes.class, IfExists.class,
BeforeTransactionCompletion.class, AfterTransactionCompletion.class,
AfterTransactionFailure.class, AfterTransactionSuccess.class, Asynchronously.class,
Disposes.class));
+ public static final Set<Class<? extends Annotation>>
MAPPED_PARAMETER_ANNOTATIONS = new HashSet<Class<? extends
Annotation>>(Arrays.asList(Disposes.class, Observes.class,
BeforeTransactionCompletion.class, AfterTransactionCompletion.class,
AfterTransactionFailure.class, AfterTransactionSuccess.class, Disposes.class));
/**
* Gets the abstracted parameters of the method
@@ -77,7 +75,7 @@
public T invoke(Object instance, Object... parameters) throws
IllegalArgumentException, IllegalAccessException, InvocationTargetException;
/**
- * Invokes the method on the class of the passed instance, not the declaring
+ * Invokes the method on the class of the passed instance, not the declaring
* class. Useful with proxies
*
* @param instance The instance to invoke
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasDisplay.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -3,7 +3,7 @@
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Current;
import javax.enterprise.inject.spi.BeanManager;
-import javax.event.Asynchronously;
+import javax.event.Notify;
import javax.event.Observes;
class TcasDisplay
@@ -13,7 +13,7 @@
private static boolean applicationScopeActive = false;
- public void drawTarget(@Observes @Asynchronously TargetEvent targetEvent)
+ public void drawTarget(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY) TargetEvent
targetEvent)
{
if (beanManager.getContext(ApplicationScoped.class).isActive())
{
@@ -25,7 +25,7 @@
}
}
- public void drawNearMiss(@Observes @Asynchronously NearMiss event)
+ public void drawNearMiss(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY) NearMiss
event)
{
event.setBean(org.jboss.jsr299.tck.impl.OldSPIBridge.getInstanceByType(beanManager,SimpleApplicationBean.class));
}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/application/standalone/TcasToFmsLink.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -2,7 +2,7 @@
import javax.enterprise.inject.Current;
import javax.enterprise.inject.spi.BeanManager;
-import javax.event.Asynchronously;
+import javax.event.Notify;
import javax.event.Observes;
class TcasToFmsLink
@@ -10,7 +10,7 @@
@Current
private BeanManager beanManager;
- public void avoidanceAction(@Observes @Asynchronously NearMiss event)
+ public void avoidanceAction(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY) NearMiss
event)
{
event.setBean(org.jboss.jsr299.tck.impl.OldSPIBridge.getInstanceByType(beanManager,SimpleApplicationBean.class));
}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/standalone/TcasDisplay.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/standalone/TcasDisplay.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/request/standalone/TcasDisplay.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -3,7 +3,7 @@
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Current;
import javax.enterprise.inject.spi.BeanManager;
-import javax.event.Asynchronously;
+import javax.event.Notify;
import javax.event.Observes;
class TcasDisplay
@@ -13,7 +13,7 @@
private static boolean requestScopeActive = false;
- public void drawTarget(@Observes @Asynchronously TargetEvent targetEvent)
+ public void drawTarget(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY) TargetEvent
targetEvent)
{
if (beanManager.getContext(RequestScoped.class).isActive())
{
@@ -25,7 +25,7 @@
}
}
- public void drawNearMiss(@Observes @Asynchronously NearMiss event)
+ public void drawNearMiss(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY) NearMiss
event)
{
event.setBean(org.jboss.jsr299.tck.impl.OldSPIBridge.getInstanceByType(beanManager,SimpleRequestBean.class));
}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/AsynchronousObserver.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/AsynchronousObserver.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/AsynchronousObserver.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,18 +1,18 @@
package org.jboss.jsr299.tck.tests.event;
-import javax.event.Asynchronously;
+import javax.event.Notify;
import javax.event.Observes;
public class AsynchronousObserver
{
private static Thread threadObservingEvent = null;
- public void observes(@Observes @Asynchronously Boolean event)
+ public void observes(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY) Boolean event)
{
threadObservingEvent = Thread.currentThread();
}
- public void observes(@Observes @Asynchronously Character event)
+ public void observes(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY) Character
event)
{
throw new RuntimeException("RE1");
}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BananaSpider.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BananaSpider.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BananaSpider.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -2,23 +2,25 @@
import java.util.Set;
-import javax.enterprise.inject.Current;
import javax.enterprise.inject.spi.BeanManager;
import javax.event.Observer;
import javax.event.Observes;
/**
* Simple bean with observer method and another injectable parameter.
- *
*/
class BananaSpider
{
- public void observeStringEvent(@Observes String someEvent, @Current BeanManager
beanManager)
+ public void observeStringEvent(@Observes String event, BeanManager beanManager, @Spun
Web web)
{
- assert someEvent != null;
- assert beanManager != null;
- Set<Observer<String>> allStringObservers =
beanManager.resolveObservers(someEvent);
+ assert event != null;
+ Set<Observer<String>> allStringObservers =
beanManager.resolveObservers(event);
assert allStringObservers != null;
assert allStringObservers.size() > 0;
+ if ("validate injected parameters".equals(event))
+ {
+ assert beanManager != null;
+ assert web != null;
+ }
}
}
Deleted:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingNotRuntime.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingNotRuntime.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingNotRuntime.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,15 +0,0 @@
-package org.jboss.jsr299.tck.tests.event;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.PARAMETER;
-
-import java.lang.annotation.Target;
-
-import javax.enterprise.inject.BindingType;
-
-@Target( { FIELD, PARAMETER })
-@BindingType
-@interface BindingNotRuntime
-{
-
-}
Copied:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingTypeNotRuntime.java
(from rev 2838,
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingNotRuntime.java)
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingTypeNotRuntime.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BindingTypeNotRuntime.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -0,0 +1,15 @@
+package org.jboss.jsr299.tck.tests.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.PARAMETER;
+
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.BindingType;
+
+@Target( { FIELD, PARAMETER })
+@BindingType
+@interface BindingTypeNotRuntime
+{
+
+}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BullTerrier.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BullTerrier.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/BullTerrier.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -7,12 +7,12 @@
private static boolean multiBindingEventObserved = false;
private static boolean singleBindingEventObserved = false;
- public void observesEvent(@Observes @Role("Admin") @Tame MultiBindingType
someEvent)
+ public void observesEvent(@Observes @Role("Admin") @Tame MultiBindingEvent
someEvent)
{
multiBindingEventObserved = true;
}
- public void observesMoreEvent(@Observes @Tame MultiBindingType someEvent)
+ public void observesMoreEvent(@Observes @Tame MultiBindingEvent someEvent)
{
singleBindingEventObserved = true;
}
@@ -26,4 +26,10 @@
{
return singleBindingEventObserved;
}
+
+ public static void reset()
+ {
+ multiBindingEventObserved = false;
+ singleBindingEventObserved = false;
+ }
}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledDeploymentType.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledDeploymentType.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledDeploymentType.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -0,0 +1,20 @@
+package org.jboss.jsr299.tck.tests.event;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.deployment.DeploymentType;
+
+@Target( { TYPE, METHOD })
+@Retention(RUNTIME)
+@Documented
+@DeploymentType
+@interface DisabledDeploymentType
+{
+
+}
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledStringObserver.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledStringObserver.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DisabledStringObserver.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -0,0 +1,15 @@
+package org.jboss.jsr299.tck.tests.event;
+
+import javax.event.Observes;
+
+@DisabledDeploymentType
+class DisabledStringObserver
+{
+ public void disabledObserver(@Observes String event)
+ {
+ if ("fail if disable observer invoked".equals(event))
+ {
+ assert false : "This observer should not be invoked since it resides on a
bean which is disabled";
+ }
+ }
+}
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DogWhisperer.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DogWhisperer.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/DogWhisperer.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -0,0 +1,14 @@
+package org.jboss.jsr299.tck.tests.event;
+
+import javax.enterprise.inject.Any;
+import javax.event.Event;
+
+class DogWhisperer
+{
+ private @Any Event<MultiBindingEvent> event;
+
+ public void issueTamingCommand()
+ {
+ event.fire(new MultiBindingEvent(), new TameAnnotationLiteral(), new
RoleBinding("Admin"));
+ }
+}
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-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/EventTest.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,4 +1,3 @@
-
package org.jboss.jsr299.tck.tests.event;
import java.lang.annotation.Annotation;
@@ -29,13 +28,15 @@
* @author Nicklas Karlsson
* @author David Allen
*
- * Spec version: Public Release Draft 2
+ * Spec version: Public Release Draft 2
*/
@Artifact
@BeansXml("beans.xml")
public class EventTest extends AbstractJSR299Test
{
-
+ private static final String FIRE_EVENT_METHOD_NAME = "fireEvent";
+ private static final String RESOLVE_OBSERVERS_METHOD_NAME =
"resolveObservers";
+
public static class AnEventType
{
}
@@ -92,27 +93,27 @@
/**
* An event binding type is a Java annotation defined as @Target({FIELD,
* PARAMETER}) ~or @Target({METHOD, FIELD, PARAMETER, TYPE}) and
- *
- * @Retention(RUNTIME)~
+ * @Retention(RUNTIME)~. All event binding types must specify the
+ * @BindingType meta-annotation.
*/
@Test(groups = { "events" })
- @SpecAssertions( { @SpecAssertion(section = "7.1", id = "d") })
+ @SpecAssertion(section = "10.1", id = "d")
public void testEventBindingTypeTargetMostAndRuntime()
{
- getCurrentManager().fireEvent("event", new TameAnnotationLiteral());
+ getCurrentManager().fireEvent("string event", new
TameAnnotationLiteral());
}
/**
* An event binding type is a Java annotation defined as ~@Target({FIELD,
* PARAMETER}) or~ @Target({METHOD, FIELD, PARAMETER, TYPE}) ~and
- *
- * @Retention(RUNTIME)~
+ * @Retention(RUNTIME)~. All event binding types must specify the
+ * @BindingType meta-annotation.
*/
@Test(groups = { "events" })
- @SpecAssertions( { @SpecAssertion(section = "7.1", id = "e") })
+ @SpecAssertion(section = "10.1", id = "e")
public void testEventBindingTypeTargetsFieldParameterAndRuntime()
{
- getCurrentManager().fireEvent("event", new
RoleBinding("Admin"));
+ getCurrentManager().fireEvent("string event", new
RoleBinding("Admin"));
}
/**
@@ -120,23 +121,28 @@
* PARAMETER}) or @Target({METHOD, FIELD, PARAMETER, TYPE}) and
* ~@Retention(RUNTIME)
*/
- @Test(groups = { "events", "ri-broken" }, expectedExceptions = {
IllegalArgumentException.class } )
- @SpecAssertions( { @SpecAssertion(section = "7.1", id = "f") })
+ @Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class } )
+ @SpecAssertion(section = "10.1", id = "f")
public void testEventBindingTypeNotRuntime()
{
- //TODO This should throw an exception since by definition this is not an event
binding type
- getCurrentManager().fireEvent("event", new
AnnotationLiteral<BindingNotRuntime>(){});
+ getCurrentManager().fireEvent("string event", new
AnnotationLiteral<BindingTypeNotRuntime>(){});
}
@Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class } )
- @SpecAssertions( { @SpecAssertion(section = "7.1", id = "g") })
- public void testEventBindingTypesSpecifyBinding()
+ @SpecAssertions({
+ @SpecAssertion(section = "10.1", id = "g"),
+ @SpecAssertion(section = "11.2.8", id = "e")
+ })
+ public void testManagerFireEventWithNonBindingAnnotationsFails()
{
- getCurrentManager().fireEvent("event", new
AnnotationLiteral<NotABindingType>(){});
+ getCurrentManager().fireEvent("string event", new
AnnotationLiteral<NotABindingType>(){});
}
@Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class })
- @SpecAssertions( { @SpecAssertion(section = "7.1", id = "a"),
@SpecAssertion(section = "7.2", id = "b") })
+ @SpecAssertions({
+ @SpecAssertion(section = "10.1", id = "aa"),
+ @SpecAssertion(section = "11.2.8", id = "c")
+ })
public void testManagerFireEventWithEventTypeParametersFails()
{
ATemplatedEventType<String> anEvent = new
ATemplatedEventType<String>();
@@ -144,37 +150,35 @@
}
@Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class })
- @SpecAssertions( { @SpecAssertion(section = "7.1", id = "b"),
@SpecAssertion(section = "7.2", id = "c") })
+ @SpecAssertions({
+ @SpecAssertion(section = "10.1", id = "aa"),
+ @SpecAssertion(section = "11.2.8", id = "c")
+ })
public void testManagerFireEventWithEventTypeWildcardsFails()
{
ATemplatedEventType<?> anEventOnAnyType = new
ATemplatedEventType<String>();
getCurrentManager().fireEvent(anEventOnAnyType);
}
+ @Test(groups = { "events" }, expectedExceptions = {
DuplicateBindingTypeException.class })
+ @SpecAssertion(section = "11.2.8", id = "d")
+ public void testDuplicateBindingsToFireEventFails() throws Exception
+ {
+ getCurrentManager().fireEvent("string event", new
TameAnnotationLiteral(), new TameAnnotationLiteral());
+ }
+
@Test(groups = { "events" })
- @SpecAssertions( { @SpecAssertion(section = "7.2", id = "a") })
+ @SpecAssertion(section = "11.2.8", id = "a")
public void testManagerInterfaceForFireEventMethod() throws Exception
{
- assert BeanManager.class.getDeclaredMethod("fireEvent", Object.class,
Annotation[].class) != null;
+ assert BeanManager.class.getDeclaredMethod(FIRE_EVENT_METHOD_NAME, Object.class,
Annotation[].class) != null;
}
- @Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class })
- @SpecAssertions( { @SpecAssertion(section = "7.2", id = "d") })
- public void testManagerFireEventWithNonBindingAnnotationsFails()
- {
- // The specs are not exactly clear on what is supposed to happen here,
- // but borrowing from Section 8.3, we'll expect the same behavior here
- // for a consistent API.
- // TODO Verify that fireEvent should fail on non-binding annotations
- AnEventType anEvent = new AnEventType();
- getCurrentManager().fireEvent(anEvent, new AnimalStereotypeAnnotationLiteral());
- }
-
/**
* The Manager interface provides a method for firing events:
*/
@Test(groups = { "events" })
- @SpecAssertion(section = "7.2", id = "a")
+ @SpecAssertion(section = "11.2.8", id = "a")
public void testManagerFireEvent()
{
// First a simple event with no bindings is fired
@@ -185,9 +189,8 @@
getCurrentManager().fireEvent(anEvent, new RoleBinding("Admin"));
}
- // TODO This is not an assertion but a definition which is circular
@Test(groups = { "events" })
- @SpecAssertion(section = "7.3", id = "a")
+ @SpecAssertion(section = "10.3", id = "a")
public void testObserversImplementObserverInterface()
{
Observer<String> observer = new Observer<String>()
@@ -197,88 +200,50 @@
return false;
}
};
- assert observer != null;
- }
-
- @Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class })
- @SpecAssertions( { @SpecAssertion(section = "7.3", id = "f") })
- public void testManagerAddObserverWithEventTypeParametersFails()
- {
- observerWithEventObjectContainsTypeVariables();
- }
-
- private <E> void observerWithEventObjectContainsTypeVariables()
- {
- Observer<ArrayList<E>> observer = new
Observer<ArrayList<E>>() {
-
- public boolean notify(ArrayList<E> event)
- {
- return false;
- }
-
- };
getCurrentManager().addObserver(observer);
}
- @Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class })
- @SpecAssertions( { @SpecAssertion(section = "7.3", id = "g") })
- public void testManagerAddObserverWithEventTypeWildcardsFails()
- {
- Observer<ArrayList<?>> observer = new
Observer<ArrayList<?>>() {
-
- public boolean notify(ArrayList<?> event)
- {
- return false;
- }
-
- };
- getCurrentManager().addObserver(observer);
- }
-
- @Test(groups = { "events", "underInvestigation" },
expectedExceptions = { IllegalArgumentException.class })
- @SpecAssertions( { @SpecAssertion(section = "7.3", id = "h") })
- public void testManagerRemoveObserverWithEventTypeParametersFails()
- {
- //TODO This requires passing a Class<T> corresponding to Event<T> which
is not possible
- assert false;
- }
-
- @Test(groups = { "events", "underInvestigation" },
expectedExceptions = { IllegalArgumentException.class })
- @SpecAssertions( { @SpecAssertion(section = "7.3", id = "i") })
- public void testManagerRemoveObserverWithEventTypeWildcardsFails()
- {
- //TODO This requires passing a Class<T> corresponding to Event<?> which
is not possible
- assert false;
- }
-
@Test(groups = { "events" })
- @SpecAssertions( { @SpecAssertion(section = "7.7", id = "a") })
+ @SpecAssertion(section = "11.2.9", id = "a")
public void testManagerResolveObserversSignature() throws Exception
{
- assert
getCurrentManager().getClass().getDeclaredMethod("resolveObservers",
Object.class, Annotation[].class) != null;
+ assert
getCurrentManager().getClass().getDeclaredMethod(RESOLVE_OBSERVERS_METHOD_NAME,
Object.class, Annotation[].class) != null;
}
@Test(groups = { "events" })
- @SpecAssertions( {
- @SpecAssertion(section = "7.5", id = "a"),
- @SpecAssertion(section = "7.5.2", id = "a"),
- @SpecAssertion(section = "11.2", id = "af")
+ @SpecAssertions({
+ @SpecAssertion(section = "10.5", id = "a"),
+ @SpecAssertion(section = "10.5.2", id = "a"),
+ @SpecAssertion(section = "12.3", id = "o")
})
public void testObserverMethodAutomaticallyRegistered()
{
- assert !getCurrentManager().resolveObservers("event").isEmpty();
+ assert !getCurrentManager().resolveObservers(new String()).isEmpty();
}
+
+ @Test(groups = { "events", "ri-broken" })
+ @SpecAssertion(section = "12.3", id = "o")
+ public void testObserverMethodNotAutomaticallyRegisteredForDisabledBeans()
+ {
+ Set<Observer<String>> observers =
getCurrentManager().resolveObservers(new String());
+ assert observers.size() == 2;
+ for (Observer<String> observer : observers)
+ {
+ // an assertion error will be raised if an inappropriate observer is called
+ observer.notify("fail if disable observer invoked");
+ }
+ }
@Test(groups = { "events" })
- @SpecAssertion(section = "7.5", id = "e")
- public void testMultipleObserverMethodsForSameEventOK()
+ @SpecAssertion(section = "10.5", id = "e")
+ public void testMultipleObserverMethodsForSameEventPermissible()
{
- assert getCurrentManager().resolveObservers("event").size() > 1;
+ assert getCurrentManager().resolveObservers(new String()).size() > 1;
}
@Test(groups = { "events" })
- @SpecAssertion(section = "7.5", id = "f")
- public void testMultipleObserverMethodsOnBeanOK()
+ @SpecAssertion(section = "10.5", id = "f")
+ public void testMultipleObserverMethodsOnBeanPermissible()
{
// Resolve the observers for types 1 and 2
Set<Observer<ObservedType1>> resolvedStringObservers =
getCurrentManager().resolveObservers(new ObservedType1());
@@ -289,7 +254,7 @@
}
@Test(groups = { "events", "ejb" })
- @SpecAssertion(section = "7.5", id = "d")
+ @SpecAssertion(section = "10.5", id = "d")
public void testObserverMethodOnEnterpriseBeanIsBusinessMethodOrStatic()
{
Set<Observer<EJBEvent>> observers =
getCurrentManager().resolveObservers(new EJBEvent());
@@ -297,7 +262,7 @@
}
@Test(groups = { "events" })
- @SpecAssertion(section = "7.5.1", id = "b")
+ @SpecAssertion(section = "10.5.1", id = "b")
public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
{
// Resolve registered observers with an event containing no binding types
@@ -306,78 +271,68 @@
}
@Test(groups = { "events" })
- @SpecAssertions( {
- @SpecAssertion(section = "7.5.2", id = "g"),
- @SpecAssertion(section = "7.7.1", id = "a"),
- @SpecAssertion(section = "7.7.2", id = "a")
+ @SpecAssertions( {
+ @SpecAssertion(section = "10.5.2", id = "c"),
+ @SpecAssertion(section = "10.2.1", id = "a"),
+ @SpecAssertion(section = "10.2.2", id = "a")
})
public void testObserverMethodMayHaveMultipleBindingTypes()
{
- // If we can resolve the observer with the two binding types,
- // then it worked
- Set<Observer<MultiBindingType>> resolvedObservers =
getCurrentManager().resolveObservers(new MultiBindingType(), new
RoleBinding("Admin"), new TameAnnotationLiteral());
+ // If we can resolve the observer with the two binding types, then it worked
+ Set<Observer<MultiBindingEvent>> resolvedObservers =
getCurrentManager().resolveObservers(new MultiBindingEvent(), new
RoleBinding("Admin"), new TameAnnotationLiteral());
assert resolvedObservers.size() == 2;
}
- /**
- * In addition to the event parameter, observer methods may declare
- * additional parameters, which may declare bindings. The container calls the
- * method Manager.getInstanceToInject() defined in Section 5.7.1, "Resolving
- * dependencies" to determine a value for each parameter of an observer
- * method and calls the observer method with those parameter values.
- *
- * To invoke an observer method, the container must pass the event object to
- * the event parameter and the object returned by
- * Manager.getInstanceToInject() to each of the other parameters.
- */
@Test(groups = { "events" })
- @SpecAssertions( {
- @SpecAssertion(section = "7.5.4", id = "a"),
- @SpecAssertion(section = "7.5.8", id = "j")
+ @SpecAssertions( {
+ @SpecAssertion(section = "10.5.3", id = "a"),
+ @SpecAssertion(section = "5.4.8", id = "c")
})
public void testObserverMethodReceivesInjectionsOnNonObservesParameters()
{
- getCurrentManager().fireEvent("string event");
+ getCurrentManager().fireEvent("validate injected parameters");
}
@Test(groups = { "events" })
- @SpecAssertions( {
- @SpecAssertion(section = "7.5.5", id = "a"),
- @SpecAssertion(section = "7.5.5", id = "b")
+ @SpecAssertions( {
+ @SpecAssertion(section = "10.5.4", id = "a"),
+ @SpecAssertion(section = "5.4.8", id = "b")
} )
public void testConditionalObserver() throws Exception
{
- RecluseSpider.notified = false;
+ RecluseSpider.reset();
getCurrentManager().fireEvent(new ConditionalEvent());
// Should not be notified since bean is not instantiated yet
- assert !RecluseSpider.notified;
+ 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.isNotified();
-
+ assert !bean.isInstanceNotified();
getCurrentManager().fireEvent(new ConditionalEvent());
- assert bean.isNotified();
+ assert RecluseSpider.isNotified() && bean.isInstanceNotified();
}
}.run();
+
+ RecluseSpider.reset();
}
@Test(groups = { "events" })
- @SpecAssertions( { @SpecAssertion(section = "7.5.8", id = "c"),
@SpecAssertion(section = "7.5.8", id = "g")} )
+ @SpecAssertions({
+ @SpecAssertion(section = "10.6.1", id = "c"),
+ @SpecAssertion(section = "10.6.1", id = "g")
+ })
public void testAsynchronousObserverIsAsynchronous() throws Exception
{
new RunInDependentContext()
{
-
@Override
protected void execute() throws Exception
{
@@ -390,7 +345,7 @@
}
@Test(groups = { "events" })
- @SpecAssertion(section = "7.5.8", id = "a")
+ @SpecAssertion(section = "10.6.1", id = "aa")
public void testObserverMethodRegistration()
{
// Resolve registered observers with an event containing no binding types
@@ -398,33 +353,56 @@
assert resolvedObservers.size() == 2;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertions( { @SpecAssertion(section = "7.5.8", id = "b"),
@SpecAssertion(section = "7.5.8", id = "h")} )
- public void testObserverMethodCalledImmediately()
+ @Test(groups = { "events" })
+ @SpecAssertions({
+ @SpecAssertion(section = "10.6.1", id = "b"),
+ @SpecAssertion(section = "10.6.1", id = "h")
+ })
+ public void testObserverMethodCalledImmediately() throws Exception
{
-
- assert false;
+ StaticObserver.reset();
+ new RunInDependentContext()
+ {
+ @Override
+ protected void execute() throws Exception
+ {
+ getCurrentManager().fireEvent(new Delivery());
+ assert StaticObserver.isDeliveryReceived() &&
StaticObserver.getThreadObservingEvent().equals(Thread.currentThread());
+ }
+
+ }.run();
+ StaticObserver.reset();
}
+ /**
+ * FIXME the spec doesn't follow this exactly because technically it isn't
supposed to use
+ * the bean resolution alorithm to obtain the instance, which it does.
+ */
@Test(groups = { "events" })
- @SpecAssertions( { @SpecAssertion(section = "7.5", id = "c"),
@SpecAssertion(section = "7.5.8", id = "k")} )
- public void testStaticObserverMethodInvoked()
+ @SpecAssertions({
+ @SpecAssertion(section = "10.5", id = "c"),
+ @SpecAssertion(section = "5.4.8", id = "k")
+ })
+ public void testStaticObserverMethodInvoked() throws Exception
{
- getCurrentManager().fireEvent(new Delivery());
- assert StaticObserver.isDeliveryReceived();
+ try
+ {
+
getCurrentConfiguration().getContexts().setInactive(getCurrentConfiguration().getContexts().getRequestContext());
+ StaticObserver.reset();
+ getCurrentManager().fireEvent(new Delivery());
+ assert StaticObserver.isDeliveryReceived();
+ StaticObserver.reset();
+ }
+ finally
+ {
+
getCurrentConfiguration().getContexts().setActive(getCurrentConfiguration().getContexts().getRequestContext());
+ }
}
- /**
- * Otherwise, if the observer method is non-static, the container must:
- *
- * • obtain the Bean object for the most specialized bean that specializes
- * the bean which declares the observer method, and then
- *
- */
@Test(groups = { "events" })
@SpecAssertions({
- @SpecAssertion(section = "7.5.8", id = "l"),
- @SpecAssertion(section = "4.3.2", id = "f")
+ @SpecAssertion(section = "4.3.2", id = "a"),
+ @SpecAssertion(section = "5.4.8", id = "b")
})
public void testObserverCalledOnMostSpecializedInstance()
{
@@ -433,42 +411,19 @@
assert Shop.deliveryObservedBy.equals(FarmShop.class.getName());
}
- /**
- * obtain the context object by calling Manager.getContext(), passing the
- * bean scope, then
- */
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.8", id = "m")
- public void testObserverContextRetrieved()
- {
- assert false;
- }
-
- /**
- * obtain an instance of the bean by calling Context.get(), passing the Bean
- * instance representing the bean, together with a CreationalContext unless
- * this observer method is a conditional observer method, and then
- */
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.8", id = "n")
- public void testObserverInstanceRetrievedFromContext()
- {
- assert false;
- }
-
- /**
- * if the get() method returned a non-null value, invoke the observer method
- * on the returned instance
- */
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.8", id = "o")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "5.4.8", id = "b")
public void testObserverMethodInvokedOnReturnedInstanceFromContext()
{
- assert false;
+ RecluseSpider spider = getInstanceByType(RecluseSpider.class);
+ spider.setWeb(new Web());
+ getCurrentManager().fireEvent(new ConditionalEvent());
+ assert spider.isInstanceNotified();
+ assert spider.getWeb().getRings() == 1;
}
@Test(groups = { "events" })
- @SpecAssertion(section = "7.5.8", id = "p")
+ @SpecAssertion(section = "7.5.8", id = "p") // skipped
public void testAsynchronousObserverThrowsExceptionIsLogged() throws Exception
{
new RunInDependentContext()
@@ -486,19 +441,18 @@
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.9", id = "a")
+ @SpecAssertion(section = "7.5.9", id = "a") // skipped
public void testAsynchronousObserverMethodContexts()
{
assert false;
}
@Test(groups = { "events" }, expectedExceptions = {
DuplicateBindingTypeException.class })
- @SpecAssertion(section = "7.6", id = "g")
+ @SpecAssertion(section = "11.2.8", id = "d")
public void testDuplicateBindingsToFireFails() throws Exception
{
new RunInDependentContext()
{
-
@Override
protected void execute() throws Exception
{
@@ -510,7 +464,7 @@
}
@Test(groups = { "events" }, expectedExceptions = {
DuplicateBindingTypeException.class })
- @SpecAssertion(section = "7.6", id = "g")
+ @SpecAssertion(section = "11.2.7", id = "d")
public void testDuplicateBindingsToObservesFails() throws Exception
{
new RunInDependentContext()
@@ -525,7 +479,9 @@
}.run();
}
-
+
+ // left off here
+
@Test(groups = { "events" }, expectedExceptions = {
IllegalArgumentException.class })
@SpecAssertion(section = "7.6", id = "h")
public void testNonBindingTypePassedToFireFails() throws Exception
@@ -624,13 +580,18 @@
assert eventBeans.size() == 1;
}
- // TODO The manager related tests require intercepting all calls
- // to it to verify that the correct calls are made.
- @Test(groups = { "events", "underInvestigation" })
- @SpecAssertion(section = "7.6", id = "s")
+ // FIXME the assertion is being verified indirectly by verifying outcome
+ // to verify directly, would need to mock BeanManager (very hard) or
+ // intercept the call to BeanManager#fireEvent() (equally hard)
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "10.4.1", id = "ed")
public void testFireMethodCallsManagerFireWithEventObject()
{
- assert false;
+ BullTerrier.reset();
+ getInstanceByType(DogWhisperer.class).issueTamingCommand();
+ assert BullTerrier.isMultiBindingEventObserved();
+ assert BullTerrier.isSingleBindingEventObserved();
+ BullTerrier.reset();
}
@Test(groups = { "events", "underInvestigation" })
@@ -694,13 +655,13 @@
@Test(groups = { "events" })
- @SpecAssertions( {
- @SpecAssertion(section = "7.7.2", id = "b"),
+ @SpecAssertions( {
+ @SpecAssertion(section = "7.7.2", id = "b"),
@SpecAssertion(section = "7.7.2", id = "c")
} )
public void testObserverMethodNotifiedWhenBindingsMatch()
{
- getCurrentManager().fireEvent(new MultiBindingType(), new
RoleBinding("Admin"), new TameAnnotationLiteral());
+ getCurrentManager().fireEvent(new MultiBindingEvent(), new
RoleBinding("Admin"), new TameAnnotationLiteral());
assert BullTerrier.isMultiBindingEventObserved();
assert BullTerrier.isSingleBindingEventObserved();
}
@@ -783,13 +744,13 @@
assert observers.size() == 1;
// Notify the observer so we can confirm that it
- // is a method only on StockWatcher, and not IntermediateStockWatcher
+ // is a method only on StockWatcher, and not IntermediateStockWatcher
// or IndirectStockWatcher
observers.iterator().next().notify(new StockPrice());
assert StockWatcher.getObserverClazz().equals(StockWatcher.class);
}
}.run();
- }
+ }
}
Copied:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingEvent.java (from
rev 2838,
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingType.java)
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingEvent.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingEvent.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -0,0 +1,6 @@
+package org.jboss.jsr299.tck.tests.event;
+
+class MultiBindingEvent
+{
+
+}
Deleted:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingType.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingType.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/MultiBindingType.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,6 +0,0 @@
-package org.jboss.jsr299.tck.tests.event;
-
-class MultiBindingType
-{
-
-}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Pomeranian.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Pomeranian.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Pomeranian.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -12,6 +12,10 @@
{
notificationThread = Thread.currentThread();
}
+
+ public void observerTameSimpleEvent(@Observes @Tame SimpleEventType someEvent)
+ {
+ }
public static void staticallyObserveEvent(@Observes SimpleEventType someEvent)
{
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/RecluseSpider.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/RecluseSpider.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/RecluseSpider.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,7 +1,7 @@
package org.jboss.jsr299.tck.tests.event;
import javax.enterprise.context.RequestScoped;
-import javax.event.IfExists;
+import javax.event.Notify;
import javax.event.Observes;
/**
@@ -11,15 +11,42 @@
@RequestScoped
class RecluseSpider
{
- public static boolean notified = false;
+ private static boolean notified = false;
+ private boolean instanceNotified = false;
+ private Web web;
- public void observe(@Observes @IfExists ConditionalEvent someEvent)
+ public void observe(@Observes(notifyObserver = Notify.IF_EXISTS) ConditionalEvent
someEvent)
{
notified = true;
+ instanceNotified = true;
+ if (web != null)
+ {
+ web.addRing();
+ }
}
- public boolean isNotified()
+ public boolean isInstanceNotified()
{
+ return instanceNotified;
+ }
+
+ public static boolean isNotified()
+ {
return notified;
}
+
+ public static void reset()
+ {
+ notified = false;
+ }
+
+ public void setWeb(Web web)
+ {
+ this.web = web;
+ }
+
+ public Web getWeb()
+ {
+ return this.web;
+ }
}
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Spun.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Spun.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Spun.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -0,0 +1,21 @@
+package org.jboss.jsr299.tck.tests.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.enterprise.inject.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+@interface Spun
+{
+}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/StaticObserver.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/StaticObserver.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/StaticObserver.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,16 +1,19 @@
package org.jboss.jsr299.tck.tests.event;
+import javax.enterprise.context.RequestScoped;
import javax.event.Observes;
-class StaticObserver
+@RequestScoped class StaticObserver
{
private static boolean deliveryReceived = false;
+ private static Thread threadObservingEvent = null;
public static void accept(@Observes Delivery delivery)
{
setDeliveryReceived(true);
+ setThreadObservingEvent(Thread.currentThread());
}
-
+
public static boolean isDeliveryReceived()
{
return deliveryReceived;
@@ -20,4 +23,20 @@
{
StaticObserver.deliveryReceived = deliveryReceived;
}
+
+ public static Thread getThreadObservingEvent()
+ {
+ return threadObservingEvent;
+ }
+
+ public static void setThreadObservingEvent(Thread threadObservingEvent)
+ {
+ StaticObserver.threadObservingEvent = threadObservingEvent;
+ }
+
+ public static void reset()
+ {
+ deliveryReceived = false;
+ threadObservingEvent = null;
+ }
}
Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SweeWaxbill.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SweeWaxbill.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/SweeWaxbill.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,10 +1,9 @@
package org.jboss.jsr299.tck.tests.event;
-import javax.event.Event;
import javax.enterprise.inject.Any;
+import javax.event.Event;
import javax.event.Observer;
-
class SweeWaxbill
{
@Any @Role("Admin")
@@ -12,7 +11,7 @@
public void methodThatFiresEvent()
{
- simpleEvent.fire("An event", new RoleBinding("Admin"));
+ simpleEvent.fire("string event", new RoleBinding("Admin"));
}
public void methodThatRegistersObserver()
Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Web.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Web.java
(rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/Web.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -0,0 +1,21 @@
+package org.jboss.jsr299.tck.tests.event;
+
+@Spun class Web
+{
+ private int rings = 0;
+
+ public void addRing()
+ {
+ this.rings++;
+ }
+
+ public void setRings(int rings)
+ {
+ this.rings = rings;
+ }
+
+ public int getRings()
+ {
+ return this.rings;
+ }
+}
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/event1/FiresOnNonEventTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/event1/FiresOnNonEventTest.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/event1/FiresOnNonEventTest.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -9,7 +9,7 @@
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
@@ -20,9 +20,9 @@
import org.hibernate.tck.annotations.SpecAssertion;
import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.jsr299.tck.api.DefinitionError;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ExpectedDeploymentException;
-import org.jboss.jsr299.tck.api.DefinitionError;
import org.testng.annotations.Test;
/**
@@ -30,7 +30,6 @@
* not an Event type.
*
* @author David Allen
- *
*/
@Artifact
@ExpectedDeploymentException(DefinitionError.class)
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/AsynchronousBeforeCompletionObserverTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/AsynchronousBeforeCompletionObserverTest.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/AsynchronousBeforeCompletionObserverTest.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -9,37 +9,36 @@
* You may obtain a copy of the License at
*
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.jboss.jsr299.tck.tests.event.broken.observer8;
-
import org.hibernate.tck.annotations.SpecAssertion;
import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.jsr299.tck.api.DefinitionError;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ExpectedDeploymentException;
-import org.jboss.jsr299.tck.api.DefinitionError;
import org.testng.annotations.Test;
/**
* Tests an asynchronous observer method that is also a
* transactional observer for the before completion phase.
*
+ * Spec version: 20090519
+ *
* @author David Allen
- *
*/
@Artifact
@ExpectedDeploymentException(DefinitionError.class)
public class AsynchronousBeforeCompletionObserverTest extends AbstractJSR299Test
{
@Test(groups = { "events" })
- @SpecAssertion(section = "7.5.7", id = "d")
+ @SpecAssertion(section = "10.5.6", id = "b")
public void testAsynchronousObserverAsBeforeCompletionObserverFails()
{
assert false;
}
-}
+}
\ No newline at end of file
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/Terrier.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/Terrier.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer8/Terrier.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,13 +1,12 @@
package org.jboss.jsr299.tck.tests.event.broken.observer8;
-import javax.event.Asynchronously;
import javax.event.BeforeTransactionCompletion;
+import javax.event.Notify;
import javax.event.Observes;
class Terrier
{
- public void observer(@Observes @Asynchronously @BeforeTransactionCompletion String
event)
+ public void observer(@Observes(notifyObserver = Notify.ASYNCHRONOUSLY)
@BeforeTransactionCompletion String event)
{
-
}
}
Deleted:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/AsynchronousConditionalObserverTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/AsynchronousConditionalObserverTest.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/AsynchronousConditionalObserverTest.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,45 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.jboss.jsr299.tck.tests.event.broken.observer9;
-
-
-import org.hibernate.tck.annotations.SpecAssertion;
-import org.jboss.jsr299.tck.AbstractJSR299Test;
-import org.jboss.testharness.impl.packaging.Artifact;
-import org.jboss.testharness.impl.packaging.ExpectedDeploymentException;
-import org.jboss.jsr299.tck.api.DefinitionError;
-import org.testng.annotations.Test;
-
-/**
- * Tests an observer method that is both conditional and
- * asynchronous, which is not allowed.
- *
- * @author David Allen
- *
- */
-@Artifact
-(a)ExpectedDeploymentException(DefinitionError.class)
-public class AsynchronousConditionalObserverTest extends AbstractJSR299Test
-{
- @Test(groups = { "events" })
- @SpecAssertion(section = "7.5.7", id = "e")
- public void testAsynchronousObserverAsConditionalObserverFails()
- {
- assert false;
- }
-}
Deleted:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/Terrier.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/Terrier.java 2009-06-23
02:38:25 UTC (rev 2860)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/event/broken/observer9/Terrier.java 2009-06-23
02:41:14 UTC (rev 2861)
@@ -1,13 +0,0 @@
-package org.jboss.jsr299.tck.tests.event.broken.observer9;
-
-import javax.event.Asynchronously;
-import javax.event.IfExists;
-import javax.event.Observes;
-
-class Terrier
-{
- public void observer(@Observes @Asynchronously @IfExists String event)
- {
-
- }
-}