Search in sources :

Example 31 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceIT method testSetFileAcls.

@Test
public void testSetFileAcls() throws Exception {
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    doReturn("file.txt").when(file).getName();
    when(fileService.defaultUnifiedRepositoryWebService.getFile(nullable(String.class))).thenReturn(file);
    String pathId = "/usr/folder/file.txt";
    RepositoryFileAclDto acl = mock(RepositoryFileAclDto.class);
    fileService.setFileAcls(pathId, acl);
    verify(acl, times(1)).setId(nullable(String.class));
    verify(file, times(1)).getId();
    verify(fileService.defaultUnifiedRepositoryWebService, times(1)).updateAcl(acl);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFileAclDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileAclDto) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceIT method testDoCreateDirsNegative.

@Test
public void testDoCreateDirsNegative() throws Exception {
    String pathId = "path:to:file:file1.ext";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto parentDir = mock(RepositoryFileDto.class);
    doReturn("").when(parentDir).getPath();
    doReturn(FileUtils.PATH_SEPARATOR).when(parentDir).getId();
    when(fileService.getRepoWs().getFile(FileUtils.PATH_SEPARATOR)).thenReturn(parentDir);
    RepositoryFileDto filePath = mock(RepositoryFileDto.class);
    doReturn("/path").when(filePath).getPath();
    doReturn("/path").when(filePath).getId();
    RepositoryFileDto fileTo = mock(RepositoryFileDto.class);
    doReturn("/path/to").when(fileTo).getPath();
    doReturn("/path/to").when(fileTo).getId();
    RepositoryFileDto fileFile = mock(RepositoryFileDto.class);
    doReturn("/path/to/file").when(fileFile).getPath();
    doReturn("/path/to/file").when(fileFile).getId();
    RepositoryFileDto fileFileExt = mock(RepositoryFileDto.class);
    doReturn("/path/to/file/file1").when(fileFileExt).getPath();
    doReturn("/path/to/file/file1").when(fileFileExt).getId();
    when(fileService.getRepoWs().getFile("/path")).thenReturn(filePath);
    when(fileService.getRepoWs().getFile("/path/to")).thenReturn(fileTo);
    when(fileService.getRepoWs().getFile("/path/to/file")).thenReturn(fileFile);
    when(fileService.getRepoWs().getFile("/path/to/file/file1.ext")).thenReturn(fileFileExt);
    assertFalse(fileService.doCreateDir(pathId));
    verify(fileService.getRepoWs(), times(0)).createFolder(nullable(String.class), any(RepositoryFileDto.class), nullable(String.class));
    when(fileService.getRepoWs().getFile("/path")).thenReturn(null);
    when(fileService.getRepoWs().createFolder(eq("/"), any(RepositoryFileDto.class), eq("/path"))).thenThrow(new InternalError("negativetest"));
    try {
        fileService.doCreateDir(pathId);
    } catch (InternalError e) {
        assertEquals(e.getMessage(), "negativetest");
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceIT method testDoGetFileLocalesException.

@Test
public void testDoGetFileLocalesException() {
    String param = "file1";
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(param).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile("/" + param);
    when(fileService.defaultUnifiedRepositoryWebService.getAvailableLocalesForFileById(repositoryFileDto.getId())).thenThrow(new InternalError());
    try {
        fileService.doGetFileLocales(param);
    } catch (FileNotFoundException e) {
        fail();
    } catch (InternalError e) {
        verify(fileService.getRepository(), times(0)).getAvailableLocalesForFileById(repositoryFileDto.getId());
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 34 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceIT method testSearchGeneratedContent.

@Test
public void testSearchGeneratedContent() {
    String lineageId = "test.prpt", pathId = "test.prpt", userFolder = "public/admin";
    RepositoryFileDto fileDetailsMock = mock(RepositoryFileDto.class);
    RepositoryFile workspaceFolder = mock(RepositoryFile.class);
    doReturn(userFolder).when(workspaceFolder).getId();
    SessionResource sessionResource = mock(SessionResource.class);
    List<RepositoryFile> children = new ArrayList<RepositoryFile>();
    RepositoryFile mockedChild = mock(RepositoryFile.class);
    doReturn(false).when(mockedChild).isFolder();
    children.add(mockedChild);
    Map<String, Serializable> mockedFileMetadata = mock(Map.class);
    doReturn(lineageId).when(mockedFileMetadata).get(QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
    when(fileService.repository.getFileMetadata(mockedChild.getId())).thenReturn(mockedFileMetadata);
    doReturn(pathId).when(fileDetailsMock).getId();
    doReturn(userFolder).when(sessionResource).doGetCurrentUserDir();
    doReturn(workspaceFolder).when(fileService.repository).getFile(userFolder);
    doReturn(sessionResource).when(fileService).getSessionResource();
    doReturn(children).when(fileService.repository).getChildren(userFolder);
    RepositoryFileDto mockedRepositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(mockedRepositoryFileDto).when(fileService).toFileDto(mockedChild, null, false);
    try {
        doReturn(fileDetailsMock).when(fileService).doGetProperties(pathId);
        List<RepositoryFileDto> list = fileService.searchGeneratedContent(userFolder, lineageId, QuartzScheduler.RESERVEDMAPKEY_LINEAGE_ID);
        assertEquals(list.size(), 1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail();
    } catch (Throwable t) {
        fail();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 35 with RepositoryFileDto

use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.

the class FileServiceIT method testDoGetGeneratedContent.

@Test
public void testDoGetGeneratedContent() {
    String pathId = "test.prpt", userFolder = "public/admin";
    RepositoryFileDto fileDetailsMock = mock(RepositoryFileDto.class);
    RepositoryFile workspaceFolder = mock(RepositoryFile.class);
    doReturn(userFolder).when(workspaceFolder).getId();
    SessionResource sessionResource = mock(SessionResource.class);
    List<RepositoryFile> children = new ArrayList<RepositoryFile>();
    RepositoryFile mockedChild = mock(RepositoryFile.class);
    doReturn(false).when(mockedChild).isFolder();
    children.add(mockedChild);
    Map<String, Serializable> mockedFileMetadata = mock(Map.class);
    doReturn(pathId).when(mockedFileMetadata).get(PentahoJcrConstants.PHO_CONTENTCREATOR);
    when(fileService.repository.getFileMetadata(mockedChild.getId())).thenReturn(mockedFileMetadata);
    doReturn(pathId).when(fileDetailsMock).getId();
    doReturn(userFolder).when(sessionResource).doGetCurrentUserDir();
    doReturn(workspaceFolder).when(fileService.repository).getFile(userFolder);
    doReturn(sessionResource).when(fileService).getSessionResource();
    doReturn(children).when(fileService.repository).getChildren(userFolder);
    RepositoryFileDto mockedRepositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(mockedRepositoryFileDto).when(fileService).toFileDto(mockedChild, null, false);
    try {
        doReturn(fileDetailsMock).when(fileService).doGetProperties(pathId);
        List<RepositoryFileDto> list = fileService.doGetGeneratedContent(pathId);
        assertEquals(list.size(), 1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        fail();
    } catch (Throwable t) {
        fail();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) SessionResource(org.pentaho.platform.web.http.api.resources.SessionResource) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.junit.Test)77 RepositoryFileDto (org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto)77 FileNotFoundException (java.io.FileNotFoundException)35 ArrayList (java.util.ArrayList)34 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)29 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)27 Serializable (java.io.Serializable)26 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)26 Matchers.anyString (org.mockito.Matchers.anyString)25 GeneralSecurityException (java.security.GeneralSecurityException)14 StringKeyStringValueDto (org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto)11 IllegalSelectorException (java.nio.channels.IllegalSelectorException)9 InvalidParameterException (java.security.InvalidParameterException)9 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)9 Properties (java.util.Properties)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 DefaultUnifiedRepositoryWebService (org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)7 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)7