db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r406148 - /db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FieldConversionTest.java
Date Sat, 13 May 2006 20:31:21 GMT
Author: arminw
Date: Sat May 13 13:31:19 2006
New Revision: 406148

URL: http://svn.apache.org/viewcvs?rev=406148&view=rev
Log:
add new tests

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FieldConversionTest.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FieldConversionTest.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FieldConversionTest.java?rev=406148&r1=406147&r2=406148&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FieldConversionTest.java
(original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/test/org/apache/ojb/broker/FieldConversionTest.java
Sat May 13 13:31:19 2006
@@ -1,12 +1,21 @@
 package org.apache.ojb.broker;
 
-import junit.framework.TestCase;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Vector;
+import java.sql.Time;
+
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
 import org.apache.ojb.broker.accesslayer.conversions.ConversionException;
 import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
-
-import java.io.Serializable;
+import org.apache.ojb.broker.accesslayer.conversions.StringList2VarcharFieldConversion;
+import org.apache.ojb.broker.accesslayer.conversions.TimeList2VarcharFieldConversion;
+import org.apache.ojb.broker.accesslayer.conversions.StringVector2VarcharFieldConversion;
+import org.apache.ojb.broker.accesslayer.conversions.IntList2VarcharFieldConversion;
+import org.apache.ojb.junit.PBTestCase;
 
 /**
  * Test case to check the field conversion.
@@ -14,41 +23,304 @@
  * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
  * @version $Id$
  */
-public class FieldConversionTest extends TestCase
+public class FieldConversionTest extends PBTestCase
 {
-    private PersistenceBroker broker;
-
     public static void main(String[] args)
     {
         String[] arr = {FieldConversionTest.class.getName()};
         junit.textui.TestRunner.main(arr);
     }
 
-    /**
-     * Insert the method's description here.
-     * Creation date: (06.12.2000 21:58:53)
-     */
-    public void setUp() throws PBFactoryException
-    {
-        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
-    }
-
-    /**
-     * Insert the method's description here.
-     * Creation date: (06.12.2000 21:59:14)
-     */
-    public void tearDown()
-    {
-        try
-        {
-            broker.clearCache();
-            broker.close();
-        }
-        catch (PersistenceBrokerException e)
-        {
-        }
+    public void setUp() throws Exception
+    {
+        super.setUp();
+    }
+
+    public void tearDown() throws Exception
+    {
+        super.tearDown();
+    }
+
+    public void testStringList2VarcharFieldConversion()
+    {
+        FieldConversion conv = new StringList2VarcharFieldConversion();
+        List list = new ArrayList();
+        list.add("1");
+        List result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add("");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add("");
+        list.add("");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add(null);
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        result = doubleConvertList2Varchar(conv, null);
+        assertEquals(null, result);
+
+        result = doubleConvertList2Varchar(conv, Collections.EMPTY_LIST);
+        assertEquals(0, result.size());
+
+        list = new ArrayList();
+        list.add("");
+        list.add("1");
+        list.add("2");
+        // '#' is not allowed, but within a String the
+        // conversion pass nevertheless
+        list.add("2#a");
+        list.add("3");
+        list.add("");
+        list.add(null);
+        list.add("");
+        list.add(null);
+        list.add("8");
+        list.add("+9+");
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        // '#' is not allowed, but within a String the
+        // conversion pass nevertheless
+        list = new ArrayList();
+        list.add("e#e");
+        list.add("test");
+        list.add("a#a#a#a#a");
+        list.add("2#####a#b");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add("NULL");
+        list.add("EMPTY");
+        list.add("EMTPY");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add("NULL");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add("EMPTY");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new ArrayList();
+        list.add("EMTPY");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
     }
 
+    public void testStringVector2VarcharFieldConversion()
+    {
+        FieldConversion conv = new StringVector2VarcharFieldConversion();
+        List list = new Vector();
+        list.add("1");
+        List result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add("");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add("");
+        list.add("");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add(null);
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        result = doubleConvertList2Varchar(conv, null);
+        assertEquals(null, result);
+
+        result = doubleConvertList2Varchar(conv, Collections.EMPTY_LIST);
+        assertEquals(0, result.size());
+
+        list = new Vector();
+        list.add("");
+        list.add("1");
+        list.add("2");
+        // '#' is not allowed, but within a String the
+        // conversion pass nevertheless
+        list.add("2#a");
+        list.add("3");
+        list.add("");
+        list.add(null);
+        list.add("");
+        list.add(null);
+        list.add("8");
+        list.add("+9+");
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        // '#' is not allowed, but within a String the
+        // conversion pass nevertheless
+        list = new Vector();
+        list.add("e#e");
+        list.add("test");
+        list.add("a#a#a#a#a");
+        list.add("2#####a#b");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add("NULL");
+        list.add("EMPTY");
+        list.add("EMTPY");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add("NULL");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add("EMPTY");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+
+        list = new Vector();
+        list.add("EMTPY");
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list, result);
+    }
+
+    public void testTimeList2VarcharFieldConversion()
+    {
+        FieldConversion conv = new TimeList2VarcharFieldConversion();
+
+        List list = new ArrayList();
+        list.add(new Time(1));
+        List result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+
+        list = new ArrayList();
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+
+        list = new ArrayList();
+        list.add(null);
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+
+        result = doubleConvertList2Varchar(conv, null);
+        assertEquals(null, result);
+
+        result = doubleConvertList2Varchar(conv, Collections.EMPTY_LIST);
+        assertEquals(0, result.size());
+
+        list = new ArrayList();
+        list.add(null);
+        list.add(new Time(1));
+        list.add(new Time(2));
+        list.add(new Time(System.currentTimeMillis()));
+        // '#' is not allowed, but within a String the
+        // conversion pass nevertheless
+        list.add(new Time(3));
+        list.add(new Time(4));
+        list.add(null);
+        list.add(null);
+        list.add(new Time(5));
+        list.add(new Time(6));
+        list.add(new Time(Long.MAX_VALUE));
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+    }
+
+    public void testIntList2VarcharFieldConversion()
+    {
+        FieldConversion conv = new IntList2VarcharFieldConversion();
+
+        List list = new ArrayList();
+        list.add(new Integer(1));
+        List result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+
+        list = new ArrayList();
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+
+        list = new ArrayList();
+        list.add(null);
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+
+        result = doubleConvertList2Varchar(conv, null);
+        assertEquals(null, result);
+
+        result = doubleConvertList2Varchar(conv, Collections.EMPTY_LIST);
+        assertEquals(0, result.size());
+
+        list = new ArrayList();
+        list.add(null);
+        list.add(new Integer(1));
+        list.add(new Integer(2));
+        // '#' is not allowed, but within a String the
+        // conversion pass nevertheless
+        list.add(new Integer(3));
+        list.add(new Integer(4));
+        list.add(null);
+        list.add(null);
+        list.add(new Integer(5));
+        list.add(new Integer(6));
+        list.add(null);
+        result = doubleConvertList2Varchar(conv, list);
+        assertEquals(list.toString(), result.toString());
+    }
+
+    private List doubleConvertList2Varchar(FieldConversion conv, List list)
+    {
+        String str = (String) conv.javaToSql(list);
+        //System.out.println("start: " + list);
+        //System.out.println("-->conv_sql: " + str);
+        List list2 = (List) conv.sqlToJava(str);
+        //System.out.println(" -->conv_java: " + list2);
+        str = (String) conv.javaToSql(list2);
+        //System.out.println(" -->conv_sql: " + str);
+        list2 = (List) conv.sqlToJava(str);
+        //System.out.println(" -->conv_java: " + list2);
+        //System.out.println("");
+
+        return list2;
+    }
+
+
+
     public void testConversion()
     {
         int id = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
@@ -58,9 +330,9 @@
         broker.store(vo);
         broker.commitTransaction();
 
-        Identity identity = new Identity(vo, broker);
+        Identity identity = broker.serviceIdentity().buildIdentity(vo);
         broker.clearCache();
-        ConversionVO find_vo = (ConversionVO) broker.getObjectByIdentity(identity);
+        broker.getObjectByIdentity(identity);
     }
 
     public static class FieldConversionConversionIdToInteger implements FieldConversion



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message