Author: pete.muir(a)jboss.org
Date: 2009-07-27 12:13:31 -0400 (Mon, 27 Jul 2009)
New Revision: 3271
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/DummyContextual.java
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java
Log:
Update test to 20090625
Added:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/DummyContextual.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/DummyContextual.java
(rev 0)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/DummyContextual.java 2009-07-27
16:13:31 UTC (rev 3271)
@@ -0,0 +1,41 @@
+package org.jboss.jsr299.tck.tests.context;
+
+import javax.enterprise.context.spi.Contextual;
+import javax.enterprise.context.spi.CreationalContext;
+
+/**
+ * @author pmuir
+ *
+ */
+final class DummyContextual implements Contextual<String>
+{
+ private CreationalContext<String> creationalContextPassedToCreate;
+ private CreationalContext<String> creationalContextPassedToDestroy;
+
+ public String create(CreationalContext<String> creationalContext)
+ {
+ this.creationalContextPassedToCreate = creationalContext;
+ return "123";
+ }
+
+ public void destroy(String instance, CreationalContext<String>
creationalContext)
+ {
+ this.creationalContextPassedToDestroy = creationalContext;
+ }
+
+ /**
+ * @return the creationalContextPassedToCreate
+ */
+ public CreationalContext<String> getCreationalContextPassedToCreate()
+ {
+ return creationalContextPassedToCreate;
+ }
+
+ /**
+ * @return the creationalContextPassedToDestroy
+ */
+ public CreationalContext<String> getCreationalContextPassedToDestroy()
+ {
+ return creationalContextPassedToDestroy;
+ }
+}
\ No newline at end of file
Property changes on:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/DummyContextual.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java
===================================================================
---
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java 2009-07-27
14:21:21 UTC (rev 3270)
+++
tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/NormalContextTest.java 2009-07-27
16:13:31 UTC (rev 3271)
@@ -1,15 +1,17 @@
package org.jboss.jsr299.tck.tests.context;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.RequestScoped;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
+import org.jboss.jsr299.tck.AbstractJSR299Test;
+import org.jboss.jsr299.tck.impl.MockCreationalContext;
import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.test.audit.annotations.SpecAssertions;
import org.jboss.test.audit.annotations.SpecVersion;
-import org.jboss.jsr299.tck.AbstractJSR299Test;
-import org.jboss.jsr299.tck.impl.MockCreationalContext;
import org.jboss.testharness.impl.packaging.Artifact;
import org.testng.annotations.Test;
@@ -20,7 +22,7 @@
* @author David Allen
*/
@Artifact
-@SpecVersion("20090519")
+@SpecVersion("20090625")
public class NormalContextTest extends AbstractJSR299Test
{
@@ -44,7 +46,7 @@
assert fourth.getId() == 10;
}
- @Test(groups = { "contexts" })
+ @Test(groups = { "contexts", "rewrite" })
@SpecAssertions( {
@SpecAssertion(section = "6.2", id = "l")
} )
@@ -52,6 +54,7 @@
{
MyContextual bean = new MyContextual(getCurrentManager());
bean.setShouldReturnNullInstances(false);
+ // TODO Remove use of this deprecated API
getCurrentManager().addBean(bean);
CreationalContext<MySessionBean> creationalContext = new
MockCreationalContext<MySessionBean>();
@@ -60,7 +63,7 @@
assert bean.isCreateCalled();
}
- @Test(groups = { "contexts" })
+ @Test(groups = { "contexts" , "rewrite"})
@SpecAssertion(section = "6.2", id = "nb")
public void testGetMayNotReturnNullUnlessContextualCreateReturnsNull()
{
@@ -68,6 +71,7 @@
// returned. Here we just test that the contextual create can return null.
MyContextual bean = new MyContextual(getCurrentManager());
bean.setShouldReturnNullInstances(true);
+ // TODO Remove use of this deprecated API
getCurrentManager().addBean(bean);
CreationalContext<MySessionBean> creationalContext = new
MockCreationalContext<MySessionBean>();
@@ -75,7 +79,7 @@
assert bean.isCreateCalled();
}
- @Test(groups = { "contexts" })
+ @Test(groups = { "contexts", "rewrite" })
@SpecAssertions( {
@SpecAssertion(section = "6.2", id = "p"),
@SpecAssertion(section = "6.3", id = "d")
@@ -84,6 +88,7 @@
{
MyContextual bean = new MyContextual(getCurrentManager());
bean.setShouldReturnNullInstances(false);
+ // TODO Remove use of this deprecated API
getCurrentManager().addBean(bean);
Context sessionContext = getCurrentManager().getContext(SessionScoped.class);
@@ -98,21 +103,43 @@
}
@Test
- // This assertion is very weak and vague
@SpecAssertion(section = "6.2", id = "r")
public void testDestroyForSameCreationalContextOnly()
{
+ // Check that the mock cc is called (via cc.release()) when we request a context
destroyed
+ // Note that this is an indirect effect
Context sessionContext = getCurrentManager().getContext(SessionScoped.class);
+ Context requestContext = getCurrentManager().getContext(RequestScoped.class);
+ Context appContext = getCurrentManager().getContext(ApplicationScoped.class);
+
Bean<AnotherSessionBean> sessionBean =
getBeans(AnotherSessionBean.class).iterator().next();
+
MockCreationalContext.reset();
CreationalContext<AnotherSessionBean> creationalContext = new
MockCreationalContext<AnotherSessionBean>();
AnotherSessionBean instance = sessionContext.get(sessionBean, creationalContext);
instance.ping();
- sessionBean.destroy(instance,
getCurrentManager().createCreationalContext(sessionBean));
- assert !MockCreationalContext.isReleaseCalled();
- sessionBean.destroy(instance, creationalContext);
+ destroyContext(sessionContext);
assert MockCreationalContext.isReleaseCalled();
+
+ // We also test this directly using a custom contextual, and ensuring that the same
contextual is passed to both methods
+ DummyContextual contextual = new DummyContextual();
+
+ sessionContext.get(contextual,
getCurrentManager().createCreationalContext(contextual));
+ destroyContext(sessionContext);
+ assert contextual.getCreationalContextPassedToCreate() ==
contextual.getCreationalContextPassedToDestroy();
+
+ // Do it for other contexts
+ contextual = new DummyContextual();
+ appContext.get(contextual,
getCurrentManager().createCreationalContext(contextual));
+ destroyContext(appContext);
+ assert contextual.getCreationalContextPassedToCreate() ==
contextual.getCreationalContextPassedToDestroy();
+
+ contextual = new DummyContextual();
+ requestContext.get(contextual,
getCurrentManager().createCreationalContext(contextual));
+ destroyContext(requestContext);
+ assert contextual.getCreationalContextPassedToCreate() ==
contextual.getCreationalContextPassedToDestroy();
+
}
@Test(groups = { "contexts" })
Show replies by date