Search in sources :

Example 6 with RepositoryFileDto

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

the class FileServiceTest 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(anyString());
    doReturn(true).when(repositoryFileDto).isHidden();
    doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(anyString());
    // 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(anyString());
    // 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(anyString());
    // 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(anyString());
    verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFileMetadata(anyString());
}
Also used : StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) Test(org.junit.Test)

Example 7 with RepositoryFileDto

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

the class FileServiceTest method testDoGetProperties.

@Test
public void testDoGetProperties() throws Exception {
    RepositoryFileDto file = mock(RepositoryFileDto.class);
    when(fileService.defaultUnifiedRepositoryWebService.getFile(anyString())).thenReturn(file);
    String pathId = "/usr/folder/file.txt";
    fileService.doGetProperties(pathId);
    verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getFile(anyString());
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 8 with RepositoryFileDto

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

the class FileServiceTest method testDoGetFileLocales.

@Test
public void testDoGetFileLocales() {
    String param = "file1";
    RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
    List<PentahoLocale> locales = new ArrayList<PentahoLocale>();
    PentahoLocale mockedLocale = mock(PentahoLocale.class);
    locales.add(mockedLocale);
    doReturn(param).when(repositoryFileDto).getId();
    doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile("/" + param);
    when(fileService.defaultUnifiedRepositoryWebService.getAvailableLocalesForFileById(repositoryFileDto.getId())).thenReturn(locales);
    try {
        fileService.doGetFileLocales(param);
        verify(fileService.getRepository(), times(0)).getAvailableLocalesForFileById(repositoryFileDto.getId());
    } catch (FileNotFoundException e) {
        fail();
    } catch (InternalError e) {
        fail();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) Test(org.junit.Test)

Example 9 with RepositoryFileDto

use of org.pentaho.platform.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 10 with RepositoryFileDto

use of org.pentaho.platform.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)

Aggregations

RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)66 Test (org.junit.Test)42 Matchers.anyString (org.mockito.Matchers.anyString)26 FileNotFoundException (java.io.FileNotFoundException)23 ArrayList (java.util.ArrayList)20 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)18 Serializable (java.io.Serializable)15 GeneralSecurityException (java.security.GeneralSecurityException)11 StringKeyStringValueDto (org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto)9 IllegalSelectorException (java.nio.channels.IllegalSelectorException)8 InvalidParameterException (java.security.InvalidParameterException)8 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)8 UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)8 IOException (java.io.IOException)7 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)6 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)6 RepositoryFileAclDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto)6 Properties (java.util.Properties)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 RepositoryFileAclAceDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto)4