svn commit: r979535 - in /ofbiz/branches/release10.04: ./ framework/entity/entitydef/entitymodel_test.xml 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: r979535 - in /ofbiz/branches/release10.04: ./ framework/entity/entitydef/entitymodel_test.xml framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java

adrianc
Author: adrianc
Date: Tue Jul 27 05:09:41 2010
New Revision: 979535

URL: http://svn.apache.org/viewvc?rev=979535&view=rev
Log:
Merged rev 958769 and 959456 from trunk - improved entity engine tests.

Entity test improvements:

1. Skip foreign key tests on datasources that don't use foreign keys.
2. Test all field types.

Modified:
    ofbiz/branches/release10.04/   (props changed)
    ofbiz/branches/release10.04/framework/entity/entitydef/entitymodel_test.xml
    ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java

Propchange: ofbiz/branches/release10.04/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 27 05:09:41 2010
@@ -1,3 +1,3 @@
 /ofbiz/branches/addbirt:831210-885099,885686-886087
 /ofbiz/branches/multitenant20100310:921280-927264
-/ofbiz/trunk:939988,939990,939999,940025,940053,940234,940248,940309,940401,940410,940425,940779,940815,940849,941007,941047,941109,941177,941199,941261,941440,941600,941999,942084,942406,942414,942671,942883-942884,943168,943271-943272,944614,944621,944623,944647,944669,944797,944895,945010,945018,945026,945118,945573,945578,945580,945582,945610,945619,945848,945852,945857,946061,946066,946073,946075,946080,946309,946313,946320,946322,946596,947004-947005,947392,947424,947679,947988,948017,948694,949174,949710,949844,950866,950870,950893,951005,951062,951098,951251,951367,951381,951672,952232,952249,952270,953294,953671,954135,954583,954733,954956,955568,956022,956206,956340,957160,958343,958514,958521,958752,958758,958953,960491,960997,963610,964558,965470,965916,966525,966785,967098,978806,978893,979104
+/ofbiz/trunk:939988,939990,939999,940025,940053,940234,940248,940309,940401,940410,940425,940779,940815,940849,941007,941047,941109,941177,941199,941261,941440,941600,941999,942084,942406,942414,942671,942883-942884,943168,943271-943272,944614,944621,944623,944647,944669,944797,944895,945010,945018,945026,945118,945573,945578,945580,945582,945610,945619,945848,945852,945857,946061,946066,946073,946075,946080,946309,946313,946320,946322,946596,947004-947005,947392,947424,947679,947988,948017,948694,949174,949710,949844,950866,950870,950893,951005,951062,951098,951251,951367,951381,951672,952232,952249,952270,953294,953671,954135,954583,954733,954956,955568,956022,956206,956340,957160,958343,958514,958521,958752,958758,958769,958953,959456,960491,960997,963610,964558,965470,965916,966525,966785,967098,978806,978893,979104

Modified: ofbiz/branches/release10.04/framework/entity/entitydef/entitymodel_test.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/entity/entitydef/entitymodel_test.xml?rev=979535&r1=979534&r2=979535&view=diff
==============================================================================
--- ofbiz/branches/release10.04/framework/entity/entitydef/entitymodel_test.xml (original)
+++ ofbiz/branches/release10.04/framework/entity/entitydef/entitymodel_test.xml Tue Jul 27 05:09:41 2010
@@ -77,13 +77,32 @@ under the License.
    ========================================================== -->
     <entity entity-name="TestBlob"
         package-name="org.ofbiz.entity.test"
-        title="Entity for testing the blob type">
+        title="Entity for testing the blob type (Deprecated)">
+        <description>Deprecated - use TestFieldType instead</description>
         <field name="testBlobId" type="id-ne"/>
         <field name="testBlobField" type="blob"/>
          <prim-key field="testBlobId"/>
     </entity>
   <!-- =========================================================
-    Testing Node entity : hierachy of nodes having
+     An entity for testing the field data types
+   ========================================================== -->
+    <entity entity-name="TestFieldType"
+        package-name="org.ofbiz.entity.test"
+        title="Entity for testing the field data types">
+        <description>An entity for testing the field data types</description>
+        <field name="testFieldTypeId" type="id-ne"/>
+        <field name="blobField" type="blob"/>
+        <field name="dateField" type="date"/>
+        <field name="timeField" type="time"/>
+        <field name="dateTimeField" type="date-time"/>
+        <field name="fixedPointField" type="fixed-point"/>
+        <field name="floatingPointField" type="floating-point"/>
+        <field name="numericField" type="numeric"/>
+        <field name="clobField" type="very-long"/>
+        <prim-key field="testFieldTypeId"/>
+    </entity>
+  <!-- =========================================================
+    Testing Node entity : hierarchy of nodes having
     'testing node member' as potential members
   ========================================================= -->
     <entity entity-name="TestingNode"

Modified: ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java?rev=979535&r1=979534&r2=979535&view=diff
==============================================================================
--- ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java (original)
+++ ofbiz/branches/release10.04/framework/entity/src/org/ofbiz/entity/test/EntityTestSuite.java Tue Jul 27 05:09:41 2010
@@ -18,14 +18,16 @@
  *******************************************************************************/
 package org.ofbiz.entity.test;
 
+import java.math.BigDecimal;
+import java.sql.Blob;
+import java.sql.Date;
+import java.sql.Time;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
-import junit.framework.TestCase;
-
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilMisc;
@@ -40,11 +42,13 @@ import org.ofbiz.entity.condition.Entity
 import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.config.DatasourceInfo;
+import org.ofbiz.entity.config.EntityConfigUtil;
+import org.ofbiz.entity.testtools.EntityTestCase;
 import org.ofbiz.entity.transaction.GenericTransactionException;
 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 EntityTestCase {
 
@@ -249,6 +253,16 @@ public class EntityTestSuite extends Ent
      * Tests foreign key integrity by trying to remove an entity which has foreign-key dependencies.  Should cause an exception.
      */
     public void testForeignKeyCreate() {
+        try {
+            String helperName = delegator.getEntityHelper("Testing").getHelperName();
+            DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
+            if (!datasourceInfo.useFks) {
+                Debug.logInfo("Datasource " + datasourceInfo.name + " use-foreign-keys set to false, skipping testForeignKeyCreate", module);
+                return;
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+        }
         GenericEntityException caught = null;
         try {
             delegator.create("Testing", "testingId", delegator.getNextSeqId("Testing"), "testingTypeId", "NO-SUCH-KEY");
@@ -263,6 +277,16 @@ public class EntityTestSuite extends Ent
      * Tests foreign key integrity by trying to remove an entity which has foreign-key dependencies.  Should cause an exception.
      */
     public void testForeignKeyRemove() {
+        try {
+            String helperName = delegator.getEntityHelper("TestingNode").getHelperName();
+            DatasourceInfo datasourceInfo = EntityConfigUtil.getDatasourceInfo(helperName);
+            if (!datasourceInfo.useFks) {
+                Debug.logInfo("Datasource " + datasourceInfo.name + " use-foreign-keys set to false, skipping testForeignKeyRemove", module);
+                return;
+            }
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+        }
         GenericEntityException caught = null;
         try {
             EntityCondition isLevel1 = EntityCondition.makeCondition("description", EntityOperator.EQUALS, "node-level #1");
@@ -465,38 +489,85 @@ public class EntityTestSuite extends Ent
     }
 
     /*
-     * This will test setting a blob field to null by creating a TestBlob entity whose blob field is not set
+     * Tests field types.
      */
-    public void testSetNullBlob() throws Exception {
+    public void testFieldTypes() throws Exception {
+        String id = "testFieldTypes";
+        byte[] b = new byte[100000];
+        for (int i = 0; i < b.length; i++) {
+            b[i] = (byte) i;
+        }
+        String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+        StringBuilder sb = new StringBuilder(alpha.length() * 1000);
+        for (int i = 0; i < 1000; i++) {
+            sb.append(alpha);
+        }
+        String clobStr = sb.toString();
+        long currentMillis = System.currentTimeMillis();
+        Date currentDate = Date.valueOf(new Date(currentMillis).toString());
+        Time currentTime = Time.valueOf(new Time(currentMillis).toString());
+        // Different databases have different precision for Timestamps, so
+        // we will ignore fractional seconds.
+        Timestamp currentTimestamp = new Timestamp(currentDate.getTime());
+        BigDecimal fixedPoint = new BigDecimal("999999999999.999999");
+        // Different databases have different precision for floating
+        // point types, so we will use a simple decimal number.
+        Double floatingPoint = 1.0123456789;
+        Long numeric = Long.MAX_VALUE;
         try {
-            delegator.create("TestBlob", "testBlobId", "null-blob");
-        } finally {
-            List<GenericValue> allTestBlobs = delegator.findList("TestBlob", null, null, null, null, false);
-            delegator.removeAll(allTestBlobs);
-        }
-    }
-
-    /*
-     * Tests setting a byte value into a blob data type using the GenericValue .setBytes method
-     */
-    public void testBlobCreate() throws Exception {
-        try {
-            byte[] b = new byte[100000];
-            for (int i = 0; i < b.length; i++) {
-                b[i] = (byte) i;
+            GenericValue testValue = delegator.makeValue("TestFieldType", "testFieldTypeId", id);
+            testValue.create();
+            testValue.set("blobField", b);
+            testValue.set("dateField", currentDate);
+            testValue.set("timeField", currentTime);
+            testValue.set("dateTimeField", currentTimestamp);
+            testValue.set("fixedPointField", fixedPoint);
+            testValue.set("floatingPointField", floatingPoint);
+            testValue.set("numericField", numeric);
+            testValue.set("clobField", clobStr);
+            testValue.store();
+            testValue = delegator.findOne("TestFieldType", UtilMisc.toMap("testFieldTypeId", id), false);
+            assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId"));
+            byte[] c = null;
+            try {
+                Blob blob = (Blob) testValue.get("blobField");
+                c = blob.getBytes(1, (int) blob.length());
+            } catch (ClassCastException e) {
+                c = (byte[]) testValue.get("blobField");
             }
-            GenericValue testingBlob = delegator.makeValue("TestBlob", "testBlobId", "byte-blob");
-            testingBlob.setBytes("testBlobField", b);
-            testingBlob.create();
-            testingBlob = delegator.findOne("TestBlob", UtilMisc.toMap("testBlobId", "byte-blob"), false);
-            byte[] c = testingBlob.getBytes("testBlobField");
-            assertEquals("Byte array read from Blob data is the same length", b.length, c.length);
+            assertEquals("Byte array read from entity is the same length", b.length, c.length);
             for (int i = 0; i < b.length; i++) {
-                assertEquals("Blob data[" + i + "]", b[i], c[i]);
+                assertEquals("Byte array data[" + i + "]", b[i], c[i]);
             }
+            assertEquals("dateField", currentDate, testValue.get("dateField"));
+            assertEquals("timeField", currentTime, testValue.get("timeField"));
+            assertEquals("dateTimeField", currentTimestamp, testValue.get("dateTimeField"));
+            assertEquals("fixedPointField", fixedPoint, testValue.get("fixedPointField"));
+            assertEquals("floatingPointField", floatingPoint, testValue.get("floatingPointField"));
+            assertEquals("numericField", numeric, testValue.get("numericField"));
+            assertEquals("clobField", clobStr, testValue.get("clobField"));
+            testValue.set("blobField", null);
+            testValue.set("dateField", null);
+            testValue.set("timeField", null);
+            testValue.set("dateTimeField", null);
+            testValue.set("fixedPointField", null);
+            testValue.set("floatingPointField", null);
+            testValue.set("numericField", null);
+            testValue.set("clobField", null);
+            testValue.store();
+            testValue = delegator.findOne("TestFieldType", UtilMisc.toMap("testFieldTypeId", id), false);
+            assertEquals("testFieldTypeId", id, testValue.get("testFieldTypeId"));
+            assertNull("blobField null", testValue.get("blobField"));
+            assertNull("dateField null", testValue.get("dateField"));
+            assertNull("timeField null", testValue.get("timeField"));
+            assertNull("dateTimeField null", testValue.get("dateTimeField"));
+            assertNull("fixedPointField null", testValue.get("fixedPointField"));
+            assertNull("floatingPointField null", testValue.get("floatingPointField"));
+            assertNull("numericField null", testValue.get("numericField"));
+            assertNull("clobField null", testValue.get("clobField"));
         } finally {
             // Remove all our newly inserted values.
-            List<GenericValue> values = delegator.findList("TestBlob", null, null, null, null, false);
+            List<GenericValue> values = delegator.findList("TestFieldType", null, null, null, null, false);
             delegator.removeAll(values);
         }
     }