use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT 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 FileServiceIT method testDoDeleteLocale.
@Test
public void testDoDeleteLocale() throws Exception {
RepositoryFileDto file = mock(RepositoryFileDto.class);
doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
doReturn("file.txt").when(file).getId();
fileService.doDeleteLocale(file.getId(), "en_US");
verify(fileService.getRepoWs(), times(1)).deleteLocalePropertiesForFile("file.txt", "en_US");
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class CopyFilesOperation_CopyTest method copyFiles_OverwriteMode.
@Test
public void copyFiles_OverwriteMode() {
CopyFilesOperation operation = new CopyFilesOperation(repo, webService, getIdList(file1, file2), PATH_DEST_DIR, FileService.MODE_OVERWRITE);
// emulate, file with the same name exists.
RepositoryFile conflictFile = mockFile(generateID(), DEFAULT, PATH_DEST_DIR + SEPARATOR + NAME_FILE_1);
operation = spy(operation);
RepositoryFileDto fileDto = mock(RepositoryFileDto.class);
doReturn(conflictFile).when(operation).toFile(fileDto);
doReturn(fileDto).when(operation).toFileDto(eq(conflictFile), nullable(Set.class), nullable(Boolean.class));
doReturn(conflictFile).when(repo).updateFile(eq(conflictFile), nullable(IRepositoryFileData.class), nullable(String.class));
operation.execute();
verify(repo).updateFile(eq(conflictFile), nullable(IRepositoryFileData.class), nullable(String.class));
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class CopyFilesOperation_CopyTest method copyFolders_RenameMode.
@Test
public void copyFolders_RenameMode() {
CopyFilesOperation operation = new CopyFilesOperation(repo, webService, getIdList(folder1, folder2), PATH_DEST_DIR, FileService.MODE_RENAME);
// emulate, file with the same name exists.
RepositoryFile conflict = mockFolder(generateID(), DEFAULT, PATH_DEST_DIR + SEPARATOR + NAME_DIR_2);
String conflictFolderPath = conflict.getPath();
RepositoryFileDto dtoConflictFolder = mock(RepositoryFileDto.class);
doReturn(dtoConflictFolder).when(webService).getFile(eq(conflictFolderPath));
operation = spy(operation);
operation.execute();
verify(repo, times(2)).createFolder(eq(destFolder.getId()), nullable(RepositoryFile.class), nullable(RepositoryFileAcl.class), nullable(String.class));
verify(operation, times(2)).performFolderDeepCopy(nullable(RepositoryFile.class), nullable(RepositoryFile.class), anyInt());
verify(repo, never()).createFile(nullable(Serializable.class), nullable(RepositoryFile.class), nullable(IRepositoryFileData.class), nullable(RepositoryFileAcl.class), nullable(String.class));
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testGetDefaultLocation_Scenario_DefaultFolderIsHidden.
@Test
public void testGetDefaultLocation_Scenario_DefaultFolderIsHidden() throws Exception {
RepositoryFileDto hiddenDto = new RepositoryFileDto();
hiddenDto.setFolder(true);
hiddenDto.setHidden(true);
hiddenDto.setId(RandomStringUtils.randomNumeric(20));
hiddenDto.setName("suzy");
hiddenDto.setPath("/home/suzy");
RepositoryFileDto defaultDto = new RepositoryFileDto();
defaultDto.setFolder(true);
defaultDto.setHidden(true);
defaultDto.setId(RandomStringUtils.randomNumeric(20));
defaultDto.setName("default");
defaultDto.setPath("/default-folder");
RepositoryFileDto publicFolderDto = new RepositoryFileDto();
publicFolderDto.setFolder(true);
publicFolderDto.setHidden(false);
publicFolderDto.setId(RandomStringUtils.randomNumeric(20));
publicFolderDto.setName("public");
publicFolderDto.setPath("/public");
DefaultUnifiedRepositoryWebService repoWs = mock(DefaultUnifiedRepositoryWebService.class);
doReturn(repoWs).when(fileService).getRepoWs();
doReturn(hiddenDto).when(repoWs).getFile("/home/suzy");
when(PentahoSystem.get(ISystemConfig.class).getProperty(eq(PentahoSystem.DEFAULT_FOLDER_WHEN_HOME_FOLDER_IS_HIDDEN_PROPERTY))).thenReturn("/default-folder");
doReturn(defaultDto).when(repoWs).getFile("/default-folder");
doReturn(publicFolderDto).when(repoWs).getFile("/public");
assertEquals(ClientRepositoryPaths.getPublicFolderPath(), fileService.doGetDefaultLocation(":home:suzy"));
}
Aggregations