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());
}
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());
}
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();
}
}
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());
}
}
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);
}
Aggregations