[webbeans-commits] Webbeans SVN: r171 - in ri/trunk/webbeans-ri: src/main/java/org/jboss/webbeans and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Sun Oct 26 16:39:56 EDT 2008
Author: pete.muir at jboss.org
Date: 2008-10-26 16:39:54 -0400 (Sun, 26 Oct 2008)
New Revision: 171
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/AbstractContext.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansFilter.java
ri/trunk/webbeans-ri/testng.xml
Log:
Stub tests for 8.3, make basic context abstract
Copied: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/AbstractContext.java (from rev 170, ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java)
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/AbstractContext.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/AbstractContext.java 2008-10-26 20:39:54 UTC (rev 171)
@@ -0,0 +1,113 @@
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Context;
+import javax.webbeans.manager.Manager;
+
+import org.jboss.webbeans.util.MapWrapper;
+
+/**
+ * Basic implementation of javax.webbeans.Context, backed by a HashMap
+ *
+ * @author Shane Bryzak
+ * @author Nicklas Karlsson (nickarls at gmail.com)
+ * @author Pete Muir
+ *
+ */
+public abstract class AbstractContext implements Context
+{
+
+ private class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
+ {
+
+ public BeanMap()
+ {
+ super(new HashMap<Bean<? extends Object>, Object>());
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Object> T get(Bean<? extends T> key)
+ {
+ return (T) super.get(key);
+ }
+
+ }
+
+ private BeanMap beans;
+ private Class<? extends Annotation> scopeType;
+ private boolean active;
+
+ public AbstractContext(Class<? extends Annotation> scopeType)
+ {
+ this.scopeType = scopeType;
+ beans = new BeanMap();
+ active = true;
+ }
+
+ public <T> T get(Bean<T> bean, boolean create)
+ {
+ if (!active)
+ {
+ throw new ContextNotActiveException();
+ }
+
+ if (beans == null)
+ {
+ // Context has been destroyed
+ return null;
+ }
+
+ T instance = beans.get(bean);
+
+ if (instance != null)
+ {
+ return instance;
+ }
+
+ if (!create)
+ {
+ return null;
+ }
+
+ // TODO should bean creation be synchronized?
+
+ instance = bean.create();
+
+ beans.put(bean, instance);
+ return instance;
+ }
+
+ public Class<? extends Annotation> getScopeType()
+ {
+ return scopeType;
+ }
+
+ private <T> void destroy(Manager manager, Bean<T> bean)
+ {
+ bean.destroy(beans.get(bean));
+ }
+
+ public void destroy(Manager manager)
+ {
+ for (Bean<? extends Object> bean : beans.keySet())
+ {
+ destroy(manager, bean);
+ }
+ beans = null;
+ }
+
+ public boolean isActive()
+ {
+ return active;
+ }
+
+ public void setActive(boolean active)
+ {
+ this.active = active;
+ }
+
+}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java 2008-10-26 19:14:11 UTC (rev 170)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java 2008-10-26 20:39:54 UTC (rev 171)
@@ -1,113 +0,0 @@
-package org.jboss.webbeans;
-
-import java.lang.annotation.Annotation;
-import java.util.HashMap;
-
-import javax.webbeans.ContextNotActiveException;
-import javax.webbeans.manager.Bean;
-import javax.webbeans.manager.Context;
-import javax.webbeans.manager.Manager;
-
-import org.jboss.webbeans.util.MapWrapper;
-
-/**
- * Basic implementation of javax.webbeans.Context, backed by a HashMap
- *
- * @author Shane Bryzak
- * @author Nicklas Karlsson (nickarls at gmail.com)
- * @author Pete Muir
- *
- */
-public class BasicContext implements Context
-{
-
- private class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
- {
-
- public BeanMap()
- {
- super(new HashMap<Bean<? extends Object>, Object>());
- }
-
- @SuppressWarnings("unchecked")
- public <T extends Object> T get(Bean<? extends T> key)
- {
- return (T) super.get(key);
- }
-
- }
-
- private BeanMap beans;
- private Class<? extends Annotation> scopeType;
- private boolean active;
-
- public BasicContext(Class<? extends Annotation> scopeType)
- {
- this.scopeType = scopeType;
- beans = new BeanMap();
- active = true;
- }
-
- public <T> T get(Bean<T> bean, boolean create)
- {
- if (!active)
- {
- throw new ContextNotActiveException();
- }
-
- if (beans == null)
- {
- // Context has been destroyed
- return null;
- }
-
- T instance = beans.get(bean);
-
- if (instance != null)
- {
- return instance;
- }
-
- if (!create)
- {
- return null;
- }
-
- // TODO should bean creation be synchronized?
-
- instance = bean.create();
-
- beans.put(bean, instance);
- return instance;
- }
-
- public Class<? extends Annotation> getScopeType()
- {
- return scopeType;
- }
-
- private <T> void destroy(Manager manager, Bean<T> bean)
- {
- bean.destroy(beans.get(bean));
- }
-
- public void destroy(Manager manager)
- {
- for (Bean<? extends Object> bean : beans.keySet())
- {
- destroy(manager, bean);
- }
- beans = null;
- }
-
- public boolean isActive()
- {
- return active;
- }
-
- public void setActive(boolean active)
- {
- this.active = active;
- }
-
-}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansFilter.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansFilter.java 2008-10-26 19:14:11 UTC (rev 170)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansFilter.java 2008-10-26 20:39:54 UTC (rev 171)
@@ -11,7 +11,7 @@
import javax.webbeans.RequestScoped;
import javax.webbeans.manager.Manager;
-import org.jboss.webbeans.BasicContext;
+import org.jboss.webbeans.AbstractContext;
/**
*
@@ -30,7 +30,7 @@
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
- BasicContext requestContext = new BasicContext(RequestScoped.class);
+ AbstractContext requestContext = new AbstractContext(RequestScoped.class) {};
try
{
Copied: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java (from rev 170, ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java)
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonContextTest.java 2008-10-26 20:39:54 UTC (rev 171)
@@ -0,0 +1,72 @@
+package org.jboss.webbeans.test;
+
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.RequestScoped;
+import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Context;
+
+import org.jboss.webbeans.AbstractContext;
+import org.jboss.webbeans.test.beans.Tuna;
+import org.jboss.webbeans.test.util.Util;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Nicklas Karlsson (nickarls at gmail.com)
+ * @author Pete Muir
+ *
+ * This class tests a basic context against section 8 of the specification
+ *
+ */
+ at SpecVersion("20081020")
+public class CommonContextTest extends AbstractTest
+{
+ Context context;
+
+ @BeforeMethod
+ public void initContext() {
+ context = new AbstractContext(RequestScoped.class) {};
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.1")
+ public void testGetWithCreateFalseReturnsNull() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ assert context.get(tunaBean, false) == null;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.1")
+ public void testGetWithCreateTrueReturnsBean() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ assert context.get(tunaBean, true) != null;
+ }
+
+ @Test(groups="contexts", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="8.1")
+ public void testInactiveContextThrowsContextNotActiveException() {
+ ((AbstractContext)context).setActive(false);
+ context.get(null, false);
+ assert true;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.1")
+ public void testReturnsCorrectExistingBean() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ Tuna firstTuna = context.get(tunaBean, true);
+ Tuna secondTuna = context.get(tunaBean, false);
+ assert firstTuna == secondTuna;
+ }
+
+ @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.1")
+ public void testProducerMethodReturningNullOK() {
+ // TODO
+ assert false;
+ }
+
+ @Test(groups="contexts")
+ public void testDestroy() {
+ Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
+ assert context.get(tunaBean, true) instanceof Tuna;
+ ((AbstractContext)context).destroy(manager);
+ assert context.get(tunaBean, false) == null;
+ }
+}
Deleted: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java 2008-10-26 19:14:11 UTC (rev 170)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java 2008-10-26 20:39:54 UTC (rev 171)
@@ -1,72 +0,0 @@
-package org.jboss.webbeans.test;
-
-import javax.webbeans.ContextNotActiveException;
-import javax.webbeans.RequestScoped;
-import javax.webbeans.manager.Bean;
-import javax.webbeans.manager.Context;
-
-import org.jboss.webbeans.BasicContext;
-import org.jboss.webbeans.test.beans.Tuna;
-import org.jboss.webbeans.test.util.Util;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-/**
- *
- * @author Nicklas Karlsson (nickarls at gmail.com)
- * @author Pete Muir
- *
- * This class tests a basic context against section 8 of the specification
- *
- */
- at SpecVersion("20081020")
-public class ContextTest extends AbstractTest
-{
- Context context;
-
- @BeforeMethod
- public void initContext() {
- context = new BasicContext(RequestScoped.class);
- }
-
- @Test(groups="contexts") @SpecAssertion(section="8.1")
- public void testGetWithCreateFalseReturnsNull() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- assert context.get(tunaBean, false) == null;
- }
-
- @Test(groups="contexts") @SpecAssertion(section="8.1")
- public void testGetWithCreateTrueReturnsBean() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- assert context.get(tunaBean, true) != null;
- }
-
- @Test(groups="contexts", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="8.1")
- public void testInactiveContextThrowsContextNotActiveException() {
- ((BasicContext)context).setActive(false);
- context.get(null, false);
- assert true;
- }
-
- @Test(groups="contexts") @SpecAssertion(section="8.1")
- public void testReturnsCorrectExistingBean() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- Tuna firstTuna = context.get(tunaBean, true);
- Tuna secondTuna = context.get(tunaBean, false);
- assert firstTuna == secondTuna;
- }
-
- @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.1")
- public void testProducerMethodReturningNullOK() {
- // TODO
- assert false;
- }
-
- @Test(groups="contexts")
- public void testDestroy() {
- Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- assert context.get(tunaBean, true) instanceof Tuna;
- ((BasicContext)context).destroy(manager);
- assert context.get(tunaBean, false) == null;
- }
-}
Added: 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 (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java 2008-10-26 20:39:54 UTC (rev 171)
@@ -0,0 +1,147 @@
+package org.jboss.webbeans.test;
+
+import org.testng.annotations.Test;
+
+public class DependentContextTest extends AbstractTest
+{
+
+ @Test(groups="contexts") @SpecAssertion(section="8.3")
+ public void testInstanceNotSharedBetweenInjectionPoints()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "el"}) @SpecAssertion(section="8.3")
+ public void testInstanceUsedForElEvalutionNotShared()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.3")
+ public void testInstanceUsedForProducerMethodNotShared()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "eventbus"}) @SpecAssertion(section="8.3")
+ public void testInstanceUsedForObserverMethodNotShared()
+ {
+ assert false;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.3")
+ public void testContextGetWithCreateTrueReturnsNewInstance()
+ {
+ assert false;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.3")
+ public void testContextGetWithCreateFalseReturnsNull()
+ {
+ assert false;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.3")
+ public void testContextIsInactive()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.3")
+ public void testContextIsActiveWhenInvokingProducerMethod()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "eventbus"}) @SpecAssertion(section="8.3")
+ public void testContextIsActiveWhenInvokingObserverMethod()
+ {
+ assert false;
+ }
+
+
+ @Test(groups={"contexts", "el"}) @SpecAssertion(section="8.3")
+ public void testContextIsActiveWhenEvaluatingElExpression()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "beanLifecycle"}) @SpecAssertion(section="8.3")
+ public void testContextIsActiveDuringBeanCreation()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "beanLifecycle"}) @SpecAssertion(section="8.3")
+ public void testContextIsActiveDuringBeanDestruction()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "injection"}) @SpecAssertion(section="8.3")
+ public void testContextIsActiveDuringInjection()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ public void testEjbBeanMayMayCreateInstanceFromInitializer()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ public void testEjbBeanMayMayCreateInstanceFromPostConstruct()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ public void testEjbBeanMayMayCreateInstanceFromPreDestroy()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "servlet"}) @SpecAssertion(section="8.3")
+ public void testServletBeanMayMayCreateInstanceFromInitializer()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts"}) @SpecAssertion(section="8.3")
+ public void testDestroyingParentDestroysDependents()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ public void testDestroyingEjbDestroysDependents()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "servlet"}) @SpecAssertion(section="8.3")
+ public void testDestroyingServletDestroysDependents()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts"}) @SpecAssertion(section="8.3")
+ public void testDependentsDestroyedWhenElEvaluationCompletes()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.3")
+ public void testDependentsDestroyedWhenProducerMethodEvaluationCompletes()
+ {
+ assert false;
+ }
+
+ @Test(groups={"contexts", "eventbus"}) @SpecAssertion(section="8.3")
+ public void testDependentsDestroyedWhenObserverMethodEvaluationCompletes()
+ {
+ assert false;
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/testng.xml
===================================================================
--- ri/trunk/webbeans-ri/testng.xml 2008-10-26 19:14:11 UTC (rev 170)
+++ ri/trunk/webbeans-ri/testng.xml 2008-10-26 20:39:54 UTC (rev 171)
@@ -19,6 +19,7 @@
<exclude name="jms" />
<exclude name="interceptors" />
<exclude name="innerClass" />
+ <exclude name="servlet" />
</run>
</groups>
<packages>
More information about the weld-commits
mailing list