PageRenderTime 25ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 2ms app.codeStats 0ms

/src/tests/net/sf/persist/tests/h2/TestH2.java

http://github.com/rufiao/persist
Java | 94 lines | 66 code | 25 blank | 3 comment | 0 complexity | a36a379fe71e86f78b557175e209f30b MD5 | raw file
 1
 2// $Id$
 3
 4package net.sf.persist.tests.h2;
 5
 6import java.io.InputStream;
 7import java.io.Reader;
 8import java.math.BigDecimal;
 9import java.sql.Blob;
10import java.sql.Clob;
11import java.sql.SQLException;
12
13import net.sf.persist.tests.common.TestSimple;
14import net.sf.persist.tests.framework.BeanMap;
15import net.sf.persist.tests.framework.BeanTest;
16import net.sf.persist.tests.framework.FieldMap;
17
18import org.junit.Test;
19
20
21public class TestH2 extends TestSimple {
22	
23	public String getProperties() {
24		return "net/sf/persist/tests/h2/h2.properties";
25	}
26	
27	// several tests are inherited from net.sf.persist.tests.common.TestSimple
28	
29	@Test
30	public void testStringTypes() throws SQLException {
31		
32		Class[] stringTypes = new Class[] { String.class, char[].class, Character[].class };
33		Class[] clobTypes = new Class[] { String.class, char[].class, Character[].class, Reader.class, Clob.class };
34		
35		// uuid not being tested
36		BeanMap beanMap = new BeanMap("StringTypes")
37			.addField( new FieldMap("charCol").setTypes(stringTypes).setSize(255) )
38			.addField( new FieldMap("varcharCol").setTypes(stringTypes).setSize(255) )
39			.addField( new FieldMap("varcharIgnorecaseCol").setTypes(stringTypes).setSize(255) )
40			.addField( new FieldMap("clobCol").setTypes(clobTypes).setSize(8192) );
41		
42		BeanTest.test(persist, beanMap);
43	}
44	
45	@Test
46	public void testNumericTypes() throws SQLException {
47		
48		Class[] integerTypes = new Class[] {Integer.class, int.class};
49		Class[] booleanTypes = new Class[] {Boolean.class, boolean.class};
50		Class[] byteTypes = new Class[] {Byte.class, byte.class};
51		Class[] shortTypes = new Class[] {Short.class, short.class};
52		Class[] longTypes = new Class[] {Long.class, long.class};
53		Class[] doubleTypes = new Class[] {Double.class, double.class, BigDecimal.class};
54		Class[] floatTypes = new Class[] {Float.class, float.class, Double.class, double.class, BigDecimal.class};
55		
56		BeanMap beanMap = new BeanMap("NumericTypes")
57			.addField( new FieldMap("intCol").setTypes(integerTypes) )
58			.addField( new FieldMap("booleanCol").setTypes(booleanTypes) )
59			.addField( new FieldMap("tinyintCol").setTypes(byteTypes) )
60			.addField( new FieldMap("smallintCol").setTypes(shortTypes) )
61			.addField( new FieldMap("bigintCol").setTypes(longTypes) )
62			.addField( new FieldMap("decimalCol").setTypes(longTypes) )
63			.addField( new FieldMap("doubleCol").setTypes(doubleTypes).setBoundaries(0,9999) )
64			.addField( new FieldMap("realCol").setTypes(floatTypes).setBoundaries(0,9999) );
65		
66		BeanTest.test(persist, beanMap);
67	}
68	
69	@Test
70	public void testDatetimeTypes() throws SQLException {
71		
72		BeanMap beanMap = new BeanMap("DatetimeTypes")
73			.addField( new FieldMap("timeCol").setTypes(java.sql.Time.class) )
74			.addField( new FieldMap("dateCol").setTypes(java.sql.Date.class) )
75			.addField( new FieldMap("timestampCol").setTypes(java.sql.Timestamp.class, java.util.Date.class) );
76		
77		BeanTest.test(persist, beanMap);
78	}
79	
80	@Test
81	public void testBinaryTypes() throws SQLException {
82		
83		Class[] binaryTypes = new Class[] { byte[].class, Byte[].class, InputStream.class, Blob.class };
84		Class[] otherTypes = new Class[] { Object.class };
85		
86		BeanMap beanMap = new BeanMap("BinaryTypes")
87			.addField( new FieldMap("binaryCol").setTypes(binaryTypes).setSize(255) )
88			.addField( new FieldMap("blobCol").setTypes(binaryTypes).setSize(255) )
89			.addField( new FieldMap("otherCol").setTypes(otherTypes).setSize(255) );
90		
91		BeanTest.test(persist, beanMap);
92	}
93
94}