[webbeans-commits] Webbeans SVN: r196 - in ri/trunk/webbeans-ri: src/main/java/org/jboss/webbeans and 4 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Tue Oct 28 08:54:18 EDT 2008
Author: pete.muir at jboss.org
Date: 2008-10-28 08:54:18 -0400 (Tue, 28 Oct 2008)
New Revision: 196
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Fox.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.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/DeferredEventNotificationTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.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/ObserverTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java
ri/trunk/webbeans-ri/testng.xml
Log:
Tests for dependent context
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-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -60,11 +60,11 @@
private Set<Bean<?>> beans;
- public ManagerImpl(List<Class<? extends Annotation>> enabledDeploymentTypes)
+ public ManagerImpl()
{
contextMap = new ContextMap();
// TODO Are there any contexts that should be initialized here?
- initEnabledDeploymentTypes(enabledDeploymentTypes);
+ initEnabledDeploymentTypes(null);
this.modelManager = new ModelManager();
this.ejbLookupManager = new EjbManager();
this.beans = new HashSet<Bean<?>>();
@@ -72,7 +72,7 @@
this.resolutionManager = new ResolutionManager(this);
}
- private void initEnabledDeploymentTypes(List<Class<? extends Annotation>> enabledDeploymentTypes)
+ protected void initEnabledDeploymentTypes(List<Class<? extends Annotation>> enabledDeploymentTypes)
{
this.enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
if (enabledDeploymentTypes == null)
@@ -170,7 +170,6 @@
contextMap.put(context.getScopeType(), sameScopeTypeContexts);
}
sameScopeTypeContexts.add(context);
- // TODO: why manager? fluent interfaces?
return this;
}
@@ -218,7 +217,7 @@
List<Context> contexts = contextMap.get(scopeType);
if (contexts == null)
{
- throw new ContextNotActiveException("No contexts for " + scopeType.getName());
+ throw new ContextNotActiveException("No active contexts for " + scopeType.getName());
}
// TODO performance? Just flag found=true and continue loop, failing when
// found=already true etc?
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-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -62,7 +62,7 @@
{
destroy(manager, bean);
}
- beans = null;
+ beans = new BeanMap();
}
}
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-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -7,7 +7,10 @@
import javax.webbeans.Production;
import javax.webbeans.Standard;
-import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.contexts.ApplicationContext;
+import org.jboss.webbeans.contexts.DependentContext;
+import org.jboss.webbeans.contexts.RequestContext;
+import org.jboss.webbeans.contexts.SessionContext;
import org.jboss.webbeans.model.StereotypeModel;
import org.jboss.webbeans.test.annotations.AnimalStereotype;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
@@ -23,31 +26,49 @@
public class AbstractTest
{
- protected ManagerImpl manager;
+ protected MockManagerImpl manager;
@BeforeMethod
- public void before()
+ public final void before()
{
-
+ manager = new MockManagerImpl();
+ init();
+ }
+
+ protected void init()
+ {
+ addStereotypes();
+ addBuiltInContexts();
+ addEnabledDeploymentTypes();
+ }
+
+ protected void addEnabledDeploymentTypes()
+ {
List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
enabledDeploymentTypes.add(Standard.class);
enabledDeploymentTypes.add(Production.class);
enabledDeploymentTypes.add(AnotherDeploymentType.class);
enabledDeploymentTypes.add(HornedAnimalDeploymentType.class);
- manager = new MockManagerImpl(enabledDeploymentTypes);
-
- initStereotypes(manager);
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
- private void initStereotypes(ManagerImpl container)
+ protected void addStereotypes()
{
- 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));
+ manager.getModelManager().addStereotype(new StereotypeModel<AnimalStereotype>(AnimalStereotype.class));
+ manager.getModelManager().addStereotype(new StereotypeModel<HornedMammalStereotype>(HornedMammalStereotype.class));
+ manager.getModelManager().addStereotype(new StereotypeModel<MammalStereotype>(MammalStereotype.class));
+ manager.getModelManager().addStereotype(new StereotypeModel<FishStereotype>(FishStereotype.class));
+ manager.getModelManager().addStereotype(new StereotypeModel<RiverFishStereotype>(RiverFishStereotype.class));
+ manager.getModelManager().addStereotype(new StereotypeModel<RequestScopedAnimalStereotype>(RequestScopedAnimalStereotype.class));
}
+
+ protected void addBuiltInContexts()
+ {
+ manager.addContext(new DependentContext());
+ manager.addContext(new RequestContext());
+ manager.addContext(new SessionContext());
+ manager.addContext(new ApplicationContext());
+ }
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -10,7 +10,6 @@
import javax.webbeans.Observes;
import javax.webbeans.Standard;
-import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.event.DeferredEventNotification;
import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedType;
@@ -20,7 +19,6 @@
import org.jboss.webbeans.test.annotations.Asynchronous;
import org.jboss.webbeans.test.beans.Tuna;
import org.jboss.webbeans.test.bindings.AsynchronousAnnotationLiteral;
-import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.jboss.webbeans.test.mock.MockObserverImpl;
import org.testng.annotations.Test;
@@ -38,6 +36,15 @@
{
// Simple class used for testing
}
+
+ @Override
+ protected void addEnabledDeploymentTypes()
+ {
+ List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
+ enabledDeploymentTypes.add(Standard.class);
+ enabledDeploymentTypes.add(AnotherDeploymentType.class);
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
+ }
public class AnObserver
{
@@ -61,13 +68,9 @@
// When the transaction is committed, the beforeCompletion() method is
// invoked which in turn invokes the observer. Here the mock observer
// is used to keep track of the event being fired.
- ManagerImpl manager;
SimpleBeanModel<Tuna> tuna;
InjectableMethod<Object> om;
- List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
- enabledDeploymentTypes.add(Standard.class);
- enabledDeploymentTypes.add(AnotherDeploymentType.class);
- manager = new MockManagerImpl(enabledDeploymentTypes);
+
// Create an observer with known binding types
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -1,11 +1,19 @@
package org.jboss.webbeans.test;
+import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
+
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.Dependent;
+import javax.webbeans.manager.Bean;
+
+import org.jboss.webbeans.contexts.DependentContext;
+import org.jboss.webbeans.test.beans.Fox;
import org.testng.annotations.Test;
public class DependentContextTest extends AbstractTest
{
- @Test(groups="contexts") @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "injection"}) @SpecAssertion(section="8.3")
public void testInstanceNotSharedBetweenInjectionPoints()
{
assert false;
@@ -32,19 +40,28 @@
@Test(groups="contexts") @SpecAssertion(section="8.3")
public void testContextGetWithCreateTrueReturnsNewInstance()
{
- assert false;
+ Bean<Fox> foxBean = createSimpleWebBean(Fox.class, manager);
+ manager.addBean(foxBean);
+ DependentContext context = new DependentContext();
+ context.setActive(true);
+ assert context.get(foxBean, true) != null;
+ assert context.get(foxBean, true) instanceof Fox;
}
@Test(groups="contexts") @SpecAssertion(section="8.3")
public void testContextGetWithCreateFalseReturnsNull()
{
- assert false;
+ Bean<Fox> foxBean = createSimpleWebBean(Fox.class, manager);
+ manager.addBean(foxBean);
+ DependentContext context = new DependentContext();
+ context.setActive(true);
+ assert context.get(foxBean, false) == null;
}
- @Test(groups="contexts") @SpecAssertion(section="8.3")
+ @Test(groups="contexts", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="8.3")
public void testContextIsInactive()
{
- assert false;
+ manager.getContext(Dependent.class).isActive();
}
@Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.3")
@@ -108,7 +125,7 @@
assert false;
}
- @Test(groups={"contexts"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "beanLifecycle"}) @SpecAssertion(section="8.3")
public void testDestroyingParentDestroysDependents()
{
assert false;
@@ -126,7 +143,7 @@
assert false;
}
- @Test(groups={"contexts"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "el"}) @SpecAssertion(section="8.3")
public void testDependentsDestroyedWhenElEvaluationCompletes()
{
assert false;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -16,7 +16,6 @@
import javax.webbeans.Standard;
import javax.webbeans.manager.Bean;
-import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.introspector.SimpleAnnotatedType;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
@@ -32,7 +31,6 @@
import org.jboss.webbeans.test.beans.broken.Gazelle;
import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.FishStereotypeAnnotationLiteral;
-import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.testng.annotations.Test;
@SpecVersion("PDR")
@@ -124,10 +122,10 @@
@Test @SpecAssertion(section={"2.5.6", "2.5.7"})
public void testDefaultEnabledDeploymentTypes()
{
- ManagerImpl container = new MockManagerImpl(null);
- assert container.getEnabledDeploymentTypes().size() == 2;
- assert container.getEnabledDeploymentTypes().get(0).equals(Standard.class);
- assert container.getEnabledDeploymentTypes().get(1).equals(Production.class);
+ manager.setEnabledDeploymentTypes(null);
+ assert manager.getEnabledDeploymentTypes().size() == 2;
+ assert manager.getEnabledDeploymentTypes().get(0).equals(Standard.class);
+ assert manager.getEnabledDeploymentTypes().get(1).equals(Production.class);
}
@Test @SpecAssertion(section={"2.5.6", "2.5.7"})
@@ -137,11 +135,11 @@
enabledDeploymentTypes.add(Standard.class);
enabledDeploymentTypes.add(AnotherDeploymentType.class);
enabledDeploymentTypes.add(HornedAnimalDeploymentType.class);
- ManagerImpl container = new MockManagerImpl(enabledDeploymentTypes);
- assert container.getEnabledDeploymentTypes().size() == 3;
- assert container.getEnabledDeploymentTypes().get(0).equals(Standard.class);
- assert container.getEnabledDeploymentTypes().get(1).equals(AnotherDeploymentType.class);
- assert container.getEnabledDeploymentTypes().get(2).equals(HornedAnimalDeploymentType.class);
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
+ assert manager.getEnabledDeploymentTypes().size() == 3;
+ assert manager.getEnabledDeploymentTypes().get(0).equals(Standard.class);
+ assert manager.getEnabledDeploymentTypes().get(1).equals(AnotherDeploymentType.class);
+ assert manager.getEnabledDeploymentTypes().get(2).equals(HornedAnimalDeploymentType.class);
}
@Test(expectedExceptions=DeploymentException.class) @SpecAssertion(section="2.5.6")
@@ -150,7 +148,7 @@
List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
enabledDeploymentTypes.add(AnotherDeploymentType.class);
enabledDeploymentTypes.add(HornedAnimalDeploymentType.class);
- new MockManagerImpl(enabledDeploymentTypes);
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
@Test(groups="webbeansxml", expectedExceptions=DeploymentException.class) @SpecAssertion(section="2.5.6")
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -39,7 +39,8 @@
List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
enabledDeploymentTypes.add(Standard.class);
enabledDeploymentTypes.add(AnotherDeploymentType.class);
- manager = new MockManagerImpl(enabledDeploymentTypes);
+ manager = new MockManagerImpl();
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
Field eventModelField = this.getClass().getDeclaredField("eventModelField");
eventBeanModel = new EventBeanModel<EventImpl<DangerCall>>(
new SimpleAnnotatedField<EventImpl<DangerCall>>(eventModelField),
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -54,7 +54,8 @@
List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
enabledDeploymentTypes.add(Standard.class);
enabledDeploymentTypes.add(AnotherDeploymentType.class);
- manager = new MockManagerImpl(enabledDeploymentTypes);
+ manager = new MockManagerImpl();
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
}
/**
Modified: 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 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -12,6 +12,12 @@
public class ManagerTest extends AbstractTest
{
+ @Override
+ protected void addBuiltInContexts()
+ {
+ // No -op, done manually here
+ }
+
@Test(groups={"manager", "injection"}) @SpecAssertion(section="4.8")
public void testInjectingManager()
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -10,7 +10,6 @@
import javax.webbeans.Observes;
import javax.webbeans.Standard;
-import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.injectable.InjectableMethod;
import org.jboss.webbeans.introspector.AnnotatedType;
import org.jboss.webbeans.introspector.SimpleAnnotatedType;
@@ -33,7 +32,7 @@
@SpecVersion("20081024-PDR")
public class ObserverTest
{
- private ManagerImpl manager;
+ private MockManagerImpl manager;
private SimpleBeanModel<Tuna> tuna;
private InjectableMethod<?> om;
@@ -59,7 +58,8 @@
List<Class<? extends Annotation>> enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
enabledDeploymentTypes.add(Standard.class);
enabledDeploymentTypes.add(AnotherDeploymentType.class);
- manager = new MockManagerImpl(enabledDeploymentTypes);
+ manager = new MockManagerImpl();
+ manager.setEnabledDeploymentTypes(enabledDeploymentTypes);
// Create an observer with known binding types
Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Fox.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Fox.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Fox.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Dependent;
+
+ at Dependent
+public class Fox
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Fox.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockManagerImpl.java 2008-10-28 12:54:18 UTC (rev 196)
@@ -19,11 +19,6 @@
private Annotation[] eventBindings = null;
private Observer<?> observer = null;
- public MockManagerImpl(List<Class<? extends Annotation>> enabledDeploymentTypes)
- {
- super(enabledDeploymentTypes);
- }
-
/* (non-Javadoc)
* @see org.jboss.webbeans.ManagerImpl#fireEvent(java.lang.Object, java.lang.annotation.Annotation[])
*/
@@ -97,5 +92,10 @@
{
return observer;
}
+
+ public void setEnabledDeploymentTypes(List<Class<? extends Annotation>> enabledDeploymentTypes)
+ {
+ initEnabledDeploymentTypes(enabledDeploymentTypes);
+ }
}
Modified: ri/trunk/webbeans-ri/testng.xml
===================================================================
--- ri/trunk/webbeans-ri/testng.xml 2008-10-28 12:25:44 UTC (rev 195)
+++ ri/trunk/webbeans-ri/testng.xml 2008-10-28 12:54:18 UTC (rev 196)
@@ -22,7 +22,6 @@
<exclude name="innerClass" />
<exclude name="servlet" />
<exclude name="clientProxy" />
- <exclude name="contexts" />
</run>
</groups>
<packages>
More information about the weld-commits
mailing list