cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [08/48] Installing Maven Failsafe Plugin
Date Sun, 02 Nov 2014 07:09:56 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/DbEntityTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/DbEntityTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/DbEntityTest.java
deleted file mode 100644
index 6bdcda6..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/DbEntityTest.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.map;
-
-import java.util.Collection;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.apache.cayenne.util.Util;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DbEntityTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    public void testSerializability() throws Exception {
-        DbEntity entity = new DbEntity("entity");
-
-        DbAttribute pk = new DbAttribute("pk");
-        pk.setPrimaryKey(true);
-        entity.addAttribute(pk);
-
-        DbAttribute generated = new DbAttribute("generated");
-        generated.setGenerated(true);
-        entity.addAttribute(generated);
-
-        DbEntity d2 = Util.cloneViaSerialization(entity);
-
-        assertNotNull(d2.getPrimaryKeys());
-        assertEquals(entity.getPrimaryKeys().size(), d2.getPrimaryKeys().size());
-
-        DbAttribute pk2 = d2.getAttribute(pk.getName());
-        assertNotNull(pk2);
-        assertTrue(d2.getPrimaryKeys().contains(pk2));
-
-        assertNotNull(d2.getGeneratedAttributes());
-        assertEquals(entity.getGeneratedAttributes().size(), d2.getGeneratedAttributes().size());
-
-        DbAttribute generated2 = d2.getAttribute(generated.getName());
-        assertNotNull(generated2);
-        assertTrue(d2.getGeneratedAttributes().contains(generated2));
-    }
-
-    public void testConstructor1() {
-        DbEntity ent = new DbEntity();
-        assertNull(ent.getName());
-    }
-
-    public void testConstructor2() {
-        DbEntity ent = new DbEntity("abc");
-        assertEquals("abc", ent.getName());
-    }
-
-    public void testCatalog() {
-        String tstName = "tst_name";
-        DbEntity ent = new DbEntity("abc");
-        ent.setCatalog(tstName);
-        assertEquals(tstName, ent.getCatalog());
-    }
-
-    public void testSchema() {
-        String tstName = "tst_name";
-        DbEntity ent = new DbEntity("abc");
-        ent.setSchema(tstName);
-        assertEquals(tstName, ent.getSchema());
-    }
-
-    public void testFullyQualifiedName() {
-
-        DbEntity e1 = new DbEntity("e1");
-        assertEquals("e1", e1.getFullyQualifiedName());
-
-        DbEntity e2 = new DbEntity("e2");
-        e2.setSchema("s2");
-        assertEquals("e2", e2.getName());
-        assertEquals("s2.e2", e2.getFullyQualifiedName());
-
-        DbEntity e3 = new DbEntity("e3");
-        e3.setSchema("s3");
-        e3.setCatalog("c3");
-        assertEquals("e3", e3.getName());
-        assertEquals("c3.s3.e3", e3.getFullyQualifiedName());
-
-        DbEntity e4 = new DbEntity("e4");
-        e4.setCatalog("c4");
-        assertEquals("e4", e4.getName());
-        assertEquals("c4.e4", e4.getFullyQualifiedName());
-    }
-
-    public void testGetPrimaryKey() {
-        DbEntity ent = new DbEntity("abc");
-
-        DbAttribute a1 = new DbAttribute();
-        a1.setName("a1");
-        a1.setPrimaryKey(false);
-        ent.addAttribute(a1);
-
-        DbAttribute a2 = new DbAttribute();
-        a2.setName("a2");
-        a2.setPrimaryKey(true);
-        ent.addAttribute(a2);
-
-        Collection<DbAttribute> pk = ent.getPrimaryKeys();
-        assertNotNull(pk);
-        assertEquals(1, pk.size());
-        assertSame(a2, pk.iterator().next());
-    }
-
-    public void testAddPKAttribute() {
-        DbEntity ent = new DbEntity("abc");
-
-        DbAttribute a1 = new DbAttribute();
-        a1.setName("a1");
-        a1.setPrimaryKey(false);
-
-        assertTrue(ent.getPrimaryKeys().isEmpty());
-        ent.addAttribute(a1);
-        assertTrue(ent.getPrimaryKeys().isEmpty());
-    }
-
-    public void testChangeAttributeToPK() {
-        DbEntity ent = new DbEntity("abc");
-
-        DbAttribute a1 = new DbAttribute();
-        a1.setName("a1");
-        a1.setPrimaryKey(false);
-        ent.addAttribute(a1);
-
-        assertFalse(ent.getPrimaryKeys().contains(a1));
-        a1.setPrimaryKey(true);
-        assertTrue(ent.getPrimaryKeys().contains(a1));
-    }
-
-    public void testChangePKAttribute() {
-        DbEntity ent = new DbEntity("abc");
-
-        DbAttribute a1 = new DbAttribute();
-        a1.setName("a1");
-        a1.setPrimaryKey(true);
-        ent.addAttribute(a1);
-
-        assertTrue(ent.getPrimaryKeys().contains(a1));
-        a1.setPrimaryKey(false);
-        assertFalse(ent.getPrimaryKeys().contains(a1));
-    }
-
-    public void testRemoveAttribute() {
-        DbEntity ent = new DbEntity("abc");
-
-        DataMap map = new DataMap("map");
-        ent.setName("ent");
-        map.addDbEntity(ent);
-
-        DbAttribute a1 = new DbAttribute();
-        a1.setName("a1");
-        a1.setPrimaryKey(false);
-        ent.addAttribute(a1);
-
-        DbEntity otherEntity = new DbEntity("22ent1");
-        assertNotNull(otherEntity.getName());
-        map.addDbEntity(otherEntity);
-        DbAttribute a11 = new DbAttribute();
-        a11.setName("a11");
-        a11.setPrimaryKey(false);
-        otherEntity.addAttribute(a11);
-
-        DbRelationship rel = new DbRelationship("relfrom");
-        ent.addRelationship(rel);
-        rel.setTargetEntity(otherEntity);
-        rel.addJoin(new DbJoin(rel, "a1", "a11"));
-
-        DbRelationship rel1 = new DbRelationship("relto");
-        otherEntity.addRelationship(rel1);
-        rel1.setTargetEntity(ent);
-        rel1.addJoin(new DbJoin(rel1, "a11", "a1"));
-
-        // check that the test case is working
-        assertSame(a1, ent.getAttribute(a1.getName()));
-        assertSame(rel, ent.getRelationship(rel.getName()));
-
-        // test removal
-        ent.removeAttribute(a1.getName());
-
-        assertNull(ent.getAttribute(a1.getName()));
-        assertEquals(0, rel1.getJoins().size());
-        assertEquals(0, rel.getJoins().size());
-    }
-
-    public void testTranslateToRelatedEntityIndependentPath() {
-        DbEntity artistE = runtime.getDataDomain().getEntityResolver().getDbEntity("ARTIST");
-
-        Expression e1 = Expression.fromString("db:paintingArray");
-        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray");
-        assertEquals("failure: " + translated, Expression.fromString("db:toArtist.paintingArray"), translated);
-    }
-
-    public void testTranslateToRelatedEntityTrimmedPath() {
-        DbEntity artistE = runtime.getDataDomain().getEntityResolver().getDbEntity("ARTIST");
-
-        Expression e1 = Expression.fromString("db:artistExhibitArray.toExhibit");
-        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray");
-        assertEquals("failure: " + translated, Expression.fromString("db:toArtist.artistExhibitArray.toExhibit"),
-                translated);
-    }
-
-    public void testTranslateToRelatedEntitySplitHalfWay() {
-        DbEntity artistE = runtime.getDataDomain().getEntityResolver().getDbEntity("ARTIST");
-
-        Expression e1 = Expression.fromString("db:paintingArray.toPaintingInfo.TEXT_REVIEW");
-        Expression translated = artistE.translateToRelatedEntity(e1, "paintingArray.toGallery");
-        assertEquals("failure: " + translated,
-                Expression.fromString("db:paintingArray.toArtist.paintingArray.toPaintingInfo.TEXT_REVIEW"), translated);
-    }
-
-    public void testTranslateToRelatedEntityMatchingPath() {
-        DbEntity artistE = runtime.getDataDomain().getEntityResolver().getDbEntity("ARTIST");
-
-        Expression e1 = Expression.fromString("db:artistExhibitArray.toExhibit");
-        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray.toExhibit");
-
-        assertEquals("failure: " + translated,
-                Expression.fromString("db:artistExhibitArray.toArtist.artistExhibitArray.toExhibit"), translated);
-    }
-
-    public void testTranslateToRelatedEntityToOne() {
-        DbEntity paintingE = runtime.getDataDomain().getEntityResolver().getDbEntity("PAINTING");
-
-        Expression e1 = Expression.fromString("db:toArtist.ARTIST_NAME = 'aa'");
-        Expression translated = paintingE.translateToRelatedEntity(e1, "toArtist");
-
-        assertEquals("failure: " + translated, Expression.fromString("db:ARTIST_NAME = 'aa'"), translated);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipIT.java
new file mode 100644
index 0000000..71a192a
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipIT.java
@@ -0,0 +1,110 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class DbRelationshipIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    protected DbEntity artistEnt;
+    protected DbEntity paintingEnt;
+    protected DbEntity galleryEnt;
+
+    @Override
+    public void setUpAfterInjection() throws Exception {
+        artistEnt = runtime.getDataDomain().getEntityResolver().getDbEntity("ARTIST");
+        paintingEnt = runtime.getDataDomain().getEntityResolver().getDbEntity("PAINTING");
+        galleryEnt = runtime.getDataDomain().getEntityResolver().getDbEntity("GALLERY");
+    }
+
+    public void testSrcFkSnapshotWithTargetSnapshot() throws Exception {
+        Map<String, Object> map = new HashMap<String, Object>();
+        Integer id = new Integer(44);
+        map.put("GALLERY_ID", id);
+
+        DbRelationship dbRel = galleryEnt.getRelationship("paintingArray");
+        Map<String, Object> targetMap = dbRel.getReverseRelationship().srcFkSnapshotWithTargetSnapshot(map);
+        assertEquals(id, targetMap.get("GALLERY_ID"));
+    }
+
+    public void testGetReverseRelationship1() throws Exception {
+        // start with "to many"
+        DbRelationship r1 = artistEnt.getRelationship("paintingArray");
+        DbRelationship r2 = r1.getReverseRelationship();
+
+        assertNotNull(r2);
+        assertSame(paintingEnt.getRelationship("toArtist"), r2);
+    }
+
+    public void testGetReverseRelationship2() throws Exception {
+        // start with "to one"
+        DbRelationship r1 = paintingEnt.getRelationship("toArtist");
+        DbRelationship r2 = r1.getReverseRelationship();
+
+        assertNotNull(r2);
+        assertSame(artistEnt.getRelationship("paintingArray"), r2);
+    }
+
+    public void testGetReverseRelationshipToSelf() {
+
+        // assemble mockup entity
+        DataMap namespace = new DataMap();
+        DbEntity e = new DbEntity("test");
+        namespace.addDbEntity(e);
+        DbRelationship rforward = new DbRelationship("rforward");
+        e.addRelationship(rforward);
+        rforward.setSourceEntity(e);
+        rforward.setTargetEntity(e);
+
+        assertNull(rforward.getReverseRelationship());
+
+        // add a joins
+        e.addAttribute(new DbAttribute("a1"));
+        e.addAttribute(new DbAttribute("a2"));
+        rforward.addJoin(new DbJoin(rforward, "a1", "a2"));
+
+        assertNull(rforward.getReverseRelationship());
+
+        // create reverse
+
+        DbRelationship rback = new DbRelationship("rback");
+        e.addRelationship(rback);
+        rback.setSourceEntity(e);
+        rback.setTargetEntity(e);
+
+        assertNull(rforward.getReverseRelationship());
+
+        // create reverse join
+        rback.addJoin(new DbJoin(rback, "a2", "a1"));
+
+        assertSame(rback, rforward.getReverseRelationship());
+        assertSame(rforward, rback.getReverseRelationship());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipTest.java
deleted file mode 100644
index 6109725..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/DbRelationshipTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.map;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class DbRelationshipTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    protected DbEntity artistEnt;
-    protected DbEntity paintingEnt;
-    protected DbEntity galleryEnt;
-
-    @Override
-    public void setUpAfterInjection() throws Exception {
-        artistEnt = runtime.getDataDomain().getEntityResolver().getDbEntity("ARTIST");
-        paintingEnt = runtime.getDataDomain().getEntityResolver().getDbEntity("PAINTING");
-        galleryEnt = runtime.getDataDomain().getEntityResolver().getDbEntity("GALLERY");
-    }
-
-    public void testSrcFkSnapshotWithTargetSnapshot() throws Exception {
-        Map<String, Object> map = new HashMap<String, Object>();
-        Integer id = new Integer(44);
-        map.put("GALLERY_ID", id);
-
-        DbRelationship dbRel = galleryEnt.getRelationship("paintingArray");
-        Map<String, Object> targetMap = dbRel.getReverseRelationship().srcFkSnapshotWithTargetSnapshot(map);
-        assertEquals(id, targetMap.get("GALLERY_ID"));
-    }
-
-    public void testGetReverseRelationship1() throws Exception {
-        // start with "to many"
-        DbRelationship r1 = artistEnt.getRelationship("paintingArray");
-        DbRelationship r2 = r1.getReverseRelationship();
-
-        assertNotNull(r2);
-        assertSame(paintingEnt.getRelationship("toArtist"), r2);
-    }
-
-    public void testGetReverseRelationship2() throws Exception {
-        // start with "to one"
-        DbRelationship r1 = paintingEnt.getRelationship("toArtist");
-        DbRelationship r2 = r1.getReverseRelationship();
-
-        assertNotNull(r2);
-        assertSame(artistEnt.getRelationship("paintingArray"), r2);
-    }
-
-    public void testGetReverseRelationshipToSelf() {
-
-        // assemble mockup entity
-        DataMap namespace = new DataMap();
-        DbEntity e = new DbEntity("test");
-        namespace.addDbEntity(e);
-        DbRelationship rforward = new DbRelationship("rforward");
-        e.addRelationship(rforward);
-        rforward.setSourceEntity(e);
-        rforward.setTargetEntity(e);
-
-        assertNull(rforward.getReverseRelationship());
-
-        // add a joins
-        e.addAttribute(new DbAttribute("a1"));
-        e.addAttribute(new DbAttribute("a2"));
-        rforward.addJoin(new DbJoin(rforward, "a1", "a2"));
-
-        assertNull(rforward.getReverseRelationship());
-
-        // create reverse
-
-        DbRelationship rback = new DbRelationship("rback");
-        e.addRelationship(rback);
-        rback.setSourceEntity(e);
-        rback.setTargetEntity(e);
-
-        assertNull(rforward.getReverseRelationship());
-
-        // create reverse join
-        rback.addJoin(new DbJoin(rback, "a2", "a1"));
-
-        assertSame(rback, rforward.getReverseRelationship());
-        assertSame(rforward, rback.getReverseRelationship());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityIT.java
new file mode 100644
index 0000000..b235267
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityIT.java
@@ -0,0 +1,204 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.map;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.util.CayenneMapEntry;
+import org.apache.cayenne.util.Util;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class EntityIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    public void testSerializability() throws Exception {
+        Entity entity = new MockEntity("entity");
+
+        Entity d1 = Util.cloneViaSerialization(entity);
+        assertEquals(entity.getName(), d1.getName());
+
+        entity.addAttribute(new MockAttribute("abc"));
+        entity.addRelationship(new MockRelationship("xyz"));
+        Entity d2 = Util.cloneViaSerialization(entity);
+        assertNotNull(d2.getAttribute("abc"));
+
+        // test that ref collection wrappers are still working
+        assertNotNull(d2.getAttributes());
+        assertEquals(entity.getAttributes().size(), d2.getAttributes().size());
+        assertTrue(d2.getAttributes().contains(d2.getAttribute("abc")));
+
+        assertNotNull(d2.getRelationships());
+        assertEquals(entity.getRelationships().size(), d2.getRelationships().size());
+        assertTrue(d2.getRelationships().contains(d2.getRelationship("xyz")));
+
+        assertNotNull(d2.getAttributeMap());
+        assertEquals(entity.getAttributes().size(), d2.getAttributeMap().size());
+        assertSame(d2.getAttribute("abc"), d2.getAttributeMap().get("abc"));
+
+        assertNotNull(d2.getRelationshipMap());
+        assertEquals(entity.getRelationships().size(), d2.getRelationshipMap().size());
+        assertSame(d2.getRelationship("xyz"), d2.getRelationshipMap().get("xyz"));
+    }
+
+    public void testName() {
+        Entity entity = new MockEntity();
+        String tstName = "tst_name";
+        entity.setName(tstName);
+        assertEquals(tstName, entity.getName());
+    }
+
+    public void testAttribute() {
+        Entity entity = new MockEntity();
+        Attribute attribute = new MockAttribute("tst_name");
+
+        entity.addAttribute(attribute);
+        assertSame(attribute, entity.getAttribute(attribute.getName()));
+
+        // attribute must have its entity switched to our entity.
+        assertSame(entity, attribute.getEntity());
+
+        // remove attribute
+        entity.removeAttribute(attribute.getName());
+        assertNull(entity.getAttribute(attribute.getName()));
+    }
+
+    public void testRelationship() {
+        Entity entity = new MockEntity();
+        Relationship rel = new MockRelationship("tst_name");
+
+        entity.addRelationship(rel);
+        assertSame(rel, entity.getRelationship(rel.getName()));
+
+        // attribute must have its entity switched to our entity.
+        assertSame(entity, rel.getSourceEntity());
+
+        // remove attribute
+        entity.removeRelationship(rel.getName());
+        assertNull(entity.getRelationship(rel.getName()));
+    }
+
+    public void testAttributeClashWithRelationship() {
+        Entity entity = new MockEntity();
+        Relationship rel = new MockRelationship("tst_name");
+
+        entity.addRelationship(rel);
+
+        try {
+            Attribute attribute = new MockAttribute("tst_name");
+            entity.addAttribute(attribute);
+
+            fail("Exception should have been thrown due to clashing attribute and relationship names.");
+        } catch (Exception e) {
+            // Exception expected.
+        }
+    }
+
+    public void testRelationshipClashWithAttribute() {
+        Entity entity = new MockEntity();
+        Attribute attribute = new MockAttribute("tst_name");
+
+        entity.addAttribute(attribute);
+
+        try {
+            Relationship rel = new MockRelationship("tst_name");
+            entity.addRelationship(rel);
+
+            fail("Exception should have been thrown due to clashing attribute and relationship names.");
+        } catch (Exception e) {
+            // Exception expected.
+        }
+    }
+
+    public void testResolveBadObjPath1() {
+        // test invalid expression path
+        Expression pathExpr = ExpressionFactory.expressionOfType(Expression.OBJ_PATH);
+        pathExpr.setOperand(0, "invalid.invalid");
+
+        // itertator should be returned, but when trying to read 1st component,
+        // it should throw an exception....
+        ObjEntity galleryEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Gallery");
+        Iterator<CayenneMapEntry> it = galleryEnt.resolvePathComponents(pathExpr);
+        assertTrue(it.hasNext());
+
+        try {
+            it.next();
+            fail();
+        } catch (Exception ex) {
+            // exception expected
+        }
+    }
+
+    public void testResolveBadObjPath2() {
+        // test invalid expression type
+        Expression badPathExpr = ExpressionFactory.expressionOfType(Expression.IN);
+        badPathExpr.setOperand(0, "a.b.c");
+        ObjEntity galleryEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Gallery");
+
+        try {
+            galleryEnt.resolvePathComponents(badPathExpr);
+            fail();
+        } catch (Exception ex) {
+            // exception expected
+        }
+    }
+
+    public void testResolveObjPath1() {
+        Expression pathExpr = ExpressionFactory.expressionOfType(Expression.OBJ_PATH);
+        pathExpr.setOperand(0, "galleryName");
+
+        ObjEntity galleryEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Gallery");
+        Iterator<CayenneMapEntry> it = galleryEnt.resolvePathComponents(pathExpr);
+
+        // iterator must contain a single ObjAttribute
+        assertNotNull(it);
+        assertTrue(it.hasNext());
+        ObjAttribute next = (ObjAttribute) it.next();
+        assertNotNull(next);
+        assertFalse(it.hasNext());
+        assertSame(galleryEnt.getAttribute("galleryName"), next);
+    }
+
+    public void testRemoveAttribute() {
+        Entity entity = new MockEntity();
+
+        entity.setName("test");
+        ObjAttribute attribute1 = new ObjAttribute("a1");
+        ObjAttribute attribute2 = new ObjAttribute("a2");
+
+        entity.addAttribute(attribute1);
+        entity.addAttribute(attribute2);
+
+        Collection<? extends Attribute> attributes = entity.getAttributes();
+        assertEquals(2, attributes.size());
+
+        entity.removeAttribute("a1");
+        attributes = entity.getAttributes();
+        assertEquals(1, attributes.size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorIT.java
new file mode 100644
index 0000000..6cb3bcb
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorIT.java
@@ -0,0 +1,95 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.reflect.ArcProperty;
+import org.apache.cayenne.reflect.ClassDescriptor;
+import org.apache.cayenne.reflect.ClassDescriptorFactory;
+import org.apache.cayenne.reflect.LazyClassDescriptorDecorator;
+import org.apache.cayenne.reflect.PropertyDescriptor;
+import org.apache.cayenne.testdo.mt.MtTable1;
+import org.apache.cayenne.testdo.mt.MtTable2;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@UseServerRuntime(ServerCase.MULTI_TIER_PROJECT)
+public class EntityResolverClassDescriptorIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    public void testServerDescriptorCaching() {
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+        resolver.getClassDescriptorMap().clearDescriptors();
+
+        ClassDescriptor descriptor = resolver.getClassDescriptor("MtTable1");
+        assertNotNull(descriptor);
+        assertSame(descriptor, resolver.getClassDescriptor("MtTable1"));
+        resolver.getClassDescriptorMap().clearDescriptors();
+
+        ClassDescriptor descriptor1 = resolver.getClassDescriptor("MtTable1");
+        assertNotNull(descriptor1);
+        assertNotSame(descriptor, descriptor1);
+    }
+
+    public void testServerDescriptorFactory() {
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+        resolver.getClassDescriptorMap().clearDescriptors();
+
+        ClassDescriptor descriptor = mock(ClassDescriptor.class);
+        ClassDescriptorFactory factory = mock(ClassDescriptorFactory.class);
+        when(factory.getDescriptor("MtTable1")).thenReturn(descriptor);
+        
+        resolver.getClassDescriptorMap().addFactory(factory);
+        try {
+            ClassDescriptor resolved = resolver.getClassDescriptor("MtTable1");
+            assertNotNull(resolved);
+            resolved = ((LazyClassDescriptorDecorator) resolved).getDescriptor();
+            assertSame(descriptor, resolved);
+        }
+        finally {
+            resolver.getClassDescriptorMap().removeFactory(factory);
+        }
+    }
+
+    public void testArcProperties() {
+        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+        resolver.getClassDescriptorMap().clearDescriptors();
+
+        ClassDescriptor descriptor = resolver.getClassDescriptor("MtTable1");
+        assertNotNull(descriptor);
+
+        PropertyDescriptor p = descriptor.getProperty(MtTable1.TABLE2ARRAY_PROPERTY);
+        assertTrue(p instanceof ArcProperty);
+
+        ClassDescriptor target = ((ArcProperty) p).getTargetDescriptor();
+        assertNotNull(target);
+        assertSame(resolver.getClassDescriptor("MtTable2"), target);
+        assertNotNull(((ArcProperty) p).getComplimentaryReverseArc());
+        assertEquals(MtTable2.TABLE1_PROPERTY, ((ArcProperty) p)
+                .getComplimentaryReverseArc()
+                .getName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorTest.java
deleted file mode 100644
index 798a5d7..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverClassDescriptorTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.map;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.reflect.ArcProperty;
-import org.apache.cayenne.reflect.ClassDescriptor;
-import org.apache.cayenne.reflect.ClassDescriptorFactory;
-import org.apache.cayenne.reflect.LazyClassDescriptorDecorator;
-import org.apache.cayenne.reflect.PropertyDescriptor;
-import org.apache.cayenne.testdo.mt.MtTable1;
-import org.apache.cayenne.testdo.mt.MtTable2;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.MULTI_TIER_PROJECT)
-public class EntityResolverClassDescriptorTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    public void testServerDescriptorCaching() {
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-        resolver.getClassDescriptorMap().clearDescriptors();
-
-        ClassDescriptor descriptor = resolver.getClassDescriptor("MtTable1");
-        assertNotNull(descriptor);
-        assertSame(descriptor, resolver.getClassDescriptor("MtTable1"));
-        resolver.getClassDescriptorMap().clearDescriptors();
-
-        ClassDescriptor descriptor1 = resolver.getClassDescriptor("MtTable1");
-        assertNotNull(descriptor1);
-        assertNotSame(descriptor, descriptor1);
-    }
-
-    public void testServerDescriptorFactory() {
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-        resolver.getClassDescriptorMap().clearDescriptors();
-
-        ClassDescriptor descriptor = mock(ClassDescriptor.class);
-        ClassDescriptorFactory factory = mock(ClassDescriptorFactory.class);
-        when(factory.getDescriptor("MtTable1")).thenReturn(descriptor);
-        
-        resolver.getClassDescriptorMap().addFactory(factory);
-        try {
-            ClassDescriptor resolved = resolver.getClassDescriptor("MtTable1");
-            assertNotNull(resolved);
-            resolved = ((LazyClassDescriptorDecorator) resolved).getDescriptor();
-            assertSame(descriptor, resolved);
-        }
-        finally {
-            resolver.getClassDescriptorMap().removeFactory(factory);
-        }
-    }
-
-    public void testArcProperties() {
-        EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
-        resolver.getClassDescriptorMap().clearDescriptors();
-
-        ClassDescriptor descriptor = resolver.getClassDescriptor("MtTable1");
-        assertNotNull(descriptor);
-
-        PropertyDescriptor p = descriptor.getProperty(MtTable1.TABLE2ARRAY_PROPERTY);
-        assertTrue(p instanceof ArcProperty);
-
-        ClassDescriptor target = ((ArcProperty) p).getTargetDescriptor();
-        assertNotNull(target);
-        assertSame(resolver.getClassDescriptor("MtTable2"), target);
-        assertNotNull(((ArcProperty) p).getComplimentaryReverseArc());
-        assertEquals(MtTable2.TABLE1_PROPERTY, ((ArcProperty) p)
-                .getComplimentaryReverseArc()
-                .getName());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackIT.java
new file mode 100644
index 0000000..3497f47
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackIT.java
@@ -0,0 +1,57 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Collections;
+
+@UseServerRuntime(ServerCase.DEFAULT_PROJECT)
+public class EntityResolverGenericStackIT extends ServerCase {
+
+    @Inject
+    private EntityResolver resolver;
+
+    public void testObjEntityLookupDuplicates() {
+
+        DataMap generic = resolver.getDataMap("generic");
+        EntityResolver resolver = new EntityResolver(Collections.singleton(generic));
+
+        ObjEntity g1 = resolver.getObjEntity("Generic1");
+        assertNotNull(g1);
+
+        ObjEntity g2 = resolver.getObjEntity("Generic2");
+        assertNotNull(g2);
+
+        assertNotSame(g1, g2);
+        assertNull(resolver.getObjEntity(Object.class));
+
+        try {
+            resolver.getObjEntity(CayenneDataObject.class);
+            fail("two entities mapped to the same class... resolver must have thrown.");
+        }
+        catch (CayenneRuntimeException e) {
+            // expected
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackTest.java
deleted file mode 100644
index b6f223b..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverGenericStackTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.map;
-
-import java.util.Collections;
-
-import org.apache.cayenne.CayenneDataObject;
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.DEFAULT_PROJECT)
-public class EntityResolverGenericStackTest extends ServerCase {
-
-    @Inject
-    private EntityResolver resolver;
-
-    public void testObjEntityLookupDuplicates() {
-
-        DataMap generic = resolver.getDataMap("generic");
-        EntityResolver resolver = new EntityResolver(Collections.singleton(generic));
-
-        ObjEntity g1 = resolver.getObjEntity("Generic1");
-        assertNotNull(g1);
-
-        ObjEntity g2 = resolver.getObjEntity("Generic2");
-        assertNotNull(g2);
-
-        assertNotSame(g1, g2);
-        assertNull(resolver.getObjEntity(Object.class));
-
-        try {
-            resolver.getObjEntity(CayenneDataObject.class);
-            fail("two entities mapped to the same class... resolver must have thrown.");
-        }
-        catch (CayenneRuntimeException e) {
-            // expected
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java
new file mode 100644
index 0000000..910c10f
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverIT.java
@@ -0,0 +1,171 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.MockQuery;
+import org.apache.cayenne.query.Query;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class EntityResolverIT extends ServerCase {
+
+    @Inject
+    private ServerRuntime runtime;
+
+    @Inject
+    private DataContext context;
+
+    public void testGetObjEntity() {
+        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
+        assertIsArtistObjEntity(resolver.getObjEntity("Artist"));
+    }
+
+    public void testLookupObjEntityByClass() {
+        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
+        assertIsArtistObjEntity(resolver.getObjEntity(Artist.class));
+    }
+
+    public void testLookupObjEntityByInstance() {
+        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
+        assertIsArtistObjEntity(resolver.getObjEntity(new Artist()));
+    }
+
+    public void testLookupObjEntityByDataobject() {
+        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
+        Artist artist = (Artist) context.newObject("Artist");
+        assertIsArtistObjEntity(resolver.getObjEntity(artist));
+    }
+
+    public void testGetDataMapList() {
+        DataMap m1 = new DataMap();
+        DataMap m2 = new DataMap();
+        List list = new ArrayList();
+        list.add(m1);
+        list.add(m2);
+
+        EntityResolver resolver = new EntityResolver(list);
+        Collection<?> maps = resolver.getDataMaps();
+        assertNotNull(maps);
+        assertEquals(2, maps.size());
+        assertTrue(maps.containsAll(list));
+    }
+
+    public void testAddDataMap() {
+
+        // create empty resolver
+        EntityResolver resolver = new EntityResolver();
+        assertEquals(0, resolver.getDataMaps().size());
+        assertNull(resolver.getObjEntity(Object.class));
+
+        DataMap m1 = new DataMap();
+        ObjEntity oe1 = new ObjEntity("test");
+        oe1.setClassName(Object.class.getName());
+        m1.addObjEntity(oe1);
+
+        resolver.addDataMap(m1);
+
+        assertEquals(1, resolver.getDataMaps().size());
+        assertSame(oe1, resolver.getObjEntity(Object.class));
+        assertEquals(resolver, m1.getNamespace());
+    }
+
+    public void testRemoveDataMap() {
+        // create a resolver with a single map
+        DataMap m1 = new DataMap();
+        ObjEntity oe1 = new ObjEntity("test");
+        oe1.setClassName(Object.class.getName());
+        m1.addObjEntity(oe1);
+        List list = new ArrayList();
+        list.add(m1);
+        EntityResolver resolver = new EntityResolver(list);
+
+        assertEquals(1, resolver.getDataMaps().size());
+        assertSame(oe1, resolver.getObjEntity(Object.class));
+
+        resolver.removeDataMap(m1);
+
+        assertEquals(0, resolver.getDataMaps().size());
+        assertNull(resolver.getObjEntity(Object.class));
+    }
+
+    public void testAddObjEntity() {
+        // create a resolver with a single map
+        DataMap m1 = new DataMap();
+        ObjEntity oe1 = new ObjEntity("test1");
+        oe1.setClassName(Object.class.getName());
+        m1.addObjEntity(oe1);
+        List list = new ArrayList();
+        list.add(m1);
+        EntityResolver resolver = new EntityResolver(list);
+
+        assertSame(oe1, resolver.getObjEntity(Object.class));
+
+        ObjEntity oe2 = new ObjEntity("test2");
+        oe2.setClassName(String.class.getName());
+        m1.addObjEntity(oe2);
+
+        assertSame(oe2, resolver.getObjEntity(String.class));
+    }
+
+    public void testGetQuery() {
+        // create a resolver with a single map
+        DataMap m1 = new DataMap();
+        Query q = new MockQuery("query1");
+        m1.addQuery(q);
+
+        EntityResolver resolver = new EntityResolver(Collections.singleton(m1));
+        assertSame(q, resolver.getQuery("query1"));
+
+        // check that the query added on-the-fly will be recognized
+        assertNull(resolver.getQuery("query2"));
+
+        Query q2 = new MockQuery("query2");
+        m1.addQuery(q2);
+        assertSame(q2, resolver.getQuery("query2"));
+    }
+
+    private void assertIsArtistObjEntity(ObjEntity ae) {
+        assertNotNull(ae);
+        assertEquals(ae, getObjEntity("Artist"));
+    }
+
+    private ObjEntity getObjEntity(String objEntityName) {
+        for (DataMap map : runtime.getDataDomain().getDataMaps()) {
+            for (ObjEntity e : map.getObjEntities()) {
+                if (objEntityName.equals(e.getName())) {
+                    return e;
+                }
+            }
+        }
+
+        throw new CayenneRuntimeException("No ObjEntity found: " + objEntityName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceIT.java
new file mode 100644
index 0000000..15c81e8
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceIT.java
@@ -0,0 +1,78 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.map;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.PEOPLE_PROJECT)
+public class EntityResolverInheritanceIT extends ServerCase {
+
+    @Inject
+    private EntityResolver resolver;
+
+    public void testGetAbstractPersonTree() throws Exception {
+        EntityInheritanceTree tree = resolver.getInheritanceTree("AbstractPerson");
+        assertNotNull(tree);
+        assertEquals(2, tree.getChildrenCount());
+        assertSame(resolver.getObjEntity("AbstractPerson"), tree.getEntity());
+    }
+
+    public void testGetEmployeeTree() throws Exception {
+        EntityInheritanceTree tree = resolver.getInheritanceTree("Employee");
+        assertNotNull(tree);
+        assertEquals(1, tree.getChildrenCount());
+        assertSame(resolver.getObjEntity("Employee"), tree.getEntity());
+    }
+
+    public void testGetManagerTree() throws Exception {
+        EntityInheritanceTree tree = resolver.getInheritanceTree("Manager");
+        assertNotNull(tree);
+        assertEquals(0, tree.getChildrenCount());
+    }
+
+    public void testLookupTreeRefresh() throws Exception {
+        ObjEntity super1 = new ObjEntity("super1");
+        ObjEntity sub1 = new ObjEntity("sub1");
+        ObjEntity sub2 = new ObjEntity("sub2");
+
+        super1.setClassName("java.lang.Float");
+
+        sub1.setSuperEntityName("super1");
+        sub1.setClassName("java.lang.Object");
+
+        sub2.setSuperEntityName("super1");
+        sub2.setClassName("java.lang.Integer");
+
+        DataMap map = new DataMap("test");
+        map.addObjEntity(super1);
+        map.addObjEntity(sub1);
+        map.addObjEntity(sub2);
+
+        assertNull(resolver.getInheritanceTree("super1"));
+
+        resolver.addDataMap(map);
+        EntityInheritanceTree tree = resolver.getInheritanceTree("super1");
+        assertNotNull(tree);
+        assertEquals(2, tree.getChildrenCount());
+        assertSame(super1, tree.getEntity());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceTest.java
deleted file mode 100644
index 5f5239f..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverInheritanceTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.map;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.PEOPLE_PROJECT)
-public class EntityResolverInheritanceTest extends ServerCase {
-
-    @Inject
-    private EntityResolver resolver;
-
-    public void testGetAbstractPersonTree() throws Exception {
-        EntityInheritanceTree tree = resolver.getInheritanceTree("AbstractPerson");
-        assertNotNull(tree);
-        assertEquals(2, tree.getChildrenCount());
-        assertSame(resolver.getObjEntity("AbstractPerson"), tree.getEntity());
-    }
-
-    public void testGetEmployeeTree() throws Exception {
-        EntityInheritanceTree tree = resolver.getInheritanceTree("Employee");
-        assertNotNull(tree);
-        assertEquals(1, tree.getChildrenCount());
-        assertSame(resolver.getObjEntity("Employee"), tree.getEntity());
-    }
-
-    public void testGetManagerTree() throws Exception {
-        EntityInheritanceTree tree = resolver.getInheritanceTree("Manager");
-        assertNotNull(tree);
-        assertEquals(0, tree.getChildrenCount());
-    }
-
-    public void testLookupTreeRefresh() throws Exception {
-        ObjEntity super1 = new ObjEntity("super1");
-        ObjEntity sub1 = new ObjEntity("sub1");
-        ObjEntity sub2 = new ObjEntity("sub2");
-
-        super1.setClassName("java.lang.Float");
-
-        sub1.setSuperEntityName("super1");
-        sub1.setClassName("java.lang.Object");
-
-        sub2.setSuperEntityName("super1");
-        sub2.setClassName("java.lang.Integer");
-
-        DataMap map = new DataMap("test");
-        map.addObjEntity(super1);
-        map.addObjEntity(sub1);
-        map.addObjEntity(sub2);
-
-        assertNull(resolver.getInheritanceTree("super1"));
-
-        resolver.addDataMap(map);
-        EntityInheritanceTree tree = resolver.getInheritanceTree("super1");
-        assertNotNull(tree);
-        assertEquals(2, tree.getChildrenCount());
-        assertSame(super1, tree.getEntity());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverTest.java
deleted file mode 100644
index 2156751..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityResolverTest.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.map;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.MockQuery;
-import org.apache.cayenne.query.Query;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class EntityResolverTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    @Inject
-    private DataContext context;
-
-    public void testGetObjEntity() {
-        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
-        assertIsArtistObjEntity(resolver.getObjEntity("Artist"));
-    }
-
-    public void testLookupObjEntityByClass() {
-        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
-        assertIsArtistObjEntity(resolver.getObjEntity(Artist.class));
-    }
-
-    public void testLookupObjEntityByInstance() {
-        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
-        assertIsArtistObjEntity(resolver.getObjEntity(new Artist()));
-    }
-
-    public void testLookupObjEntityByDataobject() {
-        EntityResolver resolver = new EntityResolver(runtime.getDataDomain().getDataMaps());
-        Artist artist = (Artist) context.newObject("Artist");
-        assertIsArtistObjEntity(resolver.getObjEntity(artist));
-    }
-
-    public void testGetDataMapList() {
-        DataMap m1 = new DataMap();
-        DataMap m2 = new DataMap();
-        List list = new ArrayList();
-        list.add(m1);
-        list.add(m2);
-
-        EntityResolver resolver = new EntityResolver(list);
-        Collection<?> maps = resolver.getDataMaps();
-        assertNotNull(maps);
-        assertEquals(2, maps.size());
-        assertTrue(maps.containsAll(list));
-    }
-
-    public void testAddDataMap() {
-
-        // create empty resolver
-        EntityResolver resolver = new EntityResolver();
-        assertEquals(0, resolver.getDataMaps().size());
-        assertNull(resolver.getObjEntity(Object.class));
-
-        DataMap m1 = new DataMap();
-        ObjEntity oe1 = new ObjEntity("test");
-        oe1.setClassName(Object.class.getName());
-        m1.addObjEntity(oe1);
-
-        resolver.addDataMap(m1);
-
-        assertEquals(1, resolver.getDataMaps().size());
-        assertSame(oe1, resolver.getObjEntity(Object.class));
-        assertEquals(resolver, m1.getNamespace());
-    }
-
-    public void testRemoveDataMap() {
-        // create a resolver with a single map
-        DataMap m1 = new DataMap();
-        ObjEntity oe1 = new ObjEntity("test");
-        oe1.setClassName(Object.class.getName());
-        m1.addObjEntity(oe1);
-        List list = new ArrayList();
-        list.add(m1);
-        EntityResolver resolver = new EntityResolver(list);
-
-        assertEquals(1, resolver.getDataMaps().size());
-        assertSame(oe1, resolver.getObjEntity(Object.class));
-
-        resolver.removeDataMap(m1);
-
-        assertEquals(0, resolver.getDataMaps().size());
-        assertNull(resolver.getObjEntity(Object.class));
-    }
-
-    public void testAddObjEntity() {
-        // create a resolver with a single map
-        DataMap m1 = new DataMap();
-        ObjEntity oe1 = new ObjEntity("test1");
-        oe1.setClassName(Object.class.getName());
-        m1.addObjEntity(oe1);
-        List list = new ArrayList();
-        list.add(m1);
-        EntityResolver resolver = new EntityResolver(list);
-
-        assertSame(oe1, resolver.getObjEntity(Object.class));
-
-        ObjEntity oe2 = new ObjEntity("test2");
-        oe2.setClassName(String.class.getName());
-        m1.addObjEntity(oe2);
-
-        assertSame(oe2, resolver.getObjEntity(String.class));
-    }
-
-    public void testGetQuery() {
-        // create a resolver with a single map
-        DataMap m1 = new DataMap();
-        Query q = new MockQuery("query1");
-        m1.addQuery(q);
-
-        EntityResolver resolver = new EntityResolver(Collections.singleton(m1));
-        assertSame(q, resolver.getQuery("query1"));
-
-        // check that the query added on-the-fly will be recognized
-        assertNull(resolver.getQuery("query2"));
-
-        Query q2 = new MockQuery("query2");
-        m1.addQuery(q2);
-        assertSame(q2, resolver.getQuery("query2"));
-    }
-
-    private void assertIsArtistObjEntity(ObjEntity ae) {
-        assertNotNull(ae);
-        assertEquals(ae, getObjEntity("Artist"));
-    }
-
-    private ObjEntity getObjEntity(String objEntityName) {
-        for (DataMap map : runtime.getDataDomain().getDataMaps()) {
-            for (ObjEntity e : map.getObjEntities()) {
-                if (objEntityName.equals(e.getName())) {
-                    return e;
-                }
-            }
-        }
-
-        throw new CayenneRuntimeException("No ObjEntity found: " + objEntityName);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/EntityTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityTest.java b/cayenne-server/src/test/java/org/apache/cayenne/map/EntityTest.java
deleted file mode 100644
index 7b404b8..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/map/EntityTest.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.map;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.apache.cayenne.util.CayenneMapEntry;
-import org.apache.cayenne.util.Util;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class EntityTest extends ServerCase {
-
-    @Inject
-    private ServerRuntime runtime;
-
-    public void testSerializability() throws Exception {
-        Entity entity = new MockEntity("entity");
-
-        Entity d1 = Util.cloneViaSerialization(entity);
-        assertEquals(entity.getName(), d1.getName());
-
-        entity.addAttribute(new MockAttribute("abc"));
-        entity.addRelationship(new MockRelationship("xyz"));
-        Entity d2 = Util.cloneViaSerialization(entity);
-        assertNotNull(d2.getAttribute("abc"));
-
-        // test that ref collection wrappers are still working
-        assertNotNull(d2.getAttributes());
-        assertEquals(entity.getAttributes().size(), d2.getAttributes().size());
-        assertTrue(d2.getAttributes().contains(d2.getAttribute("abc")));
-
-        assertNotNull(d2.getRelationships());
-        assertEquals(entity.getRelationships().size(), d2.getRelationships().size());
-        assertTrue(d2.getRelationships().contains(d2.getRelationship("xyz")));
-
-        assertNotNull(d2.getAttributeMap());
-        assertEquals(entity.getAttributes().size(), d2.getAttributeMap().size());
-        assertSame(d2.getAttribute("abc"), d2.getAttributeMap().get("abc"));
-
-        assertNotNull(d2.getRelationshipMap());
-        assertEquals(entity.getRelationships().size(), d2.getRelationshipMap().size());
-        assertSame(d2.getRelationship("xyz"), d2.getRelationshipMap().get("xyz"));
-    }
-
-    public void testName() {
-        Entity entity = new MockEntity();
-        String tstName = "tst_name";
-        entity.setName(tstName);
-        assertEquals(tstName, entity.getName());
-    }
-
-    public void testAttribute() {
-        Entity entity = new MockEntity();
-        Attribute attribute = new MockAttribute("tst_name");
-
-        entity.addAttribute(attribute);
-        assertSame(attribute, entity.getAttribute(attribute.getName()));
-
-        // attribute must have its entity switched to our entity.
-        assertSame(entity, attribute.getEntity());
-
-        // remove attribute
-        entity.removeAttribute(attribute.getName());
-        assertNull(entity.getAttribute(attribute.getName()));
-    }
-
-    public void testRelationship() {
-        Entity entity = new MockEntity();
-        Relationship rel = new MockRelationship("tst_name");
-
-        entity.addRelationship(rel);
-        assertSame(rel, entity.getRelationship(rel.getName()));
-
-        // attribute must have its entity switched to our entity.
-        assertSame(entity, rel.getSourceEntity());
-
-        // remove attribute
-        entity.removeRelationship(rel.getName());
-        assertNull(entity.getRelationship(rel.getName()));
-    }
-
-    public void testAttributeClashWithRelationship() {
-        Entity entity = new MockEntity();
-        Relationship rel = new MockRelationship("tst_name");
-
-        entity.addRelationship(rel);
-
-        try {
-            Attribute attribute = new MockAttribute("tst_name");
-            entity.addAttribute(attribute);
-
-            fail("Exception should have been thrown due to clashing attribute and relationship names.");
-        } catch (Exception e) {
-            // Exception expected.
-        }
-    }
-
-    public void testRelationshipClashWithAttribute() {
-        Entity entity = new MockEntity();
-        Attribute attribute = new MockAttribute("tst_name");
-
-        entity.addAttribute(attribute);
-
-        try {
-            Relationship rel = new MockRelationship("tst_name");
-            entity.addRelationship(rel);
-
-            fail("Exception should have been thrown due to clashing attribute and relationship names.");
-        } catch (Exception e) {
-            // Exception expected.
-        }
-    }
-
-    public void testResolveBadObjPath1() {
-        // test invalid expression path
-        Expression pathExpr = ExpressionFactory.expressionOfType(Expression.OBJ_PATH);
-        pathExpr.setOperand(0, "invalid.invalid");
-
-        // itertator should be returned, but when trying to read 1st component,
-        // it should throw an exception....
-        ObjEntity galleryEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Gallery");
-        Iterator<CayenneMapEntry> it = galleryEnt.resolvePathComponents(pathExpr);
-        assertTrue(it.hasNext());
-
-        try {
-            it.next();
-            fail();
-        } catch (Exception ex) {
-            // exception expected
-        }
-    }
-
-    public void testResolveBadObjPath2() {
-        // test invalid expression type
-        Expression badPathExpr = ExpressionFactory.expressionOfType(Expression.IN);
-        badPathExpr.setOperand(0, "a.b.c");
-        ObjEntity galleryEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Gallery");
-
-        try {
-            galleryEnt.resolvePathComponents(badPathExpr);
-            fail();
-        } catch (Exception ex) {
-            // exception expected
-        }
-    }
-
-    public void testResolveObjPath1() {
-        Expression pathExpr = ExpressionFactory.expressionOfType(Expression.OBJ_PATH);
-        pathExpr.setOperand(0, "galleryName");
-
-        ObjEntity galleryEnt = runtime.getDataDomain().getEntityResolver().getObjEntity("Gallery");
-        Iterator<CayenneMapEntry> it = galleryEnt.resolvePathComponents(pathExpr);
-
-        // iterator must contain a single ObjAttribute
-        assertNotNull(it);
-        assertTrue(it.hasNext());
-        ObjAttribute next = (ObjAttribute) it.next();
-        assertNotNull(next);
-        assertFalse(it.hasNext());
-        assertSame(galleryEnt.getAttribute("galleryName"), next);
-    }
-
-    public void testRemoveAttribute() {
-        Entity entity = new MockEntity();
-
-        entity.setName("test");
-        ObjAttribute attribute1 = new ObjAttribute("a1");
-        ObjAttribute attribute2 = new ObjAttribute("a2");
-
-        entity.addAttribute(attribute1);
-        entity.addAttribute(attribute2);
-
-        Collection<? extends Attribute> attributes = entity.getAttributes();
-        assertEquals(2, attributes.size());
-
-        entity.removeAttribute("a1");
-        attributes = entity.getAttributes();
-        assertEquals(1, attributes.size());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/map/ObjEntityIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/map/ObjEntityIT.java b/cayenne-server/src/test/java/org/apache/cayenne/map/ObjEntityIT.java
new file mode 100644
index 0000000..e7d8847
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/map/ObjEntityIT.java
@@ -0,0 +1,431 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.map;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.cayenne.CayenneDataObject;
+import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.exp.Expression;
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.exp.parser.ASTObjPath;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.apache.cayenne.util.Util;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ObjEntityIT extends ServerCase {
+
+    @Inject
+    private ObjectContext context;
+
+    @Inject
+    private ServerRuntime runtime;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+    }
+
+    public void testGetAttributeWithOverrides() {
+
+        DataMap map = new DataMap("dm");
+
+        ObjEntity superEntity = new ObjEntity("super");
+        superEntity.addAttribute(new ObjAttribute("a1", "int", superEntity));
+        superEntity.addAttribute(new ObjAttribute("a2", "int", superEntity));
+
+        map.addObjEntity(superEntity);
+
+        ObjEntity subEntity = new ObjEntity("sub");
+        subEntity.setSuperEntityName(superEntity.getName());
+        subEntity.addAttributeOverride("a1", "overridden.path");
+        subEntity.addAttribute(new ObjAttribute("a3", "int", subEntity));
+
+        map.addObjEntity(subEntity);
+
+        ObjAttribute a1 = subEntity.getAttribute("a1");
+        assertNotNull(a1);
+        assertSame(subEntity, a1.getEntity());
+        assertEquals("overridden.path", a1.getDbAttributePath());
+        assertEquals("int", a1.getType());
+
+        ObjAttribute a2 = subEntity.getAttribute("a2");
+        assertNotNull(a2);
+        assertSame(subEntity, a2.getEntity());
+        assertNull(a2.getDbAttributePath());
+
+        ObjAttribute a3 = subEntity.getAttribute("a3");
+        assertNotNull(a3);
+        assertSame(subEntity, a3.getEntity());
+    }
+
+    public void testGetPrimaryKeys() {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        Collection<ObjAttribute> pks = artistE.getPrimaryKeys();
+        assertEquals(1, pks.size());
+
+        ObjAttribute pk = pks.iterator().next();
+        assertEquals("java.lang.Long", pk.getType());
+        assertEquals("ARTIST_ID", pk.getDbAttributePath());
+        assertEquals("artistId", pk.getName());
+        assertNull(pk.getEntity());
+        assertFalse(artistE.getAttributes().contains(pk));
+
+        ObjEntity clientArtistE = artistE.getClientEntity();
+        Collection<ObjAttribute> clientpks = clientArtistE.getPrimaryKeys();
+        assertEquals(1, clientpks.size());
+        ObjAttribute clientPk = clientpks.iterator().next();
+        assertEquals("java.lang.Long", clientPk.getType());
+        assertEquals("ARTIST_ID", clientPk.getDbAttributePath());
+        assertEquals("artistId", clientPk.getName());
+        assertNull(clientPk.getEntity());
+        assertFalse(clientArtistE.getAttributes().contains(pk));
+
+        ObjEntity meaningfulPKE = runtime.getDataDomain().getEntityResolver().getObjEntity("MeaningfulPKTest1");
+        Collection<ObjAttribute> mpks = meaningfulPKE.getPrimaryKeys();
+        assertEquals(1, mpks.size());
+
+        ObjAttribute mpk = mpks.iterator().next();
+        assertTrue(meaningfulPKE.getAttributes().contains(mpk));
+
+        ObjEntity clientMeaningfulPKE = meaningfulPKE.getClientEntity();
+        Collection<ObjAttribute> clientmpks = clientMeaningfulPKE.getPrimaryKeys();
+        assertEquals(1, clientmpks.size());
+
+        ObjAttribute clientmpk = clientmpks.iterator().next();
+        assertEquals("java.lang.Integer", clientmpk.getType());
+        assertTrue(clientMeaningfulPKE.getAttributes().contains(clientmpk));
+    }
+
+    public void testAttributes() {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        ObjAttribute attr = artistE.getAttribute("artistName");
+
+        assertEquals(attr.getMaxLength(), attr.getDbAttribute().getMaxLength());
+        assertEquals(attr.isMandatory(), attr.getDbAttribute().isMandatory());
+    }
+
+    public void testLastPathComponent() {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+
+        Map<String, String> aliases = new HashMap<String, String>();
+        aliases.put("a", "paintingArray.toGallery");
+
+        PathComponent<ObjAttribute, ObjRelationship> lastAttribute = artistE.lastPathComponent(
+                Expression.fromString("paintingArray.paintingTitle"), aliases);
+        assertTrue(lastAttribute.getAttribute() != null);
+        assertEquals("paintingTitle", lastAttribute.getAttribute().getName());
+
+        PathComponent<ObjAttribute, ObjRelationship> lastRelationship = artistE.lastPathComponent(
+                Expression.fromString("paintingArray.toGallery"), aliases);
+        assertTrue(lastRelationship.getRelationship() != null);
+        assertEquals("toGallery", lastRelationship.getRelationship().getName());
+
+        PathComponent<ObjAttribute, ObjRelationship> lastLeftJoinRelationship = artistE.lastPathComponent(
+                new ASTObjPath("paintingArray+.toGallery+"), aliases);
+        assertTrue(lastLeftJoinRelationship.getRelationship() != null);
+        assertEquals("toGallery", lastLeftJoinRelationship.getRelationship().getName());
+
+        PathComponent<ObjAttribute, ObjRelationship> lastAliasedRelationship = artistE.lastPathComponent(
+                new ASTObjPath("a"), aliases);
+        assertTrue(lastAliasedRelationship.getRelationship() != null);
+        assertEquals("toGallery", lastAliasedRelationship.getRelationship().getName());
+    }
+
+    public void testGeneric() {
+        ObjEntity e1 = new ObjEntity("e1");
+        assertTrue(e1.isGeneric());
+
+        e1.setClassName("SomeClass");
+        assertFalse(e1.isGeneric());
+
+        DataMap m = new DataMap("X");
+        m.setDefaultSuperclass("SomeClass");
+        m.addObjEntity(e1);
+
+        assertTrue(e1.isGeneric());
+
+        e1.setClassName("SomeOtherClass");
+        assertFalse(e1.isGeneric());
+
+        e1.setClassName(CayenneDataObject.class.getName());
+        assertTrue(e1.isGeneric());
+    }
+
+    public void testServerOnly() {
+        ObjEntity e1 = new ObjEntity("e1");
+
+        assertFalse(e1.isServerOnly());
+        e1.setServerOnly(true);
+        assertTrue(e1.isServerOnly());
+    }
+
+    public void testClientAllowed() {
+        ObjEntity e1 = new ObjEntity("e1");
+
+        assertFalse("No parent DataMap should have automatically disabled client.", e1.isClientAllowed());
+
+        DataMap map = new DataMap("m1");
+        e1.setDataMap(map);
+
+        assertFalse(e1.isClientAllowed());
+
+        map.setClientSupported(true);
+        assertTrue(e1.isClientAllowed());
+
+        e1.setServerOnly(true);
+        assertFalse(e1.isClientAllowed());
+    }
+
+    public void testGetPrimaryKeyNames() {
+        ObjEntity entity = new ObjEntity("entity");
+        DbEntity dbentity = new DbEntity("dbe");
+
+        // need a container
+        DataMap dataMap = new DataMap();
+        dataMap.addObjEntity(entity);
+        dataMap.addDbEntity(dbentity);
+        entity.setDbEntity(dbentity);
+
+        // Test correctness with no mapped PK.
+        assertEquals(0, entity.getPrimaryKeyNames().size());
+
+        // Add a single column PK to the DB entity.
+        DbAttribute pk = new DbAttribute();
+        pk.setName("id");
+        pk.setPrimaryKey(true);
+        dbentity.addAttribute(pk);
+
+        // Test correctness with a single column PK.
+        assertEquals(1, entity.getPrimaryKeyNames().size());
+        assertTrue(entity.getPrimaryKeyNames().contains(pk.getName()));
+
+        // Add a multi-column PK to the DB entity.
+        DbAttribute pk2 = new DbAttribute();
+        pk2.setName("id2");
+        pk2.setPrimaryKey(true);
+        dbentity.addAttribute(pk2);
+
+        // Test correctness with a multi-column PK.
+        assertEquals(2, entity.getPrimaryKeyNames().size());
+        assertTrue(entity.getPrimaryKeyNames().contains(pk.getName()));
+        assertTrue(entity.getPrimaryKeyNames().contains(pk2.getName()));
+    }
+
+    public void testGetClientEntity() {
+
+        DataMap map = new DataMap();
+        map.setClientSupported(true);
+
+        final ObjEntity target = new ObjEntity("te1");
+        map.addObjEntity(target);
+
+        ObjEntity e1 = new ObjEntity("entity");
+        e1.setClassName("x.y.z");
+        e1.setClientClassName("a.b.c");
+        e1.addAttribute(new ObjAttribute("A1"));
+        e1.addAttribute(new ObjAttribute("A2"));
+        map.addObjEntity(e1);
+
+        DbEntity dbentity = new DbEntity("dbe");
+        map.addDbEntity(dbentity);
+        e1.setDbEntity(dbentity);
+
+        ObjRelationship r1 = new ObjRelationship("r1") {
+
+            @Override
+            public ObjEntity getTargetEntity() {
+                return target;
+            }
+        };
+
+        e1.addRelationship(r1);
+
+        ObjEntity e2 = e1.getClientEntity();
+        assertNotNull(e2);
+        assertEquals(e1.getName(), e2.getName());
+        assertEquals(e1.getClientClassName(), e2.getClassName());
+        assertEquals(e1.getAttributes().size(), e2.getAttributes().size());
+        assertEquals(e1.getRelationships().size(), e2.getRelationships().size());
+    }
+
+    public void testSerializability() throws Exception {
+        ObjEntity entity = new ObjEntity("entity");
+
+        ObjEntity d1 = Util.cloneViaSerialization(entity);
+        assertEquals(entity.getName(), d1.getName());
+    }
+
+    public void testDbEntityName() {
+        ObjEntity entity = new ObjEntity("entity");
+        assertNull(entity.getDbEntityName());
+
+        entity.setDbEntityName("dbe");
+        assertEquals("dbe", entity.getDbEntityName());
+
+        entity.setDbEntityName(null);
+        assertNull(entity.getDbEntityName());
+    }
+
+    public void testDbEntity() {
+        ObjEntity entity = new ObjEntity("entity");
+        DbEntity dbentity = new DbEntity("dbe");
+
+        // need a container
+        DataMap dataMap = new DataMap();
+        dataMap.addObjEntity(entity);
+        dataMap.addDbEntity(dbentity);
+
+        assertNull(entity.getDbEntity());
+
+        entity.setDbEntity(dbentity);
+        assertSame(dbentity, entity.getDbEntity());
+
+        entity.setDbEntity(null);
+        assertNull(entity.getDbEntity());
+
+        entity.setDbEntityName("dbe");
+        assertSame(dbentity, entity.getDbEntity());
+    }
+
+    public void testDbEntityNoContainer() {
+        ObjEntity entity = new ObjEntity("entity");
+        entity.setDbEntityName("dbe");
+
+        try {
+            entity.getDbEntity();
+            fail("Without a container ObjENtity shouldn't resolve DbEntity");
+        } catch (CayenneRuntimeException ex) {
+            // expected
+        }
+    }
+
+    public void testClassName() {
+        ObjEntity entity = new ObjEntity("entity");
+        String tstName = "tst_name";
+        entity.setClassName(tstName);
+        assertEquals(tstName, entity.getClassName());
+    }
+
+    public void testSuperClassName() {
+        ObjEntity entity = new ObjEntity("entity");
+        String tstName = "super_tst_name";
+        entity.setSuperClassName(tstName);
+        assertEquals(tstName, entity.getSuperClassName());
+    }
+
+    public void testAttributeForDbAttribute() throws Exception {
+        ObjEntity ae = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        DbEntity dae = ae.getDbEntity();
+
+        assertNull(ae.getAttributeForDbAttribute(dae.getAttribute("ARTIST_ID")));
+        assertNotNull(ae.getAttributeForDbAttribute(dae.getAttribute("ARTIST_NAME")));
+    }
+
+    public void testRelationshipForDbRelationship() throws Exception {
+        ObjEntity ae = runtime.getDataDomain().getEntityResolver().getObjEntity("Artist");
+        DbEntity dae = ae.getDbEntity();
+
+        assertNull(ae.getRelationshipForDbRelationship(new DbRelationship()));
+        assertNotNull(ae.getRelationshipForDbRelationship(dae.getRelationship("paintingArray")));
+    }
+
+    public void testReadOnly() throws Exception {
+        ObjEntity entity = new ObjEntity("entity");
+        assertFalse(entity.isReadOnly());
+        entity.setReadOnly(true);
+        assertTrue(entity.isReadOnly());
+    }
+
+    public void testTranslateToRelatedEntityIndependentPath() throws Exception {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity(Artist.class);
+
+        Expression e1 = Expression.fromString("paintingArray");
+        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray");
+        assertEquals("failure: " + translated, Expression.fromString("db:toArtist.paintingArray"), translated);
+    }
+
+    public void testTranslateToRelatedEntityTrimmedPath() throws Exception {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity(Artist.class);
+
+        Expression e1 = Expression.fromString("artistExhibitArray.toExhibit");
+        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray");
+        assertEquals("failure: " + translated, Expression.fromString("db:toArtist.artistExhibitArray.toExhibit"),
+                translated);
+    }
+
+    public void testTranslateToRelatedEntitySplitHalfWay() throws Exception {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity(Artist.class);
+
+        Expression e1 = Expression.fromString("paintingArray.toPaintingInfo.textReview");
+        Expression translated = artistE.translateToRelatedEntity(e1, "paintingArray.toGallery");
+        assertEquals("failure: " + translated,
+                Expression.fromString("db:paintingArray.toArtist.paintingArray.toPaintingInfo.TEXT_REVIEW"), translated);
+    }
+
+    public void testTranslateToRelatedEntityMatchingPath() throws Exception {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity(Artist.class);
+        Expression e1 = Expression.fromString("artistExhibitArray.toExhibit");
+        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray.toExhibit");
+        assertEquals("failure: " + translated,
+                Expression.fromString("db:artistExhibitArray.toArtist.artistExhibitArray.toExhibit"), translated);
+    }
+
+    public void testTranslateToRelatedEntityMultiplePaths() throws Exception {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity(Artist.class);
+
+        Expression e1 = Expression.fromString("paintingArray = $p and artistExhibitArray.toExhibit.closingDate = $d");
+        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray");
+        assertEquals("failure: " + translated, Expression.fromString("db:toArtist.paintingArray = $p "
+                + "and db:toArtist.artistExhibitArray.toExhibit.CLOSING_DATE = $d"), translated);
+    }
+    
+    public void testTranslateToRelatedEntityOuterJoin_Flattened() throws Exception {
+        ObjEntity artistE = runtime.getDataDomain().getEntityResolver().getObjEntity(Artist.class);
+
+        Expression e1 = Expression.fromString("groupArray+.name");
+        Expression translated = artistE.translateToRelatedEntity(e1, "artistExhibitArray");
+        assertEquals("failure: " + translated, Expression.fromString("db:toArtist.artistGroupArray+.toGroup+.NAME"), translated);
+    }
+
+    public void testTranslateNullArg() {
+        ObjEntity entity = context.getEntityResolver().getObjEntity("Artist");
+
+        Expression exp = ExpressionFactory.noMatchExp("dateOfBirth", null);
+        Expression translated = entity.translateToDbPath(exp);
+
+        assertFalse(translated.match(new Artist()));
+    }
+}


Mime
View raw message