Search in sources :

Example 6 with RepositoryFileDto

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

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

Example 7 with RepositoryFileDto

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

the class FileServiceTest method testDoGetFileAcl.

@Test
public void testDoGetFileAcl() {
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    RepositoryFileAclDto fileAcl = mock(RepositoryFileAclDto.class);
    when(fileAcl.isEntriesInheriting()).thenReturn(false);
    when(fileService.defaultUnifiedRepositoryWebService.getFile(anyString())).thenReturn(file);
    when(fileService.defaultUnifiedRepositoryWebService.getAcl(anyString())).thenReturn(fileAcl);
    doNothing().when(fileService).addAdminRole(fileAcl);
    String pathId = "/usr/dir/file.txt";
    fileService.doGetFileAcl(pathId);
    verify(fileService).addAdminRole(fileAcl);
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 8 with RepositoryFileDto

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

the class FileServiceTest method testDoDeleteLocale.

@Test
public void testDoDeleteLocale() throws Exception {
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    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.repository2.unified.webservices.RepositoryFileDto) Test(org.junit.Test)

Example 9 with RepositoryFileDto

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

the class FileServiceTest method testDoCreateDirs.

@Test
public void testDoCreateDirs() 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);
    when(fileService.getRepoWs().getFile("/path")).thenReturn(null);
    when(fileService.getRepoWs().getFile("/to")).thenReturn(null);
    when(fileService.getRepoWs().getFile("/file")).thenReturn(null);
    when(fileService.getRepoWs().getFile("/file1.ext")).thenReturn(null);
    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().createFolder(eq("/"), any(RepositoryFileDto.class), eq("/path"))).thenReturn(filePath);
    when(fileService.getRepoWs().createFolder(eq("/path"), any(RepositoryFileDto.class), eq("/path/to"))).thenReturn(fileTo);
    when(fileService.getRepoWs().createFolder(eq("/path/to"), any(RepositoryFileDto.class), eq("/path/to/file"))).thenReturn(fileFile);
    when(fileService.getRepoWs().createFolder(eq("/path/to/file"), any(RepositoryFileDto.class), eq("/path/to/file/file1.ext"))).thenReturn(fileFileExt);
    assertTrue(fileService.doCreateDir(pathId));
    verify(fileService.getRepoWs(), times(4)).createFolder(anyString(), any(RepositoryFileDto.class), anyString());
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with RepositoryFileDto

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

the class FileServiceTest method testDoSetLocalProperties.

@Test
public void testDoSetLocalProperties() throws Exception {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String locale = "";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
    Properties fileProperties = mock(Properties.class);
    doReturn(false).when(fileProperties).isEmpty();
    List<StringKeyStringValueDto> properties = new ArrayList<StringKeyStringValueDto>();
    properties.add(new StringKeyStringValueDto("key1", "value1"));
    properties.add(new StringKeyStringValueDto("key2", "value2"));
    fileService.doSetLocaleProperties(pathId, locale, properties);
    verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
    verify(fileService.defaultUnifiedRepositoryWebService).setLocalePropertiesForFileByFileId(anyString(), anyString(), any(Properties.class));
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Properties(java.util.Properties) 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