001: // $Id: TestDB2.java 7 2007-08-17 19:32:18Z jcamaia $
002:
003: package net.sf.persist.tests.db2;
004:
005: import java.io.InputStream;
006: import java.io.Reader;
007: import java.math.BigDecimal;
008: import java.sql.Blob;
009: import java.sql.Clob;
010: import java.sql.SQLException;
011:
012: import net.sf.persist.tests.common.TestSimple;
013: import net.sf.persist.tests.framework.BeanMap;
014: import net.sf.persist.tests.framework.BeanTest;
015: import net.sf.persist.tests.framework.FieldMap;
016:
017: import org.junit.Test;
018:
019: public class TestDB2 extends TestSimple {
020:
021: public String getProperties() {
022: return "net/sf/persist/tests/db2/db2.properties";
023: }
024:
025: // several tests are inherited from net.sf.persist.tests.common.TestSimple
026:
027: @Test
028: public void testStringTypes() throws SQLException {
029:
030: Class[] characterTypes = new Class[] { Character.class,
031: char.class, String.class };
032: Class[] stringTypes = new Class[] { String.class, char[].class,
033: Character[].class };
034: Class[] longStringTypes = new Class[] { String.class,
035: char[].class, Character[].class, Reader.class };
036: Class[] clobTypes = new Class[] { String.class, char[].class,
037: Character[].class, Reader.class, Clob.class };
038:
039: BeanMap beanMap = new BeanMap("StringTypes").addField(
040: new FieldMap("charCol").setTypes(characterTypes)
041: .setSize(1)).addField(
042: new FieldMap("varcharCol").setTypes(stringTypes)
043: .setSize(255)).addField(
044: new FieldMap("longVarcharCol")
045: .setTypes(longStringTypes).setSize(16384)
046: .setSupportsQueryByValue(false)).addField(
047: new FieldMap("clobCol").setTypes(clobTypes).setSize(
048: 16384).setSupportsQueryByValue(false));
049:
050: BeanTest.test(persist, beanMap);
051: }
052:
053: @Test
054: public void testNumericTypes() throws SQLException {
055:
056: Class[] integerTypes = new Class[] { Integer.class, int.class };
057: Class[] shortTypes = new Class[] { Short.class, short.class };
058: Class[] longTypes = new Class[] { Long.class, long.class };
059: Class[] doubleTypes = new Class[] { Double.class, double.class,
060: BigDecimal.class };
061: Class[] floatTypes = new Class[] { Float.class, float.class,
062: Double.class, double.class, BigDecimal.class };
063:
064: BeanMap beanMap = new BeanMap("NumericTypes").addField(
065: new FieldMap("smallintCol").setTypes(shortTypes))
066: .addField(
067: new FieldMap("integerCol")
068: .setTypes(integerTypes)).addField(
069: new FieldMap("bigintCol").setTypes(longTypes))
070: .addField(
071: new FieldMap("realCol").setTypes(floatTypes)
072: .setBoundaries(0, 9999)).addField(
073: new FieldMap("doublePrecisionCol").setTypes(
074: doubleTypes).setBoundaries(0, 9999)
075: .setSupportsQueryByValue(false))
076: .addField(
077: new FieldMap("floatCol").setTypes(floatTypes)
078: .setBoundaries(0, 9999)).addField(
079: new FieldMap("decimalCol").setTypes(
080: integerTypes).setBoundaries(0, 9999))
081: .addField(
082: new FieldMap("numericCol").setTypes(
083: integerTypes).setBoundaries(0, 9999));
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("dateCol").setTypes(java.sql.Date.class,
093: java.util.Date.class)).addField(
094: new FieldMap("timeCol").setTypes(java.sql.Time.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[] byteTypes = new Class[] { byte[].class, };
108: Class[] binaryTypes = new Class[] { byte[].class };
109: Class[] blobTypes = new Class[] { byte[].class,
110: InputStream.class, Blob.class };
111:
112: // TODO: check if short[] works for graphic types (which are double byte)
113:
114: BeanMap beanMap = new BeanMap("BinaryTypes").addField(
115: new FieldMap("charBitCol").setTypes(byteTypes).setSize(
116: 1)).addField(
117: new FieldMap("varcharBitCol").setTypes(binaryTypes)
118: .setSize(255)).addField(
119: new FieldMap("longVarcharBitCol").setTypes(binaryTypes)
120: .setSize(255).setSupportsQueryByValue(false))
121: // .addField( new FieldMap("graphicCol").setTypes(binaryTypes).setSize(1) )
122: // .addField( new FieldMap("vargraphicCol").setTypes(binaryTypes).setSize(255) )
123: // .addField( new FieldMap("longVargraphicCol").setTypes(binaryTypes).setSize(16384).setSupportsQueryByValue(false))
124: .addField(
125: new FieldMap("blobCol").setTypes(blobTypes)
126: .setSize(16384)
127: .setSupportsQueryByValue(false));
128:
129: BeanTest.test(persist, beanMap);
130: }
131:
132: }
|