Search in sources :

Example 91 with RepositoryFileDto

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

the class FileServiceIT method testDoMoveFilesException.

@Test
public void testDoMoveFilesException() throws Exception {
    String destPathId = "/test";
    String[] params = { "file1", "file2" };
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(destPathId).when(repositoryFileDto).getPath();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(destPathId);
    doThrow(new InternalError()).when(fileService.defaultUnifiedRepositoryWebService).moveFile(params[0], destPathId, null);
    try {
        fileService.doMoveFiles(destPathId, StringUtils.join(params, ","));
        // This line should never be reached
        fail();
    } catch (Throwable e) {
        verify(fileService.getRepoWs(), times(1)).moveFile(params[0], destPathId, null);
        verify(fileService.getRepoWs(), times(0)).moveFile(params[1], destPathId, null);
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 92 with RepositoryFileDto

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

the class FileServiceIT method testDoGetChildren.

@Test
public void testDoGetChildren() {
    RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
    Collator mockCollator = mock(Collator.class);
    List<RepositoryFileDto> mockRepositoryFileDtos = new ArrayList<RepositoryFileDto>();
    mockRepositoryFileDtos.add(mockRepositoryFileDto);
    RepositoryRequest mockRepositoryRequest = mock(RepositoryRequest.class);
    doReturn(true).when(fileService).isPathValid(nullable(String.class));
    doReturn(mockRepositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    doReturn(mockCollator).when(fileService).getCollator(anyInt());
    doReturn(mockRepositoryRequest).when(fileService).getRepositoryRequest((RepositoryFileDto) any(), anyBoolean(), nullable(String.class), anyBoolean());
    doReturn(mockRepositoryFileDtos).when(fileService.defaultUnifiedRepositoryWebService).getChildrenFromRequest(mockRepositoryRequest);
    doReturn(true).when(fileService).isShowingTitle(mockRepositoryRequest);
    List<RepositoryFileDto> repositoryFileDtos = fileService.doGetChildren("mock:path:fileName", null, true, true);
    verify(fileService, times(1)).isPathValid(nullable(String.class));
    verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getFile(nullable(String.class));
    verify(fileService, times(1)).getCollator(anyInt());
    verify(fileService, times(1)).getRepositoryRequest((RepositoryFileDto) any(), anyBoolean(), nullable(String.class), anyBoolean());
    verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getChildrenFromRequest(mockRepositoryRequest);
    verify(fileService, times(1)).isShowingTitle(mockRepositoryRequest);
    assertEquals(mockRepositoryFileDtos, repositoryFileDtos);
    assertEquals(1, repositoryFileDtos.size());
    assertEquals(mockRepositoryFileDto, repositoryFileDtos.get(0));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Collator(java.text.Collator) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 93 with RepositoryFileDto

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

the class FileServiceIT method mockDoRestoreInHomeDir.

public void mockDoRestoreInHomeDir(FileService fileService) {
    IUnifiedRepository iUnifiedRepository = mock(IUnifiedRepository.class);
    List<RepositoryFileDto> homeFolderFiles = getMockedRepositoryFileDtoList(new String[] { FILE_1, FILE_3 });
    when(fileService.doGetChildren(eq(PATH_USER_HOME_FOLDER), nullable(String.class), anyBoolean(), anyBoolean())).thenReturn(homeFolderFiles);
    when(fileService.getRepository()).thenReturn(iUnifiedRepository);
    when(fileService.doRestoreFilesInHomeDir(eq(PARAMS), anyInt())).thenCallRealMethod();
    RepositoryFile mockRepoFile1 = getMockedRepoFile(FILE_1);
    RepositoryFile mockRepoFile2 = getMockedRepoFile(FILE_2);
    when(iUnifiedRepository.getFileById(eq(FILE_1))).thenReturn(mockRepoFile1);
    when(iUnifiedRepository.getFileById(eq(FILE_2))).thenReturn(mockRepoFile2);
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 94 with RepositoryFileDto

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

the class FileServiceIT method doGetContentCreatorException.

@Test
public void doGetContentCreatorException() {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String creatorId = "creatorId";
    Map<String, Serializable> fileMetadata = mock(HashMap.class);
    doReturn(creatorId).when(fileMetadata).get("contentCreator");
    doReturn(fileMetadata).when(fileService.repository).getFileMetadata(fileId);
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    RepositoryFileDto repositoryFileDto1 = mock(RepositoryFileDto.class);
    doReturn(repositoryFileDto1).when(fileService.defaultUnifiedRepositoryWebService).getFileById(creatorId);
    try {
        fileService.doGetContentCreator(pathId);
        fail();
    } catch (FileNotFoundException e) {
    // Should catch the exception
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 95 with RepositoryFileDto

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

the class FileServiceIT method doGetMetadata.

@Test
public void doGetMetadata() {
    String pathId = "path:to:file:file1.ext";
    List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
    StringKeyStringValueDto stringKeyStringValueDto1 = mock(StringKeyStringValueDto.class);
    doReturn("key1").when(stringKeyStringValueDto1).getKey();
    doReturn("value1").when(stringKeyStringValueDto1).getValue();
    StringKeyStringValueDto stringKeyStringValueDto2 = mock(StringKeyStringValueDto.class);
    doReturn("key2").when(stringKeyStringValueDto2).getKey();
    doReturn("value2").when(stringKeyStringValueDto2).getValue();
    stringKeyStringValueDtos.add(stringKeyStringValueDto1);
    stringKeyStringValueDtos.add(stringKeyStringValueDto2);
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    doReturn(true).when(repositoryFileDto).isHidden();
    doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(nullable(String.class));
    // Test 1
    try {
        List<StringKeyStringValueDto> list = fileService.doGetMetadata(pathId);
        assertEquals(4, list.size());
        Boolean hasIsHidden = false;
        Boolean hasScheduable = false;
        for (StringKeyStringValueDto item : list) {
            if (item.getKey().equals("_PERM_HIDDEN")) {
                hasIsHidden = true;
            }
            if (item.getKey().equals(RepositoryFile.SCHEDULABLE_KEY)) {
                hasScheduable = true;
            }
        }
        assertTrue(hasIsHidden);
        assertTrue(hasScheduable);
    } catch (FileNotFoundException e) {
        fail();
    }
    stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
    stringKeyStringValueDtos.add(stringKeyStringValueDto1);
    stringKeyStringValueDtos.add(stringKeyStringValueDto2);
    StringKeyStringValueDto stringKeyStringValueDto3 = mock(StringKeyStringValueDto.class);
    doReturn(RepositoryFile.SCHEDULABLE_KEY).when(stringKeyStringValueDto3).getKey();
    doReturn("value3").when(stringKeyStringValueDto3).getValue();
    stringKeyStringValueDtos.add(stringKeyStringValueDto3);
    doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(nullable(String.class));
    // Test 2
    try {
        List<StringKeyStringValueDto> list = fileService.doGetMetadata(pathId);
        assertEquals(4, list.size());
        Boolean hasIsHidden = false;
        Boolean hasScheduable = false;
        for (StringKeyStringValueDto item : list) {
            if (item.getKey().equals("_PERM_HIDDEN")) {
                hasIsHidden = true;
            }
            if (item.getKey().equals(RepositoryFile.SCHEDULABLE_KEY)) {
                hasScheduable = true;
            }
        }
        assertTrue(hasIsHidden);
        assertTrue(hasScheduable);
    } catch (FileNotFoundException e) {
        fail();
    }
    doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(nullable(String.class));
    // Test 3
    try {
        List<StringKeyStringValueDto> list = fileService.doGetMetadata(null);
        assertEquals(null, list);
    } catch (FileNotFoundException e) {
        fail();
    }
    verify(fileService, times(2)).idToPath(pathId);
    verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFile(nullable(String.class));
    verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFileMetadata(nullable(String.class));
}
Also used : StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) 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