[webbeans-commits] Webbeans SVN: r183 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 14:47:42 -0400 (Mon, 27 Oct 2008)
New Revision: 183
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
Log:
Add tests
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2008-10-27 14:40:29 UTC (rev 182)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2008-10-27 18:47:42 UTC (rev 183)
@@ -31,7 +31,7 @@
public class InstantiationByTypeTest extends AbstractTest
{
- @Test(groups="resolution") @SpecAssertion(section="4.9")
+ @Test(groups={"resolution", "beanLifecycle"}) @SpecAssertion(section="4.9")
public void testCurrentBindingTypeAssumed()
{
assert false;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java 2008-10-27 14:40:29 UTC (rev 182)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java 2008-10-27 18:47:42 UTC (rev 183)
@@ -5,12 +5,16 @@
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.BeanImpl;
+import org.jboss.webbeans.ResolutionManager;
+import org.jboss.webbeans.injectable.InjectableField;
import org.jboss.webbeans.introspector.SimpleAnnotatedType;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.beans.Cod;
+import org.jboss.webbeans.test.beans.FishFarm;
import org.jboss.webbeans.test.beans.Haddock;
import org.jboss.webbeans.test.beans.Plaice;
import org.jboss.webbeans.test.beans.Salmon;
+import org.jboss.webbeans.test.beans.ScottishFish;
import org.jboss.webbeans.test.beans.SeaBass;
import org.jboss.webbeans.test.beans.Sole;
import org.jboss.webbeans.test.beans.Tuna;
@@ -70,9 +74,18 @@
}
@Test(groups="resolution") @SpecAssertion(section="4.10.1")
- public void testNoWebBeansFound()
+ public void testNoWebBeansFound() throws Exception
{
- assert false;
+ InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ manager.addBean(codBean);
+ manager.addBean(salmonBean);
+
+ ResolutionManager resolutionManager = manager.getResolutionManager();
+ resolutionManager.addInjectionPoint(whiteScottishFishField);
+
+ assert manager.resolveByName("foo").size() == 0;
}
/*
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 14:40:29 UTC (rev 182)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 18:47:42 UTC (rev 183)
@@ -236,9 +236,20 @@
}
@Test(groups="resolution") @SpecAssertion(section="4.9.2")
- public void testNoWebBeansFound()
+ public void testNoWebBeansFound() throws Exception
{
- assert false;
+ InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
+ Bean<Cod> plaiceBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ manager.addBean(plaiceBean);
+ manager.addBean(salmonBean);
+ manager.addBean(soleBean);
+
+ ResolutionManager resolutionManager = manager.getResolutionManager();
+ resolutionManager.addInjectionPoint(whiteScottishFishField);
+
+ assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).size() == 0;
}
@Test(groups="resolution") @SpecAssertion(section="4.9.2")
16 years, 1 month
[webbeans-commits] Webbeans SVN: r182 - in ri/trunk/webbeans-ri: src/main/java/org/jboss/webbeans and 5 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 10:40:29 -0400 (Mon, 27 Oct 2008)
New Revision: 182
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/ResolverInjectable.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerExpressionBeanModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
ri/trunk/webbeans-ri/testng.xml
Log:
Start to fix corner cases in resolution and instantiation
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -27,7 +27,7 @@
import org.jboss.webbeans.exceptions.NameResolutionLocation;
import org.jboss.webbeans.exceptions.TypesafeResolutionLocation;
import org.jboss.webbeans.injectable.Injectable;
-import org.jboss.webbeans.injectable.SimpleInjectable;
+import org.jboss.webbeans.injectable.ResolverInjectable;
import org.jboss.webbeans.util.ClientProxy;
public class ManagerImpl implements Manager
@@ -112,13 +112,13 @@
public <T> Set<Bean<T>> resolveByType(Class<T> type,
Annotation... bindingTypes)
{
- return resolveByType(new SimpleInjectable<T>(type, bindingTypes));
+ return resolveByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
}
public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType,
Annotation... bindingTypes)
{
- return resolveByType(new SimpleInjectable<T>(apiType, bindingTypes));
+ return resolveByType(new ResolverInjectable<T>(apiType, bindingTypes, getModelManager()));
}
private <T> Set<Bean<T>> resolveByType(Injectable<T, ?> injectable)
@@ -221,12 +221,12 @@
public <T> T getInstanceByType(Class<T> type, Annotation... bindingTypes)
{
- return getInstanceByType(new SimpleInjectable<T>(type, bindingTypes));
+ return getInstanceByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
}
public <T> T getInstanceByType(TypeLiteral<T> type, Annotation... bindingTypes)
{
- return getInstanceByType(new SimpleInjectable<T>(type, bindingTypes));
+ return getInstanceByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
}
private <T> T getInstanceByType(Injectable<T, ?> injectable)
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -5,6 +5,7 @@
import java.util.Map;
import org.jboss.webbeans.model.AnnotationModel;
+import org.jboss.webbeans.model.BindingTypeModel;
import org.jboss.webbeans.model.ScopeModel;
import org.jboss.webbeans.model.StereotypeModel;
import org.jboss.webbeans.model.bean.BeanModel;
@@ -22,10 +23,18 @@
super(new HashMap<Class<? extends Annotation>, T>());
}
- public <S extends Annotation> T get(Class<S> key)
+ public <S extends Annotation> T putIfAbsent(Class<S> key)
{
+ if (!containsKey(key))
+ {
+ T model = createAnnotationModel(key);
+ super.put(key, model);
+ return model;
+ }
return (T) super.get(key);
}
+
+ protected abstract <S extends Annotation> T createAnnotationModel(Class<S> type);
}
@SuppressWarnings("unchecked")
@@ -33,19 +42,45 @@
{
@Override
- public <S extends Annotation> ScopeModel<S> get(Class<S> key)
+ public <S extends Annotation> ScopeModel<S> putIfAbsent(Class<S> key)
{
- return (ScopeModel<S>) super.get(key);
+ return (ScopeModel<S>) super.putIfAbsent(key);
}
+ @Override
+ protected <S extends Annotation> ScopeModel<?> createAnnotationModel(Class<S> type)
+ {
+ return new ScopeModel<S>(type);
+ }
+
}
+ @SuppressWarnings("unchecked")
+ private class BindingTypeModelMap extends AnnotationModelMap<BindingTypeModel<?>>
+ {
+
+ @Override
+ public <S extends Annotation> BindingTypeModel<S> putIfAbsent(Class<S> key)
+ {
+ return (BindingTypeModel<S>) super.putIfAbsent(key);
+ }
+
+ @Override
+ protected <S extends Annotation> BindingTypeModel<?> createAnnotationModel(Class<S> type)
+ {
+ return new BindingTypeModel<S>(type);
+ }
+
+ }
+
private Map<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel<?>>();
private Map<Class<?>, BeanModel<?, ?>> beanModels = new HashMap<Class<?>, BeanModel<?,?>>();
private ScopeModelMap scopes = new ScopeModelMap();
+ private BindingTypeModelMap bindingTypes = new BindingTypeModelMap();
+
public void addStereotype(StereotypeModel<?> stereotype)
{
@@ -69,16 +104,14 @@
public <T extends Annotation> ScopeModel<T> getScopeModel(Class<T> scopeType)
{
- if (scopes.containsKey(scopeType))
- {
- return scopes.get(scopeType);
- }
- else
- {
- ScopeModel<T> scopeModel = new ScopeModel<T>(scopeType);
- scopes.put(scopeType, scopeModel);
- return scopeModel;
- }
+ return scopes.putIfAbsent(scopeType);
}
+
+ public <T extends Annotation> BindingTypeModel<T> getBindingTypeModel(Class<T> bindingType)
+ {
+ return bindingTypes.putIfAbsent(bindingType);
+ }
+
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -1,7 +1,6 @@
package org.jboss.webbeans.injectable;
import java.lang.annotation.Annotation;
-import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -9,7 +8,6 @@
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
import org.jboss.webbeans.introspector.AnnotatedItem;
/**
@@ -22,9 +20,6 @@
public abstract class Injectable<T, S>
{
- private static final Annotation[] DEFAULT_BINDING_ARRAY = {new CurrentAnnotationLiteral()};
- private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));
-
private AnnotatedItem<T, S> annotatedItem;
public Injectable(AnnotatedItem<T, S> annotatedItem)
@@ -34,29 +29,12 @@
public Annotation[] getBindingTypesAsArray()
{
- Annotation[] annotations = annotatedItem.getAnnotationsAsArray(BindingType.class);
- // TODO This is in the wrong place, where to put it... Probably best to wrap annotated item...
- if (annotations.length ==0)
- {
- return DEFAULT_BINDING_ARRAY;
- }
- else
- {
- return annotations;
- }
+ return annotatedItem.getAnnotationsAsArray(BindingType.class);
}
public Set<Annotation> getBindingTypes()
{
- Set<Annotation> annotations = annotatedItem.getAnnotations(BindingType.class);
- if (annotations.size() == 0)
- {
- return DEFAULT_BINDING;
- }
- else
- {
- return annotations;
- }
+ return annotatedItem.getAnnotations(BindingType.class);
}
protected Injectable() {}
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/ResolverInjectable.java (from rev 176, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/ResolverInjectable.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/ResolverInjectable.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -0,0 +1,92 @@
+package org.jboss.webbeans.injectable;
+
+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.DuplicateBindingTypeException;
+import javax.webbeans.TypeLiteral;
+
+import org.jboss.webbeans.ModelManager;
+import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
+import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
+
+/**
+ * TODO Rename this to something which implies it only ever used for resolution
+ * @author Pete Muir
+ *
+ */
+public class ResolverInjectable<T> extends Injectable<T, Object>
+{
+
+ private static final Annotation[] DEFAULT_BINDING_ARRAY = {new CurrentAnnotationLiteral()};
+ private static final Set<Annotation> DEFAULT_BINDING = new HashSet<Annotation>(Arrays.asList(DEFAULT_BINDING_ARRAY));
+
+ private boolean useDefaultBinding;
+
+ public ResolverInjectable(SimpleAnnotatedItem<T, Object> annotatedItem, ModelManager modelManager)
+ {
+ super(annotatedItem);
+ for (Annotation annotation : annotatedItem.getAnnotations())
+ {
+ if (!modelManager.getBindingTypeModel(annotation.annotationType()).isValid())
+ {
+ throw new IllegalArgumentException("Not a binding type " + annotation);
+ }
+ }
+ if (annotatedItem.getActualAnnotations().length > annotatedItem.getAnnotations(BindingType.class).size())
+ {
+ throw new DuplicateBindingTypeException(getAnnotatedItem().toString());
+ }
+
+ if (annotatedItem.getAnnotations(BindingType.class).size() == 0)
+ {
+ useDefaultBinding = true;
+ }
+ }
+
+ @Override
+ public Set<Annotation> getBindingTypes()
+ {
+ if (useDefaultBinding)
+ {
+ return DEFAULT_BINDING;
+ }
+ else
+ {
+ return super.getBindingTypes();
+ }
+ }
+
+ @Override
+ public Annotation[] getBindingTypesAsArray()
+ {
+ if (useDefaultBinding)
+ {
+ return DEFAULT_BINDING_ARRAY;
+ }
+ else
+ {
+ return super.getBindingTypesAsArray();
+ }
+ }
+
+ public ResolverInjectable(Class<T> type, Annotation[] bindingTypes, ModelManager modelManager)
+ {
+ this(new SimpleAnnotatedItem<T, Object>(bindingTypes, type), modelManager);
+ }
+
+ public ResolverInjectable(Class<T> type, Annotation[] bindingTypes, ModelManager modelManager, Type ... actualTypeArguements)
+ {
+ this(new SimpleAnnotatedItem<T, Object>(bindingTypes, type, actualTypeArguements), modelManager);
+ }
+
+ public ResolverInjectable(TypeLiteral<T> apiType, Annotation[] bindingTypes, ModelManager modelManager)
+ {
+ this(new SimpleAnnotatedItem<T, Object>(bindingTypes, apiType), modelManager);
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/ResolverInjectable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/SimpleInjectable.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -1,28 +0,0 @@
-package org.jboss.webbeans.injectable;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-
-import javax.webbeans.TypeLiteral;
-
-import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
-
-public class SimpleInjectable<T> extends Injectable<T, Object>
-{
-
- public SimpleInjectable(Class<T> type, Annotation[] bindingTypes)
- {
- super(new SimpleAnnotatedItem<T, Object>(bindingTypes, type));
- }
-
- public SimpleInjectable(Class<T> type, Annotation[] bindingTypes, Type ... actualTypeArguements)
- {
- super(new SimpleAnnotatedItem<T, Object>(bindingTypes, type, actualTypeArguements));
- }
-
- public SimpleInjectable(TypeLiteral<T> apiType, Annotation[] bindingTypes)
- {
- super(new SimpleAnnotatedItem<T, Object>(bindingTypes, apiType));
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AbstractAnnotatedItem.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -65,7 +65,7 @@
{
metaAnnotationMap = new HashMap<Class<? extends Annotation>, Set<Annotation>>();
}
- populateMetaAnnotationMap(metaAnnotationType, metaAnnotationMap, annotationMap);
+ metaAnnotationMap = populateMetaAnnotationMap(metaAnnotationType, metaAnnotationMap, annotationMap);
return metaAnnotationMap.get(metaAnnotationType);
}
@@ -73,6 +73,7 @@
{
if (annotationArray == null)
{
+ annotationArray = new Annotation[0];
annotationArray = getAnnotations(metaAnnotationType).toArray(annotationArray);
}
return annotationArray;
@@ -94,10 +95,10 @@
protected static <A extends Annotation> Map<Class<? extends Annotation>, Set<Annotation>> populateMetaAnnotationMap(
Class<A> metaAnnotationType, Map<Class<? extends Annotation>,
- Set<Annotation>> metaAnnotations,
+ Set<Annotation>> metaAnnotationMap,
Map<Class<? extends Annotation>, Annotation> annotationMap)
{
- if (!metaAnnotations.containsKey(metaAnnotationType))
+ if (!metaAnnotationMap.containsKey(metaAnnotationType))
{
Set<Annotation> s = new HashSet<Annotation>();
for (Entry<Class<? extends Annotation>, Annotation> entry : annotationMap.entrySet())
@@ -107,9 +108,9 @@
s.add(entry.getValue());
}
}
- metaAnnotations.put(metaAnnotationType, s);
+ metaAnnotationMap.put(metaAnnotationType, s);
}
- return metaAnnotations;
+ return metaAnnotationMap;
}
protected Map<Class<? extends Annotation>, Annotation> getAnnotationMap()
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedItem.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -12,19 +12,20 @@
private Type[] actualTypeArguements = new Type[0];
private Class<? extends T> type;
+ private Annotation[] actualAnnotations;
- public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap)
+ private SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap)
{
super(annotationMap);
}
- public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap, Class<? extends T> type)
+ private SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap, Class<? extends T> type)
{
super(annotationMap);
this.type = type;
}
- public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap, TypeLiteral<? extends T> apiType)
+ private SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap, TypeLiteral<? extends T> apiType)
{
super(annotationMap);
this.type = apiType.getRawType();
@@ -34,7 +35,7 @@
}
}
- public SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap, Class<? extends T> type, Type[] actualTypeArguements)
+ private SimpleAnnotatedItem(Map<Class<? extends Annotation>, Annotation> annotationMap, Class<? extends T> type, Type[] actualTypeArguements)
{
this(annotationMap, type);
this.actualTypeArguements = actualTypeArguements;
@@ -43,21 +44,25 @@
public SimpleAnnotatedItem(Annotation[] annotations)
{
this(buildAnnotationMap(annotations));
+ this.actualAnnotations = annotations;
}
public SimpleAnnotatedItem(Annotation[] annotations, Class<? extends T> type)
{
this(buildAnnotationMap(annotations), type);
+ this.actualAnnotations = annotations;
}
public SimpleAnnotatedItem(Annotation[] annotations, TypeLiteral<? extends T> apiType)
{
this(buildAnnotationMap(annotations), apiType);
+ this.actualAnnotations = annotations;
}
public SimpleAnnotatedItem(Annotation[] annotations, Class<? extends T> type, Type[] actualTypeArguements)
{
this(buildAnnotationMap(annotations), type, actualTypeArguements);
+ this.actualAnnotations = annotations;
}
public S getDelegate()
@@ -75,4 +80,9 @@
return actualTypeArguements;
}
+ public Annotation[] getActualAnnotations()
+ {
+ return actualAnnotations;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -35,7 +35,7 @@
protected void initValid()
{
- this.valid = !annotatedAnnotation.isAnnotationPresent(getMetaAnnotation());
+ this.valid = annotatedAnnotation.isAnnotationPresent(getMetaAnnotation());
}
public Class<T> getType()
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -0,0 +1,46 @@
+/*
+ * 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.webbeans.model;
+
+import java.lang.annotation.Annotation;
+
+import javax.webbeans.BindingType;
+
+/**
+ *
+ * Model of a binding type
+ *
+ * @author Pete Muir
+ *
+ */
+public class BindingTypeModel<T extends Annotation> extends AnnotationModel<T>
+{
+
+ public BindingTypeModel(Class<T> scope)
+ {
+ super(scope);
+ }
+
+ @Override
+ protected Class<? extends Annotation> getMetaAnnotation()
+ {
+ return BindingType.class;
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerExpressionBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerExpressionBeanModel.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerExpressionBeanModel.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -1,22 +1,19 @@
package org.jboss.webbeans.model.bean;
-import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.HashMap;
import javax.webbeans.Dependent;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injectable.BeanConstructor;
import org.jboss.webbeans.introspector.AnnotatedItem;
-import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
public class ProducerExpressionBeanModel<T> extends AbstractProducerBeanModel<T>
{
private AnnotatedItem<T, Method> xmlAnnotatedItem;
- private AnnotatedItem<T, Method> annotatedItem = new SimpleAnnotatedItem<T, Method>(new HashMap<Class<? extends Annotation>, Annotation>());
+ private AnnotatedItem<T, Method> annotatedItem = null /*new SimpleAnnotatedItem<T, Method>(new HashMap<Class<? extends Annotation>, Annotation>())*/;
private String location;
public ProducerExpressionBeanModel(AnnotatedItem<T, Method> xmlAnnotatedMethod, ManagerImpl container)
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/ProducerMethodBeanModel.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -5,7 +5,6 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.util.HashMap;
import java.util.Set;
import javax.webbeans.Dependent;
@@ -17,7 +16,6 @@
import org.jboss.webbeans.injectable.MethodConstructor;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
-import org.jboss.webbeans.introspector.SimpleAnnotatedItem;
import org.jboss.webbeans.util.Reflections;
public class ProducerMethodBeanModel<T> extends AbstractProducerBeanModel<T>
@@ -25,7 +23,7 @@
private MethodConstructor<T> constructor;
- private AnnotatedItem<T, Method> xmlAnnotatedItem = new SimpleAnnotatedItem<T, Method>(new HashMap<Class<? extends Annotation>, Annotation>());
+ private AnnotatedItem<T, Method> xmlAnnotatedItem = null /*new SimpleAnnotatedItem<T, Method>(new HashMap<Class<? extends Annotation>, Annotation>())*/;
private AnnotatedMethod<T> annotatedMethod;
private BeanModel<?, ?> declaringBean;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -12,18 +12,31 @@
import org.jboss.webbeans.model.bean.SimpleBeanModel;
import org.jboss.webbeans.test.beans.Cod;
import org.jboss.webbeans.test.beans.FishFarm;
+import org.jboss.webbeans.test.beans.Haddock;
+import org.jboss.webbeans.test.beans.Plaice;
import org.jboss.webbeans.test.beans.Salmon;
import org.jboss.webbeans.test.beans.ScottishFish;
+import org.jboss.webbeans.test.beans.SeaBass;
import org.jboss.webbeans.test.beans.Sole;
+import org.jboss.webbeans.test.beans.Tuna;
import org.testng.annotations.Test;
public class InstantiationByNameTest extends AbstractTest
{
@Test(groups="resolution") @SpecAssertion(section="4.10")
- public void testNoWebBeansFound()
+ public void testNoWebBeansFound() throws Exception
{
- assert false;
+ InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ manager.addBean(codBean);
+ manager.addBean(salmonBean);
+
+ ResolutionManager resolutionManager = manager.getResolutionManager();
+ resolutionManager.addInjectionPoint(whiteScottishFishField);
+
+ assert manager.getInstanceByName("foo") == null;
}
@Test(expectedExceptions=AmbiguousDependencyException.class) @SpecAssertion(section="4.10.1")
@@ -43,13 +56,29 @@
manager.getInstanceByName("whitefish");
}
- @Test(groups="resolution") @SpecAssertion(section="4.10.1")
+ @Test(groups={"resolution", "beanLifecycle"}) @SpecAssertion(section="4.10.1")
public void testGetInstanceByName()
{
- assert false;
+ Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleBeanModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), super.manager), manager);
+ Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleBeanModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), super.manager), manager);
+ Bean<Plaice> plaiceBean = new BeanImpl<Plaice>(new SimpleBeanModel<Plaice>(new SimpleAnnotatedType<Plaice>(Plaice.class), getEmptyAnnotatedType(Plaice.class), super.manager), manager);
+
+ manager.addBean(tunaBean);
+ manager.addBean(codBean);
+ manager.addBean(salmonBean);
+ manager.addBean(soleBean);
+ manager.addBean(haddockBean);
+ manager.addBean(seaBassBean);
+ manager.addBean(plaiceBean);
+
+ assert manager.getInstanceByName("salmon") instanceof Salmon;
}
- @Test(groups="resolution") @SpecAssertion(section="4.10")
+ @Test(groups={"resolution", "el"}) @SpecAssertion(section="4.10")
public void testGetInstanceByNameCalledOncePerDistinctNameInElExpression()
{
assert false;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -24,6 +24,7 @@
import org.jboss.webbeans.test.beans.Sole;
import org.jboss.webbeans.test.beans.Tuna;
import org.jboss.webbeans.test.beans.broken.PlaiceFarm;
+import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
import org.testng.annotations.Test;
@SpecVersion("PDR")
@@ -39,13 +40,13 @@
@Test(groups="resolution", expectedExceptions=DuplicateBindingTypeException.class) @SpecAssertion(section="4.9")
public void testDuplicateBindingTypesUsed()
{
- assert false;
+ manager.getInstanceByType(Tuna.class, new CurrentAnnotationLiteral(), new CurrentAnnotationLiteral());
}
@Test(groups="resolution", expectedExceptions=IllegalArgumentException.class) @SpecAssertion(section="4.9")
public void testNonBindingTypeUsed()
{
- assert false;
+ manager.getInstanceByType(Tuna.class, new AnotherDeploymentTypeAnnotationLiteral());
}
@Test(expectedExceptions=AmbiguousDependencyException.class) @SpecAssertion(section="4.9")
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 14:40:29 UTC (rev 182)
@@ -31,6 +31,7 @@
import org.jboss.webbeans.test.beans.SeaBass;
import org.jboss.webbeans.test.beans.Sole;
import org.jboss.webbeans.test.beans.Tuna;
+import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.ChunkyAnnotationLiteral;
import org.testng.annotations.Test;
@@ -63,13 +64,13 @@
@Test(groups="resolution", expectedExceptions=DuplicateBindingTypeException.class) @SpecAssertion(section="4.9.2")
public void testDuplicateBindingTypesUsed()
{
- assert false;
+ manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral(), new CurrentAnnotationLiteral());
}
@Test(groups="resolution", expectedExceptions=IllegalArgumentException.class) @SpecAssertion(section="4.9.2")
public void testNonBindingTypeUsed()
{
- assert false;
+ manager.resolveByType(Tuna.class, new AnotherDeploymentTypeAnnotationLiteral());
}
@Test
Modified: ri/trunk/webbeans-ri/testng.xml
===================================================================
--- ri/trunk/webbeans-ri/testng.xml 2008-10-27 13:48:18 UTC (rev 181)
+++ ri/trunk/webbeans-ri/testng.xml 2008-10-27 14:40:29 UTC (rev 182)
@@ -20,6 +20,8 @@
<exclude name="interceptors" />
<exclude name="innerClass" />
<exclude name="servlet" />
+ <exclude name="clientProxy" />
+ <exclude name="contexts" />
</run>
</groups>
<packages>
16 years, 1 month
[webbeans-commits] Webbeans SVN: r181 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-27 09:48:18 -0400 (Mon, 27 Oct 2008)
New Revision: 181
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PseudoContext.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
Log:
Adding PseudoContext at NormalContext level, making both abstract. Added DependentContext as implementation.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-10-27 13:16:13 UTC (rev 180)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-10-27 13:48:18 UTC (rev 181)
@@ -2,12 +2,20 @@
import java.lang.annotation.Annotation;
-public class DependentContext extends AbstractContext
+import javax.webbeans.Dependent;
+
+public class DependentContext extends PseudoContext
{
public DependentContext(Class<? extends Annotation> scopeType)
{
- super(scopeType);
+ super(Dependent.class);
}
+ @Override
+ public String toString()
+ {
+ return "Dependent context";
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-27 13:16:13 UTC (rev 180)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-27 13:48:18 UTC (rev 181)
@@ -2,7 +2,7 @@
import java.lang.annotation.Annotation;
-public class NormalContext extends AbstractContext
+public abstract class NormalContext extends AbstractContext
{
public NormalContext(Class<? extends Annotation> scopeType)
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PseudoContext.java (from rev 180, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PseudoContext.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PseudoContext.java 2008-10-27 13:48:18 UTC (rev 181)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.contexts;
+
+import java.lang.annotation.Annotation;
+
+public abstract class PseudoContext extends AbstractContext
+{
+
+ public PseudoContext(Class<? extends Annotation> scopeType)
+ {
+ super(scopeType);
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/PseudoContext.java
___________________________________________________________________
Name: svn:mergeinfo
+
16 years, 1 month
[webbeans-commits] Webbeans SVN: r180 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/introspector and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 09:16:13 -0400 (Mon, 27 Oct 2008)
New Revision: 180
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java
Log:
AnnotationModel
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-27 13:09:50 UTC (rev 179)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -207,7 +207,7 @@
Set<Bean<?>> beans = resolveByName(name);
if (beans.size() == 0)
{
- throw new UnsatisfiedDependencyException(new NameResolutionLocation(name) + "Unable to resolve any Web Beans");
+ return null;
}
else if (beans.size() > 1)
{
@@ -215,7 +215,7 @@
}
else
{
- return beans.iterator().next();
+ return getInstance(beans.iterator().next());
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java 2008-10-27 13:09:50 UTC (rev 179)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ModelManager.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.jboss.webbeans.model.AnnotationModel;
import org.jboss.webbeans.model.ScopeModel;
import org.jboss.webbeans.model.StereotypeModel;
import org.jboss.webbeans.model.bean.BeanModel;
@@ -13,30 +14,42 @@
{
@SuppressWarnings("unchecked")
- private class ScopeModelMap extends MapWrapper<Class<? extends Annotation>, ScopeModel<? extends Annotation>>
+ private abstract class AnnotationModelMap<T extends AnnotationModel<?>> extends MapWrapper<Class<? extends Annotation>, T>
{
- public ScopeModelMap()
+ public AnnotationModelMap()
{
- super(new HashMap<Class<? extends Annotation>, ScopeModel<? extends Annotation>>());
+ super(new HashMap<Class<? extends Annotation>, T>());
}
- public <T extends Annotation> ScopeModel<T> get(Class<T> key)
+ public <S extends Annotation> T get(Class<S> key)
{
- return (ScopeModel<T>) super.get(key);
+ return (T) super.get(key);
}
}
+ @SuppressWarnings("unchecked")
+ private class ScopeModelMap extends AnnotationModelMap<ScopeModel<?>>
+ {
+
+ @Override
+ public <S extends Annotation> ScopeModel<S> get(Class<S> key)
+ {
+ return (ScopeModel<S>) super.get(key);
+ }
+
+ }
+
private Map<Class<? extends Annotation>, StereotypeModel<?>> stereotypes = new HashMap<Class<? extends Annotation>, StereotypeModel<?>>();
private Map<Class<?>, BeanModel<?, ?>> beanModels = new HashMap<Class<?>, BeanModel<?,?>>();
- private ScopeModelMap scopes = new ScopeModelMap();
+ private ScopeModelMap scopes = new ScopeModelMap();
public void addStereotype(StereotypeModel<?> stereotype)
{
- stereotypes.put(stereotype.getStereotypeClass(), stereotype);
+ stereotypes.put(stereotype.getType(), stereotype);
}
public StereotypeModel<?> getStereotype(Class<? extends Annotation> annotationType)
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.introspector;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+public interface AnnotatedAnnotation<T extends Annotation> extends AnnotatedItem<T, Class<T>>
+{
+
+ /**
+ * Get all annotation members
+ * @return
+ */
+ public Set<AnnotatedMethod<?>> getMembers();
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -0,0 +1,55 @@
+package org.jboss.webbeans.introspector;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+public class SimpleAnnotatedAnnotation<T extends Annotation> extends AbstractAnnotatedItem<T, Class<T>> implements AnnotatedAnnotation<T>
+{
+
+ private Class<T> clazz;
+
+ private Set<AnnotatedMethod<?>> members;
+
+ public SimpleAnnotatedAnnotation(Class<T> annotationType)
+ {
+ super(buildAnnotationMap(annotationType));
+ this.clazz = annotationType;
+ }
+
+ public Type[] getActualTypeArguements()
+ {
+ return new Type[0];
+ }
+
+ public Set<AnnotatedMethod<?>> getMembers()
+ {
+ if (members == null)
+ {
+ initMembers();
+ }
+ return members;
+ }
+
+ public Class<T> getDelegate()
+ {
+ return clazz;
+ }
+
+ public Class<? extends T> getType()
+ {
+ return clazz;
+ }
+
+ private void initMembers()
+ {
+ this.members = new HashSet<AnnotatedMethod<?>>();
+ for (Method member : clazz.getDeclaredMethods())
+ {
+ members.add(new SimpleAnnotatedMethod<Object>(member));
+ }
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -0,0 +1,58 @@
+package org.jboss.webbeans.model;
+
+import java.lang.annotation.Annotation;
+
+import javax.webbeans.DefinitionException;
+
+import org.jboss.webbeans.introspector.AnnotatedAnnotation;
+import org.jboss.webbeans.introspector.SimpleAnnotatedAnnotation;
+
+public abstract class AnnotationModel<T extends Annotation>
+{
+
+ private AnnotatedAnnotation<T> annotatedAnnotation;
+ private boolean valid;
+
+ public AnnotationModel(Class<T> type)
+ {
+ this.annotatedAnnotation = new SimpleAnnotatedAnnotation<T>(type);
+ init();
+ }
+
+ protected void init()
+ {
+ initType();
+ initValid();
+ }
+
+ protected void initType()
+ {
+ if (!Annotation.class.isAssignableFrom(getType()))
+ {
+ throw new DefinitionException(getMetaAnnotation().toString() + " can only be applied to an annotation, it was applied to " + getType());
+ }
+ }
+
+ protected void initValid()
+ {
+ this.valid = !annotatedAnnotation.isAnnotationPresent(getMetaAnnotation());
+ }
+
+ public Class<T> getType()
+ {
+ return annotatedAnnotation.getDelegate();
+ }
+
+ protected abstract Class<? extends Annotation> getMetaAnnotation();
+
+ public boolean isValid()
+ {
+ return valid;
+ }
+
+ protected AnnotatedAnnotation<T> getAnnotatedAnnotation()
+ {
+ return annotatedAnnotation;
+ }
+
+}
\ No newline at end of file
Property changes on: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java 2008-10-27 13:09:50 UTC (rev 179)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/ScopeModel.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -18,10 +18,10 @@
package org.jboss.webbeans.model;
+import java.lang.annotation.Annotation;
+
import javax.webbeans.ScopeType;
-import org.jboss.webbeans.exceptions.NotAScopeException;
-
/**
*
* Model of a scope
@@ -29,41 +29,28 @@
* @author Pete Muir
*
*/
-public class ScopeModel<T>
+public class ScopeModel<T extends Annotation> extends AnnotationModel<T>
{
- private Class<T> scopeClass;
- private boolean normal;
- private boolean passivating;
-
public ScopeModel(Class<T> scope)
{
- if (scope.isAnnotationPresent(ScopeType.class))
- {
- ScopeType scopeType = scope.getAnnotation(ScopeType.class);
- this.scopeClass = scope;
- this.normal = scopeType.normal();
- this.passivating = scopeType.passivating();
- }
- else
- {
- throw new NotAScopeException("Scope " + scope.getName() + " is not annotated with @ScopeType");
- }
+ super(scope);
}
- public Class<T> getScopeClass()
+ public boolean isNormal()
{
- return scopeClass;
+ return getAnnotatedAnnotation().getAnnotation(ScopeType.class).normal();
}
- public boolean isNormal()
+ public boolean isPassivating()
{
- return normal;
+ return getAnnotatedAnnotation().getAnnotation(ScopeType.class).passivating();
}
- public boolean isPassivating()
+ @Override
+ protected Class<? extends Annotation> getMetaAnnotation()
{
- return passivating;
+ return ScopeType.class;
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java 2008-10-27 13:09:50 UTC (rev 179)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/StereotypeModel.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -13,18 +13,14 @@
import javax.webbeans.ScopeType;
import javax.webbeans.Stereotype;
-import org.jboss.webbeans.introspector.AnnotatedType;
-
/**
* A meta model for a stereotype, allows us to cache a stereotype and to validate it
*
* @author pmuir
*
*/
-public class StereotypeModel<T extends Annotation>
+public class StereotypeModel<T extends Annotation> extends AnnotationModel<T>
{
-
- private Class<? extends Annotation> stereotypeClass;
private Annotation defaultDeploymentType;
private Annotation defaultScopeType;
private boolean beanNameDefaulted;
@@ -32,83 +28,70 @@
private Set<Class<?>> requiredTypes;
private Set<Annotation> interceptorBindings;
- public StereotypeModel(AnnotatedType<T> annotatedClass)
+ public StereotypeModel(Class<T> sterotype)
{
- initStereotypeClass(annotatedClass);
- Stereotype stereotype = annotatedClass.getAnnotation(Stereotype.class);
- initDefaultDeploymentType(annotatedClass);
- initDefaultScopeType(annotatedClass);
- initBeanNameDefaulted(annotatedClass);
- initSupportedScopes(annotatedClass, stereotype);
- initRequiredTypes(annotatedClass, stereotype);
- initInterceptorBindings(annotatedClass);
- checkBindingTypes(annotatedClass);
+ super(sterotype);
+ initDefaultDeploymentType();
+ initDefaultScopeType();
+ initBeanNameDefaulted();
+ initSupportedScopes();
+ initRequiredTypes();
+ initInterceptorBindings();
+ checkBindingTypes();
}
- private void checkBindingTypes(AnnotatedType<T> annotatedClass)
+ private void checkBindingTypes()
{
- Set<Annotation> bindingTypes = annotatedClass.getAnnotations(BindingType.class);
+ Set<Annotation> bindingTypes = getAnnotatedAnnotation().getAnnotations(BindingType.class);
if (bindingTypes.size() > 0)
{
- throw new DefinitionException("Cannot declare binding types on a stereotype " + annotatedClass);
+ throw new DefinitionException("Cannot declare binding types on a stereotype " + getAnnotatedAnnotation());
}
}
-
- private void initStereotypeClass(AnnotatedType<T> annotatedClass)
- {
- if (Annotation.class.isAssignableFrom(annotatedClass.getAnnotatedClass()))
- {
- this.stereotypeClass = annotatedClass.getAnnotatedClass();
- }
- else
- {
- throw new RuntimeException("@Stereotype can only be applied to an annotation, it was applied to " + annotatedClass);
- }
- }
- private void initInterceptorBindings(AnnotatedType<T> annotatedClass)
+ private void initInterceptorBindings()
{
- interceptorBindings = annotatedClass.getAnnotations(InterceptorBindingType.class);
+ interceptorBindings = getAnnotatedAnnotation().getAnnotations(InterceptorBindingType.class);
}
- private void initSupportedScopes(AnnotatedType<T> annotatedElement, Stereotype stereotype)
+ private void initSupportedScopes()
{
this.supportedScopes = new HashSet<Class<? extends Annotation>>();
- Class<? extends Annotation>[] supportedScopes = stereotype.supportedScopes();
+ Class<? extends Annotation>[] supportedScopes = getAnnotatedAnnotation().getAnnotation(Stereotype.class).supportedScopes();
if (supportedScopes.length > 0)
{
this.supportedScopes.addAll(Arrays.asList(supportedScopes));
}
}
- private void initRequiredTypes(AnnotatedType<T> annotatedElement, Stereotype stereotype)
+ private void initRequiredTypes()
{
this.requiredTypes = new HashSet<Class<?>>();
- Class<?>[] requiredTypes = stereotype.requiredTypes();
+ Class<?>[] requiredTypes = getAnnotatedAnnotation().getAnnotation(Stereotype.class).requiredTypes();
if (requiredTypes.length > 0)
{
this.requiredTypes.addAll(Arrays.asList(requiredTypes));
}
}
- private void initBeanNameDefaulted(AnnotatedType<T> annotatedElement)
+ private void initBeanNameDefaulted()
{
- if (annotatedElement.isAnnotationPresent(Named.class))
+ if (getAnnotatedAnnotation().isAnnotationPresent(Named.class))
{
- if (!"".equals(annotatedElement.getAnnotation(Named.class).value()))
+ if (!"".equals(getAnnotatedAnnotation().getAnnotation(Named.class).value()))
{
- throw new DefinitionException("Cannot specify a value for a @Named stereotype " + annotatedElement);
+ throw new DefinitionException("Cannot specify a value for a @Named stereotype " + getAnnotatedAnnotation());
}
beanNameDefaulted = true;
}
}
- private void initDefaultScopeType(AnnotatedType<T> annotatedElement)
+ private void initDefaultScopeType()
{
- Set<Annotation> scopeTypes = annotatedElement.getAnnotations(ScopeType.class);
+ Set<Annotation> scopeTypes = getAnnotatedAnnotation().getAnnotations(ScopeType.class);
if (scopeTypes.size() > 1)
{
- throw new DefinitionException("At most one scope type may be specified for " + annotatedElement);
+ throw new DefinitionException("At most one scope type may be specified for " + getAnnotatedAnnotation());
}
else if (scopeTypes.size() == 1)
{
@@ -116,12 +99,12 @@
}
}
- private void initDefaultDeploymentType(AnnotatedType<T> annotatedElement)
+ private void initDefaultDeploymentType()
{
- Set<Annotation> deploymentTypes = annotatedElement.getAnnotations(DeploymentType.class);
+ Set<Annotation> deploymentTypes = getAnnotatedAnnotation().getAnnotations(DeploymentType.class);
if (deploymentTypes.size() > 1)
{
- throw new DefinitionException("At most one deployment type may be specified on " + annotatedElement);
+ throw new DefinitionException("At most one deployment type may be specified on " + getAnnotatedAnnotation());
}
else if (deploymentTypes.size() == 1)
{
@@ -183,15 +166,22 @@
return requiredTypes;
}
+ @Deprecated
public Class<? extends Annotation> getStereotypeClass()
{
- return stereotypeClass;
+ return getType();
}
@Override
public String toString()
{
- return "StereotypeModel[" + stereotypeClass.getName() + "]";
+ return "StereotypeModel[" + getType() + "]";
}
+
+ @Override
+ protected Class<? extends Annotation> getMetaAnnotation()
+ {
+ return Stereotype.class;
+ }
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-10-27 13:09:50 UTC (rev 179)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -8,7 +8,6 @@
import javax.webbeans.Standard;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.introspector.SimpleAnnotatedType;
import org.jboss.webbeans.model.StereotypeModel;
import org.jboss.webbeans.test.annotations.AnimalStereotype;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
@@ -43,12 +42,12 @@
private void initStereotypes(ManagerImpl container)
{
- container.getModelManager().addStereotype(new StereotypeModel<AnimalStereotype>(new SimpleAnnotatedType<AnimalStereotype>(AnimalStereotype.class)));
- container.getModelManager().addStereotype(new StereotypeModel<HornedMammalStereotype>(new SimpleAnnotatedType<HornedMammalStereotype>(HornedMammalStereotype.class)));
- container.getModelManager().addStereotype(new StereotypeModel<MammalStereotype>(new SimpleAnnotatedType<MammalStereotype>(MammalStereotype.class)));
- container.getModelManager().addStereotype(new StereotypeModel<FishStereotype>(new SimpleAnnotatedType<FishStereotype>(FishStereotype.class)));
- container.getModelManager().addStereotype(new StereotypeModel<RiverFishStereotype>(new SimpleAnnotatedType<RiverFishStereotype>(RiverFishStereotype.class)));
- container.getModelManager().addStereotype(new StereotypeModel<RequestScopedAnimalStereotype>(new SimpleAnnotatedType<RequestScopedAnimalStereotype>(RequestScopedAnimalStereotype.class)));
+ container.getModelManager().addStereotype(new StereotypeModel<AnimalStereotype>(AnimalStereotype.class));
+ container.getModelManager().addStereotype(new StereotypeModel<HornedMammalStereotype>(HornedMammalStereotype.class));
+ container.getModelManager().addStereotype(new StereotypeModel<MammalStereotype>(MammalStereotype.class));
+ container.getModelManager().addStereotype(new StereotypeModel<FishStereotype>(FishStereotype.class));
+ container.getModelManager().addStereotype(new StereotypeModel<RiverFishStereotype>(RiverFishStereotype.class));
+ container.getModelManager().addStereotype(new StereotypeModel<RequestScopedAnimalStereotype>(RequestScopedAnimalStereotype.class));
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java 2008-10-27 13:09:50 UTC (rev 179)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java 2008-10-27 13:16:13 UTC (rev 180)
@@ -61,7 +61,7 @@
@Test
public void testAnimalStereotype()
{
- StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(new SimpleAnnotatedType<AnimalStereotype>(AnimalStereotype.class));
+ StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(AnimalStereotype.class);
assert animalStereotype.getDefaultScopeType().annotationType().equals(RequestScoped.class);
assert animalStereotype.getInterceptorBindings().size() == 0;
assert animalStereotype.getRequiredTypes().size() == 1;
@@ -74,7 +74,7 @@
@Test
public void testAnimalOrderStereotype()
{
- StereotypeModel<AnimalOrderStereotype> animalStereotype = new StereotypeModel<AnimalOrderStereotype>(new SimpleAnnotatedType<AnimalOrderStereotype>(AnimalOrderStereotype.class));
+ StereotypeModel<AnimalOrderStereotype> animalStereotype = new StereotypeModel<AnimalOrderStereotype>(AnimalOrderStereotype.class);
assert animalStereotype.getDefaultScopeType() == null;
assert animalStereotype.getInterceptorBindings().size() == 0;
assert animalStereotype.getRequiredTypes().size() == 2;
@@ -88,7 +88,7 @@
@Test
public void testRequestScopedAnimalStereotype()
{
- StereotypeModel<RequestScopedAnimalStereotype> animalStereotype = new StereotypeModel<RequestScopedAnimalStereotype>(new SimpleAnnotatedType<RequestScopedAnimalStereotype>(RequestScopedAnimalStereotype.class));
+ StereotypeModel<RequestScopedAnimalStereotype> animalStereotype = new StereotypeModel<RequestScopedAnimalStereotype>(RequestScopedAnimalStereotype.class);
assert animalStereotype.getDefaultScopeType() == null;
assert animalStereotype.getInterceptorBindings().size() == 0;
assert animalStereotype.getRequiredTypes().size() == 1;
@@ -102,21 +102,21 @@
@Test @SpecAssertion(section="2.7.1")
public void testStereotypeWithScopeType()
{
- StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(new SimpleAnnotatedType<AnimalStereotype>(AnimalStereotype.class));
+ StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(AnimalStereotype.class);
assert animalStereotype.getDefaultScopeType().annotationType().equals(RequestScoped.class);
}
@Test @SpecAssertion(section="2.7.1")
public void testStereotypeWithoutScopeType()
{
- StereotypeModel<HornedMammalStereotype> animalStereotype = new StereotypeModel<HornedMammalStereotype>(new SimpleAnnotatedType<HornedMammalStereotype>(HornedMammalStereotype.class));
+ StereotypeModel<HornedMammalStereotype> animalStereotype = new StereotypeModel<HornedMammalStereotype>(HornedMammalStereotype.class);
assert animalStereotype.getDefaultScopeType() == null;
}
@Test @SpecAssertion(section="2.7.1")
public void testStereotypeWithoutInterceptors()
{
- StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(new SimpleAnnotatedType<AnimalStereotype>(AnimalStereotype.class));
+ StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(AnimalStereotype.class);
assert animalStereotype.getInterceptorBindings().size() == 0;
}
@@ -129,25 +129,25 @@
@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1")
public void testStereotypeWithTooManyScopeTypes()
{
- new StereotypeModel<StereotypeWithTooManyScopeTypes>(new SimpleAnnotatedType<StereotypeWithTooManyScopeTypes>(StereotypeWithTooManyScopeTypes.class));
+ new StereotypeModel<StereotypeWithTooManyScopeTypes>(StereotypeWithTooManyScopeTypes.class);
}
@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1")
public void testStereotypeWithTooManyDeploymentTypes()
{
- new StereotypeModel<StereotypeWithTooManyDeploymentTypes>(new SimpleAnnotatedType<StereotypeWithTooManyDeploymentTypes>(StereotypeWithTooManyDeploymentTypes.class));
+ new StereotypeModel<StereotypeWithTooManyDeploymentTypes>(StereotypeWithTooManyDeploymentTypes.class);
}
@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1")
public void testStereotypeWithNonEmptyNamed()
{
- new StereotypeModel<StereotypeWithNonEmptyNamed>(new SimpleAnnotatedType<StereotypeWithNonEmptyNamed>(StereotypeWithNonEmptyNamed.class));
+ new StereotypeModel<StereotypeWithNonEmptyNamed>(StereotypeWithNonEmptyNamed.class);
}
@Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1")
public void testStereotypeWithBindingTypes()
{
- new StereotypeModel<StereotypeWithBindingTypes>(new SimpleAnnotatedType<StereotypeWithBindingTypes>(StereotypeWithBindingTypes.class));
+ new StereotypeModel<StereotypeWithBindingTypes>(StereotypeWithBindingTypes.class);
}
@Test @SpecAssertion(section={"2.7.2", "2.7.4"})
16 years, 1 month
[webbeans-commits] Webbeans SVN: r179 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-27 09:09:50 -0400 (Mon, 27 Oct 2008)
New Revision: 179
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
Log:
Minor. toString for contexts, test for producer method returning null in context
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java 2008-10-27 12:07:27 UTC (rev 178)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java 2008-10-27 13:09:50 UTC (rev 179)
@@ -8,5 +8,11 @@
{
super(ApplicationScoped.class);
}
+
+ @Override
+ public String toString()
+ {
+ return "Application context";
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java 2008-10-27 12:07:27 UTC (rev 178)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ConversationContext.java 2008-10-27 13:09:50 UTC (rev 179)
@@ -9,5 +9,11 @@
{
super(ConversationScoped.class);
}
+
+ @Override
+ public String toString()
+ {
+ return "Conversation context";
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java 2008-10-27 12:07:27 UTC (rev 178)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java 2008-10-27 13:09:50 UTC (rev 179)
@@ -9,4 +9,9 @@
super(RequestScoped.class);
}
+ @Override
+ public String toString()
+ {
+ return "Request context";
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java 2008-10-27 12:07:27 UTC (rev 178)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java 2008-10-27 13:09:50 UTC (rev 179)
@@ -9,4 +9,9 @@
super(SessionScoped.class);
}
+ @Override
+ public String toString()
+ {
+ return "Session context";
+ }
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java 2008-10-27 12:07:27 UTC (rev 178)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java 2008-10-27 13:09:50 UTC (rev 179)
@@ -1,11 +1,24 @@
package org.jboss.webbeans.test;
+import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
+
+import java.lang.reflect.Method;
+
import javax.webbeans.ContextNotActiveException;
import javax.webbeans.RequestScoped;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
+import org.jboss.webbeans.BeanImpl;
import org.jboss.webbeans.contexts.AbstractContext;
+import org.jboss.webbeans.contexts.RequestContext;
+import org.jboss.webbeans.introspector.SimpleAnnotatedMethod;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.bean.ProducerMethodBeanModel;
+import org.jboss.webbeans.model.bean.SimpleBeanModel;
+import org.jboss.webbeans.test.beans.BlackWidow;
+import org.jboss.webbeans.test.beans.SpiderProducer;
+import org.jboss.webbeans.test.beans.Tarantula;
import org.jboss.webbeans.test.beans.Tuna;
import org.jboss.webbeans.test.util.Util;
import org.testng.annotations.BeforeMethod;
@@ -26,7 +39,7 @@
@BeforeMethod
public void initContext() {
- context = new AbstractContext(RequestScoped.class) {};
+ context = new RequestContext();
}
@Test(groups="contexts") @SpecAssertion(section="8.1")
@@ -57,9 +70,13 @@
}
@Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.1")
- public void testProducerMethodReturningNullOK() {
- // TODO
- assert false;
+ public void testProducerMethodReturningNullOK() throws SecurityException, NoSuchMethodException {
+ SimpleBeanModel<SpiderProducer> producer = new SimpleBeanModel<SpiderProducer>(new SimpleAnnotatedType<SpiderProducer>(SpiderProducer.class), getEmptyAnnotatedType(SpiderProducer.class), manager);
+ manager.getModelManager().addBeanModel(producer);
+ Method nullProducer = SpiderProducer.class.getMethod("produceShelob");
+ ProducerMethodBeanModel<Tarantula> producerModel = new ProducerMethodBeanModel<Tarantula>(new SimpleAnnotatedMethod<Tarantula>(nullProducer), manager);
+ Bean<Tarantula> shelobBean = new BeanImpl<Tarantula>(producerModel, manager);
+ assert context.get(shelobBean, true) == null;
}
@Test(groups="contexts")
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-10-27 12:07:27 UTC (rev 178)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-10-27 13:09:50 UTC (rev 179)
@@ -41,4 +41,8 @@
return new LadybirdSpider();
}
+ @Produces @Named("Shelob") public Tarantula produceShelob() {
+ return null;
+ }
+
}
16 years, 1 month
[webbeans-commits] Webbeans SVN: r178 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/model/bean and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 08:07:27 -0400 (Mon, 27 Oct 2008)
New Revision: 178
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
Removed:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/TypeSafeResolutionTest.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/BeanModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
Log:
Stub out remaining tests for Chapter 4
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanImpl.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -68,8 +68,7 @@
@Override
public boolean isNullable()
{
- // TODO Auto-generated method stub
- return false;
+ return !beanModel.isPrimitive();
}
@Override
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/AbstractBeanModel.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -24,6 +24,7 @@
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.model.MergedStereotypesModel;
import org.jboss.webbeans.util.LoggerUtil;
+import org.jboss.webbeans.util.Reflections;
public abstract class AbstractBeanModel<T, E> implements BeanModel<T, E>
{
@@ -41,11 +42,13 @@
protected InjectableMethod<?> removeMethod;
private Set<Class<?>> apiTypes;
protected Set<Injectable<?, ?>> injectionPoints;
+ private boolean primitive;
protected void init(ManagerImpl container)
{
mergedStereotypes = new MergedStereotypesModel<T, E>(getAnnotatedItem(), getXmlAnnotatedItem(), container);
initType();
+ initPrimitive();
log.fine("Building Web Bean bean metadata for " + getType());
initBindingTypes();
initName();
@@ -74,6 +77,11 @@
apiTypes = getTypeHierachy(getType());
}
+ protected void initPrimitive()
+ {
+ this.primitive = Reflections.isPrimitive(getType());
+ }
+
protected Set<Class<?>> getTypeHierachy(Class<?> clazz)
{
Set<Class<?>> classes = new HashSet<Class<?>>();
@@ -328,4 +336,9 @@
return this.getAnnotatedItem().isAssignableFrom(annotatedItem);
}
+ public boolean isPrimitive()
+ {
+ return primitive;
+ }
+
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/BeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/BeanModel.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/BeanModel.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -38,6 +38,8 @@
public boolean isAssignableFrom(AnnotatedItem<?, ?> annotatedItem);
+ public boolean isPrimitive();
+
public MergedStereotypesModel<T, E> getMergedStereotypes();
}
\ No newline at end of file
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -0,0 +1,53 @@
+package org.jboss.webbeans.test;
+
+import javax.webbeans.UnproxyableDependencyException;
+
+import org.testng.annotations.Test;
+
+@SpecVersion("PDR")
+public class ClientProxyTest
+{
+
+
+ @Test(groups="clientProxy") @SpecAssertion(section={"4.4", "4.8"})
+ public void testClientProxyUsedForNormalScope()
+ {
+ assert false;
+ }
+
+ @Test(groups="clientProxy") @SpecAssertion(section={"4.4", "4.8"})
+ public void testClientProxyNotUsedForPseudoScope()
+ {
+ assert false;
+ }
+
+ @Test(groups="clientProxy") @SpecAssertion(section="4.4")
+ public void testClientProxyIsSerializable()
+ {
+ assert false;
+ }
+
+ @Test(groups="clientProxy", expectedExceptions=UnproxyableDependencyException.class) @SpecAssertion(section="4.4.1")
+ public void testInjectionPointWithUnproxyableTypeResolvesToNormalScopedWebBean()
+ {
+ assert false;
+ }
+
+ @Test(groups="clientProxy") @SpecAssertion(section="4.4.2")
+ public void testClientProxyInvocation()
+ {
+ assert false;
+ }
+
+ /*
+
+ @Test(groups="clientProxy") @SpecAssertion(section="4.4")
+ public void test
+ {
+ assert false;
+ }
+
+ */
+
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClientProxyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -48,4 +48,10 @@
assert model.getDeploymentType().equals(Production.class);
}
+ @Test(groups="producerMethod") @SpecAssertion(section="4.2")
+ public void testIsNullable()
+ {
+ assert false;
+ }
+
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -0,0 +1,57 @@
+package org.jboss.webbeans.test;
+
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.NullableDependencyException;
+
+import org.testng.annotations.Test;
+
+@SpecVersion("PDR")
+public class InjectionTests extends AbstractTest
+{
+
+ @Test(groups="injection") @SpecAssertion(section="4.2")
+ public void testPrimitiveTypesEquivalentToBoxedTypes()
+ {
+ assert false;
+ }
+
+ @Test(groups="injection") @SpecAssertion(section="4.2")
+ public void testInjectionPerformsBoxingIfNecessary()
+ {
+ assert false;
+ }
+
+ @Test(groups="injection") @SpecAssertion(section="4.2")
+ public void testInjectionPerformsUnboxingIfNecessary()
+ {
+ assert false;
+ }
+
+ @Test(groups="injection", expectedExceptions=NullableDependencyException.class) @SpecAssertion(section="4.2")
+ public void testPrimitiveInjectionPointResolvesToNullableWebBean()
+ {
+ assert false;
+ }
+
+ @Test(groups="injection", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="4.3")
+ public void testInvokeNormalInjectedWebBeanWhenContextNotActive()
+ {
+ assert false;
+ }
+
+ @Test(groups="injection") @SpecAssertion(section="4.3")
+ public void testInovkeDependentScopeWhenContextNotActive()
+ {
+ assert false;
+ }
+
+ /*
+
+ @Test(groups="injection") @SpecAssertion(section="4.2")
+ public void test
+ {
+ assert false;
+ }
+
+ */
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InjectionTests.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByNameTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -3,7 +3,6 @@
import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
import javax.webbeans.AmbiguousDependencyException;
-import javax.webbeans.UnsatisfiedDependencyException;
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.BeanImpl;
@@ -21,7 +20,13 @@
public class InstantiationByNameTest extends AbstractTest
{
- @Test(expectedExceptions=AmbiguousDependencyException.class)
+ @Test(groups="resolution") @SpecAssertion(section="4.10")
+ public void testNoWebBeansFound()
+ {
+ assert false;
+ }
+
+ @Test(expectedExceptions=AmbiguousDependencyException.class) @SpecAssertion(section="4.10.1")
public void testAmbiguousDependencies() throws Exception
{
InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
@@ -38,19 +43,26 @@
manager.getInstanceByName("whitefish");
}
- @Test(expectedExceptions=UnsatisfiedDependencyException.class)
- public void testUnsatisfiedDependencies() throws Exception
+ @Test(groups="resolution") @SpecAssertion(section="4.10.1")
+ public void testGetInstanceByName()
{
- InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
- Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
- Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
- manager.addBean(codBean);
- manager.addBean(salmonBean);
-
- ResolutionManager resolutionManager = manager.getResolutionManager();
- resolutionManager.addInjectionPoint(whiteScottishFishField);
-
- manager.getInstanceByName("foo");
+ assert false;
}
+ @Test(groups="resolution") @SpecAssertion(section="4.10")
+ public void testGetInstanceByNameCalledOncePerDistinctNameInElExpression()
+ {
+ assert false;
+ }
+
+ /*
+
+ @Test(groups="el") @SpecAssertion(section="4.10")
+ public void test
+ {
+ assert false;
+ }
+
+ */
+
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/InstantiationByTypeTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -4,6 +4,7 @@
import javax.webbeans.AmbiguousDependencyException;
import javax.webbeans.AnnotationLiteral;
+import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.UnproxyableDependencyException;
import javax.webbeans.UnsatisfiedDependencyException;
import javax.webbeans.manager.Bean;
@@ -25,10 +26,29 @@
import org.jboss.webbeans.test.beans.broken.PlaiceFarm;
import org.testng.annotations.Test;
+@SpecVersion("PDR")
public class InstantiationByTypeTest extends AbstractTest
{
- @Test(expectedExceptions=AmbiguousDependencyException.class)
+ @Test(groups="resolution") @SpecAssertion(section="4.9")
+ public void testCurrentBindingTypeAssumed()
+ {
+ assert false;
+ }
+
+ @Test(groups="resolution", expectedExceptions=DuplicateBindingTypeException.class) @SpecAssertion(section="4.9")
+ public void testDuplicateBindingTypesUsed()
+ {
+ assert false;
+ }
+
+ @Test(groups="resolution", expectedExceptions=IllegalArgumentException.class) @SpecAssertion(section="4.9")
+ public void testNonBindingTypeUsed()
+ {
+ assert false;
+ }
+
+ @Test(expectedExceptions=AmbiguousDependencyException.class) @SpecAssertion(section="4.9")
public void testAmbiguousDependencies() throws Exception
{
InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
@@ -45,7 +65,7 @@
manager.getInstanceByType(ScottishFish.class, new AnnotationLiteral<Whitefish>(){});
}
- @Test(expectedExceptions=UnsatisfiedDependencyException.class)
+ @Test(expectedExceptions=UnsatisfiedDependencyException.class) @SpecAssertion(section="4.9")
public void testUnsatisfiedDependencies() throws Exception
{
InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
@@ -62,7 +82,7 @@
manager.getInstanceByType(Tuna.class, new CurrentAnnotationLiteral());
}
- @Test(expectedExceptions=UnproxyableDependencyException.class)
+ @Test(expectedExceptions=UnproxyableDependencyException.class) @SpecAssertion(section="4.9")
public void testUnproxyableDependencies() throws Exception
{
InjectableField<Plaice> plaiceField = new InjectableField<Plaice>(PlaiceFarm.class.getDeclaredField("plaice"));
@@ -75,4 +95,14 @@
manager.getInstanceByType(Plaice.class, new AnnotationLiteral<Whitefish>(){});
}
+ /*
+
+ @Test(groups="resolution") @SpecAssertion(section="4.9")
+ public void test
+ {
+ assert false;
+ }
+
+ */
+
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -0,0 +1,30 @@
+package org.jboss.webbeans.test;
+
+import org.testng.annotations.Test;
+
+@SpecVersion("PDR")
+public class ManagerTest
+{
+
+ @Test(groups={"manager", "injection"}) @SpecAssertion(section="4.8")
+ public void testInjectingManager()
+ {
+ assert false;
+ }
+
+ @Test(groups={"manager", "ejb3"}) @SpecAssertion(section="4.8")
+ public void testManagerLookupInJndi()
+ {
+ assert false;
+ }
+
+ /*
+
+ @Test(groups="manager") @SpecAssertion(section="4.8")
+ public void test
+ {
+ assert false;
+ }
+
+ */
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -1,52 +0,0 @@
-package org.jboss.webbeans.test;
-
-import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
-
-import javax.webbeans.manager.Bean;
-
-import org.jboss.webbeans.BeanImpl;
-import org.jboss.webbeans.introspector.SimpleAnnotatedType;
-import org.jboss.webbeans.model.bean.SimpleBeanModel;
-import org.jboss.webbeans.test.beans.Cod;
-import org.jboss.webbeans.test.beans.Haddock;
-import org.jboss.webbeans.test.beans.Plaice;
-import org.jboss.webbeans.test.beans.Salmon;
-import org.jboss.webbeans.test.beans.SeaBass;
-import org.jboss.webbeans.test.beans.Sole;
-import org.jboss.webbeans.test.beans.Tuna;
-import org.testng.annotations.Test;
-public class NameBasedResolutionTest extends AbstractTest
-{
-
- @Test
- public void testNamedBasedResolution()
- {
- Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
- Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
- Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
- Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
- Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleBeanModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), super.manager), manager);
- Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleBeanModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), super.manager), manager);
- Bean<Plaice> plaiceBean = new BeanImpl<Plaice>(new SimpleBeanModel<Plaice>(new SimpleAnnotatedType<Plaice>(Plaice.class), getEmptyAnnotatedType(Plaice.class), super.manager), manager);
-
- manager.addBean(tunaBean);
- manager.addBean(codBean);
- manager.addBean(salmonBean);
- manager.addBean(soleBean);
- manager.addBean(haddockBean);
- manager.addBean(seaBassBean);
-
- assert manager.resolveByName("salmon").size() == 1;
- assert manager.resolveByName("salmon").contains(salmonBean);
-
- assert manager.resolveByName("whitefish").size() == 2;
- assert manager.resolveByName("whitefish").contains(codBean);
- assert manager.resolveByName("whitefish").contains(soleBean);
-
- manager.addBean(plaiceBean);
-
- assert manager.resolveByName("whitefish").size() == 1;
- assert manager.resolveByName("whitefish").contains(plaiceBean);
- }
-
-}
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java (from rev 176, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameBasedResolutionTest.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -0,0 +1,88 @@
+package org.jboss.webbeans.test;
+
+import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
+
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.BeanImpl;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.bean.SimpleBeanModel;
+import org.jboss.webbeans.test.beans.Cod;
+import org.jboss.webbeans.test.beans.Haddock;
+import org.jboss.webbeans.test.beans.Plaice;
+import org.jboss.webbeans.test.beans.Salmon;
+import org.jboss.webbeans.test.beans.SeaBass;
+import org.jboss.webbeans.test.beans.Sole;
+import org.jboss.webbeans.test.beans.Tuna;
+import org.testng.annotations.Test;
+
+@SpecVersion("PDR")
+public class ResolutionByNameTest extends AbstractTest
+{
+
+ @Test(groups="el") @SpecAssertion(section="4.10")
+ public void testELResolver()
+ {
+ assert false;
+ }
+
+ @Test(groups="el") @SpecAssertion(section="4.10.2")
+ public void testELResolverRegisteredWithJsf()
+ {
+ assert false;
+ }
+
+ @Test(groups="el") @SpecAssertion(section="4.10.2")
+ public void testELResolverRegisteredWithServlet()
+ {
+ assert false;
+ }
+
+ @Test @SpecAssertion(section="4.10.1")
+ public void testNamedBasedResolution()
+ {
+ Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleBeanModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), super.manager), manager);
+ Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleBeanModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), super.manager), manager);
+ Bean<Plaice> plaiceBean = new BeanImpl<Plaice>(new SimpleBeanModel<Plaice>(new SimpleAnnotatedType<Plaice>(Plaice.class), getEmptyAnnotatedType(Plaice.class), super.manager), manager);
+
+ manager.addBean(tunaBean);
+ manager.addBean(codBean);
+ manager.addBean(salmonBean);
+ manager.addBean(soleBean);
+ manager.addBean(haddockBean);
+ manager.addBean(seaBassBean);
+
+ assert manager.resolveByName("salmon").size() == 1;
+ assert manager.resolveByName("salmon").contains(salmonBean);
+
+ assert manager.resolveByName("whitefish").size() == 2;
+ assert manager.resolveByName("whitefish").contains(codBean);
+ assert manager.resolveByName("whitefish").contains(soleBean);
+
+ manager.addBean(plaiceBean);
+
+ assert manager.resolveByName("whitefish").size() == 1;
+ assert manager.resolveByName("whitefish").contains(plaiceBean);
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section="4.10.1")
+ public void testNoWebBeansFound()
+ {
+ assert false;
+ }
+
+ /*
+
+ @Test(groups="el") @SpecAssertion(section="4.10")
+ public void test
+ {
+ assert false;
+ }
+
+ */
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByNameTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java (from rev 176, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/TypeSafeResolutionTest.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -0,0 +1,261 @@
+package org.jboss.webbeans.test;
+
+import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.webbeans.AnnotationLiteral;
+import javax.webbeans.DefinitionException;
+import javax.webbeans.DuplicateBindingTypeException;
+import javax.webbeans.TypeLiteral;
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.BeanImpl;
+import org.jboss.webbeans.ResolutionManager;
+import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
+import org.jboss.webbeans.injectable.InjectableField;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.bean.SimpleBeanModel;
+import org.jboss.webbeans.test.annotations.Whitefish;
+import org.jboss.webbeans.test.beans.Animal;
+import org.jboss.webbeans.test.beans.AnimalFarmer;
+import org.jboss.webbeans.test.beans.Cod;
+import org.jboss.webbeans.test.beans.Farmer;
+import org.jboss.webbeans.test.beans.FishFarm;
+import org.jboss.webbeans.test.beans.Haddock;
+import org.jboss.webbeans.test.beans.Plaice;
+import org.jboss.webbeans.test.beans.Salmon;
+import org.jboss.webbeans.test.beans.ScottishFish;
+import org.jboss.webbeans.test.beans.ScottishFishFarmer;
+import org.jboss.webbeans.test.beans.SeaBass;
+import org.jboss.webbeans.test.beans.Sole;
+import org.jboss.webbeans.test.beans.Tuna;
+import org.jboss.webbeans.test.bindings.ChunkyAnnotationLiteral;
+import org.testng.annotations.Test;
+
+@SpecVersion("PDR")
+public class ResolutionByTypeTest extends AbstractTest
+{
+
+ @Test(groups="resolution")
+ public void testInjectableField() throws Exception
+ {
+ InjectableField<Tuna> tuna = new InjectableField<Tuna>(FishFarm.class.getDeclaredField("tuna"));
+ assert tuna.getAnnotatedItem().getType().isAssignableFrom(Tuna.class);
+ assert tuna.getBindingTypes().size() == 1;
+ assert tuna.getBindingTypes().contains(new CurrentAnnotationLiteral());
+ assert tuna.getType().isAssignableFrom(Tuna.class);
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ public void testSingleApiTypeWithCurrent() throws Exception
+ {
+ InjectableField<Tuna> tunaField = new InjectableField<Tuna>(FishFarm.class.getDeclaredField("tuna"));
+ Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ beans.add(tunaBean);
+ Set<Bean<?>> possibleTargets = tunaField.getMatchingBeans(beans);
+ assert possibleTargets.size() == 1;
+ assert possibleTargets.contains(tunaBean);
+ }
+
+ @Test(groups="resolution", expectedExceptions=DuplicateBindingTypeException.class) @SpecAssertion(section="4.9.2")
+ public void testDuplicateBindingTypesUsed()
+ {
+ assert false;
+ }
+
+ @Test(groups="resolution", expectedExceptions=IllegalArgumentException.class) @SpecAssertion(section="4.9.2")
+ public void testNonBindingTypeUsed()
+ {
+ assert false;
+ }
+
+ @Test
+ public void testOneBindingType() throws Exception
+ {
+ InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ beans.add(codBean);
+ beans.add(salmonBean);
+ beans.add(soleBean);
+ Set<Bean<?>> possibleTargets = whiteScottishFishField.getMatchingBeans(beans);
+ assert possibleTargets.size() == 2;
+ assert possibleTargets.contains(codBean);
+ assert possibleTargets.contains(soleBean);
+ }
+
+ @Test
+ public void testABindingType() throws Exception
+ {
+ InjectableField<Animal> whiteChunkyFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("realChunkyWhiteFish"));
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ beans.add(codBean);
+ beans.add(salmonBean);
+ beans.add(soleBean);
+ Set<Bean<?>> possibleTargets = whiteChunkyFishField.getMatchingBeans(beans);
+ assert possibleTargets.size() == 1;
+ assert possibleTargets.contains(codBean);
+ }
+
+ @Test
+ public void testMultipleApiTypeWithCurrent() throws Exception
+ {
+ InjectableField<Animal> animalField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("animal"));
+ Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleBeanModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), super.manager), manager);
+ Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleBeanModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), super.manager), manager);
+ Set<Bean<?>> beans = new HashSet<Bean<?>>();
+ beans.add(seaBassBean);
+ beans.add(haddockBean);
+ Set<Bean<?>> possibleTargets = animalField.getMatchingBeans(beans);
+ assert possibleTargets.size() == 2;
+ assert possibleTargets.contains(seaBassBean);
+ assert possibleTargets.contains(haddockBean);
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section={"4.9.2", "4.9.4"})
+ public void testResolveByType() throws Exception
+ {
+ InjectableField<Animal> realChunkyWhiteFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("realChunkyWhiteFish"));
+ InjectableField<Animal> animalField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("animal"));
+ InjectableField<ScottishFish> scottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
+ InjectableField<Tuna> tunaField = new InjectableField<Tuna>(FishFarm.class.getDeclaredField("tuna"));
+
+ Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleBeanModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), super.manager), manager);
+ Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleBeanModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), super.manager), manager);
+
+ manager.addBean(tunaBean);
+ manager.addBean(codBean);
+ manager.addBean(salmonBean);
+ manager.addBean(soleBean);
+ manager.addBean(haddockBean);
+ manager.addBean(seaBassBean);
+
+ ResolutionManager resolutionManager = manager.getResolutionManager();
+ resolutionManager.addInjectionPoint(realChunkyWhiteFishField);
+ resolutionManager.addInjectionPoint(animalField);
+ resolutionManager.addInjectionPoint(scottishFishField);
+ resolutionManager.addInjectionPoint(tunaField);
+
+ assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).size() == 1;
+ assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).contains(tunaBean);
+
+ assert manager.resolveByType(Tuna.class).size() == 1;
+ assert manager.resolveByType(Tuna.class).contains(tunaBean);
+
+ assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).size() == 3;
+ assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(salmonBean);
+ assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(seaBassBean);
+ assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(haddockBean);
+
+ assert manager.resolveByType(Animal.class, new ChunkyAnnotationLiteral() {
+
+ public boolean realChunky()
+ {
+ return true;
+ }
+
+ }, new AnnotationLiteral<Whitefish>() {}).size() == 1;
+ assert manager.resolveByType(Animal.class, new ChunkyAnnotationLiteral() {
+
+ public boolean realChunky()
+ {
+ return true;
+ }
+
+ }, new AnnotationLiteral<Whitefish>() {}).contains(codBean);
+
+ assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).size() == 2;
+ assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).contains(codBean);
+ assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).contains(soleBean);
+
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ public void testResolveByTypeWithTypeParameter() throws Exception
+ {
+ InjectableField<Farmer<ScottishFish>> scottishFishFarmerField = new InjectableField<Farmer<ScottishFish>>(FishFarm.class.getDeclaredField("scottishFishFarmer"));
+
+ Bean<ScottishFishFarmer> scottishFishFarmerBean = new BeanImpl<ScottishFishFarmer>(new SimpleBeanModel<ScottishFishFarmer>(new SimpleAnnotatedType<ScottishFishFarmer>(ScottishFishFarmer.class), getEmptyAnnotatedType(ScottishFishFarmer.class), super.manager), manager);
+ Bean<AnimalFarmer> farmerBean = new BeanImpl<AnimalFarmer>(new SimpleBeanModel<AnimalFarmer>(new SimpleAnnotatedType<AnimalFarmer>(AnimalFarmer.class), getEmptyAnnotatedType(AnimalFarmer.class), super.manager), manager);
+
+ manager.addBean(scottishFishFarmerBean);
+ manager.addBean(farmerBean);
+
+ ResolutionManager resolutionManager = manager.getResolutionManager();
+ resolutionManager.addInjectionPoint(scottishFishFarmerField);
+
+ assert manager.resolveByType(new TypeLiteral<Farmer<ScottishFish>>(){}).size() == 1;
+ assert manager.resolveByType(new TypeLiteral<Farmer<ScottishFish>>(){}).contains(scottishFishFarmerBean);
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ public void testResolveByTypeWithArray()
+ {
+ assert false;
+ }
+
+ @Test @SpecAssertion(section="4.9.2")
+ public void testOnlyHighestEnabledPreecedenceWebBeansResolved() throws Exception
+ {
+ InjectableField<Animal> whiteFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("whiteFish"));
+
+ Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ Bean<Plaice> plaiceBean = new BeanImpl<Plaice>(new SimpleBeanModel<Plaice>(new SimpleAnnotatedType<Plaice>(Plaice.class), getEmptyAnnotatedType(Plaice.class), super.manager), manager);
+
+
+ manager.addBean(plaiceBean);
+ manager.addBean(codBean);
+ manager.addBean(soleBean);
+
+ ResolutionManager resolutionManager = manager.getResolutionManager();
+ resolutionManager.addInjectionPoint(whiteFishField);
+
+ assert manager.resolveByType(Animal.class, new AnnotationLiteral<Whitefish>() {}).size() == 1;
+ assert manager.resolveByType(Animal.class, new AnnotationLiteral<Whitefish>() {}).contains(plaiceBean);
+
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ public void testResolveByTypeNonBindingParameters()
+ {
+ assert false;
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ public void testNoWebBeansFound()
+ {
+ assert false;
+ }
+
+ @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ public void testResolveObject()
+ {
+ assert false;
+ }
+
+ @Test(groups="resolution", expectedExceptions=DefinitionException.class) @SpecAssertion(section="4.9.2.1")
+ public void testArrayValuedAnnotationMemberWithoutNonBinding()
+ {
+ assert false;
+ }
+
+ @Test(groups="resolution", expectedExceptions=DefinitionException.class) @SpecAssertion(section="4.9.2.1")
+ public void testAnnotationValuedAnnotationMemberWithoutNonBinding()
+ {
+ assert false;
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/TypeSafeResolutionTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/TypeSafeResolutionTest.java 2008-10-27 10:41:26 UTC (rev 177)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/TypeSafeResolutionTest.java 2008-10-27 12:07:27 UTC (rev 178)
@@ -1,213 +0,0 @@
-package org.jboss.webbeans.test;
-
-import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.webbeans.AnnotationLiteral;
-import javax.webbeans.Current;
-import javax.webbeans.TypeLiteral;
-import javax.webbeans.manager.Bean;
-
-import org.jboss.webbeans.BeanImpl;
-import org.jboss.webbeans.ResolutionManager;
-import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
-import org.jboss.webbeans.injectable.InjectableField;
-import org.jboss.webbeans.introspector.SimpleAnnotatedType;
-import org.jboss.webbeans.model.bean.SimpleBeanModel;
-import org.jboss.webbeans.test.annotations.Whitefish;
-import org.jboss.webbeans.test.beans.Animal;
-import org.jboss.webbeans.test.beans.AnimalFarmer;
-import org.jboss.webbeans.test.beans.Cod;
-import org.jboss.webbeans.test.beans.Farmer;
-import org.jboss.webbeans.test.beans.FishFarm;
-import org.jboss.webbeans.test.beans.Haddock;
-import org.jboss.webbeans.test.beans.Plaice;
-import org.jboss.webbeans.test.beans.Salmon;
-import org.jboss.webbeans.test.beans.ScottishFish;
-import org.jboss.webbeans.test.beans.ScottishFishFarmer;
-import org.jboss.webbeans.test.beans.SeaBass;
-import org.jboss.webbeans.test.beans.Sole;
-import org.jboss.webbeans.test.beans.Tuna;
-import org.jboss.webbeans.test.bindings.ChunkyAnnotationLiteral;
-import org.jboss.webbeans.util.Reflections;
-import org.testng.annotations.Test;
-
-public class TypeSafeResolutionTest extends AbstractTest
-{
-
- @SuppressWarnings("unchecked")
- @Test
- public void testInjectableField() throws Exception
- {
- InjectableField<Tuna> tuna = new InjectableField<Tuna>(FishFarm.class.getDeclaredField("tuna"));
- assert tuna.getAnnotatedItem().getType().isAssignableFrom(Tuna.class);
- assert tuna.getBindingTypes().size() == 1;
- assert Reflections.annotationSetMatches(tuna.getBindingTypes(), Current.class);
- assert tuna.getType().isAssignableFrom(Tuna.class);
- }
-
- @Test
- public void testSingleApiTypeWithCurrent() throws Exception
- {
- InjectableField<Tuna> tunaField = new InjectableField<Tuna>(FishFarm.class.getDeclaredField("tuna"));
- Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
- Set<Bean<?>> beans = new HashSet<Bean<?>>();
- beans.add(tunaBean);
- Set<Bean<?>> possibleTargets = tunaField.getMatchingBeans(beans);
- assert possibleTargets.size() == 1;
- assert possibleTargets.contains(tunaBean);
- }
-
- @Test
- public void testOneBindingType() throws Exception
- {
- InjectableField<ScottishFish> whiteScottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
- Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
- Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
- Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
- Set<Bean<?>> beans = new HashSet<Bean<?>>();
- beans.add(codBean);
- beans.add(salmonBean);
- beans.add(soleBean);
- Set<Bean<?>> possibleTargets = whiteScottishFishField.getMatchingBeans(beans);
- assert possibleTargets.size() == 2;
- assert possibleTargets.contains(codBean);
- assert possibleTargets.contains(soleBean);
- }
-
- @Test
- public void testABindingType() throws Exception
- {
- InjectableField<Animal> whiteChunkyFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("realChunkyWhiteFish"));
- Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
- Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
- Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
- Set<Bean<?>> beans = new HashSet<Bean<?>>();
- beans.add(codBean);
- beans.add(salmonBean);
- beans.add(soleBean);
- Set<Bean<?>> possibleTargets = whiteChunkyFishField.getMatchingBeans(beans);
- assert possibleTargets.size() == 1;
- assert possibleTargets.contains(codBean);
- }
-
- @Test
- public void testMultipleApiTypeWithCurrent() throws Exception
- {
- InjectableField<Animal> animalField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("animal"));
- Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleBeanModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), super.manager), manager);
- Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleBeanModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), super.manager), manager);
- Set<Bean<?>> beans = new HashSet<Bean<?>>();
- beans.add(seaBassBean);
- beans.add(haddockBean);
- Set<Bean<?>> possibleTargets = animalField.getMatchingBeans(beans);
- assert possibleTargets.size() == 2;
- assert possibleTargets.contains(seaBassBean);
- assert possibleTargets.contains(haddockBean);
- }
-
- @Test
- public void testResolveByType() throws Exception
- {
- InjectableField<Animal> realChunkyWhiteFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("realChunkyWhiteFish"));
- InjectableField<Animal> animalField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("animal"));
- InjectableField<ScottishFish> scottishFishField = new InjectableField<ScottishFish>(FishFarm.class.getDeclaredField("whiteScottishFish"));
- InjectableField<Tuna> tunaField = new InjectableField<Tuna>(FishFarm.class.getDeclaredField("tuna"));
-
- Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
- Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
- Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
- Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
- Bean<SeaBass> seaBassBean = new BeanImpl<SeaBass>(new SimpleBeanModel<SeaBass>(new SimpleAnnotatedType<SeaBass>(SeaBass.class), getEmptyAnnotatedType(SeaBass.class), super.manager), manager);
- Bean<Haddock> haddockBean = new BeanImpl<Haddock>(new SimpleBeanModel<Haddock>(new SimpleAnnotatedType<Haddock>(Haddock.class), getEmptyAnnotatedType(Haddock.class), super.manager), manager);
-
- manager.addBean(tunaBean);
- manager.addBean(codBean);
- manager.addBean(salmonBean);
- manager.addBean(soleBean);
- manager.addBean(haddockBean);
- manager.addBean(seaBassBean);
-
- ResolutionManager resolutionManager = manager.getResolutionManager();
- resolutionManager.addInjectionPoint(realChunkyWhiteFishField);
- resolutionManager.addInjectionPoint(animalField);
- resolutionManager.addInjectionPoint(scottishFishField);
- resolutionManager.addInjectionPoint(tunaField);
-
- assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).size() == 1;
- assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).contains(tunaBean);
-
- assert manager.resolveByType(Tuna.class).size() == 1;
- assert manager.resolveByType(Tuna.class).contains(tunaBean);
-
- assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).size() == 3;
- assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(salmonBean);
- assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(seaBassBean);
- assert manager.resolveByType(Animal.class, new CurrentAnnotationLiteral()).contains(haddockBean);
-
- assert manager.resolveByType(Animal.class, new ChunkyAnnotationLiteral() {
-
- public boolean realChunky()
- {
- return true;
- }
-
- }, new AnnotationLiteral<Whitefish>() {}).size() == 1;
- assert manager.resolveByType(Animal.class, new ChunkyAnnotationLiteral() {
-
- public boolean realChunky()
- {
- return true;
- }
-
- }, new AnnotationLiteral<Whitefish>() {}).contains(codBean);
-
- assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).size() == 2;
- assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).contains(codBean);
- assert manager.resolveByType(ScottishFish.class, new AnnotationLiteral<Whitefish>() {}).contains(soleBean);
-
- }
-
- @Test
- public void testResolveByTypeWithTypeParameter() throws Exception
- {
- InjectableField<Farmer<ScottishFish>> scottishFishFarmerField = new InjectableField<Farmer<ScottishFish>>(FishFarm.class.getDeclaredField("scottishFishFarmer"));
-
- Bean<ScottishFishFarmer> scottishFishFarmerBean = new BeanImpl<ScottishFishFarmer>(new SimpleBeanModel<ScottishFishFarmer>(new SimpleAnnotatedType<ScottishFishFarmer>(ScottishFishFarmer.class), getEmptyAnnotatedType(ScottishFishFarmer.class), super.manager), manager);
- Bean<AnimalFarmer> farmerBean = new BeanImpl<AnimalFarmer>(new SimpleBeanModel<AnimalFarmer>(new SimpleAnnotatedType<AnimalFarmer>(AnimalFarmer.class), getEmptyAnnotatedType(AnimalFarmer.class), super.manager), manager);
-
- manager.addBean(scottishFishFarmerBean);
- manager.addBean(farmerBean);
-
- ResolutionManager resolutionManager = manager.getResolutionManager();
- resolutionManager.addInjectionPoint(scottishFishFarmerField);
-
- assert manager.resolveByType(new TypeLiteral<Farmer<ScottishFish>>(){}).size() == 1;
- assert manager.resolveByType(new TypeLiteral<Farmer<ScottishFish>>(){}).contains(scottishFishFarmerBean);
- }
-
- @Test
- public void testOnlyHighestEnabledPreecedenceWebBeansResolved() throws Exception
- {
- InjectableField<Animal> whiteFishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("whiteFish"));
-
- Bean<Cod> codBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
- Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
- Bean<Plaice> plaiceBean = new BeanImpl<Plaice>(new SimpleBeanModel<Plaice>(new SimpleAnnotatedType<Plaice>(Plaice.class), getEmptyAnnotatedType(Plaice.class), super.manager), manager);
-
-
- manager.addBean(plaiceBean);
- manager.addBean(codBean);
- manager.addBean(soleBean);
-
- ResolutionManager resolutionManager = manager.getResolutionManager();
- resolutionManager.addInjectionPoint(whiteFishField);
-
- assert manager.resolveByType(Animal.class, new AnnotationLiteral<Whitefish>() {}).size() == 1;
- assert manager.resolveByType(Animal.class, new AnnotationLiteral<Whitefish>() {}).contains(plaiceBean);
-
- }
-
-}
16 years, 1 month
[webbeans-commits] Webbeans SVN: r177 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 06:41:26 -0400 (Mon, 27 Oct 2008)
New Revision: 177
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
Log:
Some comments
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-27 10:30:38 UTC (rev 176)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-27 10:41:26 UTC (rev 177)
@@ -14,7 +14,6 @@
import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
import javax.webbeans.Observer;
-import javax.webbeans.TypeLiteral;
import javax.webbeans.manager.Manager;
/**
@@ -43,6 +42,7 @@
*/
public void setEventBindings(Annotation... eventBindings)
{
+ // TODO Use constructor injection
Set<Annotation> newEventBindings = new HashSet<Annotation>();
addAnnotationBindings(newEventBindings, eventBindings);
this.eventBindings = newEventBindings;
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-10-27 10:30:38 UTC (rev 176)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-10-27 10:41:26 UTC (rev 177)
@@ -20,6 +20,9 @@
*/
public class EventObserver<T>
{
+
+ // TODO This probably should be an injectable or annotated item
+
private final Class<T> eventType;
private final Annotation[] eventBindings;
private final Observer<T> observer;
@@ -75,6 +78,7 @@
*/
public boolean isObserverInterested(Annotation... bindings)
{
+ // TODO This logic needs to be in injectable
boolean result = true;
// Check each binding specified by this observer against those provided
if (this.eventBindings != null)
@@ -87,6 +91,7 @@
int eventBindingIndex = bindingsArray.indexOf(annotation);
if (eventBindingIndex >= 0)
{
+ // TODO Use annotation equality
result = annotationsMatch(annotation, bindingsArray.get(eventBindingIndex));
} else
{
@@ -105,6 +110,7 @@
* @param annotation The first annotation to compare
* @param annotation2 The second annotation to compare
* @return
+ *
*/
private boolean annotationsMatch(Annotation annotation,
Annotation annotation2)
@@ -131,4 +137,6 @@
return result;
}
+ // TODO Implement equals and hashCode
+
}
16 years, 1 month
[webbeans-commits] Webbeans SVN: r176 - ri/trunk/webbeans-ri.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 06:30:38 -0400 (Mon, 27 Oct 2008)
New Revision: 176
Modified:
ri/trunk/webbeans-ri/pom.xml
Log:
No versions here
Modified: ri/trunk/webbeans-ri/pom.xml
===================================================================
--- ri/trunk/webbeans-ri/pom.xml 2008-10-27 10:30:05 UTC (rev 175)
+++ ri/trunk/webbeans-ri/pom.xml 2008-10-27 10:30:38 UTC (rev 176)
@@ -54,7 +54,6 @@
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
- <version>1.0</version>
</dependency>
</dependencies>
16 years, 1 month
[webbeans-commits] Webbeans SVN: r175 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 06:30:05 -0400 (Mon, 27 Oct 2008)
New Revision: 175
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java
Log:
fix build
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java 2008-10-27 10:24:30 UTC (rev 174)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java 2008-10-27 10:30:05 UTC (rev 175)
@@ -5,7 +5,7 @@
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
-import org.jboss.webbeans.AbstractContext;
+import org.jboss.webbeans.contexts.AbstractContext;
import org.jboss.webbeans.test.beans.Tuna;
import org.jboss.webbeans.test.util.Util;
import org.testng.annotations.BeforeMethod;
16 years, 1 month
[webbeans-commits] Webbeans SVN: r174 - in ri/trunk: webbeans-ri and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-27 06:24:30 -0400 (Mon, 27 Oct 2008)
New Revision: 174
Modified:
ri/trunk/pom.xml
ri/trunk/webbeans-ri/pom.xml
Log:
Added EL to dependencies.
Modified: ri/trunk/pom.xml
===================================================================
--- ri/trunk/pom.xml 2008-10-27 10:00:39 UTC (rev 173)
+++ ri/trunk/pom.xml 2008-10-27 10:24:30 UTC (rev 174)
@@ -116,6 +116,12 @@
<version>1.2.14</version>
</dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+
</dependencies>
</dependencyManagement>
Modified: ri/trunk/webbeans-ri/pom.xml
===================================================================
--- ri/trunk/webbeans-ri/pom.xml 2008-10-27 10:00:39 UTC (rev 173)
+++ ri/trunk/webbeans-ri/pom.xml 2008-10-27 10:24:30 UTC (rev 174)
@@ -50,6 +50,12 @@
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>el-api</artifactId>
+ <version>1.0</version>
+ </dependency>
</dependencies>
16 years, 1 month