tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject svn commit: r817241 - /openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/core/stateful/EntityManagerPropogationTest.java
Date Mon, 21 Sep 2009 13:22:22 GMT
Author: jlmonteiro
Date: Mon Sep 21 13:22:21 2009
New Revision: 817241

URL: http://svn.apache.org/viewvc?rev=817241&view=rev
Log:
Additional tests for "5.6.3.1 Requirements for Persistence Context Propagation" of the persistance
specification.

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=817241&r1=817240&r2=817241&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
Mon Sep 21 13:22:21 2009
@@ -31,11 +31,13 @@
 import org.apache.openejb.jee.EjbJar;
 import org.apache.openejb.jee.EjbLocalRef;
 import org.apache.openejb.jee.StatefulBean;
+import org.apache.openejb.jee.StatelessBean;
 import org.apache.openejb.jee.jpa.unit.Persistence;
 import org.apache.openejb.jee.jpa.unit.PersistenceUnit;
 import org.apache.openjpa.persistence.ArgumentException;
 
 import javax.ejb.EJB;
+import javax.ejb.EJBException;
 import javax.ejb.Remove;
 import javax.ejb.NoSuchEJBException;
 import javax.naming.InitialContext;
@@ -55,6 +57,9 @@
         _testExtendedRemove();
         _testNotTooExtended();
         _testTransaction();
+	_testSFTr2SFEx();
+	_testSFEx2SLTr2SFEx();
+	_testSLTr2SFEx();
     }
 
     public void _testExtended() throws Exception {
@@ -160,7 +165,65 @@
         }
 
     }
+    
+    public void _testSFTr2SFEx() throws Exception {
 
+        InitialContext ctx = new InitialContext();
+
+        Node node = (Node) ctx.lookup("TransactionToExtendedLocal");
+
+        try {
+//	    System.out.println("SFSB+TPC --> SFSB+EPC");
+	    node.createUntilLeaf(5, "Yellow");
+	    
+	    fail("5.6.3.1 Requirements for Persistence Context Propagation (persistence spec)" +
+	    		"\n\t--> we cannot have two persistence contexts associated with the transaction");
+	    
+	} catch (EJBException e) {
+	    // OK
+//	    System.out.println(e.getMessage());
+	}
+
+    }
+    
+    public void _testSFEx2SLTr2SFEx() throws Exception {
+
+        InitialContext ctx = new InitialContext();
+
+        Node node = (Node) ctx.lookup("ExtendedToTransactionLocal");
+        
+        try {
+//	    System.out.println("SFSB+EPC --> SLSB+TPC --> SFSB+EPC");
+	    node.createUntilLeaf(6, "red");
+	    
+	} catch (EJBException e) {
+	    fail("5.6.3.1 Requirements for Persistence Context Propagation (persistence spec)" +
+		"\n\t--> the SFSB+EPC is the one who starts the transaction and then calls the " +
+		"SLSB+TPC who then calls back to the SFSB+EPC \n\t--> IT SHOULD WORK ...");
+	}
+
+    }
+
+    public void _testSLTr2SFEx() throws Exception {
+
+        InitialContext ctx = new InitialContext();
+
+        Node node = (Node) ctx.lookup("TransactionToExtendedLocal");
+        
+        try {
+//            System.out.println("SLSB+TPC --> SFSB+EPC");
+	    node.createUntilLeaf(8, "Yellow");
+	    
+	    fail("5.6.3.1 Requirements for Persistence Context Propagation (persistence spec)" +
+	    		"\n\t--> we cannot have two persistence contexts associated with the transaction");
+	    
+	} catch (EJBException e) {
+	    // OK
+//	    System.out.println(e.getMessage());
+	}
+
+    }
+    
     public void setUp() throws OpenEJBException, IOException, NamingException {
         System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
         System.setProperty("openejb.embedded", "true");
@@ -181,6 +244,7 @@
         addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx2", "Extendedx3");
         addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx3", "Extendedx4");
         addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx4", "Extendedx5");
+        addStatefulBean(ejbJar, ExtendedContextBean.class, "ExtendedToTransaction", "StatelessTransactionToExtended");
         addStatefulBean(ejbJar, ExtendedContextBean.class, "Extendedx5", "Extendedx6");
         ejbJar.addEnterpriseBean(new StatefulBean("Extendedx6", EndNodeBean.class));
 
@@ -190,11 +254,19 @@
         addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx3", "Transactionx4");
         addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx4", "Transactionx5");
         addStatefulBean(ejbJar, TransactionContextBean.class, "Transactionx5", "Transactionx6");
+        addStatefulBean(ejbJar, TransactionContextBean.class, "TransactionToExtended", "Extendedx5");
+        
+        addStatelessBean(ejbJar, TransactionContextBean.class, "StatelessTransactionToExtended",
"Extendedx5");
         ejbJar.addEnterpriseBean(new StatefulBean("Transactionx6", EndNodeBean.class));
-
+        
         ejbJar.setAssemblyDescriptor(new AssemblyDescriptor());
         ejbJar.getAssemblyDescriptor().addApplicationException(IllegalArgumentException.class,
false);
         ejbJar.getAssemblyDescriptor().addApplicationException(ArgumentException.class, false);
+        
+//        List<ContainerTransaction> declared = ejbJar.getAssemblyDescriptor().getContainerTransaction();
+
+//        declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(),
"Extendedx5", "*"));
+//        declared.add(new ContainerTransaction(TransAttribute.REQUIRED, ExtendedContextBean.class.getName(),
"TransactionToExtended", "*"));        
 
         EjbModule ejbModule = new EjbModule(ejbJar);
 
@@ -222,6 +294,11 @@
         StatefulBean bean = ejbJar.addEnterpriseBean(new StatefulBean(name, ejbClass));
         bean.getEjbLocalRef().add(new EjbLocalRef("child", reference));
     }
+    
+    private void addStatelessBean(EjbJar ejbJar, Class<?> ejbClass, String name, String
reference) {
+        StatelessBean bean = ejbJar.addEnterpriseBean(new StatelessBean(name, ejbClass));
+        bean.getEjbLocalRef().add(new EjbLocalRef("child", reference));
+    }
 
     @Entity
     public static class Color {
@@ -262,9 +339,14 @@
         
         Color create(int id, String name);
 
+        void createUntilLeaf(int id, String name);
+
         boolean contains(Color bean);
 
         Node getChild();
+        
+        String getDelegateEntityManagerReference();
+        
     }
 
 
@@ -278,7 +360,6 @@
      * on the JTA propogation that also exists with an EXTENDED
      * persistence context
      */
-
     public static class ExtendedContextBean extends NodeBean {
 
         @PersistenceContext(unitName = "testUnit", type = EXTENDED)
@@ -309,12 +390,23 @@
             getEntityManager().persist(color);
             return color;
         }
+        
+        public void createUntilLeaf(int id, String name) {
+            this.create(id, name);
+            
+            // recursively call until the leaf is achieved
+            getChild().createUntilLeaf(id * 10 + 1, name);
+        }
 
         protected abstract EntityManager getEntityManager();
 
         public Node getChild() {
             return child;
         }
+        
+        public String getDelegateEntityManagerReference() {
+            return getEntityManager().getDelegate().toString();
+        }
 
         public boolean contains(Color bean) throws IllegalArgumentException {
             // This call should not fail as the bean was created
@@ -337,9 +429,17 @@
             return null;
         }
 
+        public void createUntilLeaf(int id, String name) {
+            return;
+        }
+
         public Node getChild() {
             return null;
         }
+        
+        public String getDelegateEntityManagerReference() {
+            return null;
+        }
 
         @Remove
         public void remove(){}



Mime
View raw message