cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [5/9] cayenne git commit: New DbLoader for dbsync utils - loading process split in independent small steps - DbLoader always return new DataMap, it doesn't accept it from outside
Date Wed, 14 Dec 2016 18:29:54 GMT
New DbLoader for dbsync utils
 - loading process split in independent small steps
 - DbLoader always return new DataMap, it doesn't accept it from outside

Final clean up of tests


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/41515467
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/41515467
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/41515467

Branch: refs/heads/master
Commit: 41515467c4a0804dcb35d99070046ea0ac44a6e0
Parents: e68c72c
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Mon Dec 12 12:34:14 2016 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Mon Dec 12 12:34:14 2016 +0300

----------------------------------------------------------------------
 .../dbsync/reverse/dbload/DbLoaderIT.java       | 75 ++++++++++++--------
 .../reverse/dbload/RelationshipsLoaderIT.java   | 16 +++++
 .../modeler/dialog/db/DbLoaderHelper.java       |  2 +-
 3 files changed, 63 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/41515467/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java
b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java
index bf0f89f..d2e87a5 100644
--- a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java
+++ b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/DbLoaderIT.java
@@ -21,12 +21,13 @@ package org.apache.cayenne.dbsync.reverse.dbload;
 
 import org.apache.cayenne.configuration.server.ServerRuntime;
 import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.dbsync.naming.DefaultObjectNameGenerator;
 import org.apache.cayenne.dbsync.naming.NoStemStemmer;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.unit.UnitDbAdapter;
 import org.apache.cayenne.unit.di.server.CayenneProjects;
 import org.apache.cayenne.unit.di.server.ServerCase;
@@ -34,16 +35,23 @@ import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
 import org.apache.cayenne.unit.di.server.UseServerRuntime;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Test;
 
 import java.sql.Connection;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 /**
  * All tests have been moved to corresponding loaders tests.
  */
 @UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
 public class DbLoaderIT extends ServerCase {
 
-    public static final DbLoaderConfiguration CONFIG = new DbLoaderConfiguration();
+    private static final DbLoaderConfiguration CONFIG = new DbLoaderConfiguration();
+
     @Inject
     private ServerRuntime runtime;
 
@@ -58,19 +66,45 @@ public class DbLoaderIT extends ServerCase {
 
     private Connection connection;
 
-    private static String msgForTypeMismatch(DbAttribute origAttr, DbAttribute newAttr) {
-        return msgForTypeMismatch(origAttr.getType(), newAttr);
-    }
 
-    private static 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 + ">");
+    /**
+     * Test that parts of loader are in place
+     */
+    @Test
+    public void testSimpleLoad() throws Exception {
+        DbLoader loader = createDbLoader(true, true);
+        DataMap loaded = loader.load();
+        assertNotNull(loaded);
+        assertEquals("__generated_by_dbloader__", loaded.getName());
+
+        // DbEntity
+        DbEntity artist = loaded.getDbEntity("ARTIST");
+        assertNotNull(artist);
+
+        // DbAttribute
+        DbAttribute id = artist.getAttribute("ARTIST_ID");
+        assertNotNull(id);
+        assertTrue(id.isMandatory());
+        assertTrue(id.isPrimaryKey());
+
+        DbAttribute name = artist.getAttribute("ARTIST_NAME");
+        assertNotNull(name);
+        assertTrue(name.isMandatory());
+
+        DbAttribute date = artist.getAttribute("DATE_OF_BIRTH");
+        assertNotNull(date);
+        assertFalse(date.isMandatory());
+
+        // DbRelationship
+        assertEquals(4, artist.getRelationships().size());
+
+        DbRelationship exhibits = artist.getRelationship("artistExhibits");
+        assertNotNull(exhibits);
+        assertEquals("ARTIST_EXHIBIT", exhibits.getTargetEntityName());
+        DbEntity target = exhibits.getTargetEntity();
+        assertNotNull(target);
     }
 
-    private static String attrMismatch(String attrName, String msg) {
-        return "[Error loading attribute '" + attrName + "': " + msg + "]";
-    }
 
     @Before
     public void before() throws Exception {
@@ -85,21 +119,4 @@ public class DbLoaderIT extends ServerCase {
     public void after() throws Exception {
         connection.close();
     }
-
-    private void assertUniqueConstraintsInRelationships(DataMap map) {
-        // unfortunately JDBC metadata doesn't provide info for UNIQUE
-        // constraints....
-        // cant reengineer them...
-        // upd. actually it's provided:
-        // http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getIndexInfo%28java.lang.String,%20java.lang.String,%20java.lang.String,%20boolean,%20boolean%29
-
-        // 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());
-         */
-    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/41515467/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipsLoaderIT.java
----------------------------------------------------------------------
diff --git a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipsLoaderIT.java
b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipsLoaderIT.java
index a73833e..e983f09 100644
--- a/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipsLoaderIT.java
+++ b/cayenne-dbsync/src/test/java/org/apache/cayenne/dbsync/reverse/dbload/RelationshipsLoaderIT.java
@@ -79,4 +79,20 @@ public class RelationshipsLoaderIT extends BaseLoaderIT {
         assertTrue("Relationship to PAINTING_INFO must be to-one", oneToOne.isToDependentPK());
     }
 
+//    private void assertUniqueConstraintsInRelationships(DataMap map) {
+        // unfortunately JDBC metadata doesn't provide info for UNIQUE
+        // constraints....
+        // cant reengineer them...
+        // upd. actually it's provided:
+        // http://docs.oracle.com/javase/7/docs/api/java/sql/DatabaseMetaData.html#getIndexInfo%28java.lang.String,%20java.lang.String,%20java.lang.String,%20boolean,%20boolean%29
+
+        // 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());
+         */
+//    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/41515467/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
index 0f49e49..462ceef 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DbLoaderHelper.java
@@ -68,7 +68,7 @@ import java.util.Collections;
 import java.util.List;
 
 /**
- * Stateful helper class that encapsulates access to DbLoader2.
+ * Stateful helper class that encapsulates access to DbLoader.
  */
 public class DbLoaderHelper {
 


Mime
View raw message