You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2012/11/09 14:48:45 UTC
svn commit: r1407451 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne:
access/DbLoaderTest.java unit/MySQLUnitDbAdapter.java unit/UnitDbAdapter.java
Author: aadamchik
Date: Fri Nov 9 13:48:44 2012
New Revision: 1407451
URL: http://svn.apache.org/viewvc?rev=1407451&view=rev
Log:
CAY-1759 cdbimport improvements: add 'catalog', rename 'schemaName' to 'schema'
catalog unit tests
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLUnitDbAdapter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/UnitDbAdapter.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java?rev=1407451&r1=1407450&r2=1407451&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DbLoaderTest.java Fri Nov 9 13:48:44 2012
@@ -58,7 +58,8 @@ public class DbLoaderTest extends Server
@Override
protected void setUpAfterInjection() throws Exception {
- loader = new DbLoader(dataSourceFactory.getSharedDataSource().getConnection(), adapter, null);
+ loader = new DbLoader(dataSourceFactory.getSharedDataSource()
+ .getConnection(), adapter, null);
}
@Override
@@ -74,16 +75,14 @@ public class DbLoaderTest extends Server
String tableLabel = adapter.tableTypeForTable();
if (tableLabel != null) {
- assertTrue(
- "Missing type for table '" + tableLabel + "' - " + tableTypes,
- tableTypes.contains(tableLabel));
+ assertTrue("Missing type for table '" + tableLabel + "' - "
+ + tableTypes, tableTypes.contains(tableLabel));
}
String viewLabel = adapter.tableTypeForView();
if (viewLabel != null) {
- assertTrue(
- "Missing type for view '" + viewLabel + "' - " + tableTypes,
- tableTypes.contains(viewLabel));
+ assertTrue("Missing type for view '" + viewLabel + "' - "
+ + tableTypes, tableTypes.contains(viewLabel));
}
}
@@ -91,9 +90,8 @@ public class DbLoaderTest extends Server
String tableLabel = adapter.tableTypeForTable();
- List<DbEntity> tables = loader.getTables(null, null, "%", new String[] {
- tableLabel
- });
+ List<DbEntity> tables = loader.getTables(null, null, "%",
+ new String[] { tableLabel });
assertNotNull(tables);
@@ -106,7 +104,8 @@ public class DbLoaderTest extends Server
}
}
- assertTrue("'ARTIST' is missing from the table list: " + tables, foundArtist);
+ assertTrue("'ARTIST' is missing from the table list: " + tables,
+ foundArtist);
}
public void testLoadWithMeaningfulPK() throws Exception {
@@ -116,13 +115,11 @@ public class DbLoaderTest extends Server
loader.setCreatingMeaningfulPK(true);
- List<DbEntity> testLoader = loader.getTables(null, null, "artist", new String[] {
- tableLabel
- });
+ List<DbEntity> testLoader = loader.getTables(null, null, "artist",
+ new String[] { tableLabel });
if (testLoader.size() == 0) {
- testLoader = loader.getTables(null, null, "ARTIST", new String[] {
- tableLabel
- });
+ testLoader = loader.getTables(null, null, "ARTIST",
+ new String[] { tableLabel });
}
loader.loadDbEntities(map, testLoader);
@@ -135,19 +132,14 @@ public class DbLoaderTest extends Server
}
/**
- * DataMap loading is in one big test method, since breaking it in individual tests
- * would require multiple reads of metatdata which is extremely slow on some RDBMS
- * (Sybase).
+ * DataMap loading is in one big test method, since breaking it in
+ * individual tests would require multiple reads of metatdata which is
+ * extremely slow on some RDBMS (Sybase).
*/
public void testLoad() throws Exception {
- boolean supportsUnique = runtime
- .getDataDomain()
- .getDataNodes()
- .iterator()
- .next()
- .getAdapter()
- .supportsUniqueConstraints();
+ boolean supportsUnique = runtime.getDataDomain().getDataNodes()
+ .iterator().next().getAdapter().supportsUniqueConstraints();
boolean supportsLobs = accessStackAdapter.supportsLobs();
boolean supportsFK = accessStackAdapter.supportsFKConstraints();
@@ -155,9 +147,8 @@ public class DbLoaderTest extends Server
String tableLabel = adapter.tableTypeForTable();
// *** TESTING THIS ***
- loader.loadDbEntities(map, loader.getTables(null, null, "%", new String[] {
- tableLabel
- }));
+ loader.loadDbEntities(map,
+ loader.getTables(null, null, "%", new String[] { tableLabel }));
assertDbEntities(map);
@@ -189,10 +180,10 @@ public class DbLoaderTest extends Server
}
assertNotNull("No relationship to PAINTING_INFO", oneToOne);
- assertFalse("Relationship to PAINTING_INFO must be to-one", oneToOne
- .isToMany());
- assertTrue("Relationship to PAINTING_INFO must be to-one", oneToOne
- .isToDependentPK());
+ assertFalse("Relationship to PAINTING_INFO must be to-one",
+ oneToOne.isToMany());
+ assertTrue("Relationship to PAINTING_INFO must be to-one",
+ oneToOne.isToDependentPK());
// test UNIQUE only if FK is supported...
if (supportsUnique) {
@@ -228,24 +219,32 @@ public class DbLoaderTest extends Server
}
private void assertUniqueConstraintsInRelationships(DataMap map) {
- // unfortunately JDBC metadata doesn't provide info for UNIQUE constraints....
+ // unfortunately JDBC metadata doesn't provide info for UNIQUE
+ // constraints....
// cant reengineer them...
// find rel to TO_ONEFK1
/*
- * Iterator it = getDbEntity(map, "TO_ONEFK2").getRelationships().iterator();
- * DbRelationship rel = (DbRelationship) it.next(); assertEquals("TO_ONEFK1",
- * rel.getTargetEntityName()); assertFalse("UNIQUE constraint was ignored...",
- * rel.isToMany());
+ * Iterator it = getDbEntity(map,
+ * "TO_ONEFK2").getRelationships().iterator(); DbRelationship rel =
+ * (DbRelationship) it.next(); assertEquals("TO_ONEFK1",
+ * rel.getTargetEntityName());
+ * assertFalse("UNIQUE constraint was ignored...", rel.isToMany());
*/
}
private void assertDbEntities(DataMap map) {
DbEntity dae = getDbEntity(map, "ARTIST");
assertNotNull(
- "Null 'ARTIST' entity, other DbEntities: " + map.getDbEntityMap(),
- dae);
+ "Null 'ARTIST' entity, other DbEntities: "
+ + map.getDbEntityMap(), dae);
assertEquals("ARTIST", dae.getName().toUpperCase());
+
+ if (accessStackAdapter.supportsCatalogs()) {
+ assertNotNull(dae.getCatalog());
+ assertEquals("CAYENNE", dae.getCatalog().toUpperCase());
+ }
+
DbAttribute a = getDbAttribute(dae, "ARTIST_ID");
assertNotNull(a);
assertTrue(a.isPrimaryKey());
@@ -256,16 +255,16 @@ public class DbLoaderTest extends Server
assertNotNull(blobEnt);
DbAttribute blobAttr = getDbAttribute(blobEnt, "BLOB_COL");
assertNotNull(blobAttr);
- assertTrue(msgForTypeMismatch(Types.BLOB, blobAttr), Types.BLOB == blobAttr
- .getType()
- || Types.LONGVARBINARY == blobAttr.getType());
+ assertTrue(msgForTypeMismatch(Types.BLOB, blobAttr),
+ Types.BLOB == blobAttr.getType()
+ || Types.LONGVARBINARY == blobAttr.getType());
DbEntity clobEnt = getDbEntity(map, "CLOB_TEST");
assertNotNull(clobEnt);
DbAttribute clobAttr = getDbAttribute(clobEnt, "CLOB_COL");
assertNotNull(clobAttr);
- assertTrue(msgForTypeMismatch(Types.CLOB, clobAttr), Types.CLOB == clobAttr
- .getType()
- || Types.LONGVARCHAR == clobAttr.getType());
+ assertTrue(msgForTypeMismatch(Types.CLOB, clobAttr),
+ Types.CLOB == clobAttr.getType()
+ || Types.LONGVARCHAR == clobAttr.getType());
}
private void assertLobObjEntities(DataMap map) {
@@ -304,14 +303,8 @@ public class DbLoaderTest extends Server
}
private DataMap originalMap() {
- return runtime
- .getDataDomain()
- .getDataNodes()
- .iterator()
- .next()
- .getDataMaps()
- .iterator()
- .next();
+ return runtime.getDataDomain().getDataNodes().iterator().next()
+ .getDataMaps().iterator().next();
}
/**
@@ -328,32 +321,27 @@ public class DbLoaderTest extends Server
DbAttribute smallintAttr = getDbAttribute(smallintTest, "SMALLINT_COL");
// check decimal
- assertTrue(
- msgForTypeMismatch(Types.DECIMAL, decimalAttr),
+ assertTrue(msgForTypeMismatch(Types.DECIMAL, decimalAttr),
Types.DECIMAL == decimalAttr.getType()
|| Types.NUMERIC == decimalAttr.getType());
assertEquals(2, decimalAttr.getScale());
// check varchar
- assertEquals(
- msgForTypeMismatch(Types.VARCHAR, varcharAttr),
- Types.VARCHAR,
- varcharAttr.getType());
+ assertEquals(msgForTypeMismatch(Types.VARCHAR, varcharAttr),
+ Types.VARCHAR, varcharAttr.getType());
assertEquals(255, varcharAttr.getMaxLength());
// check integer
- assertEquals(
- msgForTypeMismatch(Types.INTEGER, integerAttr),
- Types.INTEGER,
- integerAttr.getType());
+ assertEquals(msgForTypeMismatch(Types.INTEGER, integerAttr),
+ Types.INTEGER, integerAttr.getType());
// check float
- assertTrue(msgForTypeMismatch(Types.FLOAT, floatAttr), Types.FLOAT == floatAttr
- .getType()
- || Types.DOUBLE == floatAttr.getType()
- || Types.REAL == floatAttr.getType());
+ assertTrue(
+ msgForTypeMismatch(Types.FLOAT, floatAttr),
+ Types.FLOAT == floatAttr.getType()
+ || Types.DOUBLE == floatAttr.getType()
+ || Types.REAL == floatAttr.getType());
// check smallint
- assertTrue(
- msgForTypeMismatch(Types.SMALLINT, smallintAttr),
+ assertTrue(msgForTypeMismatch(Types.SMALLINT, smallintAttr),
Types.SMALLINT == smallintAttr.getType()
|| Types.INTEGER == smallintAttr.getType());
}
@@ -363,15 +351,13 @@ public class DbLoaderTest extends Server
for (DbEntity origEnt : originalMap().getDbEntities()) {
DbEntity newEnt = map.getDbEntity(origEnt.getName());
for (DbAttribute origAttr : origEnt.getAttributes()) {
- DbAttribute newAttr = (DbAttribute) newEnt.getAttribute(origAttr
- .getName());
+ DbAttribute newAttr = (DbAttribute) newEnt
+ .getAttribute(origAttr.getName());
assertNotNull(
"No matching DbAttribute for '" + origAttr.getName(),
newAttr);
- assertEquals(
- msgForTypeMismatch(origAttr, newAttr),
- origAttr.getType(),
- newAttr.getType());
+ assertEquals(msgForTypeMismatch(origAttr, newAttr),
+ origAttr.getType(), newAttr.getType());
// length and precision doesn't have to be the same
// it must be greater or equal
assertTrue(origAttr.getMaxLength() <= newAttr.getMaxLength());
@@ -387,17 +373,14 @@ public class DbLoaderTest extends Server
private String msgForTypeMismatch(int origType, DbAttribute newAttr) {
String nt = TypesMapping.getSqlNameByType(newAttr.getType());
String ot = TypesMapping.getSqlNameByType(origType);
- return attrMismatch(newAttr.getName(), "expected type: <"
- + ot
- + ">, but was <"
- + nt
- + ">");
+ return attrMismatch(newAttr.getName(), "expected type: <" + ot
+ + ">, but was <" + nt + ">");
}
private String attrMismatch(String attrName, String msg) {
StringBuffer buf = new StringBuffer();
- buf.append("[Error loading attribute '").append(attrName).append("': ").append(
- msg).append("]");
+ buf.append("[Error loading attribute '").append(attrName).append("': ")
+ .append(msg).append("]");
return buf.toString();
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLUnitDbAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLUnitDbAdapter.java?rev=1407451&r1=1407450&r2=1407451&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLUnitDbAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/MySQLUnitDbAdapter.java Fri Nov 9 13:48:44 2012
@@ -40,6 +40,11 @@ public class MySQLUnitDbAdapter extends
public MySQLUnitDbAdapter(DbAdapter adapter) {
super(adapter);
}
+
+ @Override
+ public boolean supportsCatalogs() {
+ return true;
+ }
@Override
public boolean supportsLobs() {
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/UnitDbAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/UnitDbAdapter.java?rev=1407451&r1=1407450&r2=1407451&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/UnitDbAdapter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/unit/UnitDbAdapter.java Fri Nov 9 13:48:44 2012
@@ -225,6 +225,10 @@ public class UnitDbAdapter {
public boolean supportsCaseInsensitiveOrder() {
return true;
}
+
+ public boolean supportsCatalogs() {
+ return false;
+ }
public boolean supportsBatchPK() {
return true;