]> source.dussan.org Git - iciql.git/commitdiff
Restructured test suite to run against multiple databases.
authorJames Moger <james.moger@gmail.com>
Thu, 11 Aug 2011 18:10:28 +0000 (14:10 -0400)
committerJames Moger <james.moger@gmail.com>
Thu, 11 Aug 2011 18:10:28 +0000 (14:10 -0400)
20 files changed:
tests/com/iciql/test/AliasMapTest.java
tests/com/iciql/test/AnnotationsTest.java
tests/com/iciql/test/BooleanModelTest.java
tests/com/iciql/test/ClobTest.java
tests/com/iciql/test/ConcurrencyTest.java
tests/com/iciql/test/DefaultValuesTest.java
tests/com/iciql/test/EnumsTest.java
tests/com/iciql/test/IciqlSuite.java
tests/com/iciql/test/ModelsTest.java
tests/com/iciql/test/PrimitivesTest.java
tests/com/iciql/test/RuntimeQueryTest.java
tests/com/iciql/test/SamplesTest.java
tests/com/iciql/test/UUIDTest.java
tests/com/iciql/test/UpdateTest.java
tests/com/iciql/test/models/Customer.java
tests/com/iciql/test/models/Order.java
tests/com/iciql/test/models/Product.java
tests/com/iciql/test/models/ProductAnnotationOnly.java
tests/com/iciql/test/models/ProductMixedAnnotation.java
tests/com/iciql/test/models/SupportedTypes.java

index 4d19bd0023a1442eaa168e95fd84c0342a560ffd..f0d5c153e747c6143eb09d391e481f1179177003 100644 (file)
@@ -37,7 +37,7 @@ public class AliasMapTest {
 
        @Test
        public void testAliasMapping() throws Exception {
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               Db db = IciqlSuite.openDb();
                db.insertAll(Product.getList());
 
                Product p = new Product();
index 92e0d5e30a85c2b38bfa14313aa021bd71395218..897acd6ddb718645c6b0f26eb767e7af94cb6bf8 100644 (file)
@@ -27,7 +27,6 @@ import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.List;
 
-import org.h2.constant.ErrorCode;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -39,6 +38,8 @@ import com.iciql.test.models.ProductAnnotationOnly;
 import com.iciql.test.models.ProductInheritedAnnotation;
 import com.iciql.test.models.ProductMixedAnnotation;
 import com.iciql.test.models.ProductNoCreateTable;
+import com.iciql.util.JdbcUtils;
+import com.iciql.util.Utils;
 
 /**
  * Test annotation processing.
@@ -54,7 +55,7 @@ public class AnnotationsTest {
 
        @Before
        public void setUp() {
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               db = IciqlSuite.openDb();
                db.insertAll(Product.getList());
                db.insertAll(ProductAnnotationOnly.getList());
                db.insertAll(ProductMixedAnnotation.getList());
@@ -69,9 +70,14 @@ public class AnnotationsTest {
        public void testIndexCreation() throws SQLException {
                // test indexes are created, and columns are in the right order
                DatabaseMetaData meta = db.getConnection().getMetaData();
+               boolean isH2 = meta.getDatabaseProductName().equals("H2");
                ResultSet rs = meta.getIndexInfo(null, "PUBLIC", "ANNOTATEDPRODUCT", false, true);
+               // first index is primary key index
+               // H2 gives this a testable name.
                assertTrue(rs.next());
-               assertStartsWith(rs.getString("INDEX_NAME"), "PRIMARY_KEY");
+               if (isH2) {
+                       assertStartsWith(rs.getString("INDEX_NAME"), "PRIMARY_KEY");
+               }
                assertTrue(rs.next());
                assertStartsWith(rs.getString("INDEX_NAME"), "ANNOTATEDPRODUCT_0");
                assertStartsWith(rs.getString("COLUMN_NAME"), "NAME");
@@ -94,18 +100,21 @@ public class AnnotationsTest {
 
                // test IQTable.annotationsOnly=true
                // public String unmappedField is ignored by iciql
-               assertEquals(0, db.from(p).where(p.unmappedField).is("unmapped").selectCount());
-
-               // test IQColumn.autoIncrement=true
+               try {
+                       db.from(p).where(p.unmappedField).is("unmapped").selectCount();
+                       assertTrue("this should never execute", false);
+               } catch (IciqlException e) {
+                       assertEquals(IciqlException.CODE_UNMAPPED_FIELD, e.getIciqlCode());
+               }
+               
                // 10 objects, 10 autoIncremented unique values
-               assertEquals(10, db.from(p).selectDistinct(p.autoIncrement).size());
+               assertEquals(10, db.from(p).selectDistinct(p.productName).size());
 
                // test IQTable.primaryKey=id
                try {
                        db.insertAll(ProductAnnotationOnly.getList());
-               } catch (IciqlException r) {
-                       SQLException s = (SQLException) r.getCause();
-                       assertEquals(ErrorCode.DUPLICATE_KEY_1, s.getErrorCode());
+               } catch (IciqlException e) {
+                       assertEquals(IciqlException.CODE_DUPLICATE_KEY, e.getIciqlCode());
                }
        }
 
@@ -123,9 +132,8 @@ public class AnnotationsTest {
                // test IQColumn.primaryKey=true
                try {
                        db.insertAll(ProductMixedAnnotation.getList());
-               } catch (IciqlException r) {
-                       SQLException s = (SQLException) r.getCause();
-                       assertEquals(ErrorCode.DUPLICATE_KEY_1, s.getErrorCode());
+               } catch (IciqlException e) {
+                       assertEquals(IciqlException.CODE_DUPLICATE_KEY, e.getIciqlCode());
                }
        }
 
@@ -171,9 +179,8 @@ public class AnnotationsTest {
                // tests IQTable.createTableIfRequired=false
                try {
                        db.insertAll(ProductNoCreateTable.getList());
-               } catch (IciqlException r) {
-                       SQLException s = (SQLException) r.getCause();
-                       assertEquals(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, s.getErrorCode());
+               } catch (IciqlException e) {
+                       assertEquals(IciqlException.CODE_TABLE_NOT_FOUND, e.getIciqlCode());
                }
        }
 
index 0287e061abc55365f0d6b3b21046f388bff53f9a..6111e725e0410e5593567b415003de7804a25d5e 100644 (file)
@@ -39,7 +39,7 @@ public class BooleanModelTest {
 \r
        @Test\r
        public void testBooleanColumn() {\r
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               Db db = IciqlSuite.openDb();\r
                db.insertAll(BooleanModel.getList());\r
                BooleanAsIntModel b = new BooleanAsIntModel();\r
                List<BooleanAsIntModel> models = db.from(b).select();\r
@@ -82,7 +82,7 @@ public class BooleanModelTest {
 \r
        @Test\r
        public void testIntColumn() {\r
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               Db db = IciqlSuite.openDb();\r
                // insert INT column\r
                db.insertAll(BooleanAsIntModel.getList());\r
 \r
index 1f2eff4cfc1d0827eaa31dfd84aef1545ecc7ab8..aada364969448fc8ddae6f652749d3e9edef3224 100644 (file)
@@ -38,14 +38,14 @@ public class ClobTest {
        @Test
        public void testClob() throws Exception {
                String create = "CREATE TABLE CLOB_TEST(ID INT PRIMARY KEY, WORDS {0})";
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               Db db = IciqlSuite.openDb();
                db.executeUpdate(MessageFormat.format(create, "VARCHAR(255)"));
                db.insertAll(StringRecord.getList());
                testSimpleUpdate(db, "VARCHAR fail");
                db.close();
 
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");
-               db.executeUpdate(MessageFormat.format(create, "TEXT"));
+               db = IciqlSuite.openDb();               
+               db.executeUpdate(MessageFormat.format(create, "CLOB"));
                db.insertAll(StringRecord.getList());
                testSimpleUpdate(db, "CLOB fail because of single quote artifacts");
                db.close();
index 88b23f622ef97821bd395673da8e114771d82af8..1641eb1f09d39bbfdcf18d4c67771161f3fd0be9 100644 (file)
@@ -27,6 +27,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import com.iciql.Db;
+import com.iciql.IciqlException;
 import com.iciql.Query;
 import com.iciql.test.models.Product;
 import com.iciql.util.Utils;
@@ -41,7 +42,7 @@ public class ConcurrencyTest {
 
        @Before
        public void setUp() {
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               db = IciqlSuite.openDb();
                db.insertAll(Product.getList());
        }
 
@@ -58,7 +59,12 @@ public class ConcurrencyTest {
                Query<Product> query2 = db.from(p);
 
                // if you could share alias instances both counts should be equal
-               long count1 = query1.where(p.category).is("Beverages").selectCount();
+               long count1 = 0;
+               try {
+                       count1 = query1.where(p.category).is("Beverages").selectCount();
+               } catch (IciqlException e) {
+                       assertEquals(IciqlException.CODE_UNMAPPED_FIELD, e.getIciqlCode());
+               }
                long count2 = query2.where(p.category).is("Beverages").selectCount();
 
                // but they aren't
@@ -84,10 +90,14 @@ public class ConcurrencyTest {
                                        try {
                                                int testCase = testNumber % 10;
                                                test(testCase, p);
-                                       } catch (Throwable rex) {
+                                       } catch (AssertionError e) {
+                                               failures.incrementAndGet();
+                                       } catch (IciqlException e) {
                                                failures.incrementAndGet();
-                                               System.err.println("EXPECTED ERROR");
-                                               rex.printStackTrace();
+                                               if (e.getIciqlCode() != IciqlException.CODE_UNMAPPED_FIELD) {
+                                                       System.err.println("UNEXPECTED ERROR in testConcurrencyFinal()");
+                                                       e.printStackTrace();
+                                               }
                                        }
                                }
                        }, "ICIQL-" + i);
@@ -115,9 +125,14 @@ public class ConcurrencyTest {
                                        try {
                                                int testCase = testNumber % 10;
                                                test(testCase, tl.get());
-                                       } catch (Throwable rex) {
+                                       } catch (AssertionError e) {
+                                               failures.incrementAndGet();
+                                       } catch (IciqlException e) {
                                                failures.incrementAndGet();
-                                               rex.printStackTrace();
+                                               if (e.getIciqlCode() != IciqlException.CODE_UNMAPPED_FIELD) {
+                                                       System.err.println("UNEXPECTED ERROR in testConcurrencyThreadLocal()");
+                                                       e.printStackTrace();
+                                               }
                                        }
                                }
                        }, "ICIQL-" + i);
index b39dd7cdbbbf7fe3ee80fef1e290e63154056066..7c7c84f0da31b6e9014b2e2d4b4c934b422b833b 100644 (file)
@@ -34,7 +34,7 @@ public class DefaultValuesTest {
 \r
        @Test\r
        public void testDefaultObjectValues() {\r
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               Db db = IciqlSuite.openDb();\r
 \r
                // insert random model\r
                DefaultValuesModel model = new DefaultValuesModel();\r
index b66aa9ea83da632ef73a1cd1cd0dfbc16e241a53..fd6af2f729ad2ebb0827b3ed488d6892d83bdc40 100644 (file)
@@ -40,7 +40,7 @@ public class EnumsTest {
 \r
        @Before\r
        public void setUp() {\r
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               db = IciqlSuite.openDb();\r
                db.insertAll(EnumIdModel.createList());\r
                db.insertAll(EnumOrdinalModel.createList());\r
                db.insertAll(EnumStringModel.createList());\r
index c9dab7793fbba81cdc0418aaadde86b135b04162..5842a2ece27608f2812e837cfbdfdfa08e13423a 100644 (file)
  */\r
 package com.iciql.test;\r
 \r
+import java.sql.SQLException;\r
+import java.text.MessageFormat;\r
+import java.util.concurrent.atomic.AtomicInteger;\r
+\r
 import org.junit.Assert;\r
+import org.junit.runner.JUnitCore;\r
+import org.junit.runner.Result;\r
 import org.junit.runner.RunWith;\r
+import org.junit.runner.notification.Failure;\r
 import org.junit.runners.Suite;\r
 import org.junit.runners.Suite.SuiteClasses;\r
 \r
+import com.iciql.Db;\r
+\r
 /**\r
  * JUnit 4 iciql test suite.\r
  * \r
+ * By default this test suite will run against the H2 database. You can change\r
+ * this by switching the DEFAULT_TEST_DB value.\r
+ * <p>\r
+ * Alternatively, you can run this class an application which will run all tests\r
+ * for all tested databases.\r
+ * \r
  */\r
 @RunWith(Suite.class)\r
 @SuiteClasses({ AliasMapTest.class, AnnotationsTest.class, BooleanModelTest.class, ClobTest.class,\r
                ConcurrencyTest.class, EnumsTest.class, ModelsTest.class, PrimitivesTest.class,\r
-               RuntimeQueryTest.class, SamplesTest.class, StatementLoggerTest.class, UpdateTest.class,\r
-               UUIDTest.class })\r
+               RuntimeQueryTest.class, SamplesTest.class, UpdateTest.class, UUIDTest.class })\r
 public class IciqlSuite {\r
 \r
-       public static void assertStartsWith(String a, String b) {\r
-               Assert.assertTrue(a.startsWith(b));\r
+       private static final TestDb[] TEST_DBS = { \r
+                       new TestDb("H2", "jdbc:h2:mem:"),\r
+                       new TestDb("HSQL", "jdbc:hsqldb:mem:db{0,number,000}") };\r
+\r
+       private static final TestDb DEFAULT_TEST_DB = TEST_DBS[0];\r
+\r
+       private static AtomicInteger openCount = new AtomicInteger(0);\r
+\r
+       public static void assertStartsWith(String value, String startsWith) {\r
+               Assert.assertTrue(MessageFormat.format("Expected \"{0}\", got: \"{1}\"", startsWith, value),\r
+                               value.startsWith(startsWith));\r
+       }\r
+\r
+       public static Db openDb() {\r
+               String testUrl = System.getProperty("iciql.url");\r
+               if (testUrl == null) {\r
+                       testUrl = DEFAULT_TEST_DB.url;\r
+               }\r
+               testUrl = MessageFormat.format(testUrl, openCount.incrementAndGet());\r
+               return Db.open(testUrl, "sa", "sa");\r
+       }\r
+\r
+       public static String getDatabaseName(Db db) {\r
+               String database = "";\r
+               try {\r
+                       database = db.getConnection().getMetaData().getDatabaseProductName();\r
+               } catch (SQLException s) {\r
+               }\r
+               return database;\r
+       }\r
+\r
+       public static void main(String... args) {\r
+               SuiteClasses suiteClasses = IciqlSuite.class.getAnnotation(SuiteClasses.class);\r
+               for (TestDb testDb : TEST_DBS) {\r
+                       System.out.println("*********************************************");\r
+                       System.out.println("Testing " + testDb.name + " " + testDb.getVersion());\r
+                       System.out.println("*********************************************");\r
+                       System.setProperty("iciql.url", testDb.url);\r
+                       Result result = JUnitCore.runClasses(suiteClasses.value());\r
+                       System.out.println(MessageFormat.format("{0} runs, {1} failures, {2} ignores in {3} msecs",\r
+                                       result.getRunCount(), result.getFailureCount(), result.getIgnoreCount(),\r
+                                       result.getRunTime()));\r
+                       for (Failure failure : result.getFailures()) {\r
+                               System.out.println(MessageFormat.format("{0}: {1}", failure.getTestHeader(),\r
+                                               failure.getMessage()));\r
+                       }\r
+                       System.out.println();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Represents a test database url.\r
+        */\r
+       private static class TestDb {\r
+               final String name;\r
+               final String url;\r
+\r
+               TestDb(String name, String url) {\r
+                       this.name = name;\r
+                       this.url = url;\r
+               }\r
+\r
+               String getVersion() {\r
+                       try {\r
+                               Db db = Db.open(url, "sa", "sa");\r
+                               String version = db.getConnection().getMetaData().getDatabaseProductVersion();\r
+                               db.close();\r
+                               return version;\r
+                       } catch (SQLException s) {\r
+                       }\r
+                       return "";\r
+               }\r
        }\r
 }\r
index 652bc4f7073b72003011efcbda1a9157d00b7e32..3a6b4e7becacaa0a29528e5dd21d47d4328272aa 100644 (file)
@@ -62,7 +62,7 @@ public class ModelsTest {
 
        @Before
        public void setUp() {
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               db = IciqlSuite.openDb();
                db.insertAll(Product.getList());
                db.insertAll(ProductAnnotationOnly.getList());
                db.insertAll(ProductMixedAnnotation.getList());
@@ -75,22 +75,28 @@ public class ModelsTest {
 
        @Test
        public void testValidateModels() {
+               boolean isH2 = IciqlSuite.getDatabaseName(db).equals("H2");
                DbInspector inspector = new DbInspector(db);
-               validateModel(inspector, new Product());
-               validateModel(inspector, new ProductAnnotationOnly());
-               validateModel(inspector, new ProductMixedAnnotation());
+               validateModel(inspector, new Product(), 3);
+               validateModel(inspector, new ProductAnnotationOnly(), isH2 ? 2 : 3);
+               validateModel(inspector, new ProductMixedAnnotation(), isH2 ? 3 : 4);
        }
 
-       private void validateModel(DbInspector inspector, Object o) {
+       private void validateModel(DbInspector inspector, Object o, int expected) {
                List<ValidationRemark> remarks = inspector.validateModel(o, false);
-               assertTrue("Validation remarks are null for " + o.getClass().getName(), remarks != null);
-               log("Validation remarks for " + o.getClass().getName());
+               assertTrue("validation remarks are null for " + o.getClass().getName(), remarks != null);
+               StringBuilder sb = new StringBuilder();
+               sb.append("validation remarks for " + o.getClass().getName());
+               sb.append('\n');
                for (ValidationRemark remark : remarks) {
-                       log(remark.toString());
+                       sb.append(remark.toString());
+                       sb.append('\n');
                        if (remark.isError()) {
                                errorCollector.addError(new SQLException(remark.toString()));
                        }
                }
+               assertTrue(remarks.get(0).message.equals("@IQSchema(name=PUBLIC)"));
+               assertEquals(sb.toString(), expected, remarks.size());
        }
 
        @Test
@@ -115,7 +121,13 @@ public class ModelsTest {
                                true);
                assertEquals(1, models.size());
                // a poor test, but a start
-               assertEquals(1456, models.get(0).length());
+               String dbName = IciqlSuite.getDatabaseName(db);
+               if (dbName.equals("H2")) {
+                       assertEquals(1478, models.get(0).length());
+               } else if (dbName.startsWith("HSQL")) {
+                       // HSQL uses Double instead of Float
+                       assertEquals(1479, models.get(0).length());
+               }
        }
 
        @Test
@@ -135,7 +147,7 @@ public class ModelsTest {
 
        @Test
        public void testTableUpgrade() {
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               Db db = IciqlSuite.openDb();
 
                // insert first, this will create version record automatically
                List<SupportedTypes> original = SupportedTypes.createList();
index 2d591c39f48f81bbc4accece51a773d6253e05ca..1cdeb1c77052b22423f6f2aa5f59e4257fa95e9b 100644 (file)
@@ -30,7 +30,7 @@ public class PrimitivesTest {
 \r
        @Test\r
        public void testPrimitives() {\r
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               Db db = IciqlSuite.openDb();\r
 \r
                // insert random model\r
                PrimitivesModel model = new PrimitivesModel();\r
index ff6fe2a49ad526fb63d3796661d2a8e388de1088..fa3ee1c7ba0447207e1a2f1b8580aa7681de11f0 100644 (file)
@@ -34,7 +34,7 @@ public class RuntimeQueryTest {
 \r
        @Test\r
        public void testRuntimeQuery() {\r
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               Db db = IciqlSuite.openDb();\r
                db.insertAll(Product.getList());\r
 \r
                Product p = new Product();\r
@@ -50,7 +50,7 @@ public class RuntimeQueryTest {
 \r
        @Test\r
        public void testExecuteQuery() throws SQLException {\r
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               Db db = IciqlSuite.openDb();\r
                db.insertAll(Product.getList());\r
 \r
                // test plain statement\r
@@ -68,7 +68,7 @@ public class RuntimeQueryTest {
        \r
        @Test\r
        public void testBuildObjects() throws SQLException {\r
-               Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               Db db = IciqlSuite.openDb();\r
                db.insertAll(Product.getList());\r
 \r
                // test plain statement\r
index 309bd5ded49ee112703e294614f692701bc5641d..30723bb65661eae9682d6a1d931e27f1d48df2e5 100644 (file)
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;\r
 \r
 import java.math.BigDecimal;\r
+import java.util.Collections;\r
 import java.util.HashSet;\r
 import java.util.List;\r
 import java.util.Set;\r
@@ -59,7 +60,7 @@ public class SamplesTest {
 \r
        @Before\r
        public void setUp() {\r
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+               db = IciqlSuite.openDb();\r
                db.insertAll(Product.getList());\r
                db.insertAll(Customer.getList());\r
                db.insertAll(Order.getList());\r
@@ -82,7 +83,7 @@ public class SamplesTest {
 \r
        @Test\r
        public void testReverseColumns() {\r
-               db.executeUpdate("create table TestReverse(id int, name varchar, additional varchar)");\r
+               db.executeUpdate("create table TestReverse(id int, name varchar(10), additional varchar(10))");\r
                TestReverse t = new TestReverse();\r
                t.id = 10;\r
                t.name = "Hello";\r
@@ -222,7 +223,7 @@ public class SamplesTest {
                final Customer c = new Customer();\r
                final Order o = new Order();\r
                List<CustOrder> orders = db.from(c).innerJoin(o).on(c.customerId).is(o.customerId).where(o.total)\r
-                               .lessThan(new BigDecimal("100.00")).orderBy(1).select(new CustOrder() {\r
+                               .lessThan(new BigDecimal("100.00")).orderBy(c.customerId).select(new CustOrder() {\r
                                        {\r
                                                customerId = c.customerId;\r
                                                orderId = o.orderId;\r
@@ -267,8 +268,10 @@ public class SamplesTest {
        @Test\r
        public void testLength() {\r
                Product p = new Product();\r
-               List<Integer> lengths = db.from(p).where(length(p.productName)).lessThan(10).orderBy(1)\r
+               List<Integer> lengths = db.from(p).where(length(p.productName)).lessThan(10)\r
                                .selectDistinct(length(p.productName));\r
+               // Formerly used orderBy(1) here, but that is not portable across DBs\r
+               Collections.sort(lengths);\r
                assertEquals("[4, 5]", lengths.toString());\r
        }\r
 \r
@@ -310,15 +313,17 @@ public class SamplesTest {
                ComplexObject co = new ComplexObject();\r
                String sql = db.from(co).where(co.id).is(1).and(co.amount).is(1L).and(co.birthday)\r
                                .lessThan(new java.util.Date()).and(co.created)\r
-                               .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello").and(co.time)\r
-                               .lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value).is(new BigDecimal("1")).getSQL();\r
-               assertEquals("SELECT * FROM ComplexObject " + "WHERE id = ? " + "AND amount = ? " + "AND birthday < ? "\r
-                               + "AND created < ? " + "AND name = ? " + "AND time < ? " + "AND value = ?", sql);\r
+                               .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello")\r
+                               .and(co.time).lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value)\r
+                               .is(new BigDecimal("1")).getSQL();\r
+               assertEquals("SELECT * FROM ComplexObject WHERE id = ? AND amount = ? "\r
+                               + "AND birthday < ? AND created < ? AND name = ? AND time < ? AND value = ?", sql);\r
 \r
                long count = db.from(co).where(co.id).is(1).and(co.amount).is(1L).and(co.birthday)\r
                                .lessThan(new java.util.Date()).and(co.created)\r
-                               .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello").and(co.time)\r
-                               .lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value).is(new BigDecimal("1")).selectCount();\r
+                               .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello")\r
+                               .and(co.time).lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value)\r
+                               .is(new BigDecimal("1")).selectCount();\r
                assertEquals(1, count);\r
        }\r
 \r
@@ -335,7 +340,7 @@ public class SamplesTest {
                                return co.id == x && co.name.equals(name) && co.name.equals("hello");\r
                        }\r
                }).getSQL();\r
-               assertEquals("SELECT * FROM ComplexObject " + "WHERE id=? " + "AND ?=name " + "AND 'hello'=name", sql);\r
+               assertEquals("SELECT * FROM ComplexObject WHERE id=? AND ?=name AND 'hello'=name", sql);\r
 \r
                long count = db.from(co).where(new Filter() {\r
                        public boolean where() {\r
@@ -393,14 +398,15 @@ public class SamplesTest {
                // };\r
 \r
                final Product p = new Product();\r
-               List<ProductGroup> list = db.from(p).groupBy(p.category).orderBy(1).select(new ProductGroup() {\r
-                       {\r
-                               category = p.category;\r
-                               productCount = count();\r
-                       }\r
-               });\r
+               List<ProductGroup> list = db.from(p).groupBy(p.category).orderBy(p.category)\r
+                               .select(new ProductGroup() {\r
+                                       {\r
+                                               category = p.category;\r
+                                               productCount = count();\r
+                                       }\r
+                               });\r
 \r
-               assertEquals("[Beverages:2, Condiments:5, " + "Meat/Poultry:1, Produce:1, Seafood:1]", list.toString());\r
+               assertEquals("[Beverages:2, Condiments:5, Meat/Poultry:1, Produce:1, Seafood:1]", list.toString());\r
        }\r
 \r
 }\r
index b35d62394feea68c404d8c238612873190b335d8..b7f83e6cde5bec5d8014e8743e64d6d3e46901e9 100644 (file)
@@ -32,7 +32,9 @@ import com.iciql.Iciql.IQColumn;
 import com.iciql.Iciql.IQTable;
 
 /**
- * Tests if UUID type.
+ * Tests of UUID type.
+ * <p>
+ * H2 only.
  */
 public class UUIDTest {
 
index 9ff5593da2a9a344e461bad56a163b9c1f601657..a4ee61cb113abef234028084de40f6fdc4f5f47c 100644 (file)
@@ -41,7 +41,7 @@ public class UpdateTest {
 
        @Before
        public void setUp() throws Exception {
-               db = Db.open("jdbc:h2:mem:", "sa", "sa");
+               db = IciqlSuite.openDb();
                db.insertAll(Product.getList());
                db.insertAll(Customer.getList());
                db.insertAll(Order.getList());
index c2b8da9bc3c5c5b79fe5a39d527c0fe5e1d65d05..a0bbb7e15222d96397fc760fec40b76472a3f9d8 100644 (file)
@@ -20,12 +20,19 @@ package com.iciql.test.models;
 import java.util.Arrays;\r
 import java.util.List;\r
 \r
+import com.iciql.Iciql.IQColumn;\r
+import com.iciql.Iciql.IQTable;\r
+\r
 /**\r
  * A table containing customer data.\r
  */\r
+@IQTable\r
 public class Customer {\r
 \r
+       @IQColumn(length = 25)\r
        public String customerId;\r
+       \r
+       @IQColumn(length = 2)\r
        public String region;\r
 \r
        public Customer() {\r
@@ -42,7 +49,8 @@ public class Customer {
        }\r
 \r
        public static List<Customer> getList() {\r
-               Customer[] list = { new Customer("ALFKI", "WA"), new Customer("ANATR", "WA"), new Customer("ANTON", "CA") };\r
+               Customer[] list = { new Customer("ALFKI", "WA"), new Customer("ANATR", "WA"),\r
+                               new Customer("ANTON", "CA") };\r
                return Arrays.asList(list);\r
        }\r
 \r
index f0cf7f344c6d94b9f59fb2cd732a0b314fcfa9b4..e123d09871fc9ecfe4fe940b78e855fb9ba6c1ea 100644 (file)
@@ -17,7 +17,9 @@
 \r
 package com.iciql.test.models;\r
 \r
+import static com.iciql.Define.length;\r
 import static com.iciql.Define.primaryKey;\r
+import static com.iciql.Define.scale;\r
 import static com.iciql.Define.tableName;\r
 \r
 import java.math.BigDecimal;\r
@@ -25,6 +27,7 @@ import java.util.Arrays;
 import java.util.Date;\r
 import java.util.List;\r
 \r
+\r
 import com.iciql.Iciql;\r
 \r
 /**\r
@@ -34,7 +37,7 @@ import com.iciql.Iciql;
 public class Order implements Iciql {\r
        public String customerId;\r
        public Integer orderId;\r
-       public Date orderDate;\r
+       public Date orderDate;  \r
        public BigDecimal total;\r
 \r
        public Order(String customerId, Integer orderId, String total, String orderDate) {\r
@@ -50,6 +53,9 @@ public class Order implements Iciql {
 \r
        public void defineIQ() {\r
                tableName("Orders");\r
+               length(customerId, 25);\r
+               length(total, 10);\r
+               scale(total, 2);\r
                primaryKey(customerId, orderId);\r
        }\r
 \r
index 065e62462b3f7a58cc99195d636bd4b485d7dad9..35eaa672f41f1eecacdc1fb47f893a65f469d420 100644 (file)
@@ -54,6 +54,7 @@ public class Product implements Iciql {
        public void defineIQ() {\r
                tableName("Product");\r
                primaryKey(productId);\r
+               length(productName, 255);\r
                length(category, 255);\r
                index(productName, category);\r
        }\r
index 673ca14f889de5119217dedbdf65a08691530412..80bf0a1630084569c4cd2d2d685d70a0e88c6507 100644 (file)
@@ -45,8 +45,8 @@ public class ProductAnnotationOnly {
        @IQColumn(name = "cat", length = 15, trim = true)
        public String category;
 
-       @IQColumn(name = "name")
-       private String productName;
+       @IQColumn(name = "name", length = 50)
+       public String productName;
 
        @SuppressWarnings("unused")
        @IQColumn
index ff7d46f9787ae719c1ce3ea4118a93127fc9511e..646f75c574e232960c1e31eb771e5f60c9aef380 100644 (file)
@@ -42,7 +42,7 @@ public class ProductMixedAnnotation {
        @IQColumn(name = "id", primaryKey = true)
        private Integer productId;
 
-       @IQColumn(name = "name")
+       @IQColumn(name = "name", length = 255)
        private String productName;
 
        public ProductMixedAnnotation() {
index 49dd9511319ba8c71fef1f19d4612d3855fe7a38..77fdbff07655bd0cd4023b7bea57c6eda23237ae 100644 (file)
@@ -18,6 +18,9 @@
 package com.iciql.test.models;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
 
@@ -75,10 +78,11 @@ public class SupportedTypes {
        @IQColumn
        private Double myDouble;
 
-       @IQColumn
+       // scale change must match the test value scale
+       @IQColumn(length = 10, scale = 5)
        private BigDecimal myBigDecimal;
 
-       @IQColumn
+       @IQColumn(length = 40)
        private String myString;
 
        @IQColumn
@@ -137,6 +141,8 @@ public class SupportedTypes {
                s.myFloat = new Float(rand.nextFloat());
                s.myDouble = new Double(rand.nextDouble());
                s.myBigDecimal = new BigDecimal(rand.nextDouble());
+               // scale must match annotation
+               s.myBigDecimal = s.myBigDecimal.setScale(5, RoundingMode.UP);
                s.myString = Long.toHexString(rand.nextLong());
                s.myUtilDate = new java.util.Date(rand.nextLong());
                s.mySqlDate = new java.sql.Date(rand.nextLong());
@@ -160,13 +166,14 @@ public class SupportedTypes {
                same &= myLong.equals(s.myLong);
                same &= myFloat.equals(s.myFloat);
                same &= myDouble.equals(s.myDouble);
-               same &= myBigDecimal.equals(s.myBigDecimal);
-               same &= myUtilDate.getTime() == s.myUtilDate.getTime();
-               same &= mySqlTimestamp.getTime() == s.mySqlTimestamp.getTime();
+               same &= myBigDecimal.compareTo(s.myBigDecimal) == 0;
+               SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+               same &= df.format(myUtilDate).equals(df.format(s.myUtilDate));
+               same &= df.format(mySqlTimestamp).equals(df.format(s.mySqlTimestamp));
                same &= mySqlDate.toString().equals(s.mySqlDate.toString());
                same &= mySqlTime.toString().equals(s.mySqlTime.toString());
                same &= myString.equals(s.myString);
-               same &= compare(myBlob, s.myBlob);
+               same &= Arrays.equals(myBlob, s.myBlob);
                same &= myDefaultFlower.equals(s.myDefaultFlower);
                same &= myFavoriteFlower.equals(s.myFavoriteFlower);
                same &= myOtherFavoriteFlower.equals(s.myOtherFavoriteFlower);
@@ -174,22 +181,7 @@ public class SupportedTypes {
                same &= myOtherFavoriteTree.equals(s.myOtherFavoriteTree);
                return same;
        }
-
-       private boolean compare(byte[] a, byte[] b) {
-               if (b == null) {
-                       return false;
-               }
-               if (a.length != b.length) {
-                       return false;
-               }
-               for (int i = 0; i < a.length; i++) {
-                       if (a[i] != b[i]) {
-                               return false;
-                       }
-               }
-               return true;
-       }
-
+       
        /**
         * This class demonstrates the table upgrade.
         */