use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.
the class DefaultDeleteHelperTest method testGetOriginalParentFolderPath.
@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();
}
}
use of org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants in project pentaho-platform by pentaho.
the class DefaultDeleteHelperTest method testUndeleteFile.
@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();
}
// must fail if there is something at the original path
when(session.itemExists(anyString())).thenReturn(true);
try {
defaultDeleteHelper.undeleteFile(session, pentahoJcrConstants, fileID);
} catch (RepositoryFileDaoFileExistsException e1) {
// it's ok
}
}
Aggregations