Search in sources :

Example 86 with RepositoryFileDto

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

the class FileServiceIT method getMockedRepositoryFileDtoList.

public List<RepositoryFileDto> getMockedRepositoryFileDtoList(String[] fileNames) {
    List<RepositoryFileDto> repoFileDtoList = new ArrayList<>();
    for (String fileName : fileNames) {
        RepositoryFileDto repoFileDto = mock(RepositoryFileDto.class);
        when(repoFileDto.getName()).thenReturn(fileName);
        when(repoFileDto.getId()).thenReturn(fileName);
        repoFileDtoList.add(repoFileDto);
    }
    return repoFileDtoList;
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList)

Example 87 with RepositoryFileDto

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

the class FileServiceIT 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(nullable(String.class))).thenReturn(file);
    when(fileService.defaultUnifiedRepositoryWebService.getAcl(nullable(String.class))).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.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 88 with RepositoryFileDto

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

the class FileServiceIT 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(nullable(String.class));
    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(nullable(String.class), nullable(String.class), any(Properties.class));
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) ArrayList(java.util.ArrayList) Properties(java.util.Properties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 89 with RepositoryFileDto

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

the class FileServiceIT 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.api.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 90 with RepositoryFileDto

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

the class FileServiceIT method testDoGetLocalProperties.

@Test
public void testDoGetLocalProperties() throws Exception {
    String pathId = "path:to:file:file1.ext";
    String fileId = "file1";
    String locale = "";
    doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
    Set<String> propertiesList = new HashSet<String>();
    propertiesList.add("prop1");
    propertiesList.add("prop2");
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    doReturn(fileId).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
    Properties properties = mock(Properties.class);
    doReturn("value1").when(properties).getProperty("prop1");
    doReturn("value2").when(properties).getProperty("prop2");
    doReturn(false).when(properties).isEmpty();
    doReturn(propertiesList).when(properties).stringPropertyNames();
    PropertiesWrapper propertiesWrapper = mock(PropertiesWrapper.class);
    when(propertiesWrapper.getProperties()).thenReturn(properties);
    doReturn(propertiesWrapper).when(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(nullable(String.class), nullable(String.class));
    List<StringKeyStringValueDto> keyValueList = fileService.doGetLocaleProperties(pathId, locale);
    verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
    verify(properties).getProperty("prop1");
    verify(properties).getProperty("prop2");
    verify(properties).isEmpty();
    verify(properties).stringPropertyNames();
    verify(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(nullable(String.class), nullable(String.class));
    assertEquals(2, keyValueList.size());
    assertEquals("prop1", keyValueList.get(1).getKey());
    assertEquals("prop2", keyValueList.get(0).getKey());
    assertEquals("value1", keyValueList.get(1).getValue());
    assertEquals("value2", keyValueList.get(0).getValue());
}
Also used : RepositoryFileDto(org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto) Properties(java.util.Properties) PropertiesWrapper(org.pentaho.platform.repository2.unified.webservices.PropertiesWrapper) HashSet(java.util.HashSet) 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