DefaultDeleteHelper implements IDeleteHelper { public void deleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId ) throws RepositoryException { Node fileToDeleteNode = session.getNodeByIdentifier( fileId.toString() ); Node trashFileIdNode = getOrCreateTrashFileIdNode( session, pentahoJcrConstants, fileId ); trashFileIdNode.setProperty( pentahoJcrConstants.getPHO_DELETEDDATE(), Calendar.getInstance() ); trashFileIdNode.setProperty( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH(), pathConversionHelper .absToRel( fileToDeleteNode.getParent().getPath() ) ); trashFileIdNode.setProperty( pentahoJcrConstants.getPHO_ORIGNAME(), fileToDeleteNode.getName() ); session.move( fileToDeleteNode.getPath(), trashFileIdNode.getPath() + RepositoryFile.SEPARATOR + fileToDeleteNode.getName() ); } DefaultDeleteHelper( final ILockHelper lockHelper, final IPathConversionHelper pathConversionHelper ); void deleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                          final Serializable fileId ); List<RepositoryFile> getDeletedFiles( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                                               final String origParentFolderPath, final String filter ); List<RepositoryFile> getDeletedFiles( final Session session, final PentahoJcrConstants pentahoJcrConstants ); List<RepositoryFile> getAllDeletedFiles( final Session session,
      final PentahoJcrConstants pentahoJcrConstants ); void permanentlyDeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                                     final Serializable fileId ); void undeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                            final Serializable fileId ); String getOriginalParentFolderPath( final Session session, final PentahoJcrConstants pentahoJcrConstants,
                                             final Serializable fileId ); static final String JCR_ROOT_VERSION; }
@Test public void testDeleteFile() throws Exception { String fileID = "testFileID"; final Node nodeDeletedFile = mock( Node.class ); final Node nodeTrash = mock( Node.class ); when( nodeTrash.hasNode( anyString() ) ).thenReturn( true ); when( nodeTrash.getNode( anyString() ) ).thenReturn( nodeDeletedFile ); final Node nodeUserFolder = mock( Node.class ); when( nodeUserFolder.hasNode( anyString() ) ).thenReturn( true ); when( nodeUserFolder.getNode( anyString() ) ).thenReturn( nodeTrash ); final Node nodeDeletedParent = mock( Node.class ); when( nodeDeletedParent.getPath() ).thenReturn( "parentPath" ); final Node nodeToRemove = mock( Node.class ); when( nodeToRemove.getPath() ).thenReturn( "nodePath" ); when( nodeToRemove.getParent() ).thenReturn( nodeDeletedParent ); when( session.getNodeByIdentifier( fileID ) ).thenReturn( nodeToRemove ); when( session.getItem( anyString() ) ).thenReturn( nodeUserFolder ); try { defaultDeleteHelper.deleteFile( session, pentahoJcrConstants, fileID ); verify( nodeDeletedFile ).setProperty( eq( pentahoJcrConstants.getPHO_DELETEDDATE() ), any( Calendar.class ) ); verify( nodeDeletedFile ).setProperty( eq( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ), anyString() ); verify( nodeDeletedFile ).setProperty( eq( pentahoJcrConstants.getPHO_ORIGNAME() ), anyString() ); verify( session ).move( eq( nodeToRemove.getPath() ), anyString() ); } catch ( Exception e ) { fail(); } }