Author: nickarls
Date: 2008-10-24 08:20:59 -0400 (Fri, 24 Oct 2008)
New Revision: 139
Added:
ri/trunk/src/
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
ri/trunk/webbeans-ri/testng.xml
Log:
Initial context tests
Added active attribute and setter to BasicContext
Modified: 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-24
11:07:08 UTC (rev 138)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java 2008-10-24
12:20:59 UTC (rev 139)
@@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Map;
+import javax.webbeans.ContextNotActiveException;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
import javax.webbeans.manager.Manager;
@@ -18,15 +19,21 @@
{
private Map<Bean<? extends Object>, Object> values;
private Class<? extends Annotation> scopeType;
+ private boolean active;
public BasicContext(Class<? extends Annotation> scopeType)
{
this.scopeType = scopeType;
values = new HashMap<Bean<?>,Object>();
+ active = true;
}
public <T> T get(Bean<T> component, boolean create)
{
+ if (!active)
+ {
+ throw new ContextNotActiveException();
+ }
T instance = (T) values.get(component);
if (instance != null)
{
@@ -78,8 +85,11 @@
}
public boolean isActive() {
- // TODO Auto-generated method stub
- return false;
+ return active;
}
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
}
Added: 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
(rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java 2008-10-24
12:20:59 UTC (rev 139)
@@ -0,0 +1,53 @@
+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.BeanImpl;
+import org.jboss.webbeans.introspector.SimpleAnnotatedType;
+import org.jboss.webbeans.model.SimpleComponentModel;
+import org.jboss.webbeans.test.components.Tuna;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.ExpectedExceptions;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Nicklas Karlsson (nickarls(a)gmail.com)
+ *
+ * This class tests a basic context against section 8 of the specification
+ *
+ */
+@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 = new BeanImpl<Tuna>(new
SimpleComponentModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class),
getEmptyAnnotatedItem(Tuna.class), super.manager), manager);
+ assert context.get(tunaBean, false) == null;
+ }
+
+ @Test(groups="contexts") @SpecAssertion(section="8.1")
+ public void testGetWithCreateTrueReturnsBean() {
+ Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new
SimpleComponentModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class),
getEmptyAnnotatedItem(Tuna.class), super.manager), 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;
+ }
+
+}
Modified: ri/trunk/webbeans-ri/testng.xml
===================================================================
--- ri/trunk/webbeans-ri/testng.xml 2008-10-24 11:07:08 UTC (rev 138)
+++ ri/trunk/webbeans-ri/testng.xml 2008-10-24 12:20:59 UTC (rev 139)
@@ -13,6 +13,7 @@
<exclude name="remoteComponentInXml" />
<exclude name="eventbus" />
<exclude name="injection" />
+ <exclude name="contexts" />
</run>
</groups>
<packages>
Show replies by date