Author: pete.muir(a)jboss.org
Date: 2009-03-22 14:46:31 -0400 (Sun, 22 Mar 2009)
New Revision: 2133
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/BootstrapTest.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlyAnimal.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlySpider.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DefangedTarantula.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Spider.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tame.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tarantula.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/TarantulaProducer.java
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
Log:
add more ordering and more tests
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-03-22
17:18:51 UTC (rev 2132)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -64,6 +64,7 @@
private Set<FieldInjectionPoint<?>> injectableFields;
// The initializer methods
private Set<MethodInjectionPoint<?>> initializerMethods;
+ private Set<String> dependencies;
/**
* Constructor
@@ -122,6 +123,11 @@
{
log.trace("Bean type specified in Java");
this.type = getAnnotatedItem().getRawType();
+ this.dependencies = new HashSet<String>();
+ for (Class<?> clazz = type.getSuperclass(); clazz != Object.class; clazz =
clazz.getSuperclass())
+ {
+ dependencies.add(clazz.getName());
+ }
}
/**
@@ -309,6 +315,12 @@
{
return initializerMethods;
}
+
+ // TODO maybe a better way to expose this?
+ public Set<String> getSuperclasses()
+ {
+ return dependencies;
+ }
/**
* Gets a string representation
Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-22
17:18:51 UTC (rev 2132)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -453,15 +453,6 @@
}
/**
- * Initializes the bean type
- */
- protected void initType()
- {
- log.trace("Bean type specified in Java");
- this.type = getAnnotatedItem().getRawType();
- }
-
- /**
* Returns the constructor
*
* @return The constructor
Modified:
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java
===================================================================
---
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java 2009-03-22
17:18:51 UTC (rev 2132)
+++
ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BootstrapOrderingBeanComparator.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -25,100 +25,56 @@
{
return o1.getId().compareTo(o2.getId());
}
- else if (o1.getType().getName().startsWith("org.jboss.webbeans")
&& !o2.getType().getName().startsWith("org.jboss.webbeans"))
+
+ if (o1 instanceof AbstractClassBean && o2 instanceof AbstractClassBean)
{
- return -1;
- }
- else if (!o1.getType().getName().startsWith("org.jboss.webbeans")
&& o2.getType().getName().startsWith("org.jboss.webbeans"))
- {
- return 1;
- }
- else if (o1 instanceof AbstractClassBean)
- {
AbstractClassBean<?> b1 = (AbstractClassBean<?>) o1;
- if (o2 instanceof NewBean && !(o1 instanceof NewBean))
+ AbstractClassBean<?> b2 = (AbstractClassBean<?>) o2;
+ if (b1.getSuperclasses().contains(b2.getType().getName()))
{
- // Always initialize new beans after class beans
- return -1;
- }
- else if (o1 instanceof NewBean && o2 instanceof AbstractClassBean
&& !(o2 instanceof NewBean))
- {
- // Always initialize new beans after class beans
+ // Place o1 after it's superclass
return 1;
}
- else if (o1 instanceof NewBean && !(o2 instanceof NewBean))
+ else if (b2.getSuperclasses().contains(b1.getType().getName()))
{
- // Always initialize new class beans after class beans but before other
beans
+ // Place o1 before it's subclass o2
return -1;
}
- else if (o1 instanceof NewBean && o2 instanceof NewBean)
- {
- return o1.getId().compareTo(o2.getId());
- }
- else if (o2 instanceof AbstractClassBean)
- {
- AbstractClassBean<?> b2 = (AbstractClassBean<?>) o2;
- if (o1.getTypes().contains(b2.getType()))
- {
- return 1;
- }
- else if (b2.getTypes().contains(b1.getType()))
- {
- return -1;
- }
- else
- {
- return o1.getId().compareTo(o2.getId());
- }
- }
- else if (o2 instanceof AbstractProducerBean)
- {
- // Producer beans are always initialized after class beans
- return -1;
- }
- else
- {
- // Ordering doesn't matter
- return o1.getId().compareTo(o2.getId());
- }
}
- else if (o1 instanceof AbstractProducerBean)
+ else if (o2 instanceof AbstractProducerBean)
{
+ // Producer beans are always initialized after class beans
+ return -1;
+ }
+
+ if (o1 instanceof AbstractProducerBean)
+ {
AbstractProducerBean<?, ?> b1 = (AbstractProducerBean<?, ?>) o1;
- if (o2 instanceof NewBean)
+ if (o2 instanceof AbstractClassBean &&
b1.getDeclaringBean().equals(o2))
{
- // Always initialize producers beans after new beans
return 1;
}
- else if (o2 instanceof AbstractClassBean)
- {
- if (b1.getDeclaringBean().equals(o2))
- {
- return 1;
- }
- else
- {
- return o1.getId().compareTo(o2.getId());
- }
- }
- else
- {
- // Ordering doesn't matter
- return o1.getId().compareTo(o2.getId());
- }
}
- else
+
+ if (o1.getType().getName().startsWith("org.jboss.webbeans") &&
!o2.getType().getName().startsWith("org.jboss.webbeans"))
{
- if (o2 instanceof AbstractClassBean || o2 instanceof AbstractProducerBean)
- {
- // Initialize undefined ordering after defined ordering
- return 1;
- }
- else
- {
- return o1.getId().compareTo(o2.getId());
- }
+ return -1;
}
+ else if (!o1.getType().getName().startsWith("org.jboss.webbeans")
&& o2.getType().getName().startsWith("org.jboss.webbeans"))
+ {
+ return 1;
+ }
+
+ if (!(o1 instanceof NewBean) && o2 instanceof NewBean)
+ {
+ return -1;
+ }
+ else if (o1 instanceof NewBean && !(o2 instanceof NewBean))
+ {
+ return 1;
+ }
+
+ return o1.getId().compareTo(o2.getId());
}
}
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/BootstrapTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/BootstrapTest.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/BootstrapTest.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,43 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.manager.Bean;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.unit.AbstractWebBeansTest;
+import org.testng.annotations.Test;
+
+@Artifact
+(a)Packaging(PackagingType.EAR)
+public class BootstrapTest extends AbstractWebBeansTest
+{
+
+ @Test(groups="bootstrap")
+ public void testProducerMethodBean()
+ {
+ //deployBeans(TarantulaProducer.class);
+ List<Bean<?>> beans = manager.getBeans();
+ Map<Class<?>, Bean<?>> classes = new HashMap<Class<?>,
Bean<?>>();
+ for (Bean<?> bean : beans)
+ {
+ if (bean instanceof RIBean)
+ {
+ classes.put(((RIBean<?>) 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;
+ }
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/BootstrapTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlyAnimal.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlyAnimal.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlyAnimal.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+interface DeadlyAnimal
+{
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlyAnimal.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlySpider.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlySpider.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlySpider.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+interface DeadlySpider extends DeadlyAnimal
+{
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeadlySpider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DefangedTarantula.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DefangedTarantula.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DefangedTarantula.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+class DefangedTarantula extends Tarantula
+{
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DefangedTarantula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-22
17:18:51 UTC (rev 2132)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/DeployerOrderingTest.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.Arrays;
+import javax.inject.AnnotationLiteral;
+
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.Classes;
import org.jboss.testharness.impl.packaging.Packaging;
@@ -110,4 +112,59 @@
}
}
+ @Test(groups="bootstrap")
+ public void testProducerMethodAfterDeclaringBean()
+ {
+ BeanDeployer beanDeployer = new BeanDeployer(manager);
+ beanDeployer.addClasses(Arrays.asList(TarantulaProducer.class, Tuna.class));
+ beanDeployer.createBeans();
+ int indexOfProducerDeclaringBean = 0;
+ int indexOfProducer = 0;
+ int i = 0;
+ assert beanDeployer.getBeans().size() == 5;
+ for (RIBean<?> bean : beanDeployer.getBeans())
+ {
+ if (bean.getType().equals(TarantulaProducer.class))
+ {
+ indexOfProducerDeclaringBean = i;
+ }
+ if (bean.getType().equals(Tarantula.class) &&
bean.getBindings().contains(new AnnotationLiteral<Tame>() {}))
+ {
+ indexOfProducer = i;
+ }
+ i++;
+ }
+ }
+
+ @Test(groups="bootstrap")
+ public void testClassHierarchies()
+ {
+ BeanDeployer beanDeployer = new BeanDeployer(manager);
+ beanDeployer.addClasses(Arrays.asList(Spider.class, Tarantula.class,
DefangedTarantula.class, Tuna.class));
+ beanDeployer.createBeans();
+ assert beanDeployer.getBeans().size() == 8;
+ int indexOfSpider = 0;
+ int indexOfTarantula = 0;
+ int indexOfDefangedTarantula = 0;
+ int i = 0;
+ for (RIBean<?> bean : beanDeployer.getBeans())
+ {
+ if (bean.getType().equals(Spider.class))
+ {
+ indexOfSpider = i;
+ }
+ if (bean.getType().equals(Tarantula.class))
+ {
+ indexOfTarantula = i;
+ }
+ if (bean.getType().equals(DefangedTarantula.class))
+ {
+ indexOfDefangedTarantula = i;
+ }
+ i++;
+ }
+ assert indexOfDefangedTarantula > indexOfTarantula;
+ assert indexOfTarantula > indexOfSpider;
+ }
+
}
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Spider.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Spider.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Spider.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+class Spider implements Animal
+{
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Spider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tame.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tame.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tame.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,22 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+@interface Tame
+{
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tame.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tarantula.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tarantula.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tarantula.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+class Tarantula extends Spider implements DeadlySpider
+{
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/Tarantula.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/TarantulaProducer.java
===================================================================
---
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/TarantulaProducer.java
(rev 0)
+++
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/TarantulaProducer.java 2009-03-22
18:46:31 UTC (rev 2133)
@@ -0,0 +1,13 @@
+package org.jboss.webbeans.test.unit.bootstrap.ordering;
+
+import javax.inject.Produces;
+
+public class TarantulaProducer
+{
+
+ @Produces @Tame public Tarantula produceTameTarantula()
+ {
+ return new DefangedTarantula();
+ }
+
+}
Property changes on:
ri/trunk/tests/src/test/java/org/jboss/webbeans/test/unit/bootstrap/ordering/TarantulaProducer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Show replies by date