[jbpm-commits] JBoss JBPM SVN: r3826 - in jbpm4/trunk/modules: pvm/src/test/java/org/jbpm/pvm/internal/db/model and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Feb 10 08:58:47 EST 2009


Author: tom.baeyens at jboss.com
Date: 2009-02-10 08:58:47 -0500 (Tue, 10 Feb 2009)
New Revision: 3826

Added:
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentDbTestCase.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentFactoryTestCase.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentTestCase.java
Removed:
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/OldDbTestCase.java
Modified:
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
   jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/variables/CustomTypeVariableTest.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
   jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
Log:
first cut of base test classes reorg

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/CommentDbTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -24,13 +24,10 @@
 import java.util.Date;
 import java.util.List;
 
-import junit.framework.Test;
-
 import org.jbpm.model.Comment;
 import org.jbpm.pvm.internal.model.CommentImpl;
+import org.jbpm.pvm.test.EnvironmentDbTestCase;
 import org.jbpm.session.DbSession;
-import org.jbpm.test.EnvironmentDbTestCase;
-import org.jbpm.test.EnvironmentFactoryTestSetup;
 
 /**
  * @author Tom Baeyens

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessCacheDbTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -23,9 +23,9 @@
 import org.jbpm.pvm.internal.builder.ProcessDefinitionBuilder;
 import org.jbpm.pvm.internal.model.ActivityImpl;
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.test.EnvironmentDbTestCase;
 import org.jbpm.session.DbSession;
 import org.jbpm.session.PvmDbSession;
-import org.jbpm.test.EnvironmentDbTestCase;
 
 /**
  * @author Guillaume Porcher

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/ProcessDefinitionDbTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -27,8 +27,8 @@
 import org.jbpm.pvm.internal.model.EventListenerReference;
 import org.jbpm.pvm.internal.model.ExceptionHandlerImpl;
 import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.test.EnvironmentDbTestCase;
 import org.jbpm.session.DbSession;
-import org.jbpm.test.EnvironmentDbTestCase;
 
 /**
  * @author Charles Souillard

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/SessionFactoryDbTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -21,11 +21,8 @@
  */
 package org.jbpm.pvm.internal.db.model;
 
-import junit.framework.Test;
-
 import org.hibernate.SessionFactory;
-import org.jbpm.test.EnvironmentDbTestCase;
-import org.jbpm.test.EnvironmentFactoryTestSetup;
+import org.jbpm.pvm.test.EnvironmentDbTestCase;
 
 /**
  * @author Tom Baeyens

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireDbTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -50,8 +50,8 @@
 import org.jbpm.pvm.internal.wire.descriptor.TrueDescriptor;
 import org.jbpm.pvm.internal.wire.operation.FieldOperation;
 import org.jbpm.pvm.internal.wire.operation.PropertyOperation;
+import org.jbpm.pvm.test.EnvironmentDbTestCase;
 import org.jbpm.session.DbSession;
-import org.jbpm.test.EnvironmentDbTestCase;
 
 /**
  * @author Guillaume Porcher

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/db/model/WireTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -21,15 +21,12 @@
  */
 package org.jbpm.pvm.internal.db.model;
 
-import junit.framework.Test;
-
 import org.hibernate.Session;
 import org.jbpm.pvm.internal.wire.descriptor.ArgDescriptor;
 import org.jbpm.pvm.internal.wire.descriptor.IntegerDescriptor;
 import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.test.EnvironmentDbTestCase;
 import org.jbpm.session.DbSession;
-import org.jbpm.test.EnvironmentDbTestCase;
-import org.jbpm.test.EnvironmentFactoryTestSetup;
 
 /**
  * @author Tom Baeyens

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/EnlistTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -3,7 +3,9 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import org.jbpm.Configuration;
 import org.jbpm.env.Environment;
+import org.jbpm.env.EnvironmentFactory;
 import org.jbpm.env.Transaction;
 import org.jbpm.pvm.internal.wire.WireContext;
 import org.jbpm.pvm.internal.wire.WireException;
@@ -23,6 +25,12 @@
     MyResource.events = null;
     super.tearDown();
   }
+  
+  public static Environment openEnvironment(String xmlString) {
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) 
+        new Configuration().setXmlString(xmlString).buildProcessEngine();
+    return environmentFactory.openEnvironment();
+  }
 
   public static class MyResource implements StandardResource {
     public static List<String> events = null;

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionFailingCommitTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -21,7 +21,9 @@
  */
 package org.jbpm.pvm.internal.tx;
 
+import org.jbpm.Configuration;
 import org.jbpm.env.Environment;
+import org.jbpm.env.EnvironmentFactory;
 import org.jbpm.test.JbpmTestCase;
 
 /**
@@ -43,6 +45,13 @@
     }
   }
 
+  public static Environment openEnvironment(String xmlString) {
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) 
+        new Configuration().setXmlString(xmlString).buildProcessEngine();
+    return environmentFactory.openEnvironment();
+  }
+
+
   public void testMultipleResourcesFailingPrepare() {
     TestResource resourceOne = null;
     TestResource resourceTwo = null;

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesCommitTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -21,7 +21,9 @@
  */
 package org.jbpm.pvm.internal.tx;
 
+import org.jbpm.Configuration;
 import org.jbpm.env.Environment;
+import org.jbpm.env.EnvironmentFactory;
 import org.jbpm.pvm.internal.tx.StandardTransaction;
 import org.jbpm.test.JbpmTestCase;
 
@@ -31,6 +33,13 @@
  */
 public class TransactionResourcesCommitTest extends JbpmTestCase {
   
+  public static Environment openEnvironment(String xmlString) {
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) 
+        new Configuration().setXmlString(xmlString).buildProcessEngine();
+    return environmentFactory.openEnvironment();
+  }
+
+
   public void testOneResourceCommit() {
 
     TestResource resourceOne = null;

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/tx/TransactionResourcesSetRollbackOnlyTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -21,7 +21,9 @@
  */
 package org.jbpm.pvm.internal.tx;
 
+import org.jbpm.Configuration;
 import org.jbpm.env.Environment;
+import org.jbpm.env.EnvironmentFactory;
 import org.jbpm.env.Transaction;
 import org.jbpm.pvm.internal.tx.StandardTransaction;
 import org.jbpm.test.JbpmTestCase;
@@ -32,6 +34,13 @@
  */
 public class TransactionResourcesSetRollbackOnlyTest extends JbpmTestCase {
 
+  public static Environment openEnvironment(String xmlString) {
+    EnvironmentFactory environmentFactory = (EnvironmentFactory) 
+        new Configuration().setXmlString(xmlString).buildProcessEngine();
+    return environmentFactory.openEnvironment();
+  }
+
+
   public void testOneResourceSetRollbackOnly() {
 
     TestResource resourceOne = null;

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -37,7 +37,7 @@
 import org.jbpm.pvm.internal.type.variable.DoubleVariable;
 import org.jbpm.pvm.internal.type.variable.LongVariable;
 import org.jbpm.pvm.internal.type.variable.StringVariable;
-import org.jbpm.test.EnvironmentTestCase;
+import org.jbpm.pvm.test.EnvironmentTestCase;
 
 /**
  * @author Tom Baeyens

Copied: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentDbTestCase.java (from rev 3816, jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java)
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentDbTestCase.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentDbTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -0,0 +1,155 @@
+/*
+ * 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.test;
+
+import java.lang.reflect.Field;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.jbpm.Execution;
+import org.jbpm.model.OpenProcessDefinition;
+import org.jbpm.session.DbSession;
+import org.jbpm.session.PvmDbSession;
+import org.jbpm.test.Db;
+
+
+/** for tests that use persistence inside environment blocks.
+ * 
+ * An environment is opened in the setUp and closed in the tearDown.
+ * DB is cleaned inbetween tests. Extra convenience methods for usage 
+ * inside an environment block are provided. 
+ * 
+ * @author Tom Baeyens
+ */
+public abstract class EnvironmentDbTestCase extends EnvironmentTestCase {
+  
+  Transaction transaction = null;
+  
+  public EnvironmentDbTestCase() {
+  }
+
+  public EnvironmentDbTestCase(String configResource) {
+    super(configResource);
+  }
+
+  public void setUp() throws Exception {
+    if (isEnvironmentFactoryCached()) {
+      Db.clean(getEnvironmentFactory());
+    }
+    super.setUp();
+    beginTransaction();
+  }
+  
+  public void tearDown() throws Exception {
+    commitTransaction();
+    super.tearDown();
+  }
+
+  void beginTransaction() {
+    Session session = environment.get(Session.class);
+    transaction = session.beginTransaction();
+  }
+
+  void commitTransaction() {
+    transaction.commit();
+    transaction = null;
+  }
+  
+  void rollbackTransaction() {
+    transaction.rollback();
+    transaction = null;
+  }
+  
+  public DbSession getDbSession() {
+    return environment.get(DbSession.class);
+  }
+  
+  public void rollbackAndBeginNewTransaction() {
+    rollbackTransaction();
+    closeEnvironment();
+    openEnvironment();
+    beginTransaction();
+  }
+  
+  public void newTransaction() {
+    try {
+      commitTransaction();
+      closeEnvironment();
+    } finally {
+      openEnvironment();
+      beginTransaction();
+    }
+  }
+
+  public void beginCacheTest() {
+    SessionFactory sessionFactory = environment.get(SessionFactory.class);
+    if (sessionFactory != null) {
+      log.debug("=================================================================");
+      log.debug("Beginning of the cache test, no more sql query should be performed before the end of the test");
+      log.debug("=================================================================");
+
+      sessionFactory.getStatistics().clear();
+      sessionFactory.getStatistics().setStatisticsEnabled(true);
+    }
+  }
+  
+  public void endCacheTest() {
+    SessionFactory sessionFactory = environment.get(SessionFactory.class);
+    if (sessionFactory != null) {
+      assertEquals(0, sessionFactory.getStatistics().getEntityLoadCount());
+      assertEquals(0, sessionFactory.getStatistics().getCollectionLoadCount());
+    }
+  }
+  
+  public <T> T reload(Object object, Class<T> persistentClass) {
+    environment.get(DbSession.class).save(object);
+    newTransaction();
+    
+    Long dbid = null;
+    try {
+      Field dbidField = getDbidField(persistentClass);
+      dbidField.setAccessible(true);
+      dbid = (Long) dbidField.get(object);
+    } catch (RuntimeException e) {
+      throw e;
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+    
+    return environment.get(DbSession.class).get(persistentClass, dbid);
+  }
+  
+  private Field getDbidField(Class<?> clazz) {
+    Field[] fields = clazz.getDeclaredFields();
+    for (int i=0; i<fields.length; i++) {
+      if  ("dbid".equals(fields[i].getName())) {
+        return fields[i];
+      }
+    }
+    Class<?> superClass = clazz.getSuperclass();
+    if (superClass!=null) {
+      return getDbidField(superClass);
+    }
+    throw new RuntimeException("no dbid field in object to reload");
+  }
+}

Copied: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentFactoryTestCase.java (from rev 3816, jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java)
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentFactoryTestCase.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentFactoryTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -0,0 +1,83 @@
+/*
+ * 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.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jbpm.Configuration;
+import org.jbpm.JbpmException;
+import org.jbpm.env.EnvironmentFactory;
+import org.jbpm.test.JbpmTestCase;
+
+
+/**
+ * @author Tom Baeyens
+ */
+public abstract class EnvironmentFactoryTestCase extends JbpmTestCase {
+  
+  String configResource;
+
+  static Map<String, EnvironmentFactory> environmentFactories = new HashMap<String, EnvironmentFactory>();
+  
+  public EnvironmentFactoryTestCase() {
+    this("jbpm.cfg.xml");
+  }
+  
+  public EnvironmentFactoryTestCase(String configResource) {
+    this.configResource = configResource;
+  }
+
+  public EnvironmentFactory getEnvironmentFactory() {
+    if (isEnvironmentFactoryCached()) {
+      return environmentFactories.get(configResource);
+    }
+    return createEnvironmentFactory();
+  }
+
+  boolean isEnvironmentFactoryCached() {
+    return environmentFactories.containsKey(configResource);
+  }
+
+  EnvironmentFactory createEnvironmentFactory() {
+    return createEnvironmentFactory(configResource);
+  }
+
+  static EnvironmentFactory createEnvironmentFactory(String configResource) {
+    try {
+      log.debug("creating environment factory for ["+configResource+"]");
+      EnvironmentFactory newEnvironmentFactory = (EnvironmentFactory) new Configuration().setResource(configResource).buildProcessEngine();
+      environmentFactories.put(configResource, newEnvironmentFactory);
+      return newEnvironmentFactory;
+    } catch (Exception e) {
+      throw new JbpmException("Exception during creation of environment factory for "+configResource, e);
+    }
+  }
+
+  static void closeEnvironmentFactory(String configResource) {
+    EnvironmentFactory environmentFactory = environmentFactories.remove(configResource);
+    if (environmentFactory!=null) {
+      log.debug("closing environment factory for ["+configResource+"]");
+      environmentFactory.close();
+    }
+  }
+}

Copied: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentTestCase.java (from rev 3816, jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java)
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentTestCase.java	                        (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/test/EnvironmentTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -0,0 +1,58 @@
+/*
+ * 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.test;
+
+import org.jbpm.env.Environment;
+
+/**
+ * @author Tom Baeyens
+ */
+public abstract class EnvironmentTestCase extends EnvironmentFactoryTestCase {
+
+  protected Environment environment;
+  
+  public EnvironmentTestCase() {
+  }
+
+  public EnvironmentTestCase(String configResource) {
+    super(configResource);
+  }
+
+  public void setUp() throws Exception {
+    super.setUp();
+    openEnvironment();
+  }
+
+  public void tearDown() throws Exception {
+    closeEnvironment();
+    super.tearDown();
+  }
+  
+  void closeEnvironment() {
+    environment.close();
+    environment = null;
+  }
+
+  void openEnvironment() {
+    environment = getEnvironmentFactory().openEnvironment();
+  }
+}

Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/variables/CustomTypeVariableTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/variables/CustomTypeVariableTest.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/variables/CustomTypeVariableTest.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -31,7 +31,7 @@
 import org.jbpm.pvm.internal.type.Variable;
 import org.jbpm.pvm.internal.type.variable.DateVariable;
 import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
-import org.jbpm.test.EnvironmentDbTestCase;
+import org.jbpm.pvm.test.EnvironmentDbTestCase;
 
 /**
  * @author Guillaume Porcher

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/Db.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -21,7 +21,6 @@
  */
 package org.jbpm.test;
 
-import java.sql.Types;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -36,7 +35,6 @@
 import org.hibernate.engine.SessionFactoryImplementor;
 import org.hibernate.mapping.ForeignKey;
 import org.hibernate.mapping.Table;
-import org.hibernate.type.Type;
 import org.jbpm.ProcessEngine;
 import org.jbpm.env.EnvironmentFactory;
 import org.jbpm.log.Log;

Deleted: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentDbTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -1,154 +0,0 @@
-/*
- * 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.test;
-
-import java.lang.reflect.Field;
-
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.jbpm.Execution;
-import org.jbpm.model.OpenProcessDefinition;
-import org.jbpm.session.DbSession;
-import org.jbpm.session.PvmDbSession;
-
-
-/** for tests that use persistence inside environment blocks.
- * 
- * An environment is opened in the setUp and closed in the tearDown.
- * DB is cleaned inbetween tests. Extra convenience methods for usage 
- * inside an environment block are provided. 
- * 
- * @author Tom Baeyens
- */
-public abstract class EnvironmentDbTestCase extends EnvironmentTestCase {
-  
-  Transaction transaction = null;
-  
-  public EnvironmentDbTestCase() {
-  }
-
-  public EnvironmentDbTestCase(String configResource) {
-    super(configResource);
-  }
-
-  public void setUp() throws Exception {
-    if (isEnvironmentFactoryCached()) {
-      Db.clean(getEnvironmentFactory());
-    }
-    super.setUp();
-    beginTransaction();
-  }
-  
-  public void tearDown() throws Exception {
-    commitTransaction();
-    super.tearDown();
-  }
-
-  void beginTransaction() {
-    Session session = environment.get(Session.class);
-    transaction = session.beginTransaction();
-  }
-
-  void commitTransaction() {
-    transaction.commit();
-    transaction = null;
-  }
-  
-  void rollbackTransaction() {
-    transaction.rollback();
-    transaction = null;
-  }
-  
-  public DbSession getDbSession() {
-    return environment.get(DbSession.class);
-  }
-  
-  public void rollbackAndBeginNewTransaction() {
-    rollbackTransaction();
-    closeEnvironment();
-    openEnvironment();
-    beginTransaction();
-  }
-  
-  public void newTransaction() {
-    try {
-      commitTransaction();
-      closeEnvironment();
-    } finally {
-      openEnvironment();
-      beginTransaction();
-    }
-  }
-
-  public void beginCacheTest() {
-    SessionFactory sessionFactory = environment.get(SessionFactory.class);
-    if (sessionFactory != null) {
-      log.debug("=================================================================");
-      log.debug("Beginning of the cache test, no more sql query should be performed before the end of the test");
-      log.debug("=================================================================");
-
-      sessionFactory.getStatistics().clear();
-      sessionFactory.getStatistics().setStatisticsEnabled(true);
-    }
-  }
-  
-  public void endCacheTest() {
-    SessionFactory sessionFactory = environment.get(SessionFactory.class);
-    if (sessionFactory != null) {
-      assertEquals(0, sessionFactory.getStatistics().getEntityLoadCount());
-      assertEquals(0, sessionFactory.getStatistics().getCollectionLoadCount());
-    }
-  }
-  
-  public <T> T reload(Object object, Class<T> persistentClass) {
-    environment.get(DbSession.class).save(object);
-    newTransaction();
-    
-    Long dbid = null;
-    try {
-      Field dbidField = getDbidField(persistentClass);
-      dbidField.setAccessible(true);
-      dbid = (Long) dbidField.get(object);
-    } catch (RuntimeException e) {
-      throw e;
-    } catch (Exception e) {
-      throw new RuntimeException(e);
-    }
-    
-    return environment.get(DbSession.class).get(persistentClass, dbid);
-  }
-  
-  private Field getDbidField(Class<?> clazz) {
-    Field[] fields = clazz.getDeclaredFields();
-    for (int i=0; i<fields.length; i++) {
-      if  ("dbid".equals(fields[i].getName())) {
-        return fields[i];
-      }
-    }
-    Class<?> superClass = clazz.getSuperclass();
-    if (superClass!=null) {
-      return getDbidField(superClass);
-    }
-    throw new RuntimeException("no dbid field in object to reload");
-  }
-}

Deleted: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -1,82 +0,0 @@
-/*
- * 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.test;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jbpm.Configuration;
-import org.jbpm.JbpmException;
-import org.jbpm.env.EnvironmentFactory;
-
-
-/**
- * @author Tom Baeyens
- */
-public abstract class EnvironmentFactoryTestCase extends JbpmTestCase {
-  
-  String configResource;
-
-  static Map<String, EnvironmentFactory> environmentFactories = new HashMap<String, EnvironmentFactory>();
-  
-  public EnvironmentFactoryTestCase() {
-    this("jbpm.cfg.xml");
-  }
-  
-  public EnvironmentFactoryTestCase(String configResource) {
-    this.configResource = configResource;
-  }
-
-  public EnvironmentFactory getEnvironmentFactory() {
-    if (isEnvironmentFactoryCached()) {
-      return environmentFactories.get(configResource);
-    }
-    return createEnvironmentFactory();
-  }
-
-  boolean isEnvironmentFactoryCached() {
-    return environmentFactories.containsKey(configResource);
-  }
-
-  EnvironmentFactory createEnvironmentFactory() {
-    return createEnvironmentFactory(configResource);
-  }
-
-  static EnvironmentFactory createEnvironmentFactory(String configResource) {
-    try {
-      log.debug("creating environment factory for ["+configResource+"]");
-      EnvironmentFactory newEnvironmentFactory = (EnvironmentFactory) new Configuration().setResource(configResource).buildProcessEngine();
-      environmentFactories.put(configResource, newEnvironmentFactory);
-      return newEnvironmentFactory;
-    } catch (Exception e) {
-      throw new JbpmException("Exception during creation of environment factory for "+configResource, e);
-    }
-  }
-
-  static void closeEnvironmentFactory(String configResource) {
-    EnvironmentFactory environmentFactory = environmentFactories.remove(configResource);
-    if (environmentFactory!=null) {
-      log.debug("closing environment factory for ["+configResource+"]");
-      environmentFactory.close();
-    }
-  }
-}

Deleted: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentFactoryTestSetup.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -1,64 +0,0 @@
-/**
- * Copyright (C) 2007  Bull S. A. S.
- * Bull, Rue Jean Jaures, B.P.68, 78340, Les Clayes-sous-Bois
- * This library 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
- * version 2.1 of the License.
- * This library 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
- * program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA  02110-1301, USA.
- **/
-package org.jbpm.test;
-
-import junit.extensions.TestSetup;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * @author Guillaume Porcher
- * 
- */
- at Deprecated
-public class EnvironmentFactoryTestSetup extends TestSetup
-{
-  private String configResource;
-
-  public EnvironmentFactoryTestSetup(Test test)
-  {
-    this(test, "environment.cfg.xml");
-  }
-
-  public EnvironmentFactoryTestSetup(Class<?> testClass)
-  {
-    this(new TestSuite(testClass), "environment.cfg.xml");
-  }
-
-  public EnvironmentFactoryTestSetup(Test test, String configResource)
-  {
-    super(test);
-    this.configResource = configResource;
-  }
-
-  public EnvironmentFactoryTestSetup(Class<?> testClass, String configResource)
-  {
-    super(new TestSuite(testClass));
-    this.configResource = configResource;
-  }
-
-  @Override
-  protected void setUp() throws Exception
-  {
-    super.setUp();
-    EnvironmentFactoryTestCase.createEnvironmentFactory(configResource);
-  }
-
-  @Override
-  protected void tearDown() throws Exception
-  {
-    EnvironmentFactoryTestCase.closeEnvironmentFactory(configResource);
-    super.tearDown();
-  }
-}

Deleted: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/EnvironmentTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -1,58 +0,0 @@
-/*
- * 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.test;
-
-import org.jbpm.env.Environment;
-
-/**
- * @author Tom Baeyens
- */
-public abstract class EnvironmentTestCase extends EnvironmentFactoryTestCase {
-
-  protected Environment environment;
-  
-  public EnvironmentTestCase() {
-  }
-
-  public EnvironmentTestCase(String configResource) {
-    super(configResource);
-  }
-
-  public void setUp() throws Exception {
-    super.setUp();
-    openEnvironment();
-  }
-
-  public void tearDown() throws Exception {
-    closeEnvironment();
-    super.tearDown();
-  }
-  
-  void closeEnvironment() {
-    environment.close();
-    environment = null;
-  }
-
-  void openEnvironment() {
-    environment = getEnvironmentFactory().openEnvironment();
-  }
-}

Modified: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/JbpmTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -24,9 +24,7 @@
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
-import org.jbpm.Configuration;
 import org.jbpm.env.Environment;
-import org.jbpm.env.EnvironmentFactory;
 import org.jbpm.log.Jdk14LogFactory;
 import org.jbpm.log.Log;
 import org.jbpm.log.LogFormatter;
@@ -58,12 +56,6 @@
     }
   }
   
-  public static Environment openEnvironment(String xmlString) {
-    EnvironmentFactory environmentFactory = (EnvironmentFactory) 
-        new Configuration().setXmlString(xmlString).buildProcessEngine();
-    return environmentFactory.openEnvironment();
-  }
-
   protected void runTest() throws Throwable {
     try {
       super.runTest();

Deleted: jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/OldDbTestCase.java
===================================================================
--- jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/OldDbTestCase.java	2009-02-10 11:18:50 UTC (rev 3825)
+++ jbpm4/trunk/modules/test-base/src/main/java/org/jbpm/test/OldDbTestCase.java	2009-02-10 13:58:47 UTC (rev 3826)
@@ -1,71 +0,0 @@
-/*
- * 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.test;
-
-import org.jbpm.ExecutionService;
-import org.jbpm.ManagementService;
-import org.jbpm.ProcessService;
-import org.jbpm.cmd.CommandService;
-
-
-/** for tests that use persistence through a command service.
- * 
- * The DB is cleaned inbetween tests.  No environment is created.
- * 
- * @author Tom Baeyens
- */
-public abstract class OldDbTestCase extends EnvironmentFactoryTestCase {
-  
-  protected CommandService commandService;
-  protected ProcessService processService;
-  protected ExecutionService executionService;
-  protected ManagementService managementService;
-
-  public OldDbTestCase() {
-    super();
-  }
-  
-  public OldDbTestCase(String configResource) {
-    super(configResource);
-  }
-  
-  public void setUp() throws Exception {
-    super.setUp();
-
-    if (isEnvironmentFactoryCached()) {
-      Db.clean(getEnvironmentFactory());
-    }
-
-    commandService = getEnvironmentFactory().get(CommandService.class);
-    processService = getEnvironmentFactory().get(ProcessService.class);
-    executionService = getEnvironmentFactory().get(ExecutionService.class);
-    managementService = getEnvironmentFactory().get(ManagementService.class);
-  }
-  
-  public void tearDown() throws Exception {
-    commandService = null;
-    processService = null;
-    executionService = null;
-    managementService = null;
-    super.tearDown();
-  }
-}




More information about the jbpm-commits mailing list