use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileResourceTest method testSetContentCreator.
@Test
public void testSetContentCreator() throws Exception {
RepositoryFileDto mockRepositoryFileDto = mock(RepositoryFileDto.class);
doNothing().when(fileResource.fileService).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
Response mockOkResponse = mock(Response.class);
doReturn(mockOkResponse).when(fileResource).buildOkResponse();
Response testResponse = fileResource.doSetContentCreator(PATH_ID, mockRepositoryFileDto);
assertEquals(mockOkResponse, testResponse);
verify(fileResource.fileService, times(1)).doSetContentCreator(PATH_ID, mockRepositoryFileDto);
verify(fileResource, times(1)).buildOkResponse();
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileResourceTest method testDoGetGeneratedContentForUserError.
@Test
public void testDoGetGeneratedContentForUserError() throws Exception {
String user = "user";
Exception mockFileNotFoundException = mock(FileNotFoundException.class);
doThrow(mockFileNotFoundException).when(fileResource.fileService).doGetGeneratedContent(PATH_ID, user);
Messages mockMessages = mock(Messages.class);
doReturn(mockMessages).when(fileResource).getMessagesInstance();
// Test 1
List<RepositoryFileDto> testList = fileResource.doGetGeneratedContentForUser(PATH_ID, user);
assertEquals(0, testList.size());
// Test 2
Throwable mockThrowable = mock(RuntimeException.class);
doThrow(mockThrowable).when(fileResource.fileService).doGetGeneratedContent(PATH_ID, user);
testList = fileResource.doGetGeneratedContentForUser(PATH_ID, user);
assertEquals(0, testList.size());
verify(fileResource.fileService, times(2)).doGetGeneratedContent(PATH_ID, user);
verify(fileResource, times(1)).getMessagesInstance();
verify(mockMessages, times(1)).getString("FileResource.GENERATED_CONTENT_FOR_USER_FAILED", PATH_ID, user);
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileResourceTest method testDoGetContentCreatorError.
@Test
public void testDoGetContentCreatorError() throws Exception {
Throwable mockThrowable = mock(RuntimeException.class);
doThrow(mockThrowable).when(fileResource.fileService).doGetContentCreator(PATH_ID);
RepositoryFileDto testDto = fileResource.doGetContentCreator(PATH_ID);
assertNull(testDto);
verify(fileResource.fileService, times(1)).doGetContentCreator(PATH_ID);
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class FileResourceIT method testDeleteFiles.
@Test
public void testDeleteFiles() {
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 });
String testFile1Id = "abc.txt";
String testFile2Id = "def.txt";
// set object in PentahoSystem
mp.defineInstance(IUnifiedRepository.class, repo);
String publicFolderPath = ClientRepositoryPaths.getPublicFolderPath();
createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile1Id, "abcdefg");
createTestFile(publicFolderPath.replaceAll("/", ":") + ":" + testFile2Id, "abcdefg");
createTestFolder(":home:admin");
RepositoryFile file1 = repo.getFile(publicFolderPath + "/" + testFile1Id);
RepositoryFile file2 = repo.getFile(publicFolderPath + "/" + testFile2Id);
WebResource webResource = resource();
webResource.path("repo/files/delete").entity(file1.getId() + "," + file2.getId()).put();
RepositoryFileDto[] deletedFiles = webResource.path("repo/files/deleted").accept(APPLICATION_XML).get(RepositoryFileDto[].class);
assertEquals(2, deletedFiles.length);
webResource.path("repo/files/deletepermanent").entity(file2.getId()).put();
} catch (Throwable ex) {
TestCase.fail();
} finally {
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
}
}
use of org.pentaho.platform.api.repository2.unified.webservices.RepositoryFileDto in project pentaho-platform by pentaho.
the class RepositoryFileAdapter method toFile.
public static RepositoryFile toFile(final RepositoryFileDto v) {
if (v == null) {
return null;
}
RepositoryFile.Builder builder = null;
if (v.getId() != null) {
builder = new RepositoryFile.Builder(v.getId(), v.getName());
} else {
builder = new RepositoryFile.Builder(v.getName());
}
if (v.getOwnerType() != -1) {
new RepositoryFileSid(v.getOwner(), RepositoryFileSid.Type.values()[v.getOwnerType()]);
}
if (v.getLocalePropertiesMapEntries() != null) {
for (LocaleMapDto localeMapDto : v.getLocalePropertiesMapEntries()) {
String locale = localeMapDto.getLocale();
Properties localeProperties = new Properties();
if (localeMapDto.getProperties() != null) {
for (StringKeyStringValueDto keyValueDto : localeMapDto.getProperties()) {
localeProperties.put(keyValueDto.getKey(), keyValueDto.getValue());
}
}
builder.localeProperties(locale, localeProperties);
}
}
return builder.path(v.getPath()).createdDate(unmarshalDate(v.getCreatedDate())).creatorId(v.getCreatorId()).description(v.getDescription()).folder(v.isFolder()).fileSize(v.getFileSize()).lastModificationDate(unmarshalDate(v.getLastModifiedDate())).locale(v.getLocale()).lockDate(unmarshalDate(v.getLockDate())).locked(v.isLocked()).lockMessage(v.getLockMessage()).lockOwner(v.getLockOwner()).title(v.getTitle()).versioned(v.isVersioned()).versionId(v.getVersionId()).originalParentFolderPath(v.getOriginalParentFolderPath()).deletedDate(unmarshalDate(v.getDeletedDate())).hidden(v.isHidden()).schedulable(!v.isNotSchedulable()).aclNode(v.isAclNode()).build();
}
Aggregations