Search in sources :

Example 21 with PentahoJcrConstants

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();
    }
}
Also used : Node(javax.jcr.Node) Matchers.anyString(org.mockito.Matchers.anyString) Property(javax.jcr.Property) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Example 22 with PentahoJcrConstants

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
    }
}
Also used : RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) Node(javax.jcr.Node) Matchers.anyString(org.mockito.Matchers.anyString) Property(javax.jcr.Property) RepositoryFileDaoReferentialIntegrityException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException) RepositoryFileDaoFileExistsException(org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException) RepositoryException(javax.jcr.RepositoryException) Test(org.junit.Test)

Aggregations

Node (javax.jcr.Node)15 RepositoryException (javax.jcr.RepositoryException)9 PentahoJcrConstants (org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants)9 RepositoryFileDaoFileExistsException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoFileExistsException)7 RepositoryFileDaoReferentialIntegrityException (org.pentaho.platform.repository2.unified.exception.RepositoryFileDaoReferentialIntegrityException)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 Property (javax.jcr.Property)5 Workspace (javax.jcr.Workspace)5 Serializable (java.io.Serializable)4 NodeIterator (javax.jcr.NodeIterator)4 PropertyIterator (javax.jcr.PropertyIterator)4 Session (javax.jcr.Session)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 ITenant (org.pentaho.platform.api.mt.ITenant)4 Tenant (org.pentaho.platform.core.mt.Tenant)4 JcrCallback (org.springframework.extensions.jcr.JcrCallback)4 Lock (javax.jcr.lock.Lock)3