svn commit: r909858 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r909858 - /ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java

adrianc
Author: adrianc
Date: Sat Feb 13 17:45:11 2010
New Revision: 909858

URL: http://svn.apache.org/viewvc?rev=909858&view=rev
Log:
Test XStream serialization/deserialization of GenericValue.

Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java

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=909858&r1=909857&r2=909858&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 Sat Feb 13 17:45:11 2010
@@ -29,6 +29,9 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.DelegatorFactory;
 import org.ofbiz.entity.GenericEntity;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericPK;
@@ -108,6 +111,31 @@
     }
 
     /*
+     * Tests XML serialization by serializing/deserializing a GenericValue
+     */
+    public void testXmlSerialization() throws Exception {
+        try {
+            // Must use the default delegator because the deserialized GenericValue can't
+            // find the randomized one.
+            Delegator localDelegator = DelegatorFactory.getDelegator("default");
+            boolean transBegin = TransactionUtil.begin();
+            localDelegator.create("TestingType", "testingTypeId", "TEST-5", "description", "Testing Type #5");
+            GenericValue testValue = localDelegator.findOne("TestingType", false, "testingTypeId", "TEST-5");
+            TestCase.assertEquals("Retrieved value has the correct description", testValue.getString("description"), "Testing Type #5");
+            String newValueStr = UtilXml.toXml(testValue);
+            GenericValue newValue = (GenericValue) UtilXml.fromXml(newValueStr);
+            TestCase.assertEquals("Retrieved value has the correct description", newValue.getString("description"), "Testing Type #5");
+            newValue.put("description", "XML Testing Type #5");
+            newValue.store();
+            newValue = localDelegator.findOne("TestingType", false, "testingTypeId", "TEST-5");
+            TestCase.assertEquals("Retrieved value has the correct description", newValue.getString("description"), "XML Testing Type #5");
+            TransactionUtil.rollback(transBegin, null, null);
+        } catch (GenericEntityException ex) {
+            TestCase.fail(ex.getMessage());
+        }
+    }
+
+    /*
      * Tests storing data with the delegator's .create method.  Also tests .findCountByCondition and .getNextSeqId
      */
     public void testCreateTree() throws Exception {