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);
}
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));
}
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"));
}
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));
}
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) {
}
}
Aggregations