Search in sources :

Example 36 with RepositoryFileDto

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

the class FileServiceIT method testDoGetGeneratedContentForUser.

@Test
public void testDoGetGeneratedContentForUser() {
    String pathId = "test.prpt", user = "admin", 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).doGetUserDir(user);
    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, user);
        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 37 with RepositoryFileDto

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

the class FileServiceIT method testDoDeleteLocale.

@Test
public void testDoDeleteLocale() throws Exception {
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    doReturn("file.txt").when(file).getId();
    fileService.doDeleteLocale(file.getId(), "en_US");
    verify(fileService.getRepoWs(), times(1)).deleteLocalePropertiesForFile("file.txt", "en_US");
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 38 with RepositoryFileDto

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

the class CopyFilesOperation_CopyTest method copyFiles_OverwriteMode.

@Test
public void copyFiles_OverwriteMode() {
    CopyFilesOperation operation = new CopyFilesOperation(repo, webService, getIdList(file1, file2), PATH_DEST_DIR, FileService.MODE_OVERWRITE);
    // emulate, file with the same name exists.
    RepositoryFile conflictFile = mockFile(generateID(), DEFAULT, PATH_DEST_DIR + SEPARATOR + NAME_FILE_1);
    operation = spy(operation);
    RepositoryFileDto fileDto = mock(RepositoryFileDto.class);
    doReturn(conflictFile).when(operation).toFile(fileDto);
    doReturn(fileDto).when(operation).toFileDto(eq(conflictFile), nullable(Set.class), nullable(Boolean.class));
    doReturn(conflictFile).when(repo).updateFile(eq(conflictFile), nullable(IRepositoryFileData.class), nullable(String.class));
    operation.execute();
    verify(repo).updateFile(eq(conflictFile), nullable(IRepositoryFileData.class), nullable(String.class));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Set(java.util.Set) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 39 with RepositoryFileDto

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

the class CopyFilesOperation_CopyTest method copyFolders_RenameMode.

@Test
public void copyFolders_RenameMode() {
    CopyFilesOperation operation = new CopyFilesOperation(repo, webService, getIdList(folder1, folder2), PATH_DEST_DIR, FileService.MODE_RENAME);
    // emulate, file with the same name exists.
    RepositoryFile conflict = mockFolder(generateID(), DEFAULT, PATH_DEST_DIR + SEPARATOR + NAME_DIR_2);
    String conflictFolderPath = conflict.getPath();
    RepositoryFileDto dtoConflictFolder = mock(RepositoryFileDto.class);
    doReturn(dtoConflictFolder).when(webService).getFile(eq(conflictFolderPath));
    operation = spy(operation);
    operation.execute();
    verify(repo, times(2)).createFolder(eq(destFolder.getId()), nullable(RepositoryFile.class), nullable(RepositoryFileAcl.class), nullable(String.class));
    verify(operation, times(2)).performFolderDeepCopy(nullable(RepositoryFile.class), nullable(RepositoryFile.class), anyInt());
    verify(repo, never()).createFile(nullable(Serializable.class), nullable(RepositoryFile.class), nullable(IRepositoryFileData.class), nullable(RepositoryFileAcl.class), nullable(String.class));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 40 with RepositoryFileDto

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

the class FileServiceTest method testGetDefaultLocation_Scenario_DefaultFolderIsHidden.

@Test
public void testGetDefaultLocation_Scenario_DefaultFolderIsHidden() throws Exception {
    RepositoryFileDto hiddenDto = new RepositoryFileDto();
    hiddenDto.setFolder(true);
    hiddenDto.setHidden(true);
    hiddenDto.setId(RandomStringUtils.randomNumeric(20));
    hiddenDto.setName("suzy");
    hiddenDto.setPath("/home/suzy");
    RepositoryFileDto defaultDto = new RepositoryFileDto();
    defaultDto.setFolder(true);
    defaultDto.setHidden(true);
    defaultDto.setId(RandomStringUtils.randomNumeric(20));
    defaultDto.setName("default");
    defaultDto.setPath("/default-folder");
    RepositoryFileDto publicFolderDto = new RepositoryFileDto();
    publicFolderDto.setFolder(true);
    publicFolderDto.setHidden(false);
    publicFolderDto.setId(RandomStringUtils.randomNumeric(20));
    publicFolderDto.setName("public");
    publicFolderDto.setPath("/public");
    DefaultUnifiedRepositoryWebService repoWs = mock(DefaultUnifiedRepositoryWebService.class);
    doReturn(repoWs).when(fileService).getRepoWs();
    doReturn(hiddenDto).when(repoWs).getFile("/home/suzy");
    when(PentahoSystem.get(ISystemConfig.class).getProperty(eq(PentahoSystem.DEFAULT_FOLDER_WHEN_HOME_FOLDER_IS_HIDDEN_PROPERTY))).thenReturn("/default-folder");
    doReturn(defaultDto).when(repoWs).getFile("/default-folder");
    doReturn(publicFolderDto).when(repoWs).getFile("/public");
    assertEquals(ClientRepositoryPaths.getPublicFolderPath(), fileService.doGetDefaultLocation(":home:suzy"));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) DefaultUnifiedRepositoryWebService(org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) Test(org.junit.Test)

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