aboutsummaryrefslogtreecommitdiffstats
path: root/tests/com/iciql/test
diff options
context:
space:
mode:
Diffstat (limited to 'tests/com/iciql/test')
-rw-r--r--tests/com/iciql/test/AnnotationsTest.java43
-rw-r--r--tests/com/iciql/test/IciqlSuite.java10
-rw-r--r--tests/com/iciql/test/ModelsTest.java15
-rw-r--r--tests/com/iciql/test/models/ProductAnnotationOnly.java4
4 files changed, 46 insertions, 26 deletions
diff --git a/tests/com/iciql/test/AnnotationsTest.java b/tests/com/iciql/test/AnnotationsTest.java
index 4f50d61..2fdbcf4 100644
--- a/tests/com/iciql/test/AnnotationsTest.java
+++ b/tests/com/iciql/test/AnnotationsTest.java
@@ -17,9 +17,7 @@
package com.iciql.test;
-import static com.iciql.test.IciqlSuite.assertStartsWith;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.sql.DatabaseMetaData;
@@ -38,6 +36,7 @@ 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.Utils;
/**
* Test annotation processing.
@@ -68,26 +67,30 @@ 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");
String schema = IciqlSuite.getDefaultSchema(db);
- ResultSet rs = meta.getIndexInfo(null, schema, "ANNOTATEDPRODUCT", false, true);
+ boolean toUpper = meta.storesUpperCaseIdentifiers();
+ boolean toLower = meta.storesLowerCaseIdentifiers();
+ ResultSet rs = meta.getIndexInfo(null, prepName(schema, toUpper, toLower),
+ prepName("ANNOTATEDPRODUCT", toUpper, toLower), false, true);
+
+ List<String> list = Utils.newArrayList();
+ while (rs.next()) {
+ String col = rs.getString("COLUMN_NAME");
+ String index = rs.getString("INDEX_NAME");
+ list.add((col + ":" + index).toLowerCase());
+ }
+ assertTrue(list.contains("name:annotatedproduct_0"));
+ assertTrue(list.contains("cat:annotatedproduct_0"));
+ assertTrue(list.contains("name:nameidx"));
+ }
- // first index is primary key index
- // H2 gives this a testable name.
- assertTrue(rs.next());
- if (isH2) {
- assertStartsWith(rs.getString("INDEX_NAME").toUpperCase(), "PRIMARY_KEY");
+ private String prepName(String name, boolean upper, boolean lower) {
+ if (upper) {
+ return name.toUpperCase();
+ } else if (lower) {
+ return name.toLowerCase();
}
- assertTrue(rs.next());
- assertStartsWith(rs.getString("INDEX_NAME").toUpperCase(), "ANNOTATEDPRODUCT_0");
- assertStartsWith(rs.getString("COLUMN_NAME").toUpperCase(), "NAME");
- assertTrue(rs.next());
- assertStartsWith(rs.getString("INDEX_NAME").toUpperCase(), "ANNOTATEDPRODUCT_0");
- assertStartsWith(rs.getString("COLUMN_NAME").toUpperCase(), "CAT");
- assertTrue(rs.next());
- assertStartsWith(rs.getString("INDEX_NAME").toUpperCase(), "NAMEIDX");
- assertStartsWith(rs.getString("COLUMN_NAME").toUpperCase(), "NAME");
- assertFalse(rs.next());
+ return name;
}
@Test
@@ -180,7 +183,7 @@ public class AnnotationsTest {
try {
db.insertAll(ProductNoCreateTable.getList());
} catch (IciqlException e) {
- assertEquals(IciqlException.CODE_TABLE_NOT_FOUND, e.getIciqlCode());
+ assertEquals(IciqlException.CODE_OBJECT_NOT_FOUND, e.getIciqlCode());
}
}
diff --git a/tests/com/iciql/test/IciqlSuite.java b/tests/com/iciql/test/IciqlSuite.java
index 0389d80..d79f277 100644
--- a/tests/com/iciql/test/IciqlSuite.java
+++ b/tests/com/iciql/test/IciqlSuite.java
@@ -78,9 +78,10 @@ public class IciqlSuite {
private static final TestDb[] TEST_DBS = { new TestDb("H2 (embedded)", "jdbc:h2:mem:db{0,number,000}"),
new TestDb("HSQL (embedded)", "jdbc:hsqldb:mem:db{0,number,000}"),
new TestDb("Derby (embedded)", "jdbc:derby:memory:db{0,number,000};create=true"),
- new TestDb("MySQL (tcp/myisam)", "jdbc:mysql://localhost:3306/iciql") };
+ new TestDb("MySQL (tcp/myisam)", "jdbc:mysql://localhost:3306/iciql"),
+ new TestDb("PostgreSQL (tcp)", "jdbc:postgresql://localhost:5432/iciql")};
- private static final TestDb DEFAULT_TEST_DB = TEST_DBS[0];
+ private static final TestDb DEFAULT_TEST_DB = TEST_DBS[4];
private static final PrintStream ERR = System.err;
@@ -96,6 +97,11 @@ public class IciqlSuite {
Assert.assertTrue(MessageFormat.format("Expected \"{0}\", got: \"{1}\"", startsWith, value),
value.startsWith(startsWith));
}
+
+ public static void assertEqualsIgnoreCase(String expected, String actual) {
+ Assert.assertTrue(MessageFormat.format("Expected \"{0}\", got: \"{1}\"", expected, actual),
+ expected.equalsIgnoreCase(actual));
+ }
public static boolean equivalentTo(double expected, double actual) {
if (Double.compare(expected, actual) == 0) {
diff --git a/tests/com/iciql/test/ModelsTest.java b/tests/com/iciql/test/ModelsTest.java
index d2e02fa..c5569d6 100644
--- a/tests/com/iciql/test/ModelsTest.java
+++ b/tests/com/iciql/test/ModelsTest.java
@@ -19,6 +19,7 @@ package com.iciql.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static com.iciql.test.IciqlSuite.assertEqualsIgnoreCase;
import java.sql.SQLException;
import java.text.MessageFormat;
@@ -93,7 +94,8 @@ public class ModelsTest {
assertEquals(sb.toString(), expected - 1, remarks.size());
} else {
assertEquals(sb.toString(), expected, remarks.size());
- assertEquals(MessageFormat.format("@IQSchema(\"{0}\")", schemaName), remarks.get(0).message);
+ assertEqualsIgnoreCase(MessageFormat.format("@IQSchema(\"{0}\")", schemaName),
+ remarks.get(0).message);
}
}
@@ -121,7 +123,7 @@ public class ModelsTest {
// a poor test, but a start
String dbName = IciqlSuite.getDatabaseEngineName(db);
if (dbName.equals("H2")) {
- assertEquals(1478, models.get(0).length());
+ assertEquals(1475, models.get(0).length());
} else if (dbName.startsWith("HSQL")) {
// HSQL uses Double instead of Float
assertEquals(1479, models.get(0).length());
@@ -129,6 +131,15 @@ public class ModelsTest {
// Derby uses java.sql.Timestamp not java.util.Date
// Derby uses username as schema name
assertEquals(1489, models.get(0).length());
+ } else if (dbName.equals("PostgreSQL")) {
+ assertEquals(1514, models.get(0).length());
+ } else if (dbName.equals("MySQL")) {
+ // MySQL uses timestamp default values like
+ // 0000-00-00 00:00:00 and CURRENT_TIMESTAMP
+ assertEquals(1561, models.get(0).length());
+ } else {
+ // unknown database
+ assertEquals(0, models.get(0).length());
}
}
}
diff --git a/tests/com/iciql/test/models/ProductAnnotationOnly.java b/tests/com/iciql/test/models/ProductAnnotationOnly.java
index e4de22d..1f6b4e2 100644
--- a/tests/com/iciql/test/models/ProductAnnotationOnly.java
+++ b/tests/com/iciql/test/models/ProductAnnotationOnly.java
@@ -37,7 +37,7 @@ public class ProductAnnotationOnly {
public String unmappedField;
@IQColumn(name = "id", autoIncrement = true)
- public Integer productId;
+ public Long productId;
@IQColumn(name = "cat", length = 15, trim = true)
public String category;
@@ -56,7 +56,7 @@ public class ProductAnnotationOnly {
// public constructor
}
- private ProductAnnotationOnly(int productId, String productName, String category, double unitPrice,
+ private ProductAnnotationOnly(long productId, String productName, String category, double unitPrice,
int unitsInStock, String unmappedField) {
this.productId = productId;
this.productName = productName;