use of com.enonic.xp.audit.CleanUpAuditLogListener in project xp by enonic.
the class AuditLogServiceImplTest method cleanUpOneBatch.
@Test
public void cleanUpOneBatch() {
when(nodeService.deleteById(ArgumentMatchers.isA(NodeId.class))).thenAnswer(answer -> NodeIds.from((NodeId) answer.getArgument(0)));
when(config.ageThreshold()).thenReturn("PT1s");
final FindNodesByQueryResult.Builder queryResult = FindNodesByQueryResult.create().totalHits(3).hits(3);
createHits(3).forEach(queryResult::addNodeHit);
when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(queryResult.build()).thenReturn(FindNodesByQueryResult.create().build());
final CleanUpAuditLogListener listener = mock(CleanUpAuditLogListener.class);
final CleanUpAuditLogResult result = auditLogService.cleanUp(CleanUpAuditLogParams.create().listener(listener).build());
assertEquals(3, result.getDeleted());
verify(listener, times(1)).start(10_000);
verify(listener, times(3)).processed();
verify(listener, times(1)).finished();
}
use of com.enonic.xp.audit.CleanUpAuditLogListener in project xp by enonic.
the class AuditLogServiceImplTest method cleanUpOneEmpty.
@Test
public void cleanUpOneEmpty() {
when(nodeService.deleteById(ArgumentMatchers.isA(NodeId.class))).thenAnswer(answer -> NodeIds.from((NodeId) answer.getArgument(0)));
when(config.ageThreshold()).thenReturn("PT1s");
when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().build());
final CleanUpAuditLogListener listener = mock(CleanUpAuditLogListener.class);
final CleanUpAuditLogResult result = auditLogService.cleanUp(CleanUpAuditLogParams.create().listener(listener).build());
assertEquals(0, result.getDeleted());
verify(listener, times(0)).start(anyInt());
verify(listener, times(0)).processed();
verify(listener, times(0)).finished();
}
use of com.enonic.xp.audit.CleanUpAuditLogListener in project xp by enonic.
the class AuditLogServiceImplTest method cleanUpMultipleBatch.
@Test
public void cleanUpMultipleBatch() {
when(nodeService.deleteById(ArgumentMatchers.isA(NodeId.class))).thenAnswer(answer -> NodeIds.from((NodeId) answer.getArgument(0)));
when(config.ageThreshold()).thenReturn("PT1s");
final FindNodesByQueryResult.Builder queryResult1 = FindNodesByQueryResult.create().totalHits(10500).hits(10000);
createHits(10000).forEach(queryResult1::addNodeHit);
final FindNodesByQueryResult.Builder queryResult2 = FindNodesByQueryResult.create().totalHits(10500).hits(500);
createHits(500).forEach(queryResult2::addNodeHit);
when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(queryResult1.build()).thenReturn(queryResult2.build()).thenReturn(FindNodesByQueryResult.create().build());
final CleanUpAuditLogListener listener = mock(CleanUpAuditLogListener.class);
final CleanUpAuditLogResult result = auditLogService.cleanUp(CleanUpAuditLogParams.create().listener(listener).build());
assertEquals(10500, result.getDeleted());
verify(listener, times(1)).start(10_000);
verify(listener, times(10_500)).processed();
verify(listener, times(1)).finished();
}
Aggregations