Search in sources :

Example 1 with Auditable3

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

Example 2 with Auditable3

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

Example 3 with Auditable3

use of org.apache.cayenne.commitlog.db.Auditable3 in project cayenne by apache.

the class CommitLogFilter_FilteredIT method testPostCommit_IgnoreToMany.

@Test
public void testPostCommit_IgnoreToMany() throws SQLException {
    auditable3.insert(1, "31", "32");
    auditable4.insert(11, "41", "42", 1);
    auditable4.insert(12, "43", "44", 1);
    final Auditable3 a3 = SelectById.query(Auditable3.class, 1).selectOne(context);
    final Auditable4 a41 = SelectById.query(Auditable4.class, 11).selectOne(context);
    final Auditable4 a42 = SelectById.query(Auditable4.class, 12).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.removeFromAuditable4s(a41);
    a3.addToAuditable4s(a42);
    context.commitChanges();
    verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
Also used : ChangeMap(org.apache.cayenne.commitlog.model.ChangeMap) ObjectId(org.apache.cayenne.ObjectId) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Auditable4(org.apache.cayenne.commitlog.db.Auditable4) Auditable3(org.apache.cayenne.commitlog.db.Auditable3) ObjectContext(org.apache.cayenne.ObjectContext) Test(org.junit.Test)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)3 ObjectId (org.apache.cayenne.ObjectId)3 Auditable3 (org.apache.cayenne.commitlog.db.Auditable3)3 ChangeMap (org.apache.cayenne.commitlog.model.ChangeMap)3 Test (org.junit.Test)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Auditable4 (org.apache.cayenne.commitlog.db.Auditable4)2