use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoGetLocalProperties.
@Test
public void testDoGetLocalProperties() throws Exception {
String pathId = "path:to:file:file1.ext";
String fileId = "file1";
String locale = "";
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
Set<String> propertiesList = new HashSet<String>();
propertiesList.add("prop1");
propertiesList.add("prop2");
RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
doReturn(fileId).when(repositoryFileDto).getId();
doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
Properties properties = mock(Properties.class);
doReturn("value1").when(properties).getProperty("prop1");
doReturn("value2").when(properties).getProperty("prop2");
doReturn(false).when(properties).isEmpty();
doReturn(propertiesList).when(properties).stringPropertyNames();
PropertiesWrapper propertiesWrapper = mock(PropertiesWrapper.class);
when(propertiesWrapper.getProperties()).thenReturn(properties);
doReturn(propertiesWrapper).when(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
List<StringKeyStringValueDto> keyValueList = fileService.doGetLocaleProperties(pathId, locale);
verify(fileService.defaultUnifiedRepositoryWebService).getFile("/path/to/file/file1.ext");
verify(properties).getProperty("prop1");
verify(properties).getProperty("prop2");
verify(properties).isEmpty();
verify(properties).stringPropertyNames();
verify(fileService.defaultUnifiedRepositoryWebService).getLocalePropertiesForFileById(anyString(), anyString());
assertEquals(2, keyValueList.size());
assertEquals("prop1", keyValueList.get(1).getKey());
assertEquals("prop2", keyValueList.get(0).getKey());
assertEquals("value1", keyValueList.get(1).getValue());
assertEquals("value2", keyValueList.get(0).getValue());
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest method testDoGetChildren.
@Test
public void testDoGetChildren() {
RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
Collator mockCollator = mock(Collator.class);
List<RepositoryFileDto> mockRepositoryFileDtos = new ArrayList<RepositoryFileDto>();
mockRepositoryFileDtos.add(mockRepositoryFileDto);
RepositoryRequest mockRepositoryRequest = mock(RepositoryRequest.class);
doReturn(true).when(fileService).isPathValid(anyString());
doReturn(mockRepositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
doReturn(mockCollator).when(fileService).getCollator(anyInt());
doReturn(mockRepositoryRequest).when(fileService).getRepositoryRequest((RepositoryFileDto) anyObject(), anyBoolean(), anyString(), anyBoolean());
doReturn(mockRepositoryFileDtos).when(fileService.defaultUnifiedRepositoryWebService).getChildrenFromRequest(mockRepositoryRequest);
doReturn(true).when(fileService).isShowingTitle(mockRepositoryRequest);
List<RepositoryFileDto> repositoryFileDtos = fileService.doGetChildren("mock:path:fileName", null, true, true);
verify(fileService, times(1)).isPathValid(anyString());
verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getFile(anyString());
verify(fileService, times(1)).getCollator(anyInt());
verify(fileService, times(1)).getRepositoryRequest((RepositoryFileDto) anyObject(), anyBoolean(), anyString(), anyBoolean());
verify(fileService.defaultUnifiedRepositoryWebService, times(1)).getChildrenFromRequest(mockRepositoryRequest);
verify(fileService, times(1)).isShowingTitle(mockRepositoryRequest);
assertEquals(mockRepositoryFileDtos, repositoryFileDtos);
assertEquals(1, repositoryFileDtos.size());
assertEquals(mockRepositoryFileDto, repositoryFileDtos.get(0));
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceTest 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-kettle by pentaho.
the class UnifiedRepositoryPurgeService method processPurgeForTree.
private void processPurgeForTree(RepositoryFileTreeDto tree, PurgeUtilitySpecification purgeSpecification) {
for (RepositoryFileTreeDto child : tree.getChildren()) {
try {
if (!child.getChildren().isEmpty()) {
processPurgeForTree(child, purgeSpecification);
}
RepositoryFileDto file = child.getFile();
getLogger().setCurrentFilePath(file.getPath());
if (file.isVersioned()) {
if (purgeSpecification.isPurgeFiles()) {
getLogger().info("Purge File");
// the latest version will be removed with deleteFileWithPermanentFlag
keepNumberOfVersions(file.getId(), 1);
getRepoWs().deleteFileWithPermanentFlag(file.getId(), true, "purge utility");
} else if (purgeSpecification.isPurgeRevisions()) {
getLogger().info("Purging Revisions");
deleteAllVersions(file.getId());
} else {
if (purgeSpecification.getBeforeDate() != null) {
getLogger().info("Checking/purging by Revision date");
deleteVersionsBeforeDate(file.getId(), purgeSpecification.getBeforeDate());
}
if (purgeSpecification.getVersionCount() >= 0) {
getLogger().info("Checking/purging by number of Revisions");
keepNumberOfVersions(file.getId(), purgeSpecification.getVersionCount());
}
}
}
} catch (Exception e) {
getLogger().error(e);
}
}
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileServiceIT 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());
}
}
Aggregations