001: // $Id: TestH2.java 7 2007-08-17 19:32:18Z jcamaia $
002:
003: package net.sf.persist.tests.h2;
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 TestH2 extends TestSimple {
020:
021: public String getProperties() {
022: return "net/sf/persist/tests/h2/h2.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[] stringTypes = new Class[] { String.class, char[].class,
031: Character[].class };
032: Class[] clobTypes = new Class[] { String.class, char[].class,
033: Character[].class, Reader.class, Clob.class };
034:
035: // uuid not being tested
036: BeanMap beanMap = new BeanMap("StringTypes").addField(
037: new FieldMap("charCol").setTypes(stringTypes).setSize(
038: 255)).addField(
039: new FieldMap("varcharCol").setTypes(stringTypes)
040: .setSize(255)).addField(
041: new FieldMap("varcharIgnorecaseCol").setTypes(
042: stringTypes).setSize(255)).addField(
043: new FieldMap("clobCol").setTypes(clobTypes).setSize(
044: 8192));
045:
046: BeanTest.test(persist, beanMap);
047: }
048:
049: @Test
050: public void testNumericTypes() throws SQLException {
051:
052: Class[] integerTypes = new Class[] { Integer.class, int.class };
053: Class[] booleanTypes = new Class[] { Boolean.class,
054: boolean.class };
055: Class[] byteTypes = new Class[] { Byte.class, byte.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("intCol").setTypes(integerTypes))
065: .addField(
066: new FieldMap("booleanCol")
067: .setTypes(booleanTypes)).addField(
068: new FieldMap("tinyintCol").setTypes(byteTypes))
069: .addField(
070: new FieldMap("smallintCol")
071: .setTypes(shortTypes)).addField(
072: new FieldMap("bigintCol").setTypes(longTypes))
073: .addField(
074: new FieldMap("decimalCol").setTypes(longTypes))
075: .addField(
076: new FieldMap("doubleCol").setTypes(doubleTypes)
077: .setBoundaries(0, 9999)).addField(
078: new FieldMap("realCol").setTypes(floatTypes)
079: .setBoundaries(0, 9999));
080:
081: BeanTest.test(persist, beanMap);
082: }
083:
084: @Test
085: public void testDatetimeTypes() throws SQLException {
086:
087: BeanMap beanMap = new BeanMap("DatetimeTypes").addField(
088: new FieldMap("timeCol").setTypes(java.sql.Time.class))
089: .addField(
090: new FieldMap("dateCol")
091: .setTypes(java.sql.Date.class))
092: .addField(
093: new FieldMap("timestampCol").setTypes(
094: java.sql.Timestamp.class,
095: java.util.Date.class));
096:
097: BeanTest.test(persist, beanMap);
098: }
099:
100: @Test
101: public void testBinaryTypes() throws SQLException {
102:
103: Class[] binaryTypes = new Class[] { byte[].class, Byte[].class,
104: InputStream.class, Blob.class };
105: Class[] otherTypes = new Class[] { Object.class };
106:
107: BeanMap beanMap = new BeanMap("BinaryTypes").addField(
108: new FieldMap("binaryCol").setTypes(binaryTypes)
109: .setSize(255)).addField(
110: new FieldMap("blobCol").setTypes(binaryTypes).setSize(
111: 255)).addField(
112: new FieldMap("otherCol").setTypes(otherTypes).setSize(
113: 255));
114:
115: BeanTest.test(persist, beanMap);
116: }
117:
118: }
|