Commits

Anonymous committed 506eb32

Updated JDBCPropertySetTest to leverage AbstractPropertySetTest. Updated JDBCPropertySet: supportsType() correctly returns false now for PROPERTIES, TEXT and XML; Added support for setting byte[] removing a ClassCastException. Added date formatting to AbstractPropertySetTest to more accurately compare dates in unit tests. Extracted TestObject from AbtractPropertySetTest and implemented equals and hashcode to work correctly with serialized values.

git-svn-id: http://svn.opensymphony.com/svn/propertyset/trunk@141bf3cbcdd-1c1a-0410-9a68-d6f521e3fa7b

  • Participants
  • Parent commits 3ad1a4a

Comments (0)

Files changed (4)

File src/java/com/opensymphony/module/propertyset/database/JDBCPropertySet.java

             break;
 
         case PropertySet.DATA:
+                if (value instanceof Data) {
+                    Data data = (Data) value;
+                    ps.setBytes(3, data.getBytes());
+                }
 
-            Data data = (Data) value;
-            ps.setBytes(3, data.getBytes());
+                if (value instanceof byte[]) {
+                    ps.setBytes(3, (byte[]) value);
+                }
 
             break;
 
             throw e;
         }
     }
+
+    public boolean supportsType(int type) {
+        switch(type) {
+            case PropertySet.PROPERTIES:
+            case PropertySet.TEXT:
+            case PropertySet.XML:
+                return false;
+        }
+        return true;
+    }
+
 }

File src/test/com/opensymphony/module/propertyset/AbstractPropertySetTest.java

 package com.opensymphony.module.propertyset;
 
 import com.opensymphony.util.XMLUtils;
-
 import junit.framework.TestCase;
-
 import org.w3c.dom.Document;
 
-import java.io.Serializable;
-
+import javax.xml.parsers.ParserConfigurationException;
+import java.text.DateFormat;
 import java.util.Date;
 import java.util.Properties;
 
-import javax.xml.parsers.ParserConfigurationException;
-
 
 /**
  * User: bbulger
 
     public void testSetAsActualTypeGetAsActualTypeForDate() {
         if (ps.supportsType(PropertySet.DATE)) {
+            DateFormat df = DateFormat.getInstance();
             Date now = new Date();
             ps.setAsActualType("testDate", now);
-            assertEquals(now, ps.getAsActualType("testDate"));
+            assertEquals(df.format(now), df.format(ps.getAsActualType("testDate")));
         }
     }
 
 
     public void testSetDateGetDate() {
         if (ps.supportsType(PropertySet.DATE)) {
+            DateFormat df = DateFormat.getInstance();
             Date now = new Date();
             ps.setDate("testDate", now);
-            assertEquals(now, ps.getDate("testDate"));
+            assertEquals(df.format(now), df.format(ps.getDate("testDate")));
             ps.setDate("testDate", new Date());
-            assertEquals(now, ps.getDate("testDate"));
+            assertEquals(df.format(now), df.format(ps.getDate("testDate")));
         }
     }
 
         }
     }
 
-    //~ Inner Classes //////////////////////////////////////////////////////////
-
-    class TestObject implements Serializable {
-        private long id;
-
-        public TestObject(long id) {
-            this.id = id;
-        }
-    }
 }

File src/test/com/opensymphony/module/propertyset/TestObject.java

+package com.opensymphony.module.propertyset;
+
+import java.io.Serializable;
+
+/**
+ * User: bbulger
+ * Date: May 22, 2004
+ */
+public class TestObject implements Serializable {
+
+    private long id;
+
+    public TestObject(long id) {
+        this.id = id;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (this.getClass() != obj.getClass()) {
+            return false;
+        }
+        TestObject testObject = (TestObject) obj;
+        return id == testObject.getId();
+    }
+
+    public int hashCode() {
+        return (int) (id ^ id >>> 32);
+    }
+
+}

File src/test/com/opensymphony/module/propertyset/database/JDBCPropertySetTest.java

  */
 package com.opensymphony.module.propertyset.database;
 
-import com.opensymphony.module.propertyset.BasePropertySetTest;
+import com.opensymphony.module.propertyset.AbstractPropertySetTest;
 import com.opensymphony.module.propertyset.DatabaseHelper;
+import com.opensymphony.module.propertyset.PropertySetManager;
+
+import java.util.HashMap;
 
 
 /**
  *
  * @author Eric Pugh (epugh@upstate.com)
  */
-public class JDBCPropertySetTest extends BasePropertySetTest {
-    //~ Constructors ///////////////////////////////////////////////////////////
-
-    public JDBCPropertySetTest(String s) {
-        super(s);
-    }
-
-    //~ Methods ////////////////////////////////////////////////////////////////
-
-    public String getType() {
-        return "jdbc";
-    }
+public class JDBCPropertySetTest extends AbstractPropertySetTest {
 
     public void setUp() throws Exception {
+        super.setUp();
         DatabaseHelper.createDatabase(getClass().getResource("/mckoi.sql"));
+        HashMap args = new HashMap();
         args.put("globalKey", "test");
-        super.setUp();
+        ps = PropertySetManager.getInstance("jdbc", args);
     }
 }