use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CommitLogFilter_FilteredIT method testPostCommit_IgnoreAttributes.
@Test
public void testPostCommit_IgnoreAttributes() throws SQLException {
auditable3.insert(1, "31", "32");
final Auditable3 a3 = SelectById.query(Auditable3.class, 1).selectOne(context);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertSame(context, invocation.getArguments()[0]);
ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
assertNull(changes.getChanges().get(new ObjectId("Auditable3", Auditable3.ID_PK_COLUMN, 1)));
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
a3.setCharProperty1("33");
a3.setCharProperty2("34");
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CommitLogFilter_FilteredIT method testPostCommit_Delete.
@Test
public void testPostCommit_Delete() throws SQLException {
auditable2.insert(1, "P1_1", "P2_1");
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertSame(context, invocation.getArguments()[0]);
ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
assertNotNull(changes);
assertEquals(1, changes.getUniqueChanges().size());
ObjectChange c = changes.getChanges().get(new ObjectId("Auditable2", Auditable2.ID_PK_COLUMN, 1));
assertNotNull(c);
assertEquals(ObjectChangeType.DELETE, c.getType());
assertEquals(1, c.getAttributeChanges().size());
assertEquals(Confidential.getInstance(), c.getAttributeChanges().get(Auditable2.CHAR_PROPERTY2.getName()).getOldValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
Auditable2 a1 = SelectById.query(Auditable2.class, 1).selectOne(context);
context.deleteObject(a1);
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CommitLogFilter_FilteredIT method testPostCommit_IgnoreToOne.
@Test
public void testPostCommit_IgnoreToOne() throws SQLException {
auditable3.insert(1, "31", "32");
auditable3.insert(2, "33", "34");
auditable4.insert(11, "41", "41", 1);
final Auditable3 a32 = SelectById.query(Auditable3.class, 2).selectOne(context);
final Auditable4 a4 = SelectById.query(Auditable4.class, 11).selectOne(context);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertSame(context, invocation.getArguments()[0]);
ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
assertNull(changes.getChanges().get(new ObjectId("Auditable4", Auditable4.ID_PK_COLUMN, 11)));
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
a4.setAuditable3(a32);
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ClientServerChannelIT method testPerformQueryObjectIDInjection.
@Test
public void testPerformQueryObjectIDInjection() throws Exception {
tMtTable1.insert(55, "g1", "s1");
Query query = new SelectQuery("MtTable1");
QueryResponse response = clientServerChannel.onQuery(null, query);
assertNotNull(response);
List<?> results = response.firstList();
assertNotNull(results);
assertEquals(1, results.size());
Object result = results.get(0);
assertTrue(result instanceof ClientMtTable1);
ClientMtTable1 clientObject = (ClientMtTable1) result;
assertNotNull(clientObject.getObjectId());
assertEquals(new ObjectId("MtTable1", MtTable1.TABLE1_ID_PK_COLUMN, 55), clientObject.getObjectId());
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class ClientExpressionIT method testArrayInASTList.
@Test
public void testArrayInASTList() throws Exception {
ClientMtTable1 t1 = context.newObject(ClientMtTable1.class);
ClientMtTable1 t2 = context.newObject(ClientMtTable1.class);
ClientMtTable1 t3 = context.newObject(ClientMtTable1.class);
context.commitChanges();
Object[] tArray = new Object[3];
tArray[0] = t1;
tArray[1] = t2;
// send array in expression factory
Expression list = ExpressionFactory.inExp(ClientMtTable2.TABLE1_PROPERTY, tArray);
tArray[2] = t3;
Object[] values = (Object[]) ((ASTList) list.getOperand(1)).getOperand(0);
assertEquals(tArray.length, values.length);
assertNotSame(tArray[2], values[2]);
assertEquals(t1.getObjectId(), values[0]);
assertEquals(t2.getObjectId(), values[1]);
ObjectId t1Id = new ObjectId("MtTable1", "TABLE1_ID", 1);
ObjectId t2Id = new ObjectId("MtTable1", "TABLE1_ID", 2);
t1.setObjectId(t1Id);
t2.setObjectId(t2Id);
// Expression and client have different arrays
assertNotSame(t1.getObjectId(), values[0]);
assertNotSame(t2.getObjectId(), values[1]);
}
Aggregations