Search in sources :

Example 26 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class ASTListTest method testEquals.

@Test
public void testEquals() throws Exception {
    ObjectId objectId = new ObjectId("Artist", "ARTIST_ID", 1);
    Persistent artist = mock(Persistent.class);
    when(artist.getObjectId()).thenReturn(objectId);
    ASTList exp = new ASTList(Collections.singletonList(artist));
    List<Persistent> collection = new ArrayList<>();
    collection.add(artist);
    ASTList exp2 = new ASTList(collection);
    ASTList exp3 = new ASTList(Collections.emptyList());
    assertEquals(exp, exp2);
    assertNotEquals(exp, exp3);
}
Also used : ObjectId(org.apache.cayenne.ObjectId) ArrayList(java.util.ArrayList) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 27 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class ASTListTest method testConstructorWithCollection.

@Test
public void testConstructorWithCollection() {
    ObjectId objectId = new ObjectId("Artist", "ARTIST_ID", 1);
    Persistent artist = mock(Persistent.class);
    when(artist.getObjectId()).thenReturn(objectId);
    ASTList exp = new ASTList(Collections.singletonList(artist));
    assertNotNull(exp.getOperand(0));
    List<Persistent> collection = new ArrayList<>();
    collection.add(artist);
    exp = new ASTList(collection);
    assertNotNull(exp.getOperand(0));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) ArrayList(java.util.ArrayList) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 28 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class EvaluatorTest method testEvaluator_Persistent_MultiKey.

@Test
public void testEvaluator_Persistent_MultiKey() {
    Map<String, Object> lhsIdMap = new HashMap<>();
    lhsIdMap.put("a", 1);
    lhsIdMap.put("b", "B");
    ObjectId lhsId = new ObjectId("X", lhsIdMap);
    Persistent lhs = mock(Persistent.class);
    when(lhs.getObjectId()).thenReturn(lhsId);
    Evaluator e = Evaluator.evaluator(lhs);
    assertNotNull(e);
    Map<String, Object> rhsId1Map = new HashMap<>();
    rhsId1Map.put("a", 1);
    rhsId1Map.put("b", "B");
    ObjectId rhsId1 = new ObjectId("X", rhsId1Map);
    Persistent rhs1 = mock(Persistent.class);
    when(rhs1.getObjectId()).thenReturn(rhsId1);
    assertTrue(e.eq(lhs, rhs1));
    assertTrue(e.eq(lhs, rhsId1));
    assertTrue(e.eq(lhs, rhsId1Map));
    Map<String, Object> rhsId2Map = new HashMap<>();
    rhsId2Map.put("a", 1);
    rhsId2Map.put("b", "BX");
    ObjectId rhsId2 = new ObjectId("X", rhsId2Map);
    Persistent rhs2 = mock(Persistent.class);
    when(rhs2.getObjectId()).thenReturn(rhsId2);
    assertFalse(e.eq(lhs, rhs2));
    assertFalse(e.eq(lhs, rhsId2));
    assertFalse(e.eq(lhs, rhsId2Map));
    assertFalse(e.eq(lhs, "B"));
}
Also used : HashMap(java.util.HashMap) ObjectId(org.apache.cayenne.ObjectId) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 29 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class EvaluatorTest method testEvaluator_Persistent.

@Test
public void testEvaluator_Persistent() {
    ObjectId lhsId = new ObjectId("X", "k", 3);
    Persistent lhs = mock(Persistent.class);
    when(lhs.getObjectId()).thenReturn(lhsId);
    Evaluator e = Evaluator.evaluator(lhs);
    assertNotNull(e);
    ObjectId rhsId1 = new ObjectId("X", "k", 3);
    Persistent rhs1 = mock(Persistent.class);
    when(rhs1.getObjectId()).thenReturn(rhsId1);
    assertTrue(e.eq(lhs, rhs1));
    assertTrue(e.eq(lhs, rhsId1));
    assertTrue(e.eq(lhs, 3));
    ObjectId rhsId2 = new ObjectId("X", "k", 4);
    Persistent rhs2 = mock(Persistent.class);
    when(rhs2.getObjectId()).thenReturn(rhsId2);
    assertFalse(e.eq(lhs, rhs2));
    assertFalse(e.eq(lhs, rhsId2));
    assertFalse(e.eq(lhs, 4));
}
Also used : ObjectId(org.apache.cayenne.ObjectId) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Example 30 with Persistent

use of org.apache.cayenne.Persistent in project cayenne by apache.

the class DataContextExtrasIT method testResolveFaultFailure.

@Test
public void testResolveFaultFailure() {
    Persistent o1 = context.findOrCreateObject(new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 234));
    try {
        context.prepareForAccess(o1, null, false);
        fail("Must blow on non-existing fault.");
    } catch (CayenneRuntimeException ignored) {
    }
}
Also used : ObjectId(org.apache.cayenne.ObjectId) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) Persistent(org.apache.cayenne.Persistent) Test(org.junit.Test)

Aggregations

Persistent (org.apache.cayenne.Persistent)88 ObjectId (org.apache.cayenne.ObjectId)38 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)17 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)17 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)17 DataObject (org.apache.cayenne.DataObject)13 Map (java.util.Map)12 ObjEntity (org.apache.cayenne.map.ObjEntity)10 EJBQLQuery (org.apache.cayenne.query.EJBQLQuery)10 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)10 DataRow (org.apache.cayenne.DataRow)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 Collection (java.util.Collection)7 HashMap (java.util.HashMap)7 ObjectContext (org.apache.cayenne.ObjectContext)6 DbEntity (org.apache.cayenne.map.DbEntity)6 List (java.util.List)5