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