Search in sources :

Example 1 with Auditable2

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));
}
Also used : ChangeMap(org.apache.cayenne.commitlog.model.ChangeMap) ObjectChange(org.apache.cayenne.commitlog.model.ObjectChange) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Auditable2(org.apache.cayenne.commitlog.db.Auditable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 2 with Auditable2

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));
}
Also used : ChangeMap(org.apache.cayenne.commitlog.model.ChangeMap) ObjectChange(org.apache.cayenne.commitlog.model.ObjectChange) ObjectId(org.apache.cayenne.ObjectId) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Auditable2(org.apache.cayenne.commitlog.db.Auditable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 3 with Auditable2

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());
}
Also used : Auditable2(org.apache.cayenne.commitlog.db.Auditable2) Test(org.junit.Test)

Example 4 with Auditable2

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));
}
Also used : ChangeMap(org.apache.cayenne.commitlog.model.ChangeMap) ObjectChange(org.apache.cayenne.commitlog.model.ObjectChange) ObjectId(org.apache.cayenne.ObjectId) InvocationOnMock(org.mockito.invocation.InvocationOnMock) AttributeChange(org.apache.cayenne.commitlog.model.AttributeChange) Auditable2(org.apache.cayenne.commitlog.db.Auditable2) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Example 5 with Auditable2

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());
}
Also used : Auditable2(org.apache.cayenne.commitlog.db.Auditable2) Test(org.junit.Test)

Aggregations

Auditable2 (org.apache.cayenne.commitlog.db.Auditable2)5 Test (org.junit.Test)5 ObjectContext (org.apache.cayenne.ObjectContext)3 ChangeMap (org.apache.cayenne.commitlog.model.ChangeMap)3 ObjectChange (org.apache.cayenne.commitlog.model.ObjectChange)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 ObjectId (org.apache.cayenne.ObjectId)2 AttributeChange (org.apache.cayenne.commitlog.model.AttributeChange)1