merge: backport junit fixes from trunk.
 * fix NPE in objEntity.getDbEntity()
 * fix psql case issue


git-svn-id: https://svn.apache.org/repos/asf/cayenne/main/tags/3.0M3@615415 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/cayenne/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java b/cayenne/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java
index 2c97ec1..9546e20 100644
--- a/cayenne/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java
+++ b/cayenne/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/merge/AbstractToModelToken.java
@@ -50,6 +50,9 @@
         Set<ObjEntity> objEntities = new HashSet<ObjEntity>();
         MappingNamespace mns = entity.getDataMap().getNamespace();
         for (ObjEntity objEntity : mns.getObjEntities()) {
+            if (objEntity.getDbEntity() == null) {
+                continue;
+            }
             if (objEntity.getDbEntity().equals(entity)) {
                 objEntities.add(objEntity);
             }
diff --git a/cayenne/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/CreateTableToModelTest.java b/cayenne/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/CreateTableToModelTest.java
index 3ffba7d..4ad9ff1 100644
--- a/cayenne/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/CreateTableToModelTest.java
+++ b/cayenne/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/merge/CreateTableToModelTest.java
@@ -60,6 +60,9 @@
 
         ObjEntity objEntity = null;
         for (ObjEntity candiate : map.getObjEntities()) {
+            if (candiate.getDbEntity() == null) {
+                continue;
+            }
             if (candiate.getDbEntity().getName().equalsIgnoreCase(dbEntity.getName())) {
                 objEntity = candiate;
                 break;
@@ -79,6 +82,8 @@
         // clear up
         map.removeObjEntity(objEntity.getName(), true);
         map.removeDbEntity(dbEntity.getName(), true);
+        // fix psql case issue
+        map.removeDbEntity(objEntity.getDbEntity().getName(), true);
         ctxt.getEntityResolver().clearCache();
         assertNull(map.getObjEntity(objEntity.getName()));
         assertNull(map.getDbEntity(dbEntity.getName()));