use of org.apache.cayenne.commitlog.db.Auditable2 in project cayenne by apache.
the class CommitLogFilter_FilteredIT method testPostCommit_Insert.
@Test
public void testPostCommit_Insert() throws SQLException {
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(2, changes.getChanges().size());
assertEquals(1, changes.getUniqueChanges().size());
ObjectChange c = changes.getUniqueChanges().iterator().next();
assertNotNull(c);
assertEquals(ObjectChangeType.INSERT, c.getType());
assertEquals(1, c.getAttributeChanges().size());
assertEquals(Confidential.getInstance(), c.getAttributeChanges().get(Auditable2.CHAR_PROPERTY2.getName()).getNewValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
Auditable2 a1 = context.newObject(Auditable2.class);
a1.setCharProperty1("yy");
a1.setCharProperty2("zz");
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.commitlog.db.Auditable2 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.commitlog.db.Auditable2 in project cayenne by apache.
the class CommitLogFilter_OutsideTxIT method testCommitLog.
@Test
public void testCommitLog() throws SQLException {
Auditable2 a1 = context.newObject(Auditable2.class);
a1.setCharProperty1("yy");
a1.setCharProperty2("zz");
Auditable2 a2 = context.newObject(Auditable2.class);
a2.setCharProperty1("yy");
a2.setCharProperty2("zz");
context.commitChanges();
List<Object[]> logs = auditLog.selectAll();
assertEquals(2, logs.size());
}
use of org.apache.cayenne.commitlog.db.Auditable2 in project cayenne by apache.
the class CommitLogFilter_FilteredIT method testPostCommit_Update.
@Test
public void testPostCommit_Update() 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.UPDATE, c.getType());
assertEquals(1, c.getAttributeChanges().size());
AttributeChange pc = c.getAttributeChanges().get(Auditable2.CHAR_PROPERTY2.getName());
assertNotNull(pc);
assertEquals(Confidential.getInstance(), pc.getOldValue());
assertEquals(Confidential.getInstance(), pc.getNewValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
Auditable2 a1 = SelectById.query(Auditable2.class, 1).selectOne(context);
a1.setCharProperty1("P1_2");
a1.setCharProperty2("P2_2");
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.commitlog.db.Auditable2 in project cayenne by apache.
the class CommitLogFilter_TxIT method testCommitLog.
@Test
public void testCommitLog() throws SQLException {
Auditable2 a1 = context.newObject(Auditable2.class);
a1.setCharProperty1("yy");
a1.setCharProperty2("zz");
Auditable2 a2 = context.newObject(Auditable2.class);
a2.setCharProperty1("yy");
a2.setCharProperty2("zz");
context.commitChanges();
List<Object[]> logs = auditLog.selectAll();
assertEquals(2, logs.size());
}
Aggregations