001: // $Id: TestSqlserver.java 7 2007-08-17 19:32:18Z jcamaia $
002:
003: package net.sf.persist.tests.sqlserver;
004:
005: import java.io.InputStream;
006: import java.io.Reader;
007: import java.math.BigDecimal;
008: import java.sql.SQLException;
009:
010: import net.sf.persist.tests.common.TestSimple;
011: import net.sf.persist.tests.framework.BeanMap;
012: import net.sf.persist.tests.framework.BeanTest;
013: import net.sf.persist.tests.framework.FieldMap;
014:
015: import org.junit.Test;
016:
017: public class TestSqlserver extends TestSimple {
018:
019: public String getProperties() {
020: return "net/sf/persist/tests/sqlserver/sqlserver.properties";
021: }
022:
023: // several tests are inherited from TestSimple
024:
025: @Test
026: public void testStringTypes() throws SQLException {
027:
028: Class[] characterTypes = new Class[] { Character.class,
029: char.class, String.class };
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 };
034:
035: BeanMap beanMap = new BeanMap("StringTypes").addField(
036: new FieldMap("charCol").setTypes(characterTypes)
037: .setSize(1)).addField(
038: new FieldMap("varcharCol").setTypes(stringTypes)
039: .setSize(255)).addField(
040: new FieldMap("textCol").setTypes(clobTypes).setSize(
041: 4096).setSupportsQueryByValue(false)).addField(
042: new FieldMap("ncharCol").setTypes(characterTypes)
043: .setSize(1)).addField(
044: new FieldMap("nvarcharCol").setTypes(stringTypes)
045: .setSize(255)).addField(
046: new FieldMap("ntextCol").setTypes(clobTypes).setSize(
047: 4096).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[] booleanTypes = new Class[] { Boolean.class,
057: boolean.class };
058: Class[] byteTypes = new Class[] { Byte.class, byte.class };
059: Class[] shortTypes = new Class[] { Short.class, short.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")
067: .addField(new FieldMap("bitCol").setTypes(booleanTypes))
068: .addField(
069: new FieldMap("tinyintCol").setTypes(byteTypes))
070: .addField(
071: new FieldMap("smallintCol")
072: .setTypes(shortTypes))
073: .addField(new FieldMap("intCol").setTypes(integerTypes))
074: .addField(new FieldMap("bigintCol").setTypes(longTypes))
075: .addField(
076: new FieldMap("smallmoneyCol").setTypes(
077: doubleTypes).setBoundaries(0, 9999))
078: .addField(
079: new FieldMap("moneyCol").setTypes(doubleTypes)
080: .setBoundaries(0, 9999)).addField(
081: new FieldMap("decimalCol")
082: .setTypes(integerTypes)).addField(
083: new FieldMap("numericCol")
084: .setTypes(integerTypes)).addField(
085: new FieldMap("floatCol").setTypes(floatTypes)
086: .setBoundaries(0, 9999)).addField(
087: new FieldMap("realCol").setTypes(floatTypes)
088: .setBoundaries(0, 9999));
089:
090: BeanTest.test(persist, beanMap);
091: }
092:
093: @Test
094: public void testDatetimeTypes() throws SQLException {
095:
096: // smalldatetime is problematic to query by value because of the 1-minute rounding;
097: // the bean has the current timestamp therefore it won't work properly
098: BeanMap beanMap = new BeanMap("DatetimeTypes")
099: .addField(
100: new FieldMap("datetimeCol").setTypes(
101: java.sql.Timestamp.class,
102: java.util.Date.class)).addField(
103: new FieldMap("smalldatetimeCol").setTypes(
104: java.sql.Timestamp.class,
105: java.util.Date.class)
106: .setSupportsQueryByValue(false));
107:
108: BeanTest.test(persist, beanMap);
109: }
110:
111: @Test
112: public void testBinaryTypes() throws SQLException {
113:
114: Class[] binaryTypes = new Class[] { byte[].class,
115: InputStream.class };
116:
117: BeanMap beanMap = new BeanMap("BinaryTypes").addField(
118: new FieldMap("binaryCol").setTypes(binaryTypes)
119: .setSize(255)).addField(
120: new FieldMap("varbinaryCol").setTypes(binaryTypes)
121: .setSize(255)).addField(
122: new FieldMap("imageCol").setTypes(binaryTypes).setSize(
123: 16384).setSupportsQueryByValue(false));
124:
125: BeanTest.test(persist, beanMap);
126: }
127:
128: }
|