[jbpm-commits] JBoss JBPM SVN: r1915 - in jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm: api and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Aug 18 05:37:43 EDT 2008


Author: tom.baeyens at jboss.com
Date: 2008-08-18 05:37:43 -0400 (Mon, 18 Aug 2008)
New Revision: 1915

Added:
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/BasicTransactionTest.java
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/TxTests.java
Removed:
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/tx/
Modified:
   jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java
Log:
added transaction test to the check-in test suite

Modified: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java	2008-08-18 09:34:17 UTC (rev 1914)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/DbTests.java	2008-08-18 09:37:43 UTC (rev 1915)
@@ -27,6 +27,7 @@
 import org.jbpm.pvm.api.db.continuation.ContinuationTests;
 import org.jbpm.pvm.api.db.svc.DbSvcTests;
 import org.jbpm.pvm.api.spring.SpringTests;
+import org.jbpm.pvm.api.tx.TxTests;
 import org.jbpm.pvm.internal.db.langext.DbLangExtTests;
 import org.jbpm.pvm.internal.db.model.DbModelTests;
 import org.jbpm.pvm.internal.jobexecutor.JobExecutorTests;
@@ -47,6 +48,7 @@
     defaultConfigTests.addTest(DbSvcTests.suite());
     defaultConfigTests.addTest(JobExecutorTests.suite());
     defaultConfigTests.addTest(ContinuationTests.suite());
+    defaultConfigTests.addTest(TxTests.suite());
     
     suite.addTest(new EnvironmentFactoryTestSetup(defaultConfigTests, "environment.cfg.xml"));
     suite.addTest(new EnvironmentFactoryTestSetup(DbLangExtTests.suite(), "org/jbpm/pvm/internal/db/langext/environment.cfg.xml"));

Copied: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/BasicTransactionTest.java (from rev 1887, jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/internal/db/tx/BasicTransactionTest.java)
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/BasicTransactionTest.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/BasicTransactionTest.java	2008-08-18 09:37:43 UTC (rev 1915)
@@ -0,0 +1,199 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.api.tx;
+
+import java.util.List;
+
+import javax.transaction.Synchronization;
+
+import org.hibernate.Session;
+import org.jbpm.pvm.PvmException;
+import org.jbpm.pvm.env.Environment;
+import org.jbpm.pvm.env.Transaction;
+import org.jbpm.pvm.internal.cmd.Command;
+import org.jbpm.pvm.internal.model.CommentImpl;
+import org.jbpm.pvm.internal.type.variable.StringVariable;
+import org.jbpm.pvm.test.base.DbTestCase;
+
+/**
+ * @author Tom Baeyens
+ */
+public class BasicTransactionTest extends DbTestCase {
+
+  public void testCommit() {
+    commandService.execute(new Command<Object>(){
+      public Object execute(Environment environment) {
+        Session session = environment.get(Session.class);
+        session.save(new CommentImpl("if i only had the time to write code"));
+        return null;
+      }
+    });
+    
+    commandService.execute(new Command<Object>(){
+      public Object execute(Environment environment) {
+        Session session = environment.get(Session.class);
+        List<CommentImpl> comments = session.createQuery("from "+CommentImpl.class.getName()).list();
+        assertEquals("if i only had the time to write code", comments.get(0).getMessage());
+        return null;
+      }
+    });
+  }
+  
+  
+  public static class MyOwnRuntimeException extends RuntimeException {
+  }
+  
+  public void testRollbackRuntimeException() {
+    try {
+      commandService.execute(new Command<Object>(){
+        public Object execute(Environment environment) {
+          Session session = environment.get(Session.class);
+          session.save(new CommentImpl("if i only had the time to write code"));
+          throw new MyOwnRuntimeException();
+        }
+      });
+      fail("expected exception");
+    } catch (MyOwnRuntimeException e) {
+      // OK
+    }
+    
+    commandService.execute(new Command<Object>(){
+      public Object execute(Environment environment) {
+        Session session = environment.get(Session.class);
+        List<CommentImpl> comments = session.createQuery("from "+CommentImpl.class.getName()).list();
+        assertEquals(0, comments.size());
+        return null;
+      }
+    });
+  }
+
+  public static class MyOwnCheckedException extends Exception {
+  }
+  
+  public void testRollbackCheckedException() {
+    try {
+      commandService.execute(new Command<Object>(){
+        public Object execute(Environment environment) throws Exception {
+          Session session = environment.get(Session.class);
+          session.save(new CommentImpl("if i only had the time to write code"));
+          throw new MyOwnCheckedException();
+        }
+      });
+      fail("expected exception");
+    } catch (PvmException e) {
+      // OK
+      assertSame(MyOwnCheckedException.class, e.getCause().getClass());
+    }
+    
+    commandService.execute(new Command<Object>(){
+      public Object execute(Environment environment) {
+        Session session = environment.get(Session.class);
+        List<CommentImpl> comments = session.createQuery("from "+CommentImpl.class.getName()).list();
+        assertEquals(0, comments.size());
+        return null;
+      }
+    });
+  }
+
+  
+  public static class SuccessfulSynchronization implements Synchronization {
+    public void beforeCompletion() {
+      Environment environment = Environment.getCurrent();
+      Session session = environment.get(Session.class);
+      StringVariable stringVariable = new StringVariable();
+      stringVariable.setValue("hello");
+      session.save(stringVariable);
+    }
+    public void afterCompletion(int arg0) {
+    }
+  }
+  
+  public void testSuccessfulSynchronization() {
+    commandService.execute(new Command<Object>(){
+      public Object execute(Environment environment) throws Exception {
+        Session session = environment.get(Session.class);
+        session.save(new CommentImpl("if i only had the time to write code"));
+        Transaction transaction = environment.get(Transaction.class);
+        SuccessfulSynchronization successfulSynchronization = new SuccessfulSynchronization(); 
+        transaction.registerSynchronization(successfulSynchronization);
+        return null;
+      }
+    });
+    
+    commandService.execute(new Command<Object>(){
+      public Object execute(Environment environment) {
+        Session session = environment.get(Session.class);
+        List<CommentImpl> comments = session.createQuery("from "+CommentImpl.class.getName()).list();
+        assertEquals("if i only had the time to write code", comments.get(0).getMessage());
+        List<StringVariable> stringVariables = session.createQuery("from "+StringVariable.class.getName()).list();
+        assertEquals("hello", stringVariables.get(0).getValue());
+        return null;
+      }
+    });
+  }
+
+  public static class UnsuccessfulSynchronization implements Synchronization {
+    public void beforeCompletion() {
+      Environment environment = Environment.getCurrent();
+      Session session = environment.get(Session.class);
+      StringVariable stringVariable = new StringVariable();
+      stringVariable.setValue("hello");
+      session.save(stringVariable);
+      throw new MyOwnRuntimeException();
+    }
+    public void afterCompletion(int arg0) {
+    }
+  }
+  
+  public void testUnsuccessfulSynchronization() {
+    try {
+      commandService.execute(new Command<Object>(){
+        public Object execute(Environment environment) throws Exception {
+          Session session = environment.get(Session.class);
+          session.save(new CommentImpl("if i only had the time to write code"));
+          Transaction transaction = environment.get(Transaction.class);
+          UnsuccessfulSynchronization unsuccessfulSynchronization = new UnsuccessfulSynchronization(); 
+          transaction.registerSynchronization(unsuccessfulSynchronization);
+          return null;
+        }
+      });
+      fail("expected exception");
+    } catch (MyOwnRuntimeException e) {
+      // OK
+    }
+
+    // the exception in the beforeCompletion in the synchronization should have caused 
+    // the previous transaction to rollback
+
+    commandService.execute(new Command<Object>(){
+      public Object execute(Environment environment) {
+        Session session = environment.get(Session.class);
+        List<CommentImpl> comments = session.createQuery("from "+CommentImpl.class.getName()).list();
+        assertEquals(0, comments.size());
+        List<StringVariable> stringVariables = session.createQuery("from "+StringVariable.class.getName()).list();
+        assertEquals(0, stringVariables.size());
+        return null;
+      }
+    });
+  }
+
+}


Property changes on: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/BasicTransactionTest.java
___________________________________________________________________
Name: svn:mergeinfo
   + 

Added: jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/TxTests.java
===================================================================
--- jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/TxTests.java	                        (rev 0)
+++ jbpm4/pvm/trunk/modules/core/src/test/java/org/jbpm/pvm/api/tx/TxTests.java	2008-08-18 09:37:43 UTC (rev 1915)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.api.tx;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public class TxTests {
+
+  public static Test suite() {
+    TestSuite suite = new TestSuite("org.jbpm.pvm.api.tx");
+    //$JUnit-BEGIN$
+    suite.addTestSuite(BasicTransactionTest.class);
+    //$JUnit-END$
+    return suite;
+  }
+
+}




More information about the jbpm-commits mailing list