001: // $Id: TestMysql.java 7 2007-08-17 19:32:18Z jcamaia $
002:
003: package net.sf.persist.tests.mysql;
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 TestMysql extends TestSimple {
020:
021: public String getProperties() {
022: return "net/sf/persist/tests/mysql/mysql.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("tinytextCol").setTypes(clobTypes)
043: .setSize(255)).addField(
044: new FieldMap("mediumtextCol").setTypes(clobTypes)
045: .setSize(1024)).addField(
046: new FieldMap("longtextCol").setTypes(clobTypes)
047: .setSize(16384)).addField(
048: new FieldMap("textCol").setTypes(clobTypes).setSize(
049: 16384)).addField(
050: new FieldMap("enumCol").setTypes(characterTypes)
051: .setSize(1)).addField(
052: new FieldMap("setCol").setTypes(characterTypes)
053: .setSize(1));
054:
055: BeanTest.test(persist, beanMap);
056: }
057:
058: @Test
059: public void testNumericTypes() throws SQLException {
060:
061: Class[] integerTypes = new Class[] { Integer.class, int.class };
062: Class[] booleanTypes = new Class[] { Boolean.class,
063: boolean.class };
064: Class[] byteTypes = new Class[] { Byte.class, byte.class };
065: Class[] shortTypes = new Class[] { Short.class, short.class };
066: Class[] longTypes = new Class[] { Long.class, long.class };
067: Class[] doubleTypes = new Class[] { Double.class, double.class,
068: BigDecimal.class };
069: Class[] floatTypes = new Class[] { Float.class, float.class,
070: Double.class, double.class, BigDecimal.class };
071:
072: BeanMap beanMap = new BeanMap("NumericTypes")
073: .addField(new FieldMap("bitCol").setTypes(booleanTypes))
074: .addField(
075: new FieldMap("booleanCol")
076: .setTypes(booleanTypes))
077: .addField(
078: new FieldMap("tinyintCol").setTypes(byteTypes))
079: .addField(
080: new FieldMap("smallintCol")
081: .setTypes(shortTypes))
082: .addField(
083: new FieldMap("mediumintCol")
084: .setTypes(shortTypes))
085: .addField(new FieldMap("intCol").setTypes(integerTypes))
086: .addField(new FieldMap("bigintCol").setTypes(longTypes))
087: .addField(
088: new FieldMap("floatCol").setTypes(floatTypes)
089: .setBoundaries(0, 9999)).addField(
090: new FieldMap("doubleCol").setTypes(doubleTypes)
091: .setBoundaries(0, 9999)).addField(
092: new FieldMap("decimalCol")
093: .setTypes(integerTypes));
094:
095: BeanTest.test(persist, beanMap);
096: }
097:
098: @Test
099: public void testDatetimeTypes() throws SQLException {
100:
101: // not testing timestamp here, it doesn't support null values
102: BeanMap beanMap = new BeanMap("DatetimeTypes").addField(
103: new FieldMap("dateCol").setTypes(java.sql.Date.class))
104: .addField(
105: new FieldMap("datetimeCol").setTypes(
106: java.sql.Timestamp.class,
107: java.util.Date.class)).addField(
108: new FieldMap("timeCol").setTypes(
109: java.sql.Time.class,
110: java.util.Date.class)).addField(
111: new FieldMap("year2Col").setTypes(Short.class,
112: short.class).setBoundaries(01, 99)
113: .setSupportsCompareMapValue(false))
114: .addField(
115: new FieldMap("year4Col").setTypes(Short.class,
116: short.class).setBoundaries(1901, 1999)
117: .setSupportsCompareMapValue(false));
118:
119: BeanTest.test(persist, beanMap);
120: }
121:
122: @Test
123: public void testBinaryTypes() throws SQLException {
124:
125: Class[] binaryTypes = new Class[] { byte[].class, Byte[].class,
126: InputStream.class, Blob.class };
127:
128: BeanMap beanMap = new BeanMap("BinaryTypes").addField(
129: new FieldMap("binaryCol").setTypes(binaryTypes)
130: .setSize(255)).addField(
131: new FieldMap("varbinaryCol").setTypes(binaryTypes)
132: .setSize(255)).addField(
133: new FieldMap("tinyblobCol").setTypes(binaryTypes)
134: .setSize(255)).addField(
135: new FieldMap("blobCol").setTypes(binaryTypes).setSize(
136: 255)).addField(
137: new FieldMap("mediumblobCol").setTypes(binaryTypes)
138: .setSize(255)).addField(
139: new FieldMap("longblobCol").setTypes(binaryTypes)
140: .setSize(16384));
141:
142: BeanTest.test(persist, beanMap);
143: }
144:
145: }
|