Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Jan 13, 2023
1 parent dc35f55 commit 53accb6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.enonic.xp.audit.CleanUpAuditLogListener;
import com.enonic.xp.audit.CleanUpAuditLogResult;
import com.enonic.xp.data.ValueFactory;
import com.enonic.xp.node.DeleteNodeParams;
import com.enonic.xp.node.FindNodesByQueryResult;
import com.enonic.xp.node.NodeHit;
import com.enonic.xp.node.NodeIndexPath;
Expand Down Expand Up @@ -74,11 +75,13 @@ private CleanUpAuditLogResult doCleanUp()
{
for ( NodeHit nodeHit : nodesToDelete.getNodeHits() )
{
result.deleted( nodeService.deleteById( nodeHit.getNodeId() ).getSize() );
result.deleted( nodeService.delete( DeleteNodeParams.create().nodeId( nodeHit.getNodeId() ).build() )
.getNodeBranchEntries()
.getSize() );

listener.processed();
}

nodeService.refresh( RefreshMode.SEARCH );
nodesToDelete = nodeService.findByQuery( query );

hits = nodesToDelete.getHits();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;

import com.enonic.xp.audit.AuditLog;
import com.enonic.xp.audit.AuditLogId;
Expand All @@ -18,12 +17,17 @@
import com.enonic.xp.data.PropertyTree;
import com.enonic.xp.index.IndexService;
import com.enonic.xp.node.CreateNodeParams;
import com.enonic.xp.node.DeleteNodeParams;
import com.enonic.xp.node.DeleteNodeResult;
import com.enonic.xp.node.FindNodesByQueryResult;
import com.enonic.xp.node.Node;
import com.enonic.xp.node.NodeBranchEntries;
import com.enonic.xp.node.NodeBranchEntry;
import com.enonic.xp.node.NodeHit;
import com.enonic.xp.node.NodeHits;
import com.enonic.xp.node.NodeId;
import com.enonic.xp.node.NodeIds;
import com.enonic.xp.node.NodePath;
import com.enonic.xp.node.NodeQuery;
import com.enonic.xp.node.NodeService;
import com.enonic.xp.node.Nodes;
Expand Down Expand Up @@ -143,8 +147,15 @@ public void find()
@Test
public void cleanUpOneEmpty()
{
when( nodeService.deleteById( ArgumentMatchers.isA( NodeId.class ) ) ).thenAnswer(
answer -> NodeIds.from( (NodeId) answer.getArgument( 0 ) ) );
when( nodeService.delete( any() ) ).thenAnswer( answer -> DeleteNodeResult.create()
.nodeBranchEntries( NodeBranchEntries.create()
.add( NodeBranchEntry.create()
.nodeId( answer.getArgument( 0, DeleteNodeParams.class ).getNodeId() )
.nodePath( NodePath.ROOT )
.build() )
.build() )
.build() );

when( config.ageThreshold() ).thenReturn( "PT1s" );

when( nodeService.findByQuery( any( NodeQuery.class ) ) ).
Expand All @@ -165,8 +176,15 @@ public void cleanUpOneEmpty()
@Test
public void cleanUpOneBatch()
{
when( nodeService.deleteById( ArgumentMatchers.isA( NodeId.class ) ) ).thenAnswer(
answer -> NodeIds.from( (NodeId) answer.getArgument( 0 ) ) );
when( nodeService.delete( any() ) ).thenAnswer( answer -> DeleteNodeResult.create()
.nodeBranchEntries( NodeBranchEntries.create()
.add( NodeBranchEntry.create()
.nodeId( answer.getArgument( 0, DeleteNodeParams.class ).getNodeId() )
.nodePath( NodePath.ROOT )
.build() )
.build() )
.build() );

when( config.ageThreshold() ).thenReturn( "PT1s" );

final FindNodesByQueryResult.Builder queryResult = FindNodesByQueryResult.create().
Expand Down Expand Up @@ -194,8 +212,15 @@ public void cleanUpOneBatch()
@Test
public void cleanUpMultipleBatch()
{
when( nodeService.deleteById( ArgumentMatchers.isA( NodeId.class ) ) ).thenAnswer(
answer -> NodeIds.from( (NodeId) answer.getArgument( 0 ) ) );
when( nodeService.delete( any() ) ).thenAnswer( answer -> DeleteNodeResult.create()
.nodeBranchEntries( NodeBranchEntries.create()
.add( NodeBranchEntry.create()
.nodeId( answer.getArgument( 0, DeleteNodeParams.class ).getNodeId() )
.nodePath( NodePath.ROOT )
.build() )
.build() )
.build() );

when( config.ageThreshold() ).thenReturn( "PT1s" );

final FindNodesByQueryResult.Builder queryResult1 = FindNodesByQueryResult.create().
Expand Down

0 comments on commit 53accb6

Please sign in to comment.