use of org.apache.cayenne.commitlog.db.Auditable1 in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_Insert.
@Test
public void testPostCommit_Insert() throws SQLException {
final Auditable1 a1 = context.newObject(Auditable1.class);
a1.setCharProperty1("yy");
final ObjectId preCommitId = a1.getObjectId();
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("yy", c.getAttributeChanges().get(Auditable1.CHAR_PROPERTY1.getName()).getNewValue());
assertNotEquals(preCommitId, a1.getObjectId());
assertEquals(preCommitId, c.getPreCommitId());
assertEquals(a1.getObjectId(), c.getPostCommitId());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.commitlog.db.Auditable1 in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_UpdateToOne.
@Test
public void testPostCommit_UpdateToOne() throws SQLException {
auditable1.insert(1, "xx");
auditable1.insert(2, "yy");
auditableChild1.insert(1, 1, "cc1");
auditableChild1.insert(2, 2, "cc2");
auditableChild1.insert(3, null, "cc3");
final AuditableChild1 ac1 = SelectById.query(AuditableChild1.class, 1).selectOne(context);
final AuditableChild1 ac2 = SelectById.query(AuditableChild1.class, 2).selectOne(context);
final AuditableChild1 ac3 = SelectById.query(AuditableChild1.class, 3).selectOne(context);
final Auditable1 a1 = SelectById.query(Auditable1.class, 1).selectOne(context);
final Auditable1 a2 = SelectById.query(Auditable1.class, 2).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];
assertNotNull(changes);
assertEquals(4, changes.getUniqueChanges().size());
ObjectChange ac1c = changes.getChanges().get(new ObjectId("AuditableChild1", AuditableChild1.ID_PK_COLUMN, 1));
assertNotNull(ac1c);
assertEquals(ObjectChangeType.UPDATE, ac1c.getType());
ToOneRelationshipChange ac1c1 = ac1c.getToOneRelationshipChanges().get(AuditableChild1.PARENT.getName());
assertEquals(a1.getObjectId(), ac1c1.getOldValue());
assertEquals(null, ac1c1.getNewValue());
ObjectChange ac2c = changes.getChanges().get(new ObjectId("AuditableChild1", AuditableChild1.ID_PK_COLUMN, 2));
assertNotNull(ac2c);
assertEquals(ObjectChangeType.UPDATE, ac2c.getType());
ToOneRelationshipChange ac2c1 = ac2c.getToOneRelationshipChanges().get(AuditableChild1.PARENT.getName());
assertEquals(a2.getObjectId(), ac2c1.getOldValue());
assertEquals(a1.getObjectId(), ac2c1.getNewValue());
ObjectChange ac3c = changes.getChanges().get(new ObjectId("AuditableChild1", AuditableChild1.ID_PK_COLUMN, 3));
assertNotNull(ac3c);
assertEquals(ObjectChangeType.UPDATE, ac3c.getType());
ToOneRelationshipChange ac3c1 = ac3c.getToOneRelationshipChanges().get(AuditableChild1.PARENT.getName());
assertEquals(null, ac3c1.getOldValue());
assertEquals(a1.getObjectId(), ac3c1.getNewValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
a1.removeFromChildren1(ac1);
a1.addToChildren1(ac2);
a1.addToChildren1(ac3);
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.commitlog.db.Auditable1 in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_Update.
@Test
public void testPostCommit_Update() throws SQLException {
auditable1.insert(1, "xx");
final Auditable1 a1 = SelectById.query(Auditable1.class, 1).selectOne(context);
a1.setCharProperty1("yy");
final ObjectId preCommitId = a1.getObjectId();
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("Auditable1", Auditable1.ID_PK_COLUMN, 1));
assertNotNull(c);
assertEquals(ObjectChangeType.UPDATE, c.getType());
assertEquals(1, c.getAttributeChanges().size());
AttributeChange pc = c.getAttributeChanges().get(Auditable1.CHAR_PROPERTY1.getName());
assertNotNull(pc);
assertEquals("xx", pc.getOldValue());
assertEquals("yy", pc.getNewValue());
assertEquals(preCommitId, a1.getObjectId());
assertEquals(preCommitId, c.getPreCommitId());
assertEquals(preCommitId, c.getPostCommitId());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.commitlog.db.Auditable1 in project cayenne by apache.
the class CommitLogFilter_ListenerInducedChangesIT method testPostCommit_Update.
@Test
public void testPostCommit_Update() throws SQLException {
auditable1.insert(1, "yy");
auditableChild1.insert(31, 1, "yyc");
final UpdateListener listener = new UpdateListener();
runtime.getDataDomain().addListener(listener);
final Auditable1 a1 = SelectById.query(Auditable1.class, 1).prefetch(Auditable1.CHILDREN1.joint()).selectFirst(context);
a1.setCharProperty1("zz");
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertNotNull(listener.toUpdate);
assertEquals(1, listener.toUpdate.size());
List<ObjectChange> sortedChanges = sortedChanges(invocation);
assertEquals(2, sortedChanges.size());
assertEquals(ObjectChangeType.UPDATE, sortedChanges.get(0).getType());
assertEquals(a1.getObjectId(), sortedChanges.get(0).getPostCommitId());
assertEquals(ObjectChangeType.UPDATE, sortedChanges.get(1).getType());
assertEquals(listener.toUpdate.get(0).getObjectId(), sortedChanges.get(1).getPostCommitId());
AttributeChange listenerInducedChange = sortedChanges.get(1).getAttributeChanges().get(AuditableChild1.CHAR_PROPERTY1.getName());
assertNotNull(listenerInducedChange);
assertEquals("yyc", listenerInducedChange.getOldValue());
assertEquals("yyc_", listenerInducedChange.getNewValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.commitlog.db.Auditable1 in project cayenne by apache.
the class CommitLogFilter_ListenerInducedChangesIT method testPostCommit_Insert.
@Test
public void testPostCommit_Insert() throws SQLException {
final InsertListener listener = new InsertListener();
runtime.getDataDomain().addListener(listener);
final Auditable1 a1 = context.newObject(Auditable1.class);
a1.setCharProperty1("yy");
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertNotNull(listener.c);
List<ObjectChange> sortedChanges = sortedChanges(invocation);
assertEquals(2, sortedChanges.size());
assertEquals(a1.getObjectId(), sortedChanges.get(0).getPostCommitId());
assertEquals(ObjectChangeType.INSERT, sortedChanges.get(0).getType());
assertEquals(listener.c.getObjectId(), sortedChanges.get(1).getPostCommitId());
assertEquals(ObjectChangeType.INSERT, sortedChanges.get(1).getType());
AttributeChange listenerInducedChange = sortedChanges.get(1).getAttributeChanges().get(AuditableChild1.CHAR_PROPERTY1.getName());
assertNotNull(listenerInducedChange);
assertEquals("c1", listenerInducedChange.getNewValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
Aggregations