use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT method testDoCreateDirs.
@Test
public void testDoCreateDirs() throws Exception {
String pathId = "path:to:file:file1.ext";
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
RepositoryFileDto parentDir = mock(RepositoryFileDto.class);
doReturn("").when(parentDir).getPath();
doReturn(FileUtils.PATH_SEPARATOR).when(parentDir).getId();
when(fileService.getRepoWs().getFile(FileUtils.PATH_SEPARATOR)).thenReturn(parentDir);
when(fileService.getRepoWs().getFile("/path")).thenReturn(null);
when(fileService.getRepoWs().getFile("/to")).thenReturn(null);
when(fileService.getRepoWs().getFile("/file")).thenReturn(null);
when(fileService.getRepoWs().getFile("/file1.ext")).thenReturn(null);
RepositoryFileDto filePath = mock(RepositoryFileDto.class);
doReturn("/path").when(filePath).getPath();
doReturn("/path").when(filePath).getId();
RepositoryFileDto fileTo = mock(RepositoryFileDto.class);
doReturn("/path/to").when(fileTo).getPath();
doReturn("/path/to").when(fileTo).getId();
RepositoryFileDto fileFile = mock(RepositoryFileDto.class);
doReturn("/path/to/file").when(fileFile).getPath();
doReturn("/path/to/file").when(fileFile).getId();
RepositoryFileDto fileFileExt = mock(RepositoryFileDto.class);
doReturn("/path/to/file/file1").when(fileFileExt).getPath();
doReturn("/path/to/file/file1").when(fileFileExt).getId();
when(fileService.getRepoWs().createFolder(eq("/"), any(RepositoryFileDto.class), eq("/path"))).thenReturn(filePath);
when(fileService.getRepoWs().createFolder(eq("/path"), any(RepositoryFileDto.class), eq("/path/to"))).thenReturn(fileTo);
when(fileService.getRepoWs().createFolder(eq("/path/to"), any(RepositoryFileDto.class), eq("/path/to/file"))).thenReturn(fileFile);
when(fileService.getRepoWs().createFolder(eq("/path/to/file"), any(RepositoryFileDto.class), eq("/path/to/file/file1.ext"))).thenReturn(fileFileExt);
assertTrue(fileService.doCreateDir(pathId));
verify(fileService.getRepoWs(), times(4)).createFolder(nullable(String.class), any(RepositoryFileDto.class), nullable(String.class));
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT method doSetMetadataException.
@Test
public void doSetMetadataException() {
String pathId = "path:to:file:file1.ext";
List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
RepositoryFileDto file = mock(RepositoryFileDto.class);
doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
RepositoryFileAclDto repositoryFileAclDto = mock(RepositoryFileAclDto.class);
doReturn("sessionName").when(repositoryFileAclDto).getOwner();
doReturn(repositoryFileAclDto).when(fileService.defaultUnifiedRepositoryWebService).getAcl(nullable(String.class));
IPentahoSession pentahoSession = mock(IPentahoSession.class);
doReturn(pentahoSession).when(fileService).getSession();
doReturn("sessionName1").when(pentahoSession).getName();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
fail();
} catch (GeneralSecurityException e) {
// Should catch the exception
}
verify(fileService.defaultUnifiedRepositoryWebService).getFile(nullable(String.class));
verify(fileService.defaultUnifiedRepositoryWebService).getAcl(nullable(String.class));
verify(repositoryFileAclDto).getOwner();
verify(fileService.policy).isAllowed(nullable(String.class));
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT method testDoMoveFiles.
@Test
public void testDoMoveFiles() 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);
fileService.doMoveFiles(destPathId, StringUtils.join(params, ","));
verify(fileService.getRepoWs(), times(1)).moveFile(params[0], destPathId, null);
verify(fileService.getRepoWs(), times(1)).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 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(nullable(String.class));
RepositoryRequest mockRequest = mock(RepositoryRequest.class);
doReturn(mockRequest).when(fileService).getRepositoryRequest(nullable(String.class), anyBoolean(), anyInt(), nullable(String.class));
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(nullable(String.class));
fileService.doGetTree(pathId, depth, filter, showHidden, includeAcls);
verify(fileService, times(1)).idToPath(nullable(String.class));
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(), nullable(String.class));
// 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(), nullable(String.class));
// 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 FileServiceIT method testDoGetFileLocales.
@Test
public void testDoGetFileLocales() {
String param = "file1";
RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
List<PentahoLocale> locales = new ArrayList<PentahoLocale>();
PentahoLocale mockedLocale = mock(PentahoLocale.class);
locales.add(mockedLocale);
doReturn(param).when(repositoryFileDto).getId();
doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile("/" + param);
when(fileService.defaultUnifiedRepositoryWebService.getAvailableLocalesForFileById(repositoryFileDto.getId())).thenReturn(locales);
try {
fileService.doGetFileLocales(param);
verify(fileService.getRepository(), times(0)).getAvailableLocalesForFileById(repositoryFileDto.getId());
} catch (FileNotFoundException e) {
fail();
} catch (InternalError e) {
fail();
}
}
Aggregations