Search in sources :

Example 66 with RepositoryFileDto

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

the class FileServiceTest method testDoSetContentCreatorFileNotFoundException.

@Test
public void testDoSetContentCreatorFileNotFoundException() throws Exception {
    String param = "file1";
    RepositoryFileDto mockFileDto = mock(RepositoryFileDto.class);
    Map<String, Serializable> fileMetadata = mock(Map.class);
    when(fileService.idToPath(param)).thenReturn("/file1");
    doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFile("/file1");
    try {
        fileService.doSetContentCreator(param, mockFileDto);
        fail();
    } catch (FileNotFoundException e) {
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 67 with RepositoryFileDto

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

the class FileServiceTest method testDoSetContentCreatorFileException.

@Test
public void testDoSetContentCreatorFileException() throws Exception {
    String param = "file1";
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    Map<String, Serializable> fileMetadata = mock(Map.class);
    doReturn(param).when(repositoryFileDto).getId();
    when(fileService.idToPath(param)).thenReturn("/file1");
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile("/file1");
    when(fileService.getRepository().getFileMetadata(repositoryFileDto.getId())).thenThrow(new InternalError());
    // failing in get
    try {
        fileService.doSetContentCreator(param, repositoryFileDto);
    } catch (FileNotFoundException e) {
        fail();
    } catch (InternalError e) {
        verify(fileMetadata, times(0)).put(PentahoJcrConstants.PHO_CONTENTCREATOR, param);
        verify(fileService.repository, times(0)).setFileMetadata(param, fileMetadata);
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 68 with RepositoryFileDto

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

the class FileServiceTest 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.repository2.unified.webservices.RepositoryFileDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 69 with RepositoryFileDto

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

the class FileServiceTest method testDoSetContentCreator.

@Test
public void testDoSetContentCreator() throws Exception {
    String param = "file1";
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    Map<String, Serializable> fileMetadata = mock(Map.class);
    String idToPathResult = "/file1";
    doReturn(param).when(repositoryFileDto).getId();
    when(fileService.idToPath(param)).thenReturn(idToPathResult);
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(eq(idToPathResult));
    when(fileService.getRepository().getFileMetadata(repositoryFileDto.getId())).thenReturn(fileMetadata);
    try {
        fileService.doSetContentCreator(param, repositoryFileDto);
        verify(fileService.getRepository(), times(1)).getFileMetadata(repositoryFileDto.getId());
        verify(fileService.getRepository(), times(1)).setFileMetadata(param, fileMetadata);
    } catch (FileNotFoundException e) {
        fail();
    } catch (InternalError e) {
        fail();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Serializable(java.io.Serializable) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 70 with RepositoryFileDto

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

the class FileServiceTest method doGetDeletedFiles.

@Test
public void doGetDeletedFiles() {
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    RepositoryFileDto repositoryFileDto1 = mock(RepositoryFileDto.class);
    List<RepositoryFileDto> fileDtos = new ArrayList<RepositoryFileDto>();
    fileDtos.add(repositoryFileDto);
    fileDtos.add(repositoryFileDto1);
    // Test 1
    doReturn(fileDtos).when(fileService.defaultUnifiedRepositoryWebService).getDeletedFiles();
    List<RepositoryFileDto> repositoryFiles = fileService.doGetDeletedFiles();
    assertEquals(2, repositoryFiles.size());
    // Test 2
    doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getDeletedFiles();
    repositoryFiles = fileService.doGetDeletedFiles();
    assertEquals(null, repositoryFiles);
    verify(fileService.defaultUnifiedRepositoryWebService, times(2)).getDeletedFiles();
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) 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