[webbeans-commits] Webbeans SVN: r1017 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/tck and 6 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Fri Jan 16 09:03:04 EST 2009
Author: pete.muir at jboss.org
Date: 2009-01-16 09:03:04 -0500 (Fri, 16 Jan 2009)
New Revision: 1017
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/BoostrapTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/ClassAnnotatedItemTest.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/AnotherDeploymentType.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/ClientProxyTest.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/FinalTuna_Broken.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Fox.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Tuna.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/TunedTuna.java
Removed:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClassAnnotatedItemTest.java
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/tck/BeansImpl.java
tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java
Log:
port client proxy tests, and tidy up
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -1,287 +0,0 @@
-package org.jboss.webbeans.test;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.webbeans.manager.Bean;
-
-import org.jboss.webbeans.bean.AbstractBean;
-import org.jboss.webbeans.bean.EnterpriseBean;
-import org.jboss.webbeans.bean.ProducerMethodBean;
-import org.jboss.webbeans.bean.SimpleBean;
-import org.jboss.webbeans.test.beans.Elephant;
-import org.jboss.webbeans.test.beans.InitializedObserver;
-import org.jboss.webbeans.test.beans.InitializedObserverWhichUsesApplicationContext;
-import org.jboss.webbeans.test.beans.InitializedObserverWhichUsesRequestContext;
-import org.jboss.webbeans.test.beans.LadybirdSpider;
-import org.jboss.webbeans.test.beans.Panther;
-import org.jboss.webbeans.test.beans.Salmon;
-import org.jboss.webbeans.test.beans.SeaBass;
-import org.jboss.webbeans.test.beans.Sole;
-import org.jboss.webbeans.test.beans.Tarantula;
-import org.jboss.webbeans.test.beans.TarantulaProducer;
-import org.jboss.webbeans.test.beans.Tiger;
-import org.jboss.webbeans.test.beans.Tuna;
-import org.jboss.webbeans.test.ejb.valid.Hound;
-import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;
-import org.testng.annotations.Test;
-
-public class BoostrapTest extends AbstractTest
-{
- @Test(groups="bootstrap")
- public void testSingleSimpleBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Tuna.class));
- webBeansBootstrap.boot();
- List<Bean<?>> beans = manager.getBeans();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : beans)
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(Tuna.class);
- }
-
- @Test(groups="bootstrap")
- public void testSingleEnterpriseBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class));
- webBeansBootstrap.boot();
- List<Bean<?>> beans = manager.getBeans();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : beans)
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(Hound.class);
- }
-
- @Test(groups="bootstrap")
- public void testMultipleSimpleBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Tuna.class, Salmon.class, SeaBass.class, Sole.class));
- webBeansBootstrap.boot();
- List<Bean<?>> beans = manager.getBeans();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : beans)
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(Tuna.class);
- assert classes.containsKey(Salmon.class);
- assert classes.containsKey(SeaBass.class);
- assert classes.containsKey(Sole.class);
-
- assert classes.get(Tuna.class) instanceof SimpleBean;
- assert classes.get(Salmon.class) instanceof SimpleBean;
- assert classes.get(SeaBass.class) instanceof SimpleBean;
- assert classes.get(Sole.class) instanceof SimpleBean;
- }
-
- @Test(groups="bootstrap")
- public void testProducerMethodBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(TarantulaProducer.class));
- webBeansBootstrap.boot();
- List<Bean<?>> beans = manager.getBeans();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : beans)
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(TarantulaProducer.class);
- assert classes.containsKey(Tarantula.class);
-
- assert classes.get(TarantulaProducer.class) instanceof SimpleBean;
- assert classes.get(Tarantula.class) instanceof ProducerMethodBean;
- }
-
- @Test(groups="bootstrap")
- public void testMultipleEnterpriseBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class));
- webBeansBootstrap.boot();
- List<Bean<?>> beans = manager.getBeans();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : beans)
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(Hound.class);
- assert classes.containsKey(Elephant.class);
- assert classes.containsKey(Panther.class);
- assert classes.containsKey(Tiger.class);
-
- assert classes.get(Hound.class) instanceof EnterpriseBean;
- assert classes.get(Elephant.class) instanceof EnterpriseBean;
- assert classes.get(Panther.class) instanceof EnterpriseBean;
- assert classes.get(Tiger.class) instanceof EnterpriseBean;
- }
-
- @Test(groups="bootstrap")
- public void testMultipleEnterpriseAndSimpleBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
- webBeansBootstrap.boot();
- List<Bean<?>> beans = manager.getBeans();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : beans)
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(Hound.class);
- assert classes.containsKey(Elephant.class);
- assert classes.containsKey(Panther.class);
- assert classes.containsKey(Tiger.class);
- assert classes.containsKey(Tuna.class);
- assert classes.containsKey(Salmon.class);
- assert classes.containsKey(SeaBass.class);
- assert classes.containsKey(Sole.class);
-
- assert classes.get(Hound.class) instanceof EnterpriseBean;
- assert classes.get(Elephant.class) instanceof EnterpriseBean;
- assert classes.get(Panther.class) instanceof EnterpriseBean;
- assert classes.get(Tiger.class) instanceof EnterpriseBean;
- assert classes.get(Tuna.class) instanceof SimpleBean;
- assert classes.get(Salmon.class) instanceof SimpleBean;
- assert classes.get(SeaBass.class) instanceof SimpleBean;
- assert classes.get(Sole.class) instanceof SimpleBean;
- }
-
- @Test(groups="bootstrap")
- public void testRegisterProducerMethodBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(TarantulaProducer.class));
- webBeansBootstrap.boot();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : manager.getBeans())
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(TarantulaProducer.class);
- assert classes.containsKey(Tarantula.class);
-
-
- assert classes.get(TarantulaProducer.class) instanceof SimpleBean;
- assert classes.get(Tarantula.class) instanceof ProducerMethodBean;
- }
-
- @Test(groups="bootstrap")
- public void testRegisterMultipleEnterpriseAndSimpleBean()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
- webBeansBootstrap.boot();
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : manager.getBeans())
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(Hound.class);
- assert classes.containsKey(Elephant.class);
- assert classes.containsKey(Panther.class);
- assert classes.containsKey(Tiger.class);
- assert classes.containsKey(Tuna.class);
- assert classes.containsKey(Salmon.class);
- assert classes.containsKey(SeaBass.class);
- assert classes.containsKey(Sole.class);
-
- assert classes.get(Hound.class) instanceof EnterpriseBean;
- assert classes.get(Elephant.class) instanceof EnterpriseBean;
- assert classes.get(Panther.class) instanceof EnterpriseBean;
- assert classes.get(Tiger.class) instanceof EnterpriseBean;
- assert classes.get(Tuna.class) instanceof SimpleBean;
- assert classes.get(Salmon.class) instanceof SimpleBean;
- assert classes.get(SeaBass.class) instanceof SimpleBean;
- assert classes.get(Sole.class) instanceof SimpleBean;
- }
-
- @Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
- public void testDiscoverFails()
- {
- webBeansBootstrap.setWebBeanDiscovery(null);
- webBeansBootstrap.boot();
- }
-
- @Test(groups="bootstrap")
- public void testDiscover()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
- webBeansBootstrap.boot();
-
- Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
- for (Bean<?> bean : manager.getBeans())
- {
- if (bean instanceof AbstractBean)
- {
- classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
- }
- }
- assert classes.containsKey(Hound.class);
- assert classes.containsKey(Elephant.class);
- assert classes.containsKey(Panther.class);
- assert classes.containsKey(Tiger.class);
- assert classes.containsKey(Tuna.class);
- assert classes.containsKey(Salmon.class);
- assert classes.containsKey(SeaBass.class);
- assert classes.containsKey(Sole.class);
-
- assert classes.get(Hound.class) instanceof EnterpriseBean;
- assert classes.get(Elephant.class) instanceof EnterpriseBean;
- assert classes.get(Panther.class) instanceof EnterpriseBean;
- assert classes.get(Tiger.class) instanceof EnterpriseBean;
- assert classes.get(Tuna.class) instanceof SimpleBean;
- assert classes.get(Salmon.class) instanceof SimpleBean;
- assert classes.get(SeaBass.class) instanceof SimpleBean;
- assert classes.get(Sole.class) instanceof SimpleBean;
- }
-
- @Test(groups="bootstrap")
- public void testInitializedEvent()
- {
- assert !InitializedObserver.observered;
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(InitializedObserver.class));
- webBeansBootstrap.boot();
-
- assert InitializedObserver.observered;
- }
-
- @Test(groups="bootstrap")
- public void testRequestContextActiveDuringInitializtionEvent()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(InitializedObserverWhichUsesRequestContext.class, Tuna.class));
- webBeansBootstrap.boot();
- }
-
- @Test(groups={"bootstrap", "broken"})
- public void testApplicationContextActiveDuringInitializtionEvent()
- {
- webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(InitializedObserverWhichUsesApplicationContext.class, LadybirdSpider.class));
- webBeansBootstrap.boot();
- }
-
-}
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClassAnnotatedItemTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClassAnnotatedItemTest.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClassAnnotatedItemTest.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -1,50 +0,0 @@
-package org.jboss.webbeans.test;
-
-import java.lang.annotation.Annotation;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.webbeans.DeploymentType;
-import javax.webbeans.Production;
-import javax.webbeans.Stereotype;
-
-import org.jboss.webbeans.introspector.AnnotatedClass;
-import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
-import org.jboss.webbeans.test.beans.Antelope;
-import org.jboss.webbeans.test.beans.Order;
-import org.testng.annotations.Test;
-
-public class ClassAnnotatedItemTest
-{
-
- @Test
- public void testDeclaredAnnotations()
- {
- AnnotatedClass<Order> annotatedElement = new AnnotatedClassImpl<Order>(Order.class);
- assert annotatedElement.getAnnotations().size() == 1;
- assert annotatedElement.getAnnotation(Production.class) != null;
- assert annotatedElement.getType().equals(Order.class);
- }
-
- @Test
- public void testMetaAnnotations()
- {
- AnnotatedClass<Order> annotatedElement = new AnnotatedClassImpl<Order>(Order.class);
- Set<Annotation> annotations = annotatedElement.getMetaAnnotations(DeploymentType.class);
- assert annotations.size() == 1;
- Iterator<Annotation> it = annotations.iterator();
- Annotation production = it.next();
- assert Production.class.equals(production.annotationType());
- }
-
- @Test
- public void testEmpty()
- {
- AnnotatedClass<Order> annotatedElement = new AnnotatedClassImpl<Order>(Order.class);
- assert annotatedElement.getAnnotation(Stereotype.class) == null;
- assert annotatedElement.getMetaAnnotations(Stereotype.class).size() == 0;
- AnnotatedClass<Antelope> classWithNoAnnotations = new AnnotatedClassImpl<Antelope>(Antelope.class);
- assert classWithNoAnnotations.getAnnotations().size() == 0;
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/tck/BeansImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/tck/BeansImpl.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/tck/BeansImpl.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -11,7 +11,9 @@
import org.jboss.webbeans.bean.ProducerFieldBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.ejb.spi.EjbDescriptor;
import org.jboss.webbeans.tck.api.Beans;
+import org.jboss.webbeans.util.Reflections;
/**
* Implements the Beans SPI for the TCK specifically for the JBoss RI.
@@ -65,20 +67,52 @@
public boolean isEntityBean(Class<?> clazz)
{
- // TODO Auto-generated method stub
+ if (CurrentManager.rootManager().getEjbDescriptorCache().containsKey(clazz))
+ {
+ for (EjbDescriptor<?> ejbDescriptor : CurrentManager.rootManager().getEjbDescriptorCache().get(clazz))
+ {
+ if (!ejbDescriptor.isMessageDriven() && !ejbDescriptor.isSingleton() && !ejbDescriptor.isStateful() && !ejbDescriptor.isStateless())
+ {
+ return true;
+ }
+ }
+ }
return false;
}
public boolean isStatefulBean(Class<?> clazz)
{
- // TODO Auto-generated method stub
+ if (CurrentManager.rootManager().getEjbDescriptorCache().containsKey(clazz))
+ {
+ for (EjbDescriptor<?> ejbDescriptor : CurrentManager.rootManager().getEjbDescriptorCache().get(clazz))
+ {
+ if (ejbDescriptor.isStateful())
+ {
+ return true;
+ }
+ }
+ }
return false;
}
public boolean isStatelessBean(Class<?> clazz)
{
- // TODO Auto-generated method stub
+ if (CurrentManager.rootManager().getEjbDescriptorCache().containsKey(clazz))
+ {
+ for (EjbDescriptor<?> ejbDescriptor : CurrentManager.rootManager().getEjbDescriptorCache().get(clazz))
+ {
+ if (ejbDescriptor.isStateless())
+ {
+ return true;
+ }
+ }
+ }
return false;
}
+
+ public boolean isProxy(Object instance)
+ {
+ return Reflections.isProxy(instance);
+ }
}
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/BoostrapTest.java (from rev 1012, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BoostrapTest.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/BoostrapTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/BoostrapTest.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,288 @@
+package org.jboss.webbeans.test.unit;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bean.EnterpriseBean;
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.AbstractTest;
+import org.jboss.webbeans.test.beans.Elephant;
+import org.jboss.webbeans.test.beans.InitializedObserver;
+import org.jboss.webbeans.test.beans.InitializedObserverWhichUsesApplicationContext;
+import org.jboss.webbeans.test.beans.InitializedObserverWhichUsesRequestContext;
+import org.jboss.webbeans.test.beans.LadybirdSpider;
+import org.jboss.webbeans.test.beans.Panther;
+import org.jboss.webbeans.test.beans.Salmon;
+import org.jboss.webbeans.test.beans.SeaBass;
+import org.jboss.webbeans.test.beans.Sole;
+import org.jboss.webbeans.test.beans.Tarantula;
+import org.jboss.webbeans.test.beans.TarantulaProducer;
+import org.jboss.webbeans.test.beans.Tiger;
+import org.jboss.webbeans.test.beans.Tuna;
+import org.jboss.webbeans.test.ejb.valid.Hound;
+import org.jboss.webbeans.test.mock.MockWebBeanDiscovery;
+import org.testng.annotations.Test;
+
+public class BoostrapTest extends AbstractTest
+{
+ @Test(groups="bootstrap")
+ public void testSingleSimpleBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Tuna.class));
+ webBeansBootstrap.boot();
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Tuna.class);
+ }
+
+ @Test(groups="bootstrap")
+ public void testSingleEnterpriseBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class));
+ webBeansBootstrap.boot();
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Hound.class);
+ }
+
+ @Test(groups="bootstrap")
+ public void testMultipleSimpleBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Tuna.class, Salmon.class, SeaBass.class, Sole.class));
+ webBeansBootstrap.boot();
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Tuna.class);
+ assert classes.containsKey(Salmon.class);
+ assert classes.containsKey(SeaBass.class);
+ assert classes.containsKey(Sole.class);
+
+ assert classes.get(Tuna.class) instanceof SimpleBean;
+ assert classes.get(Salmon.class) instanceof SimpleBean;
+ assert classes.get(SeaBass.class) instanceof SimpleBean;
+ assert classes.get(Sole.class) instanceof SimpleBean;
+ }
+
+ @Test(groups="bootstrap")
+ public void testProducerMethodBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(TarantulaProducer.class));
+ webBeansBootstrap.boot();
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(TarantulaProducer.class);
+ assert classes.containsKey(Tarantula.class);
+
+ assert classes.get(TarantulaProducer.class) instanceof SimpleBean;
+ assert classes.get(Tarantula.class) instanceof ProducerMethodBean;
+ }
+
+ @Test(groups="bootstrap")
+ public void testMultipleEnterpriseBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class));
+ webBeansBootstrap.boot();
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Hound.class);
+ assert classes.containsKey(Elephant.class);
+ assert classes.containsKey(Panther.class);
+ assert classes.containsKey(Tiger.class);
+
+ assert classes.get(Hound.class) instanceof EnterpriseBean;
+ assert classes.get(Elephant.class) instanceof EnterpriseBean;
+ assert classes.get(Panther.class) instanceof EnterpriseBean;
+ assert classes.get(Tiger.class) instanceof EnterpriseBean;
+ }
+
+ @Test(groups="bootstrap")
+ public void testMultipleEnterpriseAndSimpleBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
+ webBeansBootstrap.boot();
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Hound.class);
+ assert classes.containsKey(Elephant.class);
+ assert classes.containsKey(Panther.class);
+ assert classes.containsKey(Tiger.class);
+ assert classes.containsKey(Tuna.class);
+ assert classes.containsKey(Salmon.class);
+ assert classes.containsKey(SeaBass.class);
+ assert classes.containsKey(Sole.class);
+
+ assert classes.get(Hound.class) instanceof EnterpriseBean;
+ assert classes.get(Elephant.class) instanceof EnterpriseBean;
+ assert classes.get(Panther.class) instanceof EnterpriseBean;
+ assert classes.get(Tiger.class) instanceof EnterpriseBean;
+ assert classes.get(Tuna.class) instanceof SimpleBean;
+ assert classes.get(Salmon.class) instanceof SimpleBean;
+ assert classes.get(SeaBass.class) instanceof SimpleBean;
+ assert classes.get(Sole.class) instanceof SimpleBean;
+ }
+
+ @Test(groups="bootstrap")
+ public void testRegisterProducerMethodBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(TarantulaProducer.class));
+ webBeansBootstrap.boot();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : manager.getBeans())
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(TarantulaProducer.class);
+ assert classes.containsKey(Tarantula.class);
+
+
+ assert classes.get(TarantulaProducer.class) instanceof SimpleBean;
+ assert classes.get(Tarantula.class) instanceof ProducerMethodBean;
+ }
+
+ @Test(groups="bootstrap")
+ public void testRegisterMultipleEnterpriseAndSimpleBean()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
+ webBeansBootstrap.boot();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : manager.getBeans())
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Hound.class);
+ assert classes.containsKey(Elephant.class);
+ assert classes.containsKey(Panther.class);
+ assert classes.containsKey(Tiger.class);
+ assert classes.containsKey(Tuna.class);
+ assert classes.containsKey(Salmon.class);
+ assert classes.containsKey(SeaBass.class);
+ assert classes.containsKey(Sole.class);
+
+ assert classes.get(Hound.class) instanceof EnterpriseBean;
+ assert classes.get(Elephant.class) instanceof EnterpriseBean;
+ assert classes.get(Panther.class) instanceof EnterpriseBean;
+ assert classes.get(Tiger.class) instanceof EnterpriseBean;
+ assert classes.get(Tuna.class) instanceof SimpleBean;
+ assert classes.get(Salmon.class) instanceof SimpleBean;
+ assert classes.get(SeaBass.class) instanceof SimpleBean;
+ assert classes.get(Sole.class) instanceof SimpleBean;
+ }
+
+ @Test(groups="bootstrap", expectedExceptions=IllegalStateException.class)
+ public void testDiscoverFails()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(null);
+ webBeansBootstrap.boot();
+ }
+
+ @Test(groups="bootstrap")
+ public void testDiscover()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(Hound.class, Elephant.class, Panther.class, Tiger.class, Tuna.class, Salmon.class, SeaBass.class, Sole.class));
+ webBeansBootstrap.boot();
+
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>, Bean<?>>();
+ for (Bean<?> bean : manager.getBeans())
+ {
+ if (bean instanceof AbstractBean)
+ {
+ classes.put(((AbstractBean<?, ?>) bean).getType(), bean);
+ }
+ }
+ assert classes.containsKey(Hound.class);
+ assert classes.containsKey(Elephant.class);
+ assert classes.containsKey(Panther.class);
+ assert classes.containsKey(Tiger.class);
+ assert classes.containsKey(Tuna.class);
+ assert classes.containsKey(Salmon.class);
+ assert classes.containsKey(SeaBass.class);
+ assert classes.containsKey(Sole.class);
+
+ assert classes.get(Hound.class) instanceof EnterpriseBean;
+ assert classes.get(Elephant.class) instanceof EnterpriseBean;
+ assert classes.get(Panther.class) instanceof EnterpriseBean;
+ assert classes.get(Tiger.class) instanceof EnterpriseBean;
+ assert classes.get(Tuna.class) instanceof SimpleBean;
+ assert classes.get(Salmon.class) instanceof SimpleBean;
+ assert classes.get(SeaBass.class) instanceof SimpleBean;
+ assert classes.get(Sole.class) instanceof SimpleBean;
+ }
+
+ @Test(groups="bootstrap")
+ public void testInitializedEvent()
+ {
+ assert !InitializedObserver.observered;
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(InitializedObserver.class));
+ webBeansBootstrap.boot();
+
+ assert InitializedObserver.observered;
+ }
+
+ @Test(groups="bootstrap")
+ public void testRequestContextActiveDuringInitializtionEvent()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(InitializedObserverWhichUsesRequestContext.class, Tuna.class));
+ webBeansBootstrap.boot();
+ }
+
+ @Test(groups={"bootstrap", "broken"})
+ public void testApplicationContextActiveDuringInitializtionEvent()
+ {
+ webBeansBootstrap.setWebBeanDiscovery(new MockWebBeanDiscovery(InitializedObserverWhichUsesApplicationContext.class, LadybirdSpider.class));
+ webBeansBootstrap.boot();
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/BoostrapTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/ClassAnnotatedItemTest.java (from rev 1012, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ClassAnnotatedItemTest.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/ClassAnnotatedItemTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/ClassAnnotatedItemTest.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,50 @@
+package org.jboss.webbeans.test.unit;
+
+import java.lang.annotation.Annotation;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.webbeans.DeploymentType;
+import javax.webbeans.Production;
+import javax.webbeans.Stereotype;
+
+import org.jboss.webbeans.introspector.AnnotatedClass;
+import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.test.beans.Antelope;
+import org.jboss.webbeans.test.beans.Order;
+import org.testng.annotations.Test;
+
+public class ClassAnnotatedItemTest
+{
+
+ @Test
+ public void testDeclaredAnnotations()
+ {
+ AnnotatedClass<Order> annotatedElement = new AnnotatedClassImpl<Order>(Order.class);
+ assert annotatedElement.getAnnotations().size() == 1;
+ assert annotatedElement.getAnnotation(Production.class) != null;
+ assert annotatedElement.getType().equals(Order.class);
+ }
+
+ @Test
+ public void testMetaAnnotations()
+ {
+ AnnotatedClass<Order> annotatedElement = new AnnotatedClassImpl<Order>(Order.class);
+ Set<Annotation> annotations = annotatedElement.getMetaAnnotations(DeploymentType.class);
+ assert annotations.size() == 1;
+ Iterator<Annotation> it = annotations.iterator();
+ Annotation production = it.next();
+ assert Production.class.equals(production.annotationType());
+ }
+
+ @Test
+ public void testEmpty()
+ {
+ AnnotatedClass<Order> annotatedElement = new AnnotatedClassImpl<Order>(Order.class);
+ assert annotatedElement.getAnnotation(Stereotype.class) == null;
+ assert annotatedElement.getMetaAnnotations(Stereotype.class).size() == 0;
+ AnnotatedClass<Antelope> classWithNoAnnotations = new AnnotatedClassImpl<Antelope>(Antelope.class);
+ assert classWithNoAnnotations.getAnnotations().size() == 0;
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/unit/ClassAnnotatedItemTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java
===================================================================
--- tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ tck/trunk/api/src/main/java/org/jboss/webbeans/tck/api/Beans.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -85,6 +85,7 @@
* @return true only if class declares an entity bean
*/
public boolean isEntityBean(Class<?> clazz);
+
/**
* Create a new producer field bean from the given method.
*
@@ -95,4 +96,6 @@
*/
public <T> Bean<T> createProducerFieldBean(Field field, Bean<?> declaringBean);
+ public boolean isProxy(Object instance);
+
}
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterable.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -9,7 +9,7 @@
* @author Pete Muir
* @see org.jboss.webbeans.util.EnumerationIterator
*/
-public class EnumerationIterable<T> implements Iterable<T>
+class EnumerationIterable<T> implements Iterable<T>
{
// The enumeration-iteartor
private EnumerationIterator<T> iterator;
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/EnumerationIterator.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -9,7 +9,7 @@
* @author Pete Muir
*/
@SuppressWarnings("unchecked")
-public class EnumerationIterator<T> implements Iterator<T>
+class EnumerationIterator<T> implements Iterator<T>
{
// The enumeration
private Enumeration e;
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Reflections.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -1,25 +1,11 @@
package org.jboss.webbeans.tck.impl.util;
-import java.beans.Introspector;
-import java.io.Serializable;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
-import javax.webbeans.BindingType;
-import javax.webbeans.ExecutionException;
-
/**
* Utility class for static reflection-type operations
*
@@ -28,299 +14,7 @@
*/
public class Reflections
{
-
/**
- * Gets the property name from a getter method
- *
- * @param method The getter method
- * @return The name of the property. Returns null if method wasn't JavaBean
- * getter-styled
- */
- public static String getPropertyName(Method method)
- {
- String methodName = method.getName();
- if (methodName.matches("^(get).*") && method.getParameterTypes().length == 0)
- {
- return Introspector.decapitalize(methodName.substring(3));
- }
- else if (methodName.matches("^(is).*") && method.getParameterTypes().length == 0)
- {
- return Introspector.decapitalize(methodName.substring(2));
- }
- else
- {
- return null;
- }
-
- }
-
- /**
- * Checks if class is final
- *
- * @param clazz The class to check
- * @return True if final, false otherwise
- */
- public static boolean isFinal(Class<?> clazz)
- {
- return Modifier.isFinal(clazz.getModifiers());
- }
-
- /**
- * Checks if member is final
- *
- * @param member The member to check
- * @return True if final, false otherwise
- */
- public static boolean isFinal(Member member)
- {
- return Modifier.isFinal(member.getModifiers());
- }
-
- /**
- * Checks if type or member is final
- *
- * @param type Type or member
- * @return True if final, false otherwise
- */
- public static boolean isTypeOrAnyMethodFinal(Class<?> type)
- {
- if (isFinal(type))
- {
- return true;
- }
- for (Method method : type.getDeclaredMethods())
- {
- if (isFinal(method))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Checks if type is primitive
- *
- * @param type Type to check
- * @return True if primitive, false otherwise
- */
- public static boolean isPrimitive(Class<?> type)
- {
- return type.isPrimitive();
- }
-
- /**
- * Checks if type is static
- *
- * @param type Type to check
- * @return True if static, false otherwise
- */
- public static boolean isStatic(Class<?> type)
- {
- return Modifier.isStatic(type.getModifiers());
- }
-
- /**
- * Checks if member is static
- *
- * @param member Member to check
- * @return True if static, false otherwise
- */
- public static boolean isStatic(Member member)
- {
- return Modifier.isStatic(member.getModifiers());
- }
-
- public static boolean isTransient(Member member)
- {
- return Modifier.isTransient(member.getModifiers());
- }
-
- /**
- * Checks if clazz is abstract
- *
- * @param clazz Class to check
- * @return True if abstract, false otherwise
- */
- public static boolean isAbstract(Class<?> clazz)
- {
- return Modifier.isAbstract(clazz.getModifiers());
- }
-
- /**
- * Checks if class is a static inner one
- *
- * @param clazz Class to check
- * @return True if static, false otherwise
- */
- public static boolean isStaticInnerClass(Class<?> clazz)
- {
- return clazz.isMemberClass() && isStatic(clazz);
- }
-
- /**
- * Checks if class is a non-static inner one
- *
- * @param clazz Class to Check
- * @return True if static, false otherwise
- */
- public static boolean isNonStaticInnerClass(Class<?> clazz)
- {
- return clazz.isMemberClass() && !isStatic(clazz);
- }
-
- /**
- * Gets a constructor with matching parameter types
- *
- * @param <T> The type
- * @param clazz The class
- * @param parameterTypes The parameter types
- * @return The matching constructor. Null is returned if none is found
- */
- public static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... parameterTypes)
- {
- try
- {
- return clazz.getConstructor(parameterTypes);
- }
- catch (NoSuchMethodException e)
- {
- return null;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Error accessing constructor (with parameters " + parameterTypes + ") of " + clazz, e);
- }
- }
-
- /**
- * Gets all methods with a given annotation
- *
- * @param clazz The class the examine
- * @param annotationType The annotation type to search for
- * @return A list of matching methods. An empty list is returned if no
- * matches are found
- */
- public static List<Method> getMethods(Class<?> clazz, Class<? extends Annotation> annotationType)
- {
- List<Method> methods = new ArrayList<Method>();
- for (Method method : clazz.getMethods())
- {
- if (method.isAnnotationPresent(annotationType))
- {
- methods.add(method);
- }
- }
- return methods;
- }
-
- /**
- * Gets all constructors with a given annotation
- *
- * @param <T> The type of the class
- * @param clazz The class
- * @param annotationType The annotation type
- * @return A list of matching constructors. An empty list is returned if no
- * matches are found
- */
- @SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>> getAnnotatedConstructors(Class<? extends T> clazz, Class<? extends Annotation> annotationType)
- {
- List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
- for (Constructor<?> constructor : clazz.getConstructors())
- {
- if (constructor.isAnnotationPresent(annotationType))
- {
- constructors.add((Constructor<T>) constructor);
- }
- }
- return constructors;
- }
-
- /**
- * Gets constructors with a given annotated parameter
- *
- * @param <T> The type
- * @param clazz The class
- * @param parameterAnnotationType The parameter annotation type
- * @return A list of matching constructors. An empty list is returned if no
- * matches are found
- */
- @SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>> getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> parameterAnnotationType)
- {
- List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
- for (Constructor<?> constructor : clazz.getConstructors())
- {
- for (Annotation[] annotations : constructor.getParameterAnnotations())
- {
- for (Annotation annotation : annotations)
- {
- if (annotation.annotationType().equals(parameterAnnotationType))
- {
- constructors.add((Constructor<T>) constructor);
- }
- }
- }
- }
- return constructors;
- }
-
- /**
- * Gets constructors with a given meta-annotated parameter
- *
- * @param <T> The type
- * @param clazz The class
- * @param metaAnnotationType The parameter meta-annotation type
- * @return A list of matching constructors. An empty list is returned if no
- * matches are found
- */
- @SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>> getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> metaAnnotationType)
- {
- List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
- for (Constructor<?> constructor : clazz.getConstructors())
- {
- for (Annotation[] annotations : constructor.getParameterAnnotations())
- {
- for (Annotation annotation : annotations)
- {
- if (annotation.annotationType().isAnnotationPresent(metaAnnotationType))
- {
- constructors.add((Constructor<T>) constructor);
- }
- }
- }
- }
- return constructors;
- }
-
- /**
- * Checks if all annotations types are in a given set of annotations
- *
- * @param annotations The annotation set
- * @param annotationTypes The annotation types to match
- * @return True if match, false otherwise
- */
- public static boolean annotationTypeSetMatches(Set<Class<? extends Annotation>> annotations, Class<? extends Annotation>... annotationTypes)
- {
- List<Class<? extends Annotation>> annotationTypeList = new ArrayList<Class<? extends Annotation>>();
- annotationTypeList.addAll(Arrays.asList(annotationTypes));
- for (Class<? extends Annotation> annotation : annotations)
- {
- if (annotationTypeList.contains(annotation))
- {
- annotationTypeList.remove(annotation);
- }
- else
- {
- return false;
- }
- }
- return annotationTypeList.size() == 0;
- }
-
- /**
* Checks if all annotations are in a given set of annotations
*
* @param annotations The annotation set
@@ -345,285 +39,4 @@
return annotationTypeList.size() == 0;
}
- /**
- * Gets the actual type arguments of a class
- *
- * @param clazz The class to examine
- * @return The type arguments
- */
- public static Type[] getActualTypeArguments(Class<?> clazz)
- {
- if (clazz.getGenericSuperclass() instanceof ParameterizedType)
- {
- return ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments();
- }
- else
- {
- return new Type[0];
- }
- }
-
- /**
- * Checks if raw type is array type
- *
- * @param rawType The raw type to check
- * @return True if array, false otherwise
- */
- public static boolean isArrayType(Class<?> rawType)
- {
- return rawType.isArray();
- }
-
- /**
- * Checks if type is parameterized type
- *
- * @param type The type to check
- * @return True if parameterized, false otherwise
- */
- public static boolean isParameterizedType(Class<?> type)
- {
- return type.getTypeParameters().length > 0;
- }
-
- /**
- * Invokes a method and wraps exceptions
- *
- * @param method The method to invoke
- * @param instance The instance to invoke on
- * @param parameters The parameters
- * @return The return value
- */
- public static Object invokeAndWrap(Method method, Object instance, Object... parameters)
- {
- try
- {
- return method.invoke(instance, parameters);
- }
- catch (IllegalArgumentException e)
- {
- throw new ExecutionException("Error invoking method " + method.getName() + " on " + method.getDeclaringClass(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new ExecutionException("Error invoking method " + method.getName() + " on " + method.getDeclaringClass(), e);
- }
- catch (InvocationTargetException e)
- {
- throw new ExecutionException("Error invoking method " + method.getName() + " on " + method.getDeclaringClass(), e);
- }
- }
-
- /**
- * Invokes a method and wraps exceptions
- *
- * @param methodName The method name to find on the instance and invoke
- * @param parameterTypes The method name to find on the instance and invoke
- * @param instance The instance to invoke on
- * @param parameterValues The parameters values
- * @return The return value
- */
- public static Object invokeAndWrap(String methodName, Class<?>[] parameterTypes, Object instance, Object[] parameterValues)
- {
- try
- {
- return instance.getClass().getMethod(methodName, parameterTypes).invoke(instance, parameterValues);
- }
- catch (IllegalArgumentException e)
- {
- throw new ExecutionException("Error invoking method " + methodName + " on " + instance.getClass(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new ExecutionException("Error invoking method " + methodName + " on " + instance.getClass(), e);
- }
- catch (InvocationTargetException e)
- {
- throw new ExecutionException("Error invoking method " + methodName + " on " + instance.getClass(), e);
- }
- catch (SecurityException e)
- {
- throw new ExecutionException("Error invoking method " + methodName + " on " + instance.getClass(), e);
- }
- catch (NoSuchMethodException e)
- {
- throw new ExecutionException("Error invoking method " + methodName + " on " + instance.getClass(), e);
- }
- }
-
- /**
- * Sets value of a field and wraps exceptions
- *
- * @param field The field to set on
- * @param target The instance to set on
- * @param value The value to set
- */
- public static void setAndWrap(Field field, Object target, Object value)
- {
- try
- {
- field.set(target, value);
- }
- catch (IllegalArgumentException e)
- {
- throw new ExecutionException("Error setting field " + field.getName() + " on " + field.getDeclaringClass(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new ExecutionException("Error setting field " + field.getName() + " on " + field.getDeclaringClass(), e);
- }
- }
-
- /**
- * Sets value of a field and wraps exceptions
- *
- * @param field The field to set on
- * @param target The instance to set on
- * @param value The value to set
- */
- public static void setAndWrap(String fieldName, Object target, Object value)
- {
- try
- {
- target.getClass().getField(fieldName).set(target, value);
- }
- catch (IllegalArgumentException e)
- {
- throw new ExecutionException("Error setting field " + fieldName + " on " + target.getClass(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new ExecutionException("Error setting field " + fieldName + " on " + target.getClass(), e);
- }
- catch (SecurityException e)
- {
- throw new ExecutionException("Error setting field " + fieldName + " on " + target.getClass(), e);
- }
- catch (NoSuchFieldException e)
- {
- throw new ExecutionException("Error setting field " + fieldName + " on " + target.getClass(), e);
- }
- }
-
- /**
- * Gets value of a field and wraps exceptions
- *
- * @param field The field to set on
- * @param target The instance to set on
- * @return The value to set
- */
- public static Object getAndWrap(Field field, Object target)
- {
- try
- {
- return field.get(target);
- }
- catch (IllegalArgumentException e)
- {
- throw new ExecutionException("Error getting field " + field.getName() + " on " + field.getDeclaringClass(), e);
- }
- catch (IllegalAccessException e)
- {
- throw new ExecutionException("Error getting field " + field.getName() + " on " + field.getDeclaringClass(), e);
- }
- }
-
- /**
- * Looks up a method in the type hierarchy of an instance
- *
- * @param method The method to look for
- * @param instance The instance to start from
- * @return The method found, or an NoSuchMethodException if it is not found
- */
- public static Method lookupMethod(Method method, Object instance)
- {
- for (Class<? extends Object> clazz = instance.getClass(); clazz != null; clazz = clazz.getSuperclass())
- {
- try
- {
- Method targetMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
- if (!targetMethod.isAccessible())
- {
- targetMethod.setAccessible(true);
- }
- return targetMethod;
- }
- catch (NoSuchMethodException nsme)
- {
- // Expected, nothing to see here.
- }
- }
- throw new IllegalArgumentException("Method " + method.getName() + " not implemented by instance");
- }
-
- /**
- * Indicates if an instance is a Javassist proxy
- *
- * @param instance The instance to examine
- * @return True if proxy, false otherwise
- */
- public static boolean isProxy(Object instance)
- {
- return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
- }
-
- /**
- * Gets the type hierarchy for a class
- *
- * A recursive function that adds the class to the set of type and then calls
- * itself with the suprerclass as paramater until the top of the hierarchy is
- * reached. For each steps, adds all interfaces of the class to the set.
- * Since the data structure is a set, duplications are eliminated
- *
- * @param clazz The class to examine
- * @return The set of classes and interfaces in the hierarchy
- * @see #getTypeHierachy(Class, Set)
- */
- public static Set<Class<?>> getTypeHierachy(Class<?> clazz)
- {
- Set<Class<?>> classes = new HashSet<Class<?>>();
- getTypeHierachy(clazz, classes);
- return classes;
- }
-
- /**
- * Gets the flattened type hierarchy for a class, including all super classes
- * and the entire interface type hierarchy
- *
- * @param clazz the class to examine
- * @param classes the set of types
- */
- public static void getTypeHierachy(Class<?> clazz, Set<? super Class<?>> classes)
- {
- if (clazz != null)
- {
- classes.add(clazz);
- getTypeHierachy(clazz.getSuperclass(), classes);
- for (Class<?> c : clazz.getInterfaces())
- {
- getTypeHierachy(c, classes);
- }
- }
- }
-
- /**
- * Checks the bindingType to make sure the annotation was declared properly
- * as a binding type (annotated with @BindingType).
- *
- * @param bindingType The binding type to check
- * @return true only if the annotation is really a binding type
- */
- public static boolean isBindingType(Annotation bindingType)
- {
- boolean isBindingAnnotation = false;
- if (bindingType.annotationType().isAnnotationPresent(BindingType.class))
- {
- isBindingAnnotation = true;
- }
- return isBindingAnnotation;
- }
-
- public static boolean isSerializable(Class<?> clazz)
- {
- return getTypeHierachy(clazz).contains(Serializable.class);
- }
-}
\ No newline at end of file
+}
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/ResourceLoadingException.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -8,7 +8,7 @@
* @author Pete Muir
*
*/
-public class ResourceLoadingException extends ExecutionException
+class ResourceLoadingException extends ExecutionException
{
private static final long serialVersionUID = 1L;
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/SimpleResourceLoader.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -3,7 +3,7 @@
import java.io.IOException;
import java.net.URL;
-public class SimpleResourceLoader
+class SimpleResourceLoader
{
public Class<?> classForName(String name)
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java 2009-01-16 13:44:43 UTC (rev 1016)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/impl/util/Strings.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -2,7 +2,7 @@
import java.util.StringTokenizer;
-public class Strings
+class Strings
{
public static String[] split(String strings, String delims)
{
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/AnotherDeploymentType.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/AnotherDeploymentType.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/AnotherDeploymentType.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.tck.tests.lookup.clientProxy;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.DeploymentType;
+
+ at Target( { TYPE, METHOD })
+ at Retention(RUNTIME)
+ at Documented
+ at DeploymentType
+ at interface AnotherDeploymentType
+{
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/AnotherDeploymentType.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/ClientProxyTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/ClientProxyTest.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/ClientProxyTest.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,101 @@
+package org.jboss.webbeans.tck.tests.lookup.clientProxy;
+
+import static org.jboss.webbeans.tck.impl.WebBeansTCKImpl.configuration;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.util.List;
+
+import javax.webbeans.DefinitionException;
+import javax.webbeans.UnproxyableDependencyException;
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.tck.impl.SpecAssertion;
+import org.jboss.webbeans.tck.impl.SpecVersion;
+import org.jboss.webbeans.tck.tests.AbstractTest;
+import org.testng.annotations.Test;
+
+ at SpecVersion("20081206")
+public class ClientProxyTest extends AbstractTest
+{
+
+ @Override
+ protected List<Class<? extends Annotation>> getEnabledDeploymentTypes()
+ {
+ List<Class<? extends Annotation>> deploymentTypes = super.getEnabledDeploymentTypes();
+ deploymentTypes.add(AnotherDeploymentType.class);
+ return deploymentTypes;
+ }
+
+ @Test(groups = "configuration().getBeans()")
+ @SpecAssertion(section = { "5.4" })
+ public void testClientProxyUsedForNormalScope()
+ {
+ Bean<Tuna> tunaBean = getSimpleBean(Tuna.class);
+ manager.addBean(tunaBean);
+ Tuna tuna = manager.getInstance(tunaBean);
+ assert configuration().getBeans().isProxy(tuna);
+ }
+
+ @Test(groups = "configuration().getBeans()")
+ @SpecAssertion(section = { "5.4" })
+ public void testClientProxyNotUsedForPseudoScope()
+ {
+ Bean<Fox> foxBean = getSimpleBean(Fox.class);
+ try
+ {
+ activateDependentContext();
+ Fox fox = manager.getInstance(foxBean);
+ assert !configuration().getBeans().isProxy(fox);
+ }
+ finally
+ {
+ deactivateDependentContext();
+ }
+ }
+
+ @Test(groups = "configuration().getBeans()")
+ @SpecAssertion(section = "5.4")
+ public void testSimpleWebBeanClientProxyIsSerializable() throws IOException, ClassNotFoundException
+ {
+ Bean<TunedTuna> tunaBean = getSimpleBean(TunedTuna.class);
+ manager.addBean(tunaBean);
+ TunedTuna tuna = manager.getInstance(tunaBean);
+ assert configuration().getBeans().isProxy(tuna);
+ byte[] bytes = serialize(tuna);
+ tuna = (TunedTuna) deserialize(bytes);
+ assert configuration().getBeans().isProxy(tuna);
+ assert tuna.getState().equals("tuned");
+ }
+
+ @Test(groups = "configuration().getBeans()", expectedExceptions = UnproxyableDependencyException.class)
+ @SpecAssertion(section = "5.4.1")
+ public void testInjectionPointWithUnproxyableTypeWhichResolvesToNormalScopedWebBean()
+ {
+ Bean<FinalTuna_Broken> tunaBean = getSimpleBean(FinalTuna_Broken.class);
+ manager.addBean(tunaBean);
+ @SuppressWarnings("unused")
+ FinalTuna_Broken tuna = manager.getInstanceByType(FinalTuna_Broken.class);
+ assert false;
+ }
+
+ @Test(groups = "configuration().getBeans()")
+ @SpecAssertion(section = "5.4.2")
+ public void testClientProxyInvocation()
+ {
+ Bean<TunedTuna> tunaBean = getSimpleBean(TunedTuna.class);
+ manager.addBean(tunaBean);
+ TunedTuna tuna = manager.getInstance(tunaBean);
+ assert configuration().getBeans().isProxy(tuna);
+ assert tuna.getState().equals("tuned");
+ }
+
+ @Test(groups = "configuration().getBeans()", expectedExceptions=DefinitionException.class)
+ public void testGettingUnknownBeanFails() {
+ Bean<Tuna> tunaBean = getSimpleBean(Tuna.class);
+ @SuppressWarnings("unused")
+ Tuna tuna = manager.getInstance(tunaBean);
+ assert false;
+ }
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/ClientProxyTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/FinalTuna_Broken.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/FinalTuna_Broken.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/FinalTuna_Broken.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.tck.tests.lookup.clientProxy;
+
+import javax.webbeans.RequestScoped;
+
+ at AnotherDeploymentType
+ at RequestScoped
+final class FinalTuna_Broken
+{
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/FinalTuna_Broken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Fox.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Fox.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Fox.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.tck.tests.lookup.clientProxy;
+
+import javax.webbeans.Dependent;
+
+ at Dependent
+class Fox
+{
+
+ public String getName()
+ {
+ return "gavin";
+ }
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Fox.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Tuna.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Tuna.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Tuna.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.tck.tests.lookup.clientProxy;
+
+import javax.webbeans.RequestScoped;
+
+ at AnotherDeploymentType
+ at RequestScoped
+class Tuna
+{
+
+ public String getName()
+ {
+ return "Ophir";
+ }
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/Tuna.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/TunedTuna.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/TunedTuna.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/TunedTuna.java 2009-01-16 14:03:04 UTC (rev 1017)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.tck.tests.lookup.clientProxy;
+
+import javax.webbeans.RequestScoped;
+
+ at AnotherDeploymentType
+ at RequestScoped
+class TunedTuna
+{
+ public String getState()
+ {
+ return "tuned";
+ }
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/tests/lookup/clientProxy/TunedTuna.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list