use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ObjectIdQueryTest method testEquals.
/**
* Proper 'equals' and 'hashCode' implementations are important when mapping
* results obtained in a QueryChain back to the query.
*/
@Test
public void testEquals() throws Exception {
ObjectIdQuery q1 = new ObjectIdQuery(new ObjectId("abc", "a", 1));
ObjectIdQuery q2 = new ObjectIdQuery(new ObjectId("abc", "a", 1));
ObjectIdQuery q3 = new ObjectIdQuery(new ObjectId("abc", "a", 3));
ObjectIdQuery q4 = new ObjectIdQuery(new ObjectId("123", "a", 1));
assertTrue(q1.equals(q2));
assertEquals(q1.hashCode(), q2.hashCode());
assertFalse(q1.equals(q3));
assertFalse(q1.hashCode() == q3.hashCode());
assertFalse(q1.equals(q4));
assertFalse(q1.hashCode() == q4.hashCode());
}
use of org.apache.cayenne.ObjectId 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.ObjectId 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.ObjectId 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) {
}
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataContextIT method testCurrentSnapshotWithToOneFault.
/**
* Testing snapshot with to-one fault. This was a bug CAY-96.
*/
@Test
public void testCurrentSnapshotWithToOneFault() throws Exception {
createGalleriesAndExhibitsDataSet();
// Exhibit with Gallery as Fault must still include Gallery
// Artist and Exhibit (Exhibit has unresolved to-one to gallery as in
// the
// CAY-96 bug report)
ObjectId eId = new ObjectId("Exhibit", Exhibit.EXHIBIT_ID_PK_COLUMN, 2);
Exhibit e = (Exhibit) context.performQuery(new ObjectIdQuery(eId)).get(0);
assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
DataRow snapshot = context.currentSnapshot(e);
// assert that after taking a snapshot, we have FK in, but the
// relationship
// is still a Fault
assertTrue(e.readPropertyDirectly(Exhibit.TO_GALLERY.getName()) instanceof Fault);
assertEquals(new Integer(33002), snapshot.get("GALLERY_ID"));
}
Aggregations