Author: pete.muir(a)jboss.org
Date: 2008-12-07 09:32:47 -0500 (Sun, 07 Dec 2008)
New Revision: 433
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bindings/InitializedBinding.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserver.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesApplicationContext.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesRequestContext.java
Removed:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InitializationTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java
Log:
Use all api types when looking for observers, support for discovering observer methods at
bootstrap, initialized event
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -118,6 +118,11 @@
{
return getAnnotatedItem().getAnnotatedFields(Observable.class);
}
+
+ public Set<AnnotatedMethod<Object>> getObserverMethods()
+ {
+ return getAnnotatedItem().getMethodsWithAnnotatedParameters(Observes.class);
+ }
/**
* Initializes the injection points
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bindings/InitializedBinding.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bindings/InitializedBinding.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bindings/InitializedBinding.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.bindings;
+
+import javax.webbeans.AnnotationLiteral;
+import javax.webbeans.manager.Initialized;
+
+public class InitializedBinding extends AnnotationLiteral<Initialized> implements
Initialized
+{
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bindings/InitializedBinding.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -19,13 +19,19 @@
import static org.jboss.webbeans.util.BeanFactory.createEnterpriseBean;
import static org.jboss.webbeans.util.BeanFactory.createEventBean;
+import static org.jboss.webbeans.util.BeanFactory.createObserver;
import static org.jboss.webbeans.util.BeanFactory.createProducerMethodBean;
import static org.jboss.webbeans.util.BeanFactory.createSimpleBean;
+import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
+import javax.webbeans.DefinitionException;
+import javax.webbeans.Observer;
+import javax.webbeans.Observes;
+
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.MetaDataCache;
@@ -33,7 +39,9 @@
import org.jboss.webbeans.bean.AbstractClassBean;
import org.jboss.webbeans.bean.EventBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bindings.InitializedBinding;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
+import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.log.LogProvider;
@@ -131,13 +139,28 @@
ProducerMethodBean<?> producerMethodBean =
createProducerMethodBean(producerMethod, bean);
beans.add(producerMethodBean);
CurrentManager.rootManager().getResolver().addInjectionPoints(producerMethodBean.getInjectionPoints());
+ log.info("Web Bean: " + producerMethodBean);
}
for (AnnotatedField<Object> eventField : bean.getEventFields())
{
EventBean<?> eventBean = createEventBean(eventField);
beans.add(eventBean);
CurrentManager.rootManager().getResolver().addInjectionPoints(eventBean.getInjectionPoints());
+ log.info("Web Bean: " + eventBean);
}
+ for (AnnotatedMethod<Object> observerMethod : bean.getObserverMethods())
+ {
+ ObserverImpl<?> observer = createObserver(observerMethod, bean);
+ if (observerMethod.getAnnotatedParameters(Observes.class).size() == 1)
+ {
+ registerObserver(observer,
observerMethod.getAnnotatedParameters(Observes.class).get(0).getType(),
observerMethod.getAnnotatedParameters(Observes.class).get(0).getBindingTypesAsArray());
+ }
+ else
+ {
+ throw new DefinitionException("Observer method can only have one
parameter annotated @Observes " + observer);
+ }
+
+ }
log.info("Web Bean: " + bean);
}
return beans;
@@ -162,6 +185,8 @@
registerBeans(webBeanDiscovery.discoverWebBeanClasses());
log.info("Validing Web Bean injection points");
CurrentManager.rootManager().getResolver().resolveInjectionPoints();
+ CurrentManager.rootManager().fireEvent(CurrentManager.rootManager(), new
InitializedBinding());
+ log.info("Web Beans RI initialized");
}
/**
@@ -205,5 +230,11 @@
}
return webBeanDiscoveryClasses;
}
+
+ @SuppressWarnings("unchecked")
+ private static <T> void registerObserver(Observer<T> observer,
Class<?> eventType, Annotation[] bindings)
+ {
+ CurrentManager.rootManager().addObserver(observer, (Class<T>) eventType,
bindings);
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -33,6 +33,7 @@
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.transaction.TransactionListener;
import org.jboss.webbeans.util.JNDI;
+import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
import com.google.common.collect.ForwardingMap;
@@ -176,11 +177,14 @@
public <T> Set<Observer<T>> getObservers(T event, Annotation...
bindings)
{
Set<Observer<T>> interestedObservers = new
HashSet<Observer<T>>();
- for (EventObserver<?> observer : registeredObservers.get(event.getClass()))
+ for (Class<?> clazz : Reflections.getTypeHierachy(event.getClass()))
{
- if (observer.isObserverInterested(bindings))
+ for (EventObserver<?> observer : registeredObservers.get(clazz))
{
- interestedObservers.add((Observer<T>) observer.getObserver());
+ if (observer.isObserverInterested(bindings))
+ {
+ interestedObservers.add((Observer<T>) observer.getObserver());
+ }
}
}
return interestedObservers;
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-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -24,6 +24,7 @@
import javax.webbeans.Observer;
import org.jboss.webbeans.MetaDataCache;
+import org.jboss.webbeans.util.Strings;
/**
* <p>
@@ -183,5 +184,16 @@
}
return true;
}
+
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Event Observer:\n");
+ buffer.append(" Event Type: " + eventType.getName() +"\n");
+ buffer.append(Strings.collectionToString(" Event Bindings: ",
eventBindings));
+ buffer.append(" Observer: " + observer);
+ return buffer.toString();
+ }
}
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-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -55,11 +55,11 @@
{
private Bean<?> observerBean;
private final AnnotatedMethod<Object> observerMethod;
- private final Class<T> eventType;
private TransactionObservationPhase transactionObservationPhase;
private boolean conditional;
private ManagerImpl manager;
+
/**
* Creates an Observer which describes and encapsulates an observer method
* (7.5).
@@ -72,12 +72,11 @@
* @param observer The observer method to notify
* @param eventType The type of event being observed
*/
- public ObserverImpl(final ManagerImpl manager, final Bean<?> observerBean, final
AnnotatedMethod<Object> observer, final Class<T> eventType)
+ public ObserverImpl(final AnnotatedMethod<Object> observer, final Bean<?>
observerBean, final ManagerImpl manager)
{
this.manager = manager;
this.observerBean = observerBean;
this.observerMethod = observer;
- this.eventType = eventType;
initTransactionObservationPhase();
conditional = !observerMethod.getAnnotatedParameters(IfExists.class).isEmpty();
}
@@ -115,11 +114,6 @@
}
}
- public Class<T> getEventType()
- {
- return eventType;
- }
-
public void notify(final T event)
{
// Get the most specialized instance of the component
@@ -176,5 +170,15 @@
{
return transactionObservationPhase.equals(currentPhase);
}
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("Observer Implentation: \n");
+ builder.append(" Observer (Declaring) bean: " + observerBean);
+ builder.append(" Observer method: " + observerMethod);
+ return builder.toString();
+ }
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -81,13 +81,22 @@
public AnnotatedConstructor<T> getConstructor(List<Class<?>>
arguments);
/**
- * Gets all members annotated with annotationType
+ * Gets all methods annotated with annotationType
*
* @param annotationType The annotation to match
* @return A set of abstracted methods with the given annotation. Returns an
* empty set if there are no matches
*/
public Set<AnnotatedMethod<Object>> getAnnotatedMethods(Class<? extends
Annotation> annotationType);
+
+ /**
+ * Gets all with parameters annotated with annotationType
+ *
+ * @param annotationType The annotation to match
+ * @return A set of abstracted methods with the given annotation. Returns an
+ * empty set if there are no matches
+ */
+ public Set<AnnotatedMethod<Object>>
getMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType);
/**
* Gets the superclass
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -19,8 +19,15 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Set;
+import javax.webbeans.BindingType;
+import javax.webbeans.DeploymentType;
+import javax.webbeans.ScopeType;
+import javax.webbeans.Stereotype;
+
/**
* AnnotatedItem provides a uniform access to the annotations on an annotated
* item defined either in Java or XML
@@ -30,6 +37,11 @@
*/
public interface AnnotatedItem<T, S>
{
+
+// The set of meta-annotations to map
+ @SuppressWarnings("unchecked")
+ public static final Set<Class<? extends Annotation>>
MAPPED_METAANNOTATIONS = new HashSet<Class<? extends
Annotation>>(Arrays.asList(BindingType.class, DeploymentType.class,
Stereotype.class, ScopeType.class));
+
/**
* Gets all annotations on the item
*
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -19,8 +19,18 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import javax.webbeans.AfterTransactionCompletion;
+import javax.webbeans.AfterTransactionFailure;
+import javax.webbeans.AfterTransactionSuccess;
+import javax.webbeans.BeforeTransactionCompletion;
+import javax.webbeans.Disposes;
+import javax.webbeans.IfExists;
+import javax.webbeans.Observes;
import javax.webbeans.manager.Manager;
/**
@@ -32,6 +42,8 @@
*/
public interface AnnotatedMethod<T> extends AnnotatedItem<T, Method>
{
+
+ 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));
/**
* Gets the abstracted parameters of the method
@@ -42,9 +54,9 @@
public List<AnnotatedParameter<Object>> getParameters();
/**
- * Gets the list of annotated parameters for a given meta annotation
+ * Gets the list of annotated parameters for a given annotation
*
- * @param metaAnnotationType The meta annotation to match
+ * @param metaAnnotationType The annotation to match
* @return A set of matching parameter abstractions. Returns an empty list if
* there are no matches.
*/
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedItem.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -30,9 +30,6 @@
import java.util.Set;
import javax.webbeans.BindingType;
-import javax.webbeans.DeploymentType;
-import javax.webbeans.ScopeType;
-import javax.webbeans.Stereotype;
import javax.webbeans.manager.Manager;
import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
@@ -162,10 +159,6 @@
// The set of default binding types
private static final Set<Annotation> DEFAULT_BINDING = new
HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));
- // The set of meta-annotations to map
- @SuppressWarnings("unchecked")
- private static final Set<Class<? extends Annotation>>
MAPPED_METAANNOTATIONS = new HashSet<Class<? extends
Annotation>>(Arrays.asList(BindingType.class, DeploymentType.class,
Stereotype.class, ScopeType.class));
-
// Cached string representation
private String toString;
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedClassImpl.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -137,6 +137,7 @@
}
methods.add(value);
}
+
}
/**
@@ -224,6 +225,8 @@
private final Set<AnnotatedMethod<Object>> methods;
// The map from annotation type to abstracted method with annotation
private final AnnotatedMethodMap annotatedMethods;
+ // The map from annotation type to method with a parameter with annotation
+ private final AnnotatedMethodMap methodsByAnnotatedParameters;
// The set of abstracted constructors
private final Set<AnnotatedConstructor<T>> constructors;
@@ -234,6 +237,7 @@
// Cached string representation
private String toString;
+
/**
* Constructor
@@ -309,6 +313,7 @@
this.methods = new HashSet<AnnotatedMethod<Object>>();
this.annotatedMethods = new AnnotatedMethodMap();
+ this.methodsByAnnotatedParameters = new AnnotatedMethodMap();
for (Class<?> c = clazz; c != Object.class && c != null; c =
c.getSuperclass())
{
for (Method method : clazz.getDeclaredMethods())
@@ -328,6 +333,13 @@
}
annotatedMethods.get(annotation.annotationType()).add(annotatedMethod);
}
+ for (Class<? extends Annotation> annotationType :
AnnotatedMethod.MAPPED_PARAMETER_ANNOTATIONS)
+ {
+ if (annotatedMethod.getAnnotatedParameters(annotationType).size() > 0)
+ {
+ methodsByAnnotatedParameters.put(annotationType, annotatedMethod);
+ }
+ }
}
}
}
@@ -485,6 +497,11 @@
{
return constructorsByArgumentMap.get(arguments);
}
+
+ public Set<AnnotatedMethod<Object>>
getMethodsWithAnnotatedParameters(Class<? extends Annotation> annotationType)
+ {
+ return methodsByAnnotatedParameters.get(annotationType);
+ }
/**
* Gets a string representation of the constructor
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedMethodImpl.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -46,6 +46,7 @@
*/
public class AnnotatedMethodImpl<T> extends AbstractAnnotatedMember<T,
Method> implements AnnotatedMethod<T>
{
+
// The actual type arguments
private final Type[] actualTypeArguments;
// The underlying method
@@ -101,7 +102,10 @@
this.parameters.add(parameter);
for (Annotation annotation : parameter.getAnnotations())
{
- annotatedParameters.put(annotation.annotationType(), parameter);
+ if (MAPPED_PARAMETER_ANNOTATIONS.contains(annotation.annotationType()))
+ {
+ annotatedParameters.put(annotation.annotationType(), parameter);
+ }
}
}
else
@@ -109,10 +113,6 @@
Class<? extends Object> clazz = method.getParameterTypes()[i];
AnnotatedParameter<Object> parameter = new
AnnotatedParameterImpl<Object>(new Annotation[0], (Class<Object>) clazz);
this.parameters.add(parameter);
- for (Annotation annotation : parameter.getAnnotations())
- {
- annotatedParameters.put(annotation.annotationType(), parameter);
- }
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java 2008-12-07
12:16:02 UTC (rev 432)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -27,6 +27,7 @@
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bean.XmlEnterpriseBean;
import org.jboss.webbeans.bean.XmlSimpleBean;
+import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -122,5 +123,10 @@
{
return new EventBean<T>(field, CurrentManager.rootManager());
}
+
+ public static <T> ObserverImpl<T>
createObserver(AnnotatedMethod<Object> method, AbstractClassBean<?>
declaringBean)
+ {
+ return new ObserverImpl<T>(method, declaringBean,
CurrentManager.rootManager());
+ }
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -14,6 +14,10 @@
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.ejb.DefaultEnterpriseBeanLookup;
import org.jboss.webbeans.test.beans.Elephant;
+import org.jboss.webbeans.test.beans.InitializedObserver;
+import org.jboss.webbeans.test.beans.InitializedObserverWhichUsesApplicationContext;
+import org.jboss.webbeans.test.beans.InitializedObserverWhichUsesRequestContext;
+import org.jboss.webbeans.test.beans.LadybirdSpider;
import org.jboss.webbeans.test.beans.Panther;
import org.jboss.webbeans.test.beans.Salmon;
import org.jboss.webbeans.test.beans.SeaBass;
@@ -218,4 +222,27 @@
assert classes.get(SeaBass.class) instanceof SimpleBean;
assert classes.get(Sole.class) instanceof SimpleBean;
}
+
+ @Test(groups="bootstrap")
+ public void testInitializedEvent()
+ {
+ assert !InitializedObserver.observered;
+
+ bootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserver.class)), null, null));
+
+ assert InitializedObserver.observered;
+ }
+
+ @Test(groups="bootstrap")
+ public void testRequestContextActiveDuringInitializtionEvent()
+ {
+ bootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserverWhichUsesRequestContext.class,
Tuna.class)), null, null));
+ }
+
+ @Test(groups="bootstrap")
+ public void testApplicationContextActiveDuringInitializtionEvent()
+ {
+ bootstrap.boot(new MockWebBeanDiscovery(new
HashSet<Class<?>>(Arrays.asList(InitializedObserverWhichUsesApplicationContext.class,
LadybirdSpider.class)), null, null));
+ }
+
}
Deleted:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InitializationTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InitializationTest.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InitializationTest.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -1,14 +0,0 @@
-package org.jboss.webbeans.test;
-
-import org.testng.annotations.Test;
-
-public class InitializationTest
-{
-
- @Test
- public void test()
- {
-
- }
-
-}
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -1,102 +0,0 @@
-package org.jboss.webbeans.test;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-import javax.webbeans.AnnotationLiteral;
-import javax.webbeans.Observer;
-import javax.webbeans.Observes;
-
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.bean.SimpleBean;
-import org.jboss.webbeans.event.ObserverImpl;
-import org.jboss.webbeans.introspector.AnnotatedMethod;
-import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
-import org.jboss.webbeans.introspector.jlr.AnnotatedMethodImpl;
-import org.jboss.webbeans.test.annotations.Asynchronous;
-import org.jboss.webbeans.test.mock.MockManagerImpl;
-import org.jboss.webbeans.util.BeanFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- * Unit tests for the implementation of Observer.
- *
- * @author David Allen
- *
- */
-@SpecVersion("20081024-PDR")
-public class ObserverTest
-{
- private MockManagerImpl manager;
- //private SimpleBean<Tuna> tuna;
- private SimpleBean<SampleObserver> ob;
- private AnnotatedMethod<Object> om;
- Observer<SampleEvent> observer;
-
- private static boolean notified = false;
-
- public static class SampleEvent
- {
- // Simple class used for testing
- }
-
- public static class SampleObserver
- {
-
- public void observe(@Observes @Asynchronous SampleEvent e)
- {
- // An observer method
- notified = true;
- }
-
- }
-
- public static @interface Foo {}
-
- @BeforeMethod
- public void before() throws Exception
- {
- manager = new MockManagerImpl();
- CurrentManager.setRootManager(manager);
- ob = BeanFactory.createSimpleBean(SampleObserver.class);
- manager.addBean(ob);
- Method method = SampleObserver.class.getMethod("observe",
SampleEvent.class);
- om = new AnnotatedMethodImpl<Object>(method, new
AnnotatedClassImpl<SampleObserver>(SampleObserver.class));
- observer = new ObserverImpl<SampleEvent>(manager, ob, om,
SampleEvent.class);
- Annotation annotation = method.getParameterAnnotations()[0][1];
- manager.addObserver(observer, SampleEvent.class, annotation);
- notified = false;
- }
-
- /**
- * Test method for
- * {@link org.jboss.webbeans.event.ObserverImpl#notify(javax.webbeans.Container,
java.lang.Object)}
- * .
- */
- @Test(groups = "observerMethod")
@SpecAssertion(section={"7.5.7"})
- public final void testNotify() throws Exception
- {
- SampleEvent event = new SampleEvent();
- notified = false;
- observer.notify(event);
- assert notified == true;
- }
-
- @Test(groups = "observerMethod")
@SpecAssertion(section={"7.5.7"})
- public final void testNotifyViaManager() throws Exception
- {
- notified = false;
- manager.fireEvent(new SampleEvent());
- assert notified == false;
- manager.fireEvent(new Object(), new AnnotationLiteral<Asynchronous>() {});
- assert notified == false;
- manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Foo>() {});
- assert notified == false;
- manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Asynchronous>()
{});
- assert notified == true;
- notified = false;
- manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Asynchronous>()
{}, new AnnotationLiteral<Foo>() {});
- assert notified == true;
- }
-
-}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -0,0 +1,101 @@
+package org.jboss.webbeans.test;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.webbeans.AnnotationLiteral;
+import javax.webbeans.Observer;
+import javax.webbeans.Observes;
+
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.introspector.AnnotatedMethod;
+import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.introspector.jlr.AnnotatedMethodImpl;
+import org.jboss.webbeans.test.annotations.Asynchronous;
+import org.jboss.webbeans.test.mock.MockManagerImpl;
+import org.jboss.webbeans.util.BeanFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ * Unit tests for the implementation of Observer.
+ *
+ * @author David Allen
+ *
+ */
+@SpecVersion("20081024-PDR")
+public class ObserverTest
+{
+ private MockManagerImpl manager;
+ //private SimpleBean<Tuna> tuna;
+ private SimpleBean<SampleObserver> ob;
+ private AnnotatedMethod<Object> om;
+ Observer<SampleEvent> observer;
+
+ private static boolean notified = false;
+
+ public static class SampleEvent
+ {
+ // Simple class used for testing
+ }
+
+ public static class SampleObserver
+ {
+
+ public void observe(@Observes @Asynchronous SampleEvent e)
+ {
+ // An observer method
+ notified = true;
+ }
+
+ }
+
+ public static @interface Foo {}
+
+ @BeforeMethod
+ public void before() throws Exception
+ {
+ manager = new MockManagerImpl();
+ CurrentManager.setRootManager(manager);
+ ob = BeanFactory.createSimpleBean(SampleObserver.class);
+ manager.addBean(ob);
+ Method method = SampleObserver.class.getMethod("observe",
SampleEvent.class);
+ om = new AnnotatedMethodImpl<Object>(method, new
AnnotatedClassImpl<SampleObserver>(SampleObserver.class));
+ observer = BeanFactory.createObserver( om, ob);
+ Annotation annotation = method.getParameterAnnotations()[0][1];
+ manager.addObserver(observer, SampleEvent.class, annotation);
+ notified = false;
+ }
+
+ /**
+ * Test method for
+ * {@link org.jboss.webbeans.event.ObserverImpl#notify(javax.webbeans.Container,
java.lang.Object)}
+ * .
+ */
+ @Test(groups = "observerMethod")
@SpecAssertion(section={"7.5.7"})
+ public final void testNotify() throws Exception
+ {
+ SampleEvent event = new SampleEvent();
+ notified = false;
+ observer.notify(event);
+ assert notified == true;
+ }
+
+ @Test(groups = "observerMethod")
@SpecAssertion(section={"7.5.7"})
+ public final void testNotifyViaManager() throws Exception
+ {
+ notified = false;
+ manager.fireEvent(new SampleEvent());
+ assert notified == false;
+ manager.fireEvent(new Object(), new AnnotationLiteral<Asynchronous>() {});
+ assert notified == false;
+ manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Foo>() {});
+ assert notified == false;
+ manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Asynchronous>()
{});
+ assert notified == true;
+ notified = false;
+ manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Asynchronous>()
{}, new AnnotationLiteral<Foo>() {});
+ assert notified == true;
+ }
+
+}
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserver.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserver.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserver.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+public class InitializedObserver
+{
+
+ public static boolean observered;
+
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ observered = true;
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserver.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesApplicationContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesApplicationContext.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesApplicationContext.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -0,0 +1,18 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Current;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+public class InitializedObserverWhichUsesApplicationContext
+{
+
+ @Current LadybirdSpider spider;
+
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ spider.spinWeb();
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesApplicationContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesRequestContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesRequestContext.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesRequestContext.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -0,0 +1,18 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Current;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+public class InitializedObserverWhichUsesRequestContext
+{
+
+ @Current Tuna tuna;
+
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ tuna.getName();
+ }
+
+}
Property changes on:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/InitializedObserverWhichUsesRequestContext.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java 2008-12-07
12:16:02 UTC (rev 432)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/LadybirdSpider.java 2008-12-07
14:32:47 UTC (rev 433)
@@ -6,4 +6,9 @@
public class LadybirdSpider extends Spider
{
+ public void spinWeb()
+ {
+
+ }
+
}