use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT 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 FileServiceIT method testDoGetChildren.
@Test
public void testDoGetChildren() {
RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
Collator mockCollator = mock(Collator.class);
List<RepositoryFileDto> mockRepositoryFileDtos = new ArrayList<RepositoryFileDto>();
mockRepositoryFileDtos.add(mockRepositoryFileDto);
RepositoryRequest mockRepositoryRequest = mock(RepositoryRequest.class);
doReturn(true).when(fileService).isPathValid(nullable(String.class));
doReturn(mockRepositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
doReturn(mockCollator).when(fileService).getCollator(anyInt());
doReturn(mockRepositoryRequest).when(fileService).getRepositoryRequest((RepositoryFileDto) any(), anyBoolean(), nullable(String.class), anyBoolean());
doReturn(mockRepositoryFileDtos).when(fileService.defaultUnifiedRepositoryWebService).getChildrenFromRequest(mockRepositoryRequest);
doReturn(true).when(fileService).isShowingTitle(mockRepositoryRequest);
List<RepositoryFileDto> repositoryFileDtos = fileService.doGetChildren("mock:path:fileName", null, true, true);
verify(fileService, times(1)).isPathValid(nullable(String.class));
verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getFile(nullable(String.class));
verify(fileService, times(1)).getCollator(anyInt());
verify(fileService, times(1)).getRepositoryRequest((RepositoryFileDto) any(), anyBoolean(), nullable(String.class), anyBoolean());
verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getChildrenFromRequest(mockRepositoryRequest);
verify(fileService, times(1)).isShowingTitle(mockRepositoryRequest);
assertEquals(mockRepositoryFileDtos, repositoryFileDtos);
assertEquals(1, repositoryFileDtos.size());
assertEquals(mockRepositoryFileDto, repositoryFileDtos.get(0));
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT method mockDoRestoreInHomeDir.
public void mockDoRestoreInHomeDir(FileService fileService) {
IUnifiedRepository iUnifiedRepository = mock(IUnifiedRepository.class);
List<RepositoryFileDto> homeFolderFiles = getMockedRepositoryFileDtoList(new String[] { FILE_1, FILE_3 });
when(fileService.doGetChildren(eq(PATH_USER_HOME_FOLDER), nullable(String.class), anyBoolean(), anyBoolean())).thenReturn(homeFolderFiles);
when(fileService.getRepository()).thenReturn(iUnifiedRepository);
when(fileService.doRestoreFilesInHomeDir(eq(PARAMS), anyInt())).thenCallRealMethod();
RepositoryFile mockRepoFile1 = getMockedRepoFile(FILE_1);
RepositoryFile mockRepoFile2 = getMockedRepoFile(FILE_2);
when(iUnifiedRepository.getFileById(eq(FILE_1))).thenReturn(mockRepoFile1);
when(iUnifiedRepository.getFileById(eq(FILE_2))).thenReturn(mockRepoFile2);
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT method doGetContentCreatorException.
@Test
public void doGetContentCreatorException() {
String pathId = "path:to:file:file1.ext";
String fileId = "file1";
String creatorId = "creatorId";
Map<String, Serializable> fileMetadata = mock(HashMap.class);
doReturn(creatorId).when(fileMetadata).get("contentCreator");
doReturn(fileMetadata).when(fileService.repository).getFileMetadata(fileId);
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
doReturn(fileId).when(repositoryFileDto).getId();
doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
RepositoryFileDto repositoryFileDto1 = mock(RepositoryFileDto.class);
doReturn(repositoryFileDto1).when(fileService.defaultUnifiedRepositoryWebService).getFileById(creatorId);
try {
fileService.doGetContentCreator(pathId);
fail();
} catch (FileNotFoundException e) {
// Should catch the exception
}
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT 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(nullable(String.class));
doReturn(true).when(repositoryFileDto).isHidden();
doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(nullable(String.class));
// 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(nullable(String.class));
// 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(nullable(String.class));
// 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(nullable(String.class));
verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFileMetadata(nullable(String.class));
}
Aggregations