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