Search in sources :

Example 31 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EOModelProcessorTest method testLoadModelWithDependencies.

@Test
public void testLoadModelWithDependencies() throws Exception {
    URL url = getClass().getClassLoader().getResource("wotests/cross-model-relationships.eomodeld/");
    assertNotNull(url);
    DataMap map = processor.loadEOModel(url);
    ObjEntity entity = map.getObjEntity("CrossModelRelTest");
    assertNotNull(entity);
    ObjAttribute a1 = entity.getAttribute("testAttribute");
    assertNotNull(a1);
    DbAttribute da1 = a1.getDbAttribute();
    assertNotNull(da1);
    assertSame(da1, entity.getDbEntity().getAttribute("TEST_ATTRIBUTE"));
    // for now cross model relationships are simply ignored
    // eventually we must handle those...
    assertEquals(0, entity.getRelationships().size());
    assertEquals(0, entity.getDbEntity().getRelationships().size());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbAttribute(org.apache.cayenne.map.DbAttribute) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 32 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EOModelProcessorTest method testLoadFlattened.

@Test
public void testLoadFlattened() throws Exception {
    URL url = getClass().getClassLoader().getResource("wotests/flattened.eomodeld/");
    assertNotNull(url);
    // see CAY-1806
    DataMap map = processor.loadEOModel(url);
    ObjEntity artistE = map.getObjEntity("Artist");
    assertNotNull(artistE);
    assertEquals(2, artistE.getRelationships().size());
    assertNotNull(artistE.getRelationship("exhibitArray"));
    assertNotNull(artistE.getRelationship("artistExhibitArray"));
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 33 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EOModelProcessorTest method assertLoaded.

protected void assertLoaded(String mapName, DataMap map) throws Exception {
    assertNotNull(map);
    assertEquals(mapName, map.getName());
    // check obj entities
    ObjEntity artistE = map.getObjEntity("Artist");
    assertNotNull(artistE);
    assertEquals("Artist", artistE.getName());
    // check Db entities
    DbEntity artistDE = map.getDbEntity("ARTIST");
    DbEntity artistDE1 = artistE.getDbEntity();
    assertSame(artistDE, artistDE1);
    // check attributes
    ObjAttribute a1 = artistE.getAttribute("artistName");
    assertNotNull(a1);
    DbAttribute da1 = a1.getDbAttribute();
    assertNotNull(da1);
    assertSame(da1, artistDE.getAttribute("ARTIST_NAME"));
    // check ObjRelationships
    ObjRelationship rel = artistE.getRelationship("artistExhibitArray");
    assertNotNull(rel);
    assertEquals(1, rel.getDbRelationships().size());
    // check DbRelationships
    DbRelationship drel = artistDE.getRelationship("artistExhibitArray");
    assertNotNull(drel);
    assertSame(drel, rel.getDbRelationships().get(0));
    // flattened relationships
    ObjRelationship frel = artistE.getRelationship("exhibitArray");
    assertNotNull(frel);
    assertEquals(2, frel.getDbRelationships().size());
    // storing data map may uncover some inconsistencies
    PrintWriter mockupWriter = new NullPrintWriter();
    map.encodeAsXML(new XMLEncoder(mockupWriter), new EmptyConfigurationNodeVisitor());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) XMLEncoder(org.apache.cayenne.util.XMLEncoder) EmptyConfigurationNodeVisitor(org.apache.cayenne.configuration.EmptyConfigurationNodeVisitor) DbEntity(org.apache.cayenne.map.DbEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) PrintWriter(java.io.PrintWriter)

Example 34 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EOModelProcessorInheritanceTest method testLoadFlattenedRelationship.

@Test
public void testLoadFlattenedRelationship() throws Exception {
    DataMap map = processor.loadEOModel(url);
    ObjEntity e1 = map.getObjEntity("HelperFlatEntity");
    assertNotNull(e1);
    ObjRelationship fr = (ObjRelationship) e1.getRelationship("singleTables");
    assertNotNull(fr);
    assertEquals("singleTableJoins.toSingleTable", fr.getDbRelationshipPath());
    assertEquals("SingleTableConcreteEntityOne", fr.getTargetEntityName());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Example 35 with ObjEntity

use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.

the class EOModelPrototypesTest method testOverridingAttributes.

// TODO: move this test to EOModelProcessorInheritanceTst. The original problem had
// nothing to do with prototypes...
@Test
public void testOverridingAttributes() throws Exception {
    DataMap map = new EOModelProcessor().loadEOModel(url);
    ObjEntity estimateOE = map.getObjEntity("Estimate");
    assertSame(estimateOE, estimateOE.getAttribute("created").getEntity());
    assertSame(estimateOE, estimateOE.getAttribute("estimateNumber").getEntity());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DataMap(org.apache.cayenne.map.DataMap) Test(org.junit.Test)

Aggregations

ObjEntity (org.apache.cayenne.map.ObjEntity)294 Test (org.junit.Test)110 DbEntity (org.apache.cayenne.map.DbEntity)72 ObjAttribute (org.apache.cayenne.map.ObjAttribute)68 ObjRelationship (org.apache.cayenne.map.ObjRelationship)62 DataMap (org.apache.cayenne.map.DataMap)57 DbAttribute (org.apache.cayenne.map.DbAttribute)37 DbRelationship (org.apache.cayenne.map.DbRelationship)29 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)27 ObjectId (org.apache.cayenne.ObjectId)26 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)22 ArrayList (java.util.ArrayList)19 Embeddable (org.apache.cayenne.map.Embeddable)18 EntityResolver (org.apache.cayenne.map.EntityResolver)17 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)16 Expression (org.apache.cayenne.exp.Expression)15 Persistent (org.apache.cayenne.Persistent)12 EntityEvent (org.apache.cayenne.map.event.EntityEvent)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Entity (org.apache.cayenne.map.Entity)11