use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoDeleteLocale.
@Test
public void testDoDeleteLocale() throws Exception {
RepositoryFileDto file = mock(RepositoryFileDto.class);
doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
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.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest 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(anyString(), any(RepositoryFileDto.class), anyString());
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoSetLocalProperties.
@Test
public void testDoSetLocalProperties() throws Exception {
String pathId = "path:to:file:file1.ext";
String fileId = "file1";
String locale = "";
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
doReturn(fileId).when(repositoryFileDto).getId();
doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
Properties fileProperties = mock(Properties.class);
doReturn(false).when(fileProperties).isEmpty();
List<StringKeyStringValueDto> properties = new ArrayList<StringKeyStringValueDto>();
properties.add(new StringKeyStringValueDto("key1", "value1"));
properties.add(new StringKeyStringValueDto("key2", "value2"));
fileService.doSetLocaleProperties(pathId, locale, properties);
verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
verify(fileService.defaultUnifiedRepositoryWebService).setLocalePropertiesForFileByFileId(anyString(), anyString(), any(Properties.class));
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method doGetContentCreator.
@Test
public void doGetContentCreator() {
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(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
RepositoryFileDto repositoryFileDto1 = mock(RepositoryFileDto.class);
doReturn(repositoryFileDto1).when(fileService.defaultUnifiedRepositoryWebService).getFileById(creatorId);
// Test 1
RepositoryFileDto repositoryFileDto2 = null;
try {
repositoryFileDto2 = fileService.doGetContentCreator(pathId);
} catch (Exception e) {
fail();
}
assertEquals(repositoryFileDto1, repositoryFileDto2);
// Test 2
doReturn(null).when(fileMetadata).get("contentCreator");
try {
repositoryFileDto2 = fileService.doGetContentCreator(pathId);
assertEquals(null, repositoryFileDto2);
} catch (Exception e) {
fail();
}
// Test 3
doReturn("").when(fileMetadata).get("contentCreator");
try {
repositoryFileDto2 = fileService.doGetContentCreator(pathId);
assertEquals(null, repositoryFileDto2);
} catch (Exception e) {
fail();
}
verify(fileService, times(3)).idToPath(pathId);
verify(fileService.repository, times(3)).getFileMetadata(fileId);
verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFile(anyString());
verify(fileService.defaultUnifiedRepositoryWebService).getFileById(anyString());
}
use of org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoCreateDirsNegative.
@Test
public void testDoCreateDirsNegative() 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);
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().getFile("/path")).thenReturn(filePath);
when(fileService.getRepoWs().getFile("/path/to")).thenReturn(fileTo);
when(fileService.getRepoWs().getFile("/path/to/file")).thenReturn(fileFile);
when(fileService.getRepoWs().getFile("/path/to/file/file1.ext")).thenReturn(fileFileExt);
assertFalse(fileService.doCreateDir(pathId));
verify(fileService.getRepoWs(), times(0)).createFolder(anyString(), any(RepositoryFileDto.class), anyString());
when(fileService.getRepoWs().getFile("/path")).thenReturn(null);
when(fileService.getRepoWs().createFolder(eq("/"), any(RepositoryFileDto.class), eq("/path"))).thenThrow(new InternalError("negativetest"));
try {
fileService.doCreateDir(pathId);
} catch (InternalError e) {
assertEquals(e.getMessage(), "negativetest");
}
}
Aggregations