Search in sources :

Example 1 with CleanUpAuditLogListener

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();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) CleanUpAuditLogListener(com.enonic.xp.audit.CleanUpAuditLogListener) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Example 2 with CleanUpAuditLogListener

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();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) CleanUpAuditLogListener(com.enonic.xp.audit.CleanUpAuditLogListener) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Example 3 with CleanUpAuditLogListener

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();
}
Also used : CleanUpAuditLogResult(com.enonic.xp.audit.CleanUpAuditLogResult) CleanUpAuditLogListener(com.enonic.xp.audit.CleanUpAuditLogListener) FindNodesByQueryResult(com.enonic.xp.node.FindNodesByQueryResult) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) Test(org.junit.jupiter.api.Test)

Aggregations

CleanUpAuditLogListener (com.enonic.xp.audit.CleanUpAuditLogListener)3 CleanUpAuditLogResult (com.enonic.xp.audit.CleanUpAuditLogResult)3 NodeId (com.enonic.xp.node.NodeId)3 Test (org.junit.jupiter.api.Test)3 FindNodesByQueryResult (com.enonic.xp.node.FindNodesByQueryResult)2 NodeQuery (com.enonic.xp.node.NodeQuery)2