You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2009/01/29 04:20:28 UTC

svn commit: r738731 - /openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java

Author: dblevins
Date: Thu Jan 29 03:20:28 2009
New Revision: 738731

URL: http://svn.apache.org/viewvc?rev=738731&view=rev
Log:
Added two more extended persistence context tests.  We should be well covered now.

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java?rev=738731&r1=738730&r2=738731&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java (original)
+++ openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java Thu Jan 29 03:20:28 2009
@@ -36,6 +36,8 @@
 import org.apache.openjpa.persistence.ArgumentException;
 
 import javax.ejb.EJB;
+import javax.ejb.Remove;
+import javax.ejb.NoSuchEJBException;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.persistence.Entity;
@@ -67,6 +69,72 @@
 
     }
 
+    /**
+     * Test that the extended persistence context can
+     * survive the removal of the parent
+     * 
+     * @throws Exception
+     */
+    public void testExtendedRemove() throws Exception {
+
+        InitialContext ctx = new InitialContext();
+
+        Node node = (Node) ctx.lookup("ExtendedLocal");
+
+        // This bean should still be attached
+        // when the transaction commits
+        Color attached = node.create(1, "Red");
+
+        while (node.getChild() != null) {
+
+            assertTrue(node.contains(attached));
+
+            Node next = node.getChild();
+
+            node.remove();
+
+            try {
+                node.contains(attached);
+                fail("The Stateful bean should have been removed");
+            } catch (NoSuchEJBException e) {
+                // good
+            }
+            node = next;
+        }
+
+    }
+
+    /**
+     * Test that two Stateful session bean siblings
+     * do not share the same extended persistence context
+     *
+     * A stateful session bean must be a child in order
+     * for the context to be propogated to that bean.
+     *
+     * @throws Exception
+     */
+    public void testNotTooExtended() throws Exception {
+
+        InitialContext ctx = new InitialContext();
+
+        // Stateful Node tree A and Node tree B are syblings
+        Node chainA = (Node) ctx.lookup("ExtendedLocal");
+
+        Node chainB = (Node) ctx.lookup("ExtendedLocal");
+
+        // This bean should still be attached
+        // when the transaction commits
+        Color attachedA = chainA.create(1, "Red");
+
+        while (chainB.getChild() != null) {
+
+            assertFalse(chainB.contains(attachedA));
+
+            chainB = chainB.getChild();
+        }
+
+    }
+
     public void testTransaction() throws Exception {
 
         InitialContext ctx = new InitialContext();
@@ -182,6 +250,9 @@
     }
 
     public static interface Node {
+
+        void remove();
+        
         Color create(int id, String name);
 
         boolean contains(Color bean);
@@ -244,6 +315,9 @@
             return getEntityManager().contains(bean);
         }
 
+        @Remove
+        public void remove(){}
+
     }
 
     public static class EndNodeBean implements Node {
@@ -259,6 +333,10 @@
         public Node getChild() {
             return null;
         }
+
+        @Remove
+        public void remove(){}
+
     }
 
 }