PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 0ms app.codeStats 0ms

/src/tests/net/sf/persist/tests/sqlserver/TestSqlserver.java

http://github.com/rufiao/persist
Java | 99 lines | 70 code | 25 blank | 4 comment | 0 complexity | 7e4cf97edd6fde5e3cd565696c02db74 MD5 | raw file
 1
 2// $Id$
 3
 4package net.sf.persist.tests.sqlserver;
 5
 6import java.io.InputStream;
 7import java.io.Reader;
 8import java.math.BigDecimal;
 9import java.sql.SQLException;
10
11import net.sf.persist.tests.common.TestSimple;
12import net.sf.persist.tests.framework.BeanMap;
13import net.sf.persist.tests.framework.BeanTest;
14import net.sf.persist.tests.framework.FieldMap;
15
16import org.junit.Ignore;
17import org.junit.Test;
18
19@Ignore("ignoring until a windows VM is automated")
20public class TestSqlserver extends TestSimple {
21	
22	public String getProperties() {
23		return "net/sf/persist/tests/sqlserver/sqlserver.properties";
24	}
25	
26	// several tests are inherited from TestSimple
27	
28	@Test
29	public void testStringTypes() throws SQLException {
30		
31		Class[] characterTypes = new Class[] {Character.class, char.class, String.class};
32		Class[] stringTypes = new Class[] {String.class, char[].class, Character[].class};
33		Class[] clobTypes = new Class[] {String.class, char[].class, Character[].class, Reader.class};
34		
35		BeanMap beanMap = new BeanMap("StringTypes")
36			.addField( new FieldMap("charCol").setTypes(characterTypes).setSize(1) )
37			.addField( new FieldMap("varcharCol").setTypes(stringTypes).setSize(255) )
38			.addField( new FieldMap("textCol").setTypes(clobTypes).setSize(4096).setSupportsQueryByValue(false) )
39			.addField( new FieldMap("ncharCol").setTypes(characterTypes).setSize(1) )
40			.addField( new FieldMap("nvarcharCol").setTypes(stringTypes).setSize(255) )
41			.addField( new FieldMap("ntextCol").setTypes(clobTypes).setSize(4096).setSupportsQueryByValue(false) );		
42
43		BeanTest.test(persist, beanMap);
44	}
45	
46	@Test
47	public void testNumericTypes() throws SQLException {
48		
49		Class[] integerTypes = new Class[] {Integer.class, int.class};
50		Class[] booleanTypes = new Class[] {Boolean.class, boolean.class};
51		Class[] byteTypes = new Class[] {Byte.class, byte.class};
52		Class[] shortTypes = new Class[] {Short.class, short.class};
53		Class[] longTypes = new Class[] {Long.class, long.class};
54		Class[] doubleTypes = new Class[] {Double.class, double.class, BigDecimal.class};
55		Class[] floatTypes = new Class[] {Float.class, float.class, Double.class, double.class, BigDecimal.class};
56		
57		BeanMap beanMap = new BeanMap("NumericTypes")
58			.addField( new FieldMap("bitCol").setTypes(booleanTypes) )
59			.addField( new FieldMap("tinyintCol").setTypes(byteTypes) )
60			.addField( new FieldMap("smallintCol").setTypes(shortTypes) )
61			.addField( new FieldMap("intCol").setTypes(integerTypes) )
62			.addField( new FieldMap("bigintCol").setTypes(longTypes) )
63			.addField( new FieldMap("smallmoneyCol").setTypes(doubleTypes).setBoundaries(0,9999) )
64			.addField( new FieldMap("moneyCol").setTypes(doubleTypes).setBoundaries(0,9999) )
65			.addField( new FieldMap("decimalCol").setTypes(integerTypes) )
66			.addField( new FieldMap("numericCol").setTypes(integerTypes) )
67			.addField( new FieldMap("floatCol").setTypes(floatTypes).setBoundaries(0,9999) )
68			.addField( new FieldMap("realCol").setTypes(floatTypes).setBoundaries(0,9999) );
69			
70		BeanTest.test(persist, beanMap);
71	}
72	
73	@Test
74	public void testDatetimeTypes() throws SQLException {
75		
76		// smalldatetime is problematic to query by value because of the 1-minute rounding;
77		// the bean has the current timestamp therefore it won't work properly
78		BeanMap beanMap = new BeanMap("DatetimeTypes")
79			.addField( new FieldMap("datetimeCol").setTypes(java.sql.Timestamp.class, java.util.Date.class) )
80			.addField( new FieldMap("smalldatetimeCol").setTypes(java.sql.Timestamp.class, java.util.Date.class).setSupportsQueryByValue(false) );
81		
82		BeanTest.test(persist, beanMap);
83	}
84	
85	@Test
86	public void testBinaryTypes() throws SQLException {
87		
88		Class[] binaryTypes = new Class[] { byte[].class, InputStream.class };
89		
90		BeanMap beanMap = new BeanMap("BinaryTypes")
91			.addField( new FieldMap("binaryCol").setTypes(binaryTypes).setSize(255) )
92			.addField( new FieldMap("varbinaryCol").setTypes(binaryTypes).setSize(255) )
93			.addField( new FieldMap("imageCol").setTypes(binaryTypes).setSize(16384).setSupportsQueryByValue(false) );
94		
95		BeanTest.test(persist, beanMap);
96	}
97	
98
99}