001: // $Id: TestDerby.java 7 2007-08-17 19:32:18Z jcamaia $
002:
003: package net.sf.persist.tests.derby;
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 TestDerby extends TestSimple {
020:
021: public String getProperties() {
022: return "net/sf/persist/tests/derby/derby.properties";
023: }
024:
025: // several tests are inherited from 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[] clobTypes = new Class[] { String.class, char[].class,
035: Character[].class, Reader.class, Clob.class };
036:
037: BeanMap beanMap = new BeanMap("StringTypes").addField(
038: new FieldMap("charCol").setTypes(characterTypes)
039: .setSize(1)).addField(
040: new FieldMap("varcharCol").setTypes(stringTypes)
041: .setSize(255)).addField(
042: new FieldMap("longVarcharCol").setTypes(stringTypes)
043: .setSize(16384).setSupportsQueryByValue(false))
044: .addField(
045: new FieldMap("clobCol").setTypes(clobTypes)
046: .setSize(16384)
047: .setSupportsQueryByValue(false));
048:
049: BeanTest.test(persist, beanMap);
050: }
051:
052: @Test
053: public void testNumericTypes() throws SQLException {
054:
055: Class[] integerTypes = new Class[] { Integer.class, int.class };
056: Class[] shortTypes = new Class[] { Short.class, short.class };
057: Class[] longTypes = new Class[] { Long.class, long.class };
058: Class[] doubleTypes = new Class[] { Double.class, double.class,
059: BigDecimal.class };
060: Class[] floatTypes = new Class[] { Float.class, float.class,
061: Double.class, double.class, BigDecimal.class };
062:
063: BeanMap beanMap = new BeanMap("NumericTypes").addField(
064: new FieldMap("smallintCol").setTypes(shortTypes))
065: .addField(
066: new FieldMap("integerCol")
067: .setTypes(integerTypes)).addField(
068: new FieldMap("bigintCol").setTypes(longTypes))
069: .addField(
070: new FieldMap("realCol").setTypes(floatTypes)
071: .setBoundaries(0, 9999)).addField(
072: new FieldMap("doublePrecisionCol").setTypes(
073: doubleTypes).setBoundaries(0, 9999)
074: .setSupportsQueryByValue(false))
075: .addField(
076: new FieldMap("floatCol").setTypes(floatTypes)
077: .setBoundaries(0, 9999)).addField(
078: new FieldMap("decimalCol").setTypes(
079: integerTypes).setBoundaries(0, 9999))
080: .addField(
081: new FieldMap("numericCol").setTypes(
082: integerTypes).setBoundaries(0, 9999));
083:
084: BeanTest.test(persist, beanMap);
085: }
086:
087: @Test
088: public void testDatetimeTypes() throws SQLException {
089:
090: BeanMap beanMap = new BeanMap("DatetimeTypes").addField(
091: new FieldMap("dateCol").setTypes(java.sql.Date.class,
092: java.util.Date.class)).addField(
093: new FieldMap("timeCol").setTypes(java.sql.Time.class,
094: java.util.Date.class))
095: .addField(
096: new FieldMap("timestampCol").setTypes(
097: java.sql.Timestamp.class,
098: java.util.Date.class));
099:
100: BeanTest.test(persist, beanMap);
101: }
102:
103: @Test
104: public void testBinaryTypes() throws SQLException {
105:
106: Class[] byteTypes = new Class[] { byte[].class, Byte[].class };
107: Class[] binaryTypes = new Class[] { byte[].class, Byte[].class,
108: InputStream.class };
109: Class[] blobTypes = new Class[] { byte[].class, Byte[].class,
110: InputStream.class, Blob.class };
111:
112: BeanMap beanMap = new BeanMap("BinaryTypes").addField(
113: new FieldMap("charBitCol").setTypes(byteTypes).setSize(
114: 1)).addField(
115: new FieldMap("varcharBitCol").setTypes(binaryTypes)
116: .setSize(255)).addField(
117: new FieldMap("longVarcharBitCol").setTypes(binaryTypes)
118: .setSize(16384).setSupportsQueryByValue(false))
119: .addField(
120: new FieldMap("blobCol").setTypes(blobTypes)
121: .setSize(16384)
122: .setSupportsQueryByValue(false));
123:
124: BeanTest.test(persist, beanMap);
125: }
126:
127: }
|