use of org.apache.cayenne.commitlog.db.Auditable1 in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_Delete.
@Test
public void testPostCommit_Delete() throws SQLException {
auditable1.insert(1, "xx");
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.DELETE, c.getType());
assertEquals(1, c.getAttributeChanges().size());
assertEquals("xx", c.getAttributeChanges().get(Auditable1.CHAR_PROPERTY1.getName()).getOldValue());
assertNull(c.getAttributeChanges().get(Auditable1.CHAR_PROPERTY1.getName()).getNewValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
Auditable1 a1 = SelectById.query(Auditable1.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.Auditable1 in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_UpdateToMany.
@Test
public void testPostCommit_UpdateToMany() throws SQLException {
auditable1.insert(1, "xx");
auditableChild1.insert(1, 1, "cc1");
auditableChild1.insert(2, null, "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);
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 a1c = changes.getChanges().get(new ObjectId("Auditable1", Auditable1.ID_PK_COLUMN, 1));
assertNotNull(a1c);
assertEquals(ObjectChangeType.UPDATE, a1c.getType());
assertEquals(0, a1c.getAttributeChanges().size());
assertEquals(1, a1c.getToManyRelationshipChanges().size());
ToManyRelationshipChange a1c1 = a1c.getToManyRelationshipChanges().get(Auditable1.CHILDREN1.getName());
assertNotNull(a1c1);
assertEquals(2, a1c1.getAdded().size());
assertTrue(a1c1.getAdded().contains(ac2.getObjectId()));
assertTrue(a1c1.getAdded().contains(ac3.getObjectId()));
assertEquals(1, a1c1.getRemoved().size());
assertTrue(a1c1.getRemoved().contains(ac1.getObjectId()));
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_FilteredIT method testPostCommit_UpdateToMany.
@Test
public void testPostCommit_UpdateToMany() throws SQLException {
auditable1.insert(1, "xx");
auditableChild1.insert(1, 1, "cc1");
auditableChild1.insert(2, null, "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);
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 a1c = changes.getChanges().get(new ObjectId("Auditable1", Auditable1.ID_PK_COLUMN, 1));
assertNotNull(a1c);
assertEquals(ObjectChangeType.UPDATE, a1c.getType());
assertEquals(0, a1c.getAttributeChanges().size());
assertEquals(1, a1c.getToManyRelationshipChanges().size());
ToManyRelationshipChange a1c1 = a1c.getToManyRelationshipChanges().get(Auditable1.CHILDREN1.getName());
assertNotNull(a1c1);
assertEquals(2, a1c1.getAdded().size());
assertTrue(a1c1.getAdded().contains(ac2.getObjectId()));
assertTrue(a1c1.getAdded().contains(ac3.getObjectId()));
assertEquals(1, a1c1.getRemoved().size());
assertTrue(a1c1.getRemoved().contains(ac1.getObjectId()));
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_ListenerInducedChangesIT method testPostCommit_Delete.
@Test
public void testPostCommit_Delete() throws SQLException {
auditable1.insert(1, "yy");
auditableChild1.insert(31, 1, "yyc");
final DeleteListener listener = new DeleteListener();
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.toDelete);
assertEquals(1, listener.toDelete.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.DELETE, sortedChanges.get(1).getType());
assertEquals(listener.toDelete.get(0).getObjectId(), sortedChanges.get(1).getPostCommitId());
AttributeChange listenerInducedChange = sortedChanges.get(1).getAttributeChanges().get(AuditableChild1.CHAR_PROPERTY1.getName());
assertNotNull(listenerInducedChange);
assertEquals("yyc", listenerInducedChange.getOldValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
Aggregations