use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoGetTree.
@Test
public void testDoGetTree() {
String pathId = ":path:to:file:file1.ext";
int depth = 1;
String filter = "*|FOLDERS";
boolean showHidden = true;
boolean includeAcls = true;
// Test 1
doReturn("test").when(fileService).idToPath(anyString());
RepositoryRequest mockRequest = mock(RepositoryRequest.class);
doReturn(mockRequest).when(fileService).getRepositoryRequest(anyString(), anyBoolean(), anyInt(), anyString());
RepositoryFileDto mockChildFile = mock(RepositoryFileDto.class);
doReturn("test").when(mockChildFile).getId();
RepositoryFileTreeDto mockChildDto = mock(RepositoryFileTreeDto.class);
doReturn(mockChildFile).when(mockChildDto).getFile();
List<RepositoryFileTreeDto> mockChildrenDto = new ArrayList<RepositoryFileTreeDto>();
mockChildrenDto.add(mockChildDto);
RepositoryFileTreeDto mockTreeDto = mock(RepositoryFileTreeDto.class);
doReturn(mockChildrenDto).when(mockTreeDto).getChildren();
doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);
doReturn(true).when(fileService).isShowingTitle(mockRequest);
Collator mockCollator = mock(Collator.class);
doReturn(mockCollator).when(fileService).getCollatorInstance();
doNothing().when(fileService).sortByLocaleTitle(mockCollator, mockTreeDto);
Map<String, Serializable> fileMeta = new HashMap<String, Serializable>();
fileMeta.put(IUnifiedRepository.SYSTEM_FOLDER, new Boolean(false));
doReturn(fileMeta).when(fileService.repository).getFileMetadata(anyString());
fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
verify(fileService, times(1)).idToPath(anyString());
verify(mockRequest, times(1)).setIncludeAcls(anyBoolean());
verify(mockCollator, times(1)).setStrength(Collator.PRIMARY);
verify(fileService, times(1)).sortByLocaleTitle(mockCollator, mockTreeDto);
// verify( mockTreeDto ).setChildren( mockChildrenDto );
// Test 2 - path id is null
pathId = null;
fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
verify(fileService, times(1)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(), anyString());
// Test 3 - path id is set to the file utils path separator
pathId = FileUtils.PATH_SEPARATOR;
fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
verify(fileService, times(2)).getRepositoryRequest(eq(FileUtils.PATH_SEPARATOR), anyBoolean(), anyInt(), anyString());
// Test 3 - includeSystemFolders is false
mockRequest.setIncludeSystemFolders(false);
doReturn(mockTreeDto).when(fileService.defaultUnifiedRepositoryWebService).getTreeFromRequest(mockRequest);
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest 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), anyString(), 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.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoGetGeneratedContentForUser.
@Test
public void testDoGetGeneratedContentForUser() {
String pathId = "test.prpt", user = "admin", userFolder = "public/admin";
RepositoryFileDto fileDetailsMock = mock(RepositoryFileDto.class);
RepositoryFile workspaceFolder = mock(RepositoryFile.class);
doReturn(userFolder).when(workspaceFolder).getId();
SessionResource sessionResource = mock(SessionResource.class);
List<RepositoryFile> children = new ArrayList<RepositoryFile>();
RepositoryFile mockedChild = mock(RepositoryFile.class);
doReturn(false).when(mockedChild).isFolder();
children.add(mockedChild);
Map<String, Serializable> mockedFileMetadata = mock(Map.class);
doReturn(pathId).when(mockedFileMetadata).get(PentahoJcrConstants.PHO_CONTENTCREATOR);
when(fileService.repository.getFileMetadata(mockedChild.getId())).thenReturn(mockedFileMetadata);
doReturn(pathId).when(fileDetailsMock).getId();
doReturn(userFolder).when(sessionResource).doGetUserDir(user);
doReturn(workspaceFolder).when(fileService.repository).getFile(userFolder);
doReturn(sessionResource).when(fileService).getSessionResource();
doReturn(children).when(fileService.repository).getChildren(userFolder);
RepositoryFileDto mockedRepositoryFileDto = mock(RepositoryFileDto.class);
doReturn(mockedRepositoryFileDto).when(fileService).toFileDto(mockedChild, null, false);
try {
doReturn(fileDetailsMock).when(fileService).doGetProperties(pathId);
List<RepositoryFileDto> list = fileService.doGetGeneratedContent(pathId, user);
assertEquals(list.size(), 1);
} catch (FileNotFoundException e) {
e.printStackTrace();
fail();
} catch (Throwable t) {
fail();
}
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoGetFileLocalesFileNotFoundException.
@Test
public void testDoGetFileLocalesFileNotFoundException() {
String param = "file1";
RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
doReturn(param).when(repositoryFileDto).getId();
doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFile("/" + param);
try {
fileService.doGetFileLocales(param);
fail();
} catch (FileNotFoundException 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 FileResourceTest method testDoGetRootProperties.
@Test
public void testDoGetRootProperties() {
RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
doReturn(mockRepositoryFileDto).when(fileResource.fileService).doGetRootProperties();
RepositoryFileDto testRepositoryFileDto = fileResource.doGetRootProperties();
assertEquals(mockRepositoryFileDto, testRepositoryFileDto);
verify(fileResource.fileService, times(1)).doGetRootProperties();
}
Aggregations