DefaultDeleteHelper implements IDeleteHelper { public void undeleteFile( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId ) throws RepositoryException { Node fileToUndeleteNode = session.getNodeByIdentifier( fileId.toString() ); String trashFileIdNodePath = fileToUndeleteNode.getParent().getPath(); String origParentFolderPath = getOriginalParentFolderPath( session, pentahoJcrConstants, fileToUndeleteNode, false ); String absDestPath = origParentFolderPath + RepositoryFile.SEPARATOR + fileToUndeleteNode.getName(); if ( session.itemExists( absDestPath ) ) { RepositoryFile file = JcrRepositoryFileUtils.nodeToFile( session, pentahoJcrConstants, pathConversionHelper, lockHelper, (Node) session.getItem( absDestPath ) ); throw new RepositoryFileDaoFileExistsException( file ); } session.move( fileToUndeleteNode.getPath(), absDestPath ); session.getItem( trashFileIdNodePath ).remove(); } 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 testUndeleteFile() throws Exception { String fileID = "testFileID"; final Property origParentFolderPathProperty = mock( Property.class ); when( origParentFolderPathProperty.getString() ).thenReturn( "origParentFolderPath" ); final Node nodeDeletedParent = mock( Node.class ); when( nodeDeletedParent.getPath() ).thenReturn( "parentPath" ); when( nodeDeletedParent.hasProperty( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ) ).thenReturn( true ); when( nodeDeletedParent.getProperty( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ) ).thenReturn( origParentFolderPathProperty ); final Node nodeToRemove = mock( Node.class ); when( nodeToRemove.getPath() ).thenReturn( "nodePath" ); when( nodeToRemove.getParent() ).thenReturn( nodeDeletedParent ); when( session.getItem( anyString() ) ).thenReturn( nodeDeletedParent ); when( session.getNodeByIdentifier( fileID ) ).thenReturn( nodeToRemove ); try { defaultDeleteHelper.undeleteFile( session, pentahoJcrConstants, fileID ); verify( session ).move( eq( nodeToRemove.getPath() ), anyString() ); verify( nodeDeletedParent ).remove(); } catch ( Exception e ) { e.printStackTrace(); fail(); } when( session.itemExists( anyString() ) ).thenReturn( true ); try { defaultDeleteHelper.undeleteFile( session, pentahoJcrConstants, fileID ); } catch ( RepositoryFileDaoFileExistsException e1 ) { } }