DefaultDeleteHelper implements IDeleteHelper { private String getOriginalParentFolderPath( final Session session, final PentahoJcrConstants pentahoJcrConstants, final Node trashFileNode, final boolean relative ) throws RepositoryException { if ( trashFileNode.getParent().hasProperty( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ) ) { String relPath = trashFileNode.getParent().getProperty( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ).getString(); return relative ? relPath : pathConversionHelper.relToAbs( relPath ); } else { final String prefix = session.getNamespacePrefix( PentahoJcrConstants.PHO_NS ); String originalParentFolderId = trashFileNode.getParent().getParent().getName().substring( prefix.length() + 1 ); String absPath = session.getNodeByIdentifier( originalParentFolderId ).getPath(); return relative ? pathConversionHelper.absToRel( absPath ) : absPath; } } 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 testGetOriginalParentFolderPath() throws Exception { final String fileID = "testFileID"; final String origParentFolderPath = "origParentFolderPath"; final String relToAbs_origParentFolderPath = "relToAbs_origParentFolderPath"; final Property origParentFolderPathProperty = mock( Property.class ); when( origParentFolderPathProperty.getString() ).thenReturn( origParentFolderPath ); final Node parentNode = mock( Node.class ); when( parentNode.getProperty( eq( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ) ) ).thenReturn( origParentFolderPathProperty ); when( parentNode.hasProperty( eq( pentahoJcrConstants.getPHO_ORIGPARENTFOLDERPATH() ) ) ).thenReturn( true ); final Node node = mock( Node.class ); when( session.getNodeByIdentifier( eq( fileID ) ) ).thenReturn( node ); when( node.getParent() ).thenReturn( parentNode ); when( pathConversionHelper.relToAbs( eq( origParentFolderPath ) ) ).thenReturn( relToAbs_origParentFolderPath ); try { final String originalParentFolderPath = defaultDeleteHelper.getOriginalParentFolderPath( session, pentahoJcrConstants, fileID ); assertEquals( relToAbs_origParentFolderPath, originalParentFolderPath ); } catch ( Exception e ) { e.printStackTrace(); fail(); } }