001: // $Id: TestPostgreSQL.java 7 2007-08-17 19:32:18Z jcamaia $
002:
003: package net.sf.persist.tests.postgresql;
004:
005: import java.io.InputStream;
006: import java.math.BigDecimal;
007: import java.sql.Blob;
008: import java.sql.Clob;
009: import java.sql.SQLException;
010:
011: import net.sf.persist.tests.common.TestSimple;
012: import net.sf.persist.tests.framework.BeanMap;
013: import net.sf.persist.tests.framework.BeanTest;
014: import net.sf.persist.tests.framework.FieldMap;
015:
016: import org.junit.Test;
017:
018: public class TestPostgreSQL extends TestSimple {
019:
020: public String getProperties() {
021: return "net/sf/persist/tests/postgresql/postgresql.properties";
022: }
023:
024: // several tests inherited from net.sf.persist.tests.common.TestSimple
025:
026: @Test
027: public void testStringTypes() throws SQLException {
028:
029: Class[] characterTypes = new Class[] { Character.class,
030: char.class, String.class };
031: Class[] stringTypes = new Class[] { String.class, char[].class,
032: Character[].class };
033: Class[] clobTypes = new Class[] { Clob.class };
034:
035: // postgres has a serious bug on returning java.sql.Types.BIGINT type on the ResultSetMetadata for Clob columns
036: // therefore we won't test comparing the clobCol value returned from a map with it
037: BeanMap beanMap = new BeanMap("StringTypes").addField(
038: new FieldMap("char1Col").setTypes(characterTypes)
039: .setSize(1)).addField(
040: new FieldMap("charCol").setTypes(stringTypes).setSize(
041: 255)).addField(
042: new FieldMap("varcharCol").setTypes(stringTypes)
043: .setSize(255)).addField(
044: new FieldMap("textCol").setTypes(stringTypes).setSize(
045: 255)).addField(
046: new FieldMap("clobCol").setTypes(clobTypes).setSize(
047: 8192).setSupportsQueryByValue(false)
048: .setSupportsCompareMapValue(false));
049:
050: BeanTest.test(persist, beanMap);
051: }
052:
053: @Test
054: public void testNumericTypes() throws SQLException {
055:
056: Class[] shortTypes = new Class[] { Short.class, short.class };
057: Class[] integerTypes = new Class[] { Integer.class, int.class };
058: Class[] booleanTypes = new Class[] { Boolean.class,
059: boolean.class };
060: Class[] longTypes = new Class[] { Long.class, long.class };
061: Class[] doubleTypes = new Class[] { Double.class, double.class,
062: BigDecimal.class };
063: Class[] floatTypes = new Class[] { Float.class, float.class,
064: Double.class, double.class, BigDecimal.class };
065:
066: BeanMap beanMap = new BeanMap("NumericTypes").addField(
067: new FieldMap("smallintCol").setTypes(shortTypes))
068: .addField(
069: new FieldMap("integerCol")
070: .setTypes(integerTypes)).addField(
071: new FieldMap("bigintCol").setTypes(longTypes))
072: .addField(
073: new FieldMap("decimalCol").setTypes(longTypes))
074: .addField(
075: new FieldMap("numericCol").setTypes(longTypes))
076: .addField(
077: new FieldMap("realCol").setTypes(floatTypes)
078: .setBoundaries(0, 9999)).addField(
079: new FieldMap("doublePrecisionCol").setTypes(
080: doubleTypes).setBoundaries(0, 9999))
081: .addField(
082: new FieldMap("booleanCol")
083: .setTypes(booleanTypes));
084:
085: BeanTest.test(persist, beanMap);
086: }
087:
088: @Test
089: public void testDatetimeTypes() throws SQLException {
090:
091: BeanMap beanMap = new BeanMap("DatetimeTypes").addField(
092: new FieldMap("timeCol").setTypes(java.sql.Time.class,
093: java.util.Date.class)).addField(
094: new FieldMap("dateCol").setTypes(java.sql.Date.class,
095: java.util.Date.class))
096: .addField(
097: new FieldMap("timestampCol").setTypes(
098: java.sql.Timestamp.class,
099: java.util.Date.class));
100:
101: BeanTest.test(persist, beanMap);
102: }
103:
104: @Test
105: public void testBinaryTypes() throws SQLException {
106:
107: Class[] binaryTypes = new Class[] { byte[].class, Byte[].class,
108: InputStream.class };
109: Class[] blobTypes = new Class[] { Blob.class };
110:
111: // postgres has a serious bug on returning java.sql.Types.BIGINT type on the ResultSetMetadata for Blob columns
112: // therefore we won't test comparing the blobCol value returned from a map with it
113: BeanMap beanMap = new BeanMap("BinaryTypes").addField(
114: new FieldMap("byteaCol").setTypes(binaryTypes).setSize(
115: 16384)).addField(
116: new FieldMap("blobCol").setTypes(blobTypes).setSize(
117: 8192).setSupportsQueryByValue(false)
118: .setSupportsCompareMapValue(false));
119:
120: BeanTest.test(persist, beanMap);
121: }
122:
123: }
|