use of org.pentaho.platform.api.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.api.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.api.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.api.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.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileResourceIT method testFileCreator.
@Test
public void testFileCreator() {
loginAsRepositoryAdmin();
ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, authenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, authenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName });
try {
login("admin", mainTenant_1, new String[] { authenticatedAuthorityName });
// set object in PentahoSystem
mp.defineInstance(IUnifiedRepository.class, repo);
WebResource webResource = resource();
String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + "file1.txt", "abcdefg");
RepositoryFile file1 = repo.getFile(publicFolderPath + "/" + "file1.txt");
RepositoryFileDto file2 = new RepositoryFileDto();
file2.setId(file1.getId().toString());
webResource.path("repo/files/public:file1.txt/creator").entity(file2).put();
} catch (Throwable ex) {
TestCase.fail();
} finally {
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
logout();
}
}
Aggregations