You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2009/04/15 08:01:38 UTC

svn commit: r765057 - in /ofbiz/trunk: applications/accounting/src/org/ofbiz/accounting/test/ applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/ applications/order/src/org/ofbiz/order/test/ applications/product/src/org/ofbiz/pro...

Author: lektran
Date: Wed Apr 15 06:01:36 2009
New Revision: 765057

URL: http://svn.apache.org/viewvc?rev=765057&view=rev
Log:
OFBIZ-2259:  Implemented test data rollback per test-suite using the GenericDelegator

Provides the following benefits:
1. Test data independence per component suite
2. Ability to run tests repeatedly without reloading the database
3. Continued database independence for the testing tools
4. The possibility of future improvements for controlling when data is rolled back (per unit test, group of unit tests within a suite or
even tree structured tests where data is partially rolled back before continuing)
5. The future possibility to export data changes resulting from a test run
6. The future possibility to verify a test result automatically based on the output of #4

The rollback currently doesn't catch changes resulting from async service calls and also doesn't rollback changes to SequenceValueItem

Added:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/testtools/
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/testtools/EntityTestCase.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/testtools/
    ofbiz/trunk/framework/service/src/org/ofbiz/service/testtools/OFBizTestCase.java
Removed:
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestCaseBase.java
Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/test/PurchaseOrderTest.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/test/SalesOrderTest.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java
    ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServicesTests.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
    ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTests.java
    ofbiz/trunk/framework/testtools/build.xml
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JythonTest.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java
    ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/test/FinAccountTests.java Wed Apr 15 06:01:36 2009
@@ -19,25 +19,21 @@
 
 package org.ofbiz.accounting.test;
 
-import junit.framework.TestCase;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericValue;
-import org.ofbiz.service.GenericDispatcher;
-import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.service.ModelService;
-import org.ofbiz.base.util.UtilMisc;
-
 import java.math.BigDecimal;
 import java.util.Map;
 
 import javolution.util.FastMap;
 
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.testtools.OFBizTestCase;
+
 /**
  * FinAccountTests
  */
-public class FinAccountTests extends TestCase {
+public class FinAccountTests extends OFBizTestCase {
 
-    protected LocalDispatcher dispatcher = null;
     protected GenericValue userLogin = null;
 
     public FinAccountTests(String name) {
@@ -45,8 +41,6 @@
     }
 
     protected void setUp() throws Exception {
-        GenericDelegator delegator = GenericDelegator.getGenericDelegator("test");
-        dispatcher = GenericDispatcher.getLocalDispatcher("test-dispatcher", delegator);
         userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
     }
 

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/clearcommerce/CCServicesTest.java Wed Apr 15 06:01:36 2009
@@ -42,14 +42,11 @@
 import org.ofbiz.service.GenericDispatcher;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.service.testtools.OFBizTestCase;
 
-public class CCServicesTest extends TestCase {
+public class CCServicesTest extends OFBizTestCase {
 
     public static final String module = CCServicesTest.class.getName();
-    public static final String DELEGATOR_NAME = "test";
-    public GenericDelegator delegator = null;
-    public static final String DISPATCHER_NAME = "test-dispatcher";
-    public LocalDispatcher dispatcher = null;
 
     // test data
     protected GenericValue emailAddr = null;
@@ -66,9 +63,6 @@
     }
 
     protected void setUp() throws Exception {
-        this.delegator = GenericDelegator.getGenericDelegator(DELEGATOR_NAME);
-        this.dispatcher = GenericDispatcher.getLocalDispatcher(DISPATCHER_NAME, delegator);
-
         // populate test data
         configFile = new String("paymentTest.properties");
         creditAmount = new BigDecimal("234.00");
@@ -98,10 +92,6 @@
                 "TotalNumberPayments", "4");
     }
 
-    protected void tearDown() throws Exception {
-        dispatcher.deregister();
-    }
-
     /*
      * Check the authorisation
      */

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/test/PurchaseOrderTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/test/PurchaseOrderTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/test/PurchaseOrderTest.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/test/PurchaseOrderTest.java Wed Apr 15 06:01:36 2009
@@ -18,24 +18,19 @@
  *******************************************************************************/
 package org.ofbiz.order.test;
 
-import junit.framework.TestCase;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericValue;
-import org.ofbiz.service.GenericDispatcher;
-import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.base.util.UtilMisc;
-
 import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
-import javolution.util.FastMap;
 import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.testtools.OFBizTestCase;
 
-public class PurchaseOrderTest extends TestCase {
+public class PurchaseOrderTest extends OFBizTestCase {
 
-    protected LocalDispatcher dispatcher = null;
-    protected GenericDelegator delegator = null;
     protected GenericValue userLogin = null;
     protected String orderId = null;
     protected String statusId = null;
@@ -45,8 +40,6 @@
     }
 
     protected void setUp() throws Exception {
-        delegator = GenericDelegator.getGenericDelegator("test");
-        dispatcher = GenericDispatcher.getLocalDispatcher("test-dispatcher", delegator);
         userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
     }
 

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/test/SalesOrderTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/test/SalesOrderTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/test/SalesOrderTest.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/test/SalesOrderTest.java Wed Apr 15 06:01:36 2009
@@ -18,23 +18,19 @@
  *******************************************************************************/
 package org.ofbiz.order.test;
 
-import junit.framework.TestCase;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericValue;
-import org.ofbiz.service.GenericDispatcher;
-import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.base.util.UtilMisc;
-
 import java.math.BigDecimal;
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+
 import javolution.util.FastMap;
 
-public class SalesOrderTest extends TestCase {
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.testtools.OFBizTestCase;
+
+public class SalesOrderTest extends OFBizTestCase {
 
-    protected LocalDispatcher dispatcher = null;
-    protected GenericDelegator delegator = null;
     protected GenericValue userLogin = null;
 
     public SalesOrderTest(String name) {
@@ -42,8 +38,6 @@
     }
 
     protected void setUp() throws Exception {
-        delegator = GenericDelegator.getGenericDelegator("test");
-        dispatcher = GenericDispatcher.getLocalDispatcher("test-dispatcher", delegator);
         userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
     }
 

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java Wed Apr 15 06:01:36 2009
@@ -19,23 +19,18 @@
 
 package org.ofbiz.product.test;
 
-import junit.framework.TestCase;
-
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericValue;
-import org.ofbiz.service.GenericDispatcher;
-import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.base.util.UtilDateTime;
-
 import java.math.BigDecimal;
 import java.util.Map;
+
 import javolution.util.FastMap;
 
-public class InventoryItemTransferTest extends TestCase {
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.service.testtools.OFBizTestCase;
+
+public class InventoryItemTransferTest extends OFBizTestCase {
 
-    protected LocalDispatcher dispatcher = null;
-    protected GenericDelegator delegator = null;
     protected GenericValue userLogin = null;
     protected static String inventoryTransferId = null;
     protected BigDecimal transferQty = BigDecimal.ONE;
@@ -45,8 +40,6 @@
     }
 
     protected void setUp() throws Exception {
-        delegator = GenericDelegator.getGenericDelegator("test");
-        dispatcher = GenericDispatcher.getLocalDispatcher("test-dispatcher", delegator);
         userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
     }
 

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java Wed Apr 15 06:01:36 2009
@@ -25,21 +25,16 @@
 
 import javolution.util.FastList;
 import javolution.util.FastMap;
-import junit.framework.TestCase;
 
 import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericValue;
-import org.ofbiz.service.GenericDispatcher;
-import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.testtools.OFBizTestCase;
 
 /**
  * Facility Tests
  */
-public class StockMovesTest extends TestCase {
+public class StockMovesTest extends OFBizTestCase {
 
-    protected LocalDispatcher dispatcher = null;
-    protected GenericDelegator delegator = null;
     protected GenericValue userLogin = null;
 
     public StockMovesTest(String name) {
@@ -47,8 +42,6 @@
     }
 
     protected void setUp() throws Exception {
-        delegator = GenericDelegator.getGenericDelegator("test");
-        dispatcher = GenericDispatcher.getLocalDispatcher("test-dispatcher", delegator);
         userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "system"));
     }
 

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServicesTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServicesTests.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServicesTests.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/thirdparty/usps/UspsServicesTests.java Wed Apr 15 06:01:36 2009
@@ -32,6 +32,7 @@
 import org.ofbiz.service.GenericDispatcher;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.service.testtools.OFBizTestCase;
 
 
 /**
@@ -39,28 +40,18 @@
  *
  * These were created for simple validation only.
  */
-public class UspsServicesTests extends TestCase {
+public class UspsServicesTests extends OFBizTestCase {
 
     public static String module = UspsServicesTests.class.getName();
 
-    public static final String DELEGATOR_NAME = "test";
-    public static final String DISPATCHER_NAME = "test-dispatcher";
-
-    private GenericDelegator delegator = null;
-    private LocalDispatcher dispatcher = null;
-
-
     public UspsServicesTests(String name) {
         super(name);
     }
 
     protected void setUp() throws Exception {
-        delegator = GenericDelegator.getGenericDelegator(DELEGATOR_NAME);
-        dispatcher = GenericDispatcher.getLocalDispatcher(DISPATCHER_NAME, delegator);
     }
 
     protected void tearDown() throws Exception {
-        dispatcher.deregister();
     }
 
     public void testUspsTrackConfirm() throws Exception {

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericDelegator.java Wed Apr 15 06:01:36 2009
@@ -25,6 +25,7 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
@@ -114,6 +115,13 @@
     /** A ThreadLocal variable to allow other methods to specify a session identifier (usually the visitId, though technically the Entity Engine doesn't know anything about the Visit entity) */
     protected static ThreadLocal<List<Object>> sessionIdentifierStack = new ThreadLocal<List<Object>>();
 
+    private boolean testMode = false;
+    private boolean testRollbackInProgress = false;
+    private List<TestOperation> testOperations = null;
+    private enum OperationType {INSERT, UPDATE, DELETE};
+    
+    private String originalDelegatorName = null;
+
 
     public static GenericDelegator getGenericDelegator(String delegatorName) {
         if (delegatorName == null) {
@@ -287,7 +295,7 @@
 
         // NOTE: doing some things before the ECAs and such to make sure it is in place just in case it is used in a service engine startup thing or something
         // put the delegator in the master Map by its name
-        this.delegatorCache.put(delegatorName, this);
+        GenericDelegator.delegatorCache.put(delegatorName, this);
 
         // setup the crypto class
         this.crypto = new EntityCrypto(this);
@@ -320,7 +328,12 @@
         }
 
         // setup the Entity ECA Handler
+        initEntityEcaHandler();
+    }
+
+    public void initEntityEcaHandler() {
         if (getDelegatorInfo().useEntityEca) {
+            ClassLoader loader = Thread.currentThread().getContextClassLoader();
             // initialize the entity eca handler
             String entityEcaHandlerClassName = getDelegatorInfo().entityEcaHandlerClassName;
 
@@ -342,11 +355,15 @@
         }
     }
 
+    public String getDelegatorName() {
+        return this.delegatorName;
+    }
+    
     /** Gets the name of the server configuration that corresponds to this delegator
      * @return server configuration name
      */
-    public String getDelegatorName() {
-        return this.delegatorName;
+    public String getOriginalDelegatorName() {
+        return this.originalDelegatorName == null ? this.delegatorName : this.originalDelegatorName;
     }
 
     protected DelegatorInfo getDelegatorInfo() {
@@ -388,7 +405,7 @@
      *@return String with the helper name that corresponds to this delegator and the specified entityName
      */
     public String getEntityGroupName(String entityName) {
-        return getModelGroupReader().getEntityGroupName(entityName, getDelegatorName());
+        return getModelGroupReader().getEntityGroupName(entityName, getOriginalDelegatorName());
     }
 
     /** Gets a Map of entity name & entity model pairs that are in the named group
@@ -710,6 +727,10 @@
 
             try {
                 value = helper.create(value);
+
+                if (testMode) {
+                    storeForTestRollback(new TestOperation(OperationType.INSERT, value));
+                }
             } catch (GenericEntityException e) {
                 // see if this was caused by an existing record before resetting the sequencer and trying again
                 // NOTE: use the helper directly so ECA rules, etc won't be run
@@ -725,6 +746,10 @@
                     value.setNextSeqId();
                     value = helper.create(value);
                     Debug.logInfo("Successfully created new entity record on retry with a sequenced value [" + value.getPrimaryKey() + "], after getting refreshed bank for entity [" + value.getEntityName() + "]", module);
+
+                    if (testMode) {
+                        storeForTestRollback(new TestOperation(OperationType.INSERT, value));
+                    }
                 }
             }
 
@@ -792,6 +817,9 @@
 
             value = helper.create(value);
 
+            if (testMode) {
+                storeForTestRollback(new TestOperation(OperationType.INSERT, value));
+            }
             if (value != null) {
                 value.setDelegator(this);
                 if (value.lockEnabled()) {
@@ -874,7 +902,7 @@
 
     protected void saveEntitySyncRemoveInfo(GenericEntity dummyPK) throws GenericEntityException {
         // don't store remove info on entities where it is disabled
-        if (dummyPK.getModelEntity().getNoAutoStamp()) {
+        if (dummyPK.getModelEntity().getNoAutoStamp() || this.testRollbackInProgress) {
             return;
         }
 
@@ -940,9 +968,17 @@
                 createEntityAuditLogAll(this.findOne(primaryKey.getEntityName(), primaryKey, false), true, true);
             }
 
+            GenericValue removedEntity = null;
+            if (testMode) {
+                removedEntity = this.findOne(primaryKey.entityName, primaryKey, false);
+            }
             int num = helper.removeByPrimaryKey(primaryKey);
             this.saveEntitySyncRemoveInfo(primaryKey);
 
+            if (testMode) {
+                storeForTestRollback(new TestOperation(OperationType.DELETE, removedEntity));
+            }
+
             ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, primaryKey, false);
 
             return num;
@@ -1001,7 +1037,17 @@
                 createEntityAuditLogAll(value, true, true);
             }
 
+            GenericValue removedValue = null;
+            if (testMode) {
+                removedValue = this.findOne(value.getEntityName(), value.getPrimaryKey(), false);
+            }
+
             int num = helper.removeByPrimaryKey(value.getPrimaryKey());
+
+            if (testMode) {
+                storeForTestRollback(new TestOperation(OperationType.DELETE, removedValue));
+            }
+
             this.saveEntitySyncRemoveInfo(value.getPrimaryKey());
 
             ecaRunner.evalRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, value, false);
@@ -1092,7 +1138,20 @@
             ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
             GenericHelper helper = getEntityHelper(entityName);
 
-            return helper.removeByCondition(modelEntity, condition);
+            List<GenericValue> removedEntities = null;
+            if (testMode) {
+                removedEntities = this.findList(entityName, condition, null, null, null, false);
+            }
+
+            int rowsAffected = helper.removeByCondition(modelEntity, condition);
+
+            if (testMode) {
+                for (GenericValue entity : removedEntities) {
+                    storeForTestRollback(new TestOperation(OperationType.DELETE, entity));
+                }
+            }
+
+            return rowsAffected;
         } catch (GenericEntityException e) {
             String errMsg = "Failure in removeByCondition operation for entity [" + entityName + "]: " + e.toString() + ". Rolling back transaction.";
             Debug.logError(e, errMsg, module);
@@ -1209,7 +1268,20 @@
             ModelEntity modelEntity = getModelReader().getModelEntity(entityName);
             GenericHelper helper = getEntityHelper(entityName);
 
-            return helper.storeByCondition(modelEntity, fieldsToSet, condition);
+            List<GenericValue> updatedEntities = null;
+            if (testMode) {
+                updatedEntities = this.findList(entityName, condition, null, null, null, false);
+            }
+
+            int rowsAffected =  helper.storeByCondition(modelEntity, fieldsToSet, condition);
+
+            if (testMode) {
+                for (GenericValue entity : updatedEntities) {
+                    storeForTestRollback(new TestOperation(OperationType.UPDATE, entity));
+                }
+            }
+
+            return rowsAffected;
         } catch (GenericEntityException e) {
             String errMsg = "Failure in storeByCondition operation for entity [" + entityName + "]: " + e.toString() + ". Rolling back transaction.";
             Debug.logError(e, errMsg, module);
@@ -1265,8 +1337,17 @@
                 createEntityAuditLogAll(value, true, false);
             }
 
+            GenericValue updatedEntity = null;
+
+            if (testMode) {
+                updatedEntity = this.findOne(value.entityName, value.getPrimaryKey(), false);
+            }
+
             int retVal = helper.store(value);
 
+            if (testMode) {
+                storeForTestRollback(new TestOperation(OperationType.UPDATE, updatedEntity));
+            }
             // refresh the valueObject to get the new version
             if (value.lockEnabled()) {
                 refresh(value, doCacheClear);
@@ -3003,6 +3084,7 @@
     }
 
     protected EntityEcaRuleRunner<?> getEcaRuleRunner(String entityName) {
+        if (this.testRollbackInProgress) return createEntityEcaRuleRunner(null, null);
         return createEntityEcaRuleRunner(this.entityEcaHandler, entityName);
     }
 
@@ -3274,7 +3356,7 @@
     }
 
     protected void createEntityAuditLogSingle(GenericValue value, ModelField mf, boolean isUpdate, boolean isRemove) throws GenericEntityException {
-        if (value == null || mf == null || !mf.getEnableAuditLog()) {
+        if (value == null || mf == null || !mf.getEnableAuditLog() || this.testRollbackInProgress) {
             return;
         }
 
@@ -3345,8 +3427,12 @@
         newDelegator.cache = this.cache;
         newDelegator.andCacheFieldSets = this.andCacheFieldSets;
         newDelegator.distributedCacheClear = this.distributedCacheClear;
+        newDelegator.originalDelegatorName = getOriginalDelegatorName();
         newDelegator.entityEcaHandler = this.entityEcaHandler;
         newDelegator.crypto = this.crypto;
+        // In case this delegator is in testMode give it a reference to
+        // the rollback list
+        newDelegator.testOperations = this.testOperations;
         // not setting the sequencer so that we have unique sequences.
 
         return newDelegator;
@@ -3355,4 +3441,71 @@
     public GenericDelegator cloneDelegator() {
         return this.cloneDelegator(this.delegatorName);
     }
+    
+    public GenericDelegator makeTestDelegator(String delegatorName) {
+        GenericDelegator testDelegator = this.cloneDelegator(delegatorName);
+        testDelegator.initEntityEcaHandler();
+        testDelegator.setTestMode(true);
+        return testDelegator;
+    }
+
+    private void setTestMode(boolean testMode) {
+        this.testMode = testMode;
+        if (testMode) {
+            this.testOperations = FastList.newInstance();
+        } else {
+            this.testOperations.clear();
+        }
+    }
+    
+    private void storeForTestRollback(TestOperation testOperation) {
+        if (!this.testMode || this.testRollbackInProgress) {
+            throw new IllegalStateException("An attempt was made to store a TestOperation during rollback or outside of test mode");
+        }
+        this.testOperations.add(testOperation);
+    }
+
+    public void rollback() {
+        if (!this.testMode) {
+            Debug.logError("Rollback requested outside of testmode", module);
+        }
+        this.testMode = false;
+        this.testRollbackInProgress = true;
+        synchronized (testOperations) {
+            Debug.logInfo("Rolling back " + testOperations.size() + " entity operations", module);
+            ListIterator<TestOperation> iterator = this.testOperations.listIterator(this.testOperations.size());
+            while (iterator.hasPrevious()) {
+                TestOperation testOperation = iterator.previous();
+                try {
+                    if (testOperation.getOperation().equals(OperationType.INSERT)) {
+                        this.removeValue(testOperation.getValue());
+                    } else if (testOperation.getOperation().equals(OperationType.UPDATE)) {
+                        this.store(testOperation.getValue());
+                    } else if (testOperation.getOperation().equals(OperationType.DELETE)) {
+                        this.create(testOperation.getValue());
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logWarning(e.toString(), module);
+                }
+            }
+            this.testOperations.clear();
+        }
+        this.testRollbackInProgress = false;
+        this.testMode = true;
+    }
+
+    public class TestOperation {
+        private final OperationType operation;
+        public OperationType getOperation() {
+            return operation;
+        }
+        public GenericValue getValue() {
+            return value;
+        }
+        private final GenericValue value;
+        public TestOperation(OperationType operation, GenericValue value) {
+            this.operation = operation;
+            this.value = value;
+        }
+    }
 }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/GenericEntity.java Wed Apr 15 06:01:36 2009
@@ -279,7 +279,7 @@
         return modelEntity;
     }
 
-    /** Get the GenericDelegator instance that created this value object and that is repsonsible for it.
+    /** Get the GenericDelegator instance that created this value object and that is responsible for it.
      *@return GenericDelegator object
      */
     public GenericDelegator getDelegator() {
@@ -293,7 +293,7 @@
         return internalDelegator;
     }
 
-    /** Set the GenericDelegator instance that created this value object and that is repsonsible for it. */
+    /** Set the GenericDelegator instance that created this value object and that is responsible for it. */
     public void setDelegator(GenericDelegator internalDelegator) {
         if (internalDelegator == null) return;
         this.delegatorName = internalDelegator.getDelegatorName();

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Wed Apr 15 06:01:36 2009
@@ -29,7 +29,6 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.entity.GenericDelegator;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericPK;
@@ -42,12 +41,11 @@
 import org.ofbiz.entity.transaction.TransactionUtil;
 import org.ofbiz.entity.util.EntityFindOptions;
 import org.ofbiz.entity.util.EntityListIterator;
+import org.ofbiz.entity.testtools.EntityTestCase;
 
-public class EntityTestSuite extends TestCase {
+public class EntityTestSuite extends EntityTestCase {
 
     public static final String module = EntityTestSuite.class.getName();
-    public static final String DELEGATOR_NAME = "test";
-    public GenericDelegator delegator = null;
     /*
      * This sets how many values to insert when trying to create a large number of values.  10,000 causes HSQL to crash but is ok
      * with Derby.  Going up to 100,000 causes problems all around because Java List seems to be capped at about 65,000 values.
@@ -62,10 +60,6 @@
 
     final static private int _level1max = 3;   // number of TestingNode entities to create
 
-    protected void setUp() throws Exception {
-        this.delegator = GenericDelegator.getGenericDelegator(DELEGATOR_NAME);
-    }
-
     /*
      * Tests storing values with the delegator's .create, .makeValue, and .storeAll methods
      */

Added: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/testtools/EntityTestCase.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/testtools/EntityTestCase.java?rev=765057&view=auto
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/testtools/EntityTestCase.java (added)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/testtools/EntityTestCase.java Wed Apr 15 06:01:36 2009
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+
+package org.ofbiz.entity.testtools;
+
+import junit.framework.TestCase;
+
+import org.ofbiz.entity.GenericDelegator;
+
+public class EntityTestCase extends TestCase {
+
+    protected GenericDelegator delegator = null;
+
+    public EntityTestCase(String name) {
+        super(name);
+    }
+
+    public void setDelegator(GenericDelegator delegator) {
+        this.delegator = delegator;
+    }
+    
+    public GenericDelegator getDelegator() {
+        return delegator;
+    }
+}

Modified: ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java (original)
+++ ofbiz/trunk/framework/entityext/src/org/ofbiz/entityext/eca/DelegatorEcaHandler.java Wed Apr 15 06:01:36 2009
@@ -49,7 +49,7 @@
     public void setDelegator(GenericDelegator delegator) {
         this.delegator = delegator;
         this.delegatorName = delegator.getDelegatorName();
-        this.entityEcaReaderName = EntityEcaUtil.getEntityEcaReaderName(this.delegatorName);
+        this.entityEcaReaderName = EntityEcaUtil.getEntityEcaReaderName(delegator.getOriginalDelegatorName());
         this.dctx = EntityServiceFactory.getDispatchContext(delegator);
 
         //preload the cache

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/GenericDispatcher.java Wed Apr 15 06:01:36 2009
@@ -49,12 +49,12 @@
     public static LocalDispatcher getLocalDispatcher(String dispatcherName, GenericDelegator delegator, Collection<URL> readerURLs, ClassLoader loader, ServiceDispatcher serviceDispatcher) {
         if (dispatcherName == null) {
             dispatcherName = "default";
-            Debug.logWarning("Got a getGenericDelegator call with a null dispatcherName, assuming default for the name.", module);
+            Debug.logWarning("Got a getGenericDispatcher call with a null dispatcherName, assuming default for the name.", module);
         }
         LocalDispatcher dispatcher = dispatcherCache.get(dispatcherName);
 
         if (dispatcher == null) {
-            synchronized (GenericDelegator.class) {
+            synchronized (GenericDispatcher.class) {
                 // must check if null again as one of the blocked threads can still enter
                 dispatcher = dispatcherCache.get(dispatcherName);
                 if (dispatcher == null) {
@@ -69,7 +69,7 @@
                         loader = GenericDispatcher.class.getClassLoader();
                     }
 
-                    ServiceDispatcher sd = serviceDispatcher != null? serviceDispatcher : ServiceDispatcher.getInstance(dispatcherName, delegator);
+                    ServiceDispatcher sd = serviceDispatcher != null ? serviceDispatcher : ServiceDispatcher.getInstance(dispatcherName, delegator);
                     LocalDispatcher thisDispatcher = null;
                     if (sd != null) {
                         dispatcher = sd.getLocalDispatcher(dispatcherName);

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Wed Apr 15 06:01:36 2009
@@ -94,13 +94,17 @@
             try {
                 this.security = SecurityFactory.getInstance(delegator);
             } catch (SecurityConfigurationException e) {
-                Debug.logError(e, "[ServiceDispatcher.init] : No instance of security imeplemtation found.", module);
+                Debug.logError(e, "[ServiceDispatcher.init] : No instance of security implementation found.", module);
             }
         }
 
         // job manager needs to always be running, but the poller thread does not
         try {
-            this.jm = new JobManager(this.delegator, enableJM);
+            GenericDelegator origDelegator = this.delegator;
+            if (!this.delegator.getOriginalDelegatorName().equals(this.delegator.getDelegatorName())) {
+                origDelegator = GenericDelegator.getGenericDelegator(this.delegator.getOriginalDelegatorName());
+            }
+            this.jm = JobManager.getInstance(origDelegator, enableJM);
         } catch (GeneralRuntimeException e) {
             Debug.logWarning(e.getMessage(), module);
         }
@@ -155,6 +159,7 @@
                 }
             }
         }
+
         if (name != null && context != null) {
             sd.register(name, context);
         }

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/job/JobManager.java Wed Apr 15 06:01:36 2009
@@ -82,6 +82,15 @@
         jp = new JobPoller(this, enabled);
         JobManager.registeredManagers.put(delegator.getDelegatorName(), this);
     }
+    
+    public static JobManager getInstance(GenericDelegator delegator, boolean enabled)
+    {
+        JobManager jm = JobManager.registeredManagers.get(delegator.getDelegatorName());
+        if (jm == null) {
+            jm = new JobManager(delegator, enabled);
+        }
+        return jm;
+    }
 
     /** Queues a Job to run now. */
     public void runJob(Job job) throws JobManagerException {

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTests.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTests.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTests.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/test/ServiceEngineTests.java Wed Apr 15 06:01:36 2009
@@ -20,27 +20,17 @@
 
 import java.util.Map;
 
-import junit.framework.TestCase;
 import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.service.GenericDispatcher;
-import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.service.testtools.OFBizTestCase;
 
-public class ServiceEngineTests extends TestCase {
-
-    public static final String DELEGATOR_NAME = "test";
-    public static final String DISPATCHER_NAME = "test-dispatcher";
-
-    private LocalDispatcher dispatcher = null;
+public class ServiceEngineTests extends OFBizTestCase {
 
     public ServiceEngineTests(String name) {
         super(name);
     }
 
     protected void setUp() throws Exception {
-        GenericDelegator delegator = GenericDelegator.getGenericDelegator(DELEGATOR_NAME);
-        dispatcher = GenericDispatcher.getLocalDispatcher(DISPATCHER_NAME, delegator);
     }
 
     protected void tearDown() throws Exception {

Added: ofbiz/trunk/framework/service/src/org/ofbiz/service/testtools/OFBizTestCase.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/testtools/OFBizTestCase.java?rev=765057&view=auto
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/testtools/OFBizTestCase.java (added)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/testtools/OFBizTestCase.java Wed Apr 15 06:01:36 2009
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+
+package org.ofbiz.service.testtools;
+
+import org.ofbiz.entity.testtools.EntityTestCase;
+import org.ofbiz.service.LocalDispatcher;
+
+public class OFBizTestCase extends EntityTestCase {
+
+    protected LocalDispatcher dispatcher = null;
+    
+    public LocalDispatcher getDispatcher() {
+        return dispatcher;
+    }
+
+    public OFBizTestCase(String name) {
+        super(name);
+    }
+
+    public void setDispatcher(LocalDispatcher dispatcher) {
+        this.dispatcher = dispatcher;
+    }
+}

Modified: ofbiz/trunk/framework/testtools/build.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/build.xml?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/build.xml (original)
+++ ofbiz/trunk/framework/testtools/build.xml Wed Apr 15 06:01:36 2009
@@ -32,6 +32,7 @@
     <path id="local.class.path">
         <!-- <fileset dir="${lib.dir}" includes="*.jar"/> -->
         <fileset dir="../base/lib" includes="*.jar"/>
+        <fileset dir="../base/lib/commons" includes="*.jar"/>
         <fileset dir="../base/build/lib" includes="*.jar"/>
         <fileset dir="../entity/lib" includes="*.jar"/>
         <fileset dir="../entity/build/lib" includes="*.jar"/>

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/EntityXmlAssertTest.java Wed Apr 15 06:01:36 2009
@@ -26,6 +26,7 @@
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityDataAssert;
 import org.ofbiz.entity.util.EntitySaxReader;
+import org.ofbiz.service.testtools.OFBizTestCase;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.location.FlexibleLocation;
@@ -37,7 +38,7 @@
 import java.util.Iterator;
 import java.net.URL;
 
-public class EntityXmlAssertTest extends TestCaseBase {
+public class EntityXmlAssertTest extends OFBizTestCase {
 
     public static final String module = ServiceTest.class.getName();
 
@@ -47,8 +48,8 @@
     /**
      * @param modelTestSuite
      */
-    public EntityXmlAssertTest(String caseName, ModelTestSuite modelTestSuite, Element mainElement) {
-        super(caseName, modelTestSuite);
+    public EntityXmlAssertTest(String caseName, Element mainElement) {
+        super(caseName);
         this.entityXmlUrlString = mainElement.getAttribute("entity-xml-url");
         this.action = mainElement.getAttribute("action");
         if (UtilValidate.isEmpty(this.action)) this.action = "assert";
@@ -58,7 +59,7 @@
         int testCaseCount = 0;
         try {
             URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
-            List<GenericValue> checkValueList = modelTestSuite.getDelegator().readXmlDocument(entityXmlURL);
+            List<GenericValue> checkValueList = delegator.readXmlDocument(entityXmlURL);
             testCaseCount = checkValueList.size();
         } catch (Exception e) {
             Debug.logError(e, "Error getting test case count", module);
@@ -71,7 +72,6 @@
 
         try {
             URL entityXmlURL = FlexibleLocation.resolveLocation(entityXmlUrlString);
-            GenericDelegator delegator = modelTestSuite.getDelegator();
             List<Object> errorMessages = FastList.newInstance();
 
             if ("assert".equals(this.action)) {

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JunitSuiteWrapper.java Wed Apr 15 06:01:36 2009
@@ -76,19 +76,8 @@
         }
     }
 
-    public List<TestSuite> makeTestSuites() {
-        List<TestSuite> testSuites = FastList.newInstance();
-
-        for (ModelTestSuite modelTestSuite: this.modelTestSuiteList) {
-            TestSuite suite = new TestSuite();
-            suite.setName(modelTestSuite.getSuiteName());
-            for (Test tst: modelTestSuite.getTestList()) {
-                suite.addTest(tst);
-            }
-            testSuites.add(suite);
-        }
-
-        return testSuites;
+    public List<ModelTestSuite> getModelTestSuites() {
+        return this.modelTestSuiteList;
     }
 
     public List<Test> getAllTestList() {

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JythonTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JythonTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JythonTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/JythonTest.java Wed Apr 15 06:01:36 2009
@@ -18,11 +18,12 @@
  *******************************************************************************/
 package org.ofbiz.testtools;
 
+import org.ofbiz.service.testtools.OFBizTestCase;
 import org.w3c.dom.Element;
 
 import junit.framework.TestResult;
 
-public class JythonTest extends TestCaseBase {
+public class JythonTest extends OFBizTestCase {
 
     public static final String module = JythonTest.class.getName();
 
@@ -31,8 +32,8 @@
     /**
      * @param modelTestSuite
      */
-    public JythonTest(String caseName, ModelTestSuite modelTestSuite, Element mainElement) {
-        super(caseName, modelTestSuite);
+    public JythonTest(String caseName, Element mainElement) {
+        super(caseName);
         this.scriptLocation = mainElement.getAttribute("script-location");
     }
 

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ModelTestSuite.java Wed Apr 15 06:01:36 2009
@@ -26,14 +26,18 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.apache.commons.lang.RandomStringUtils;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.testtools.EntityTestCase;
 import org.ofbiz.service.GenericDispatcher;
+import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.testtools.OFBizTestCase;
 import org.w3c.dom.Element;
 
 /**
@@ -44,8 +48,8 @@
     public static final String module = ModelTestSuite.class.getName();
 
     protected String suiteName;
-    protected String delegatorName;
-    protected String dispatcherName;
+    protected String originalDelegatorName;
+    protected String originalDispatcherName;
 
     protected GenericDelegator delegator;
     protected LocalDispatcher dispatcher;
@@ -55,14 +59,16 @@
     public ModelTestSuite(Element mainElement, String testCase) {
         this.suiteName = mainElement.getAttribute("suite-name");
 
-        this.delegatorName = mainElement.getAttribute("delegator-name");
-        if (UtilValidate.isEmpty(this.delegatorName)) this.delegatorName = "test";
+        this.originalDelegatorName = mainElement.getAttribute("delegator-name");
+        if (UtilValidate.isEmpty(this.originalDelegatorName)) this.originalDelegatorName = "test";
 
-        this.dispatcherName = mainElement.getAttribute("dispatcher-name");
-        if (UtilValidate.isEmpty(this.dispatcherName)) this.dispatcherName = "test-dispatcher";
+        this.originalDispatcherName = mainElement.getAttribute("dispatcher-name");
+        if (UtilValidate.isEmpty(this.originalDispatcherName)) this.originalDispatcherName = "test-dispatcher";
+        
+        String uniqueSuffix = "-" + RandomStringUtils.randomAlphanumeric(10);
 
-        this.delegator = GenericDelegator.getGenericDelegator(this.delegatorName);
-        this.dispatcher = GenericDispatcher.getLocalDispatcher(this.dispatcherName, delegator);
+        this.delegator = GenericDelegator.getGenericDelegator(this.originalDelegatorName).makeTestDelegator(this.originalDelegatorName + uniqueSuffix);
+        this.dispatcher = GenericDispatcher.getLocalDispatcher(originalDispatcherName + uniqueSuffix, delegator);
 
         for (Element testCaseElement : UtilXml.childElementList(mainElement, UtilMisc.toSet("test-case", "test-group"))) {
             String caseName = testCaseElement.getAttribute("case-name");
@@ -105,16 +111,16 @@
                 Debug.logError(e, errMsg, module);
             }
         } else if ("service-test".equals(nodeName)) {
-            this.testList.add(new ServiceTest(caseName, this, testElement));
+            this.testList.add(new ServiceTest(caseName, testElement));
         } else if ("simple-method-test".equals(nodeName)) {
-            this.testList.add(new SimpleMethodTest(caseName, this, testElement));
+            this.testList.add(new SimpleMethodTest(caseName, testElement));
         } else if ("entity-xml".equals(nodeName)) {
-            this.testList.add(new EntityXmlAssertTest(caseName, this, testElement));
+            this.testList.add(new EntityXmlAssertTest(caseName, testElement));
         } else if ("entity-xml-assert".equals(nodeName)) {
             // this is the old, deprecated name for the element, changed because it now does assert or load
-            this.testList.add(new EntityXmlAssertTest(caseName, this, testElement));
+            this.testList.add(new EntityXmlAssertTest(caseName, testElement));
         } else if ("jython-test".equals(nodeName)) {
-            this.testList.add(new JythonTest(caseName, this, testElement));
+            this.testList.add(new JythonTest(caseName, testElement));
         }
 
     }
@@ -126,12 +132,35 @@
     GenericDelegator getDelegator() {
         return this.delegator;
     }
-
-    LocalDispatcher getDispatcher() {
-        return this.dispatcher;
-    }
-
+    
     List<Test> getTestList() {
         return testList;
     }
+    
+    
+    public TestSuite makeTestSuite() {
+        TestSuite suite = new TestSuite();
+        suite.setName(this.getSuiteName());
+        for (Test tst: this.getTestList()) {
+            prepareTest(tst);
+            suite.addTest(tst);
+        }
+
+        return suite;
+    }
+    
+    private void prepareTest(Test test)
+    {
+        if (test instanceof TestSuite) {
+            Enumeration<Test> subTests = ((TestSuite) test).tests();
+            while (subTests.hasMoreElements()) {
+                prepareTest(subTests.nextElement());
+            }
+        } else if (test instanceof EntityTestCase) {
+            ((EntityTestCase)test).setDelegator(delegator);
+            if (test instanceof OFBizTestCase) {
+                ((OFBizTestCase)test).setDispatcher(dispatcher);
+            }
+        }
+    }
 }

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/ServiceTest.java Wed Apr 15 06:01:36 2009
@@ -26,6 +26,7 @@
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.ServiceUtil;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.service.testtools.OFBizTestCase;
 import org.ofbiz.base.util.UtilGenerics;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
@@ -34,7 +35,7 @@
 import java.util.List;
 import java.util.Iterator;
 
-public class ServiceTest extends TestCaseBase {
+public class ServiceTest extends OFBizTestCase {
 
     public static final String module = ServiceTest.class.getName();
 
@@ -43,8 +44,8 @@
     /**
      * @param modelTestSuite
      */
-    public ServiceTest(String caseName, ModelTestSuite modelTestSuite, Element mainElement) {
-        super(caseName, modelTestSuite);
+    public ServiceTest(String caseName, Element mainElement) {
+        super(caseName);
         this.serviceName = mainElement.getAttribute("service-name");
     }
 
@@ -55,8 +56,6 @@
     public void run(TestResult result) {
         result.startTest(this);
 
-        LocalDispatcher dispatcher = modelTestSuite.getDispatcher();
-
         try {
 
             Map<String, Object> serviceResult = dispatcher.runSync(serviceName, UtilMisc.toMap("test", this, "testResult", result));

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/SimpleMethodTest.java Wed Apr 15 06:01:36 2009
@@ -33,9 +33,10 @@
 import org.ofbiz.minilang.SimpleMethod;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.service.testtools.OFBizTestCase;
 import org.w3c.dom.Element;
 
-public class SimpleMethodTest extends TestCaseBase {
+public class SimpleMethodTest extends OFBizTestCase {
 
     public static final String module = ServiceTest.class.getName();
 
@@ -45,8 +46,8 @@
     /**
      * @param modelTestSuite
      */
-    public SimpleMethodTest(String caseName, ModelTestSuite modelTestSuite, Element mainElement) {
-        super(caseName, modelTestSuite);
+    public SimpleMethodTest(String caseName, Element mainElement) {
+        super(caseName);
         this.methodLocation = mainElement.getAttribute("location");
         this.methodName = mainElement.getAttribute("name");
     }
@@ -58,8 +59,6 @@
     public void run(TestResult result) {
         result.startTest(this);
 
-        LocalDispatcher dispatcher = modelTestSuite.getDispatcher();
-
         try {
 
             Map serviceResult = SimpleMethod.runSimpleService(methodLocation, methodName, dispatcher.getDispatchContext(),

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestListContainer.java Wed Apr 15 06:01:36 2009
@@ -18,25 +18,20 @@
  *******************************************************************************/
 package org.ofbiz.testtools;
 
-import org.ofbiz.base.component.AlreadyLoadedException;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.List;
+
+import javolution.util.FastList;
+
 import org.ofbiz.base.component.ComponentConfig;
-import org.ofbiz.base.component.ComponentException;
 import org.ofbiz.base.config.GenericConfigException;
 import org.ofbiz.base.config.ResourceHandler;
-import org.ofbiz.base.container.ComponentContainer;
 import org.ofbiz.base.container.Container;
 import org.ofbiz.base.container.ContainerException;
 import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.base.util.UtilXml;
-
-import javolution.util.FastList;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.FileOutputStream;
-import java.io.PrintStream;
-import java.util.List;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 

Modified: ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java?rev=765057&r1=765056&r2=765057&view=diff
==============================================================================
--- ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java (original)
+++ ofbiz/trunk/framework/testtools/src/org/ofbiz/testtools/TestRunContainer.java Wed Apr 15 06:01:36 2009
@@ -26,6 +26,7 @@
 import org.ofbiz.base.container.Container;
 import org.ofbiz.base.container.ContainerException;
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.entity.GenericDelegator;
 
 import java.io.*;
 import java.util.Enumeration;
@@ -111,7 +112,9 @@
             throw new ContainerException("No tests found (" + component + " / " + suiteName + " / " + testCase + ")");
         }
 
-        for (TestSuite suite: jsWrapper.makeTestSuites()) {
+        for (ModelTestSuite modelSuite: jsWrapper.getModelTestSuites()) {
+            GenericDelegator testDelegator = modelSuite.getDelegator();
+            TestSuite suite = modelSuite.makeTestSuite();
             JUnitTest test = new JUnitTest();
             test.setName(suite.getName());
 
@@ -130,13 +133,14 @@
 
             // add the suite to the xml listener
             xml.startTestSuite(test);
-
             // run the tests
             suite.run(results);
             test.setCounts(results.runCount(), results.failureCount(), results.errorCount());
+            // rollback all entity operations performed by the delegator
+            testDelegator.rollback();
             xml.endTestSuite(test);
 
-            // dispay the results
+            // display the results
             Debug.log("[JUNIT] Pass: " + results.wasSuccessful() + " | # Tests: " + results.runCount() + " | # Failed: " +
                     results.failureCount() + " # Errors: " + results.errorCount(), module);
             if (Debug.importantOn()) {