use of org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto in project pentaho-platform by pentaho.
the class FileServiceTest method doSetMetadata.
@Test
public void doSetMetadata() {
String pathId = "path:to:file:file1.ext";
List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
StringKeyStringValueDto stringKeyStringValueDto1 = mock(StringKeyStringValueDto.class);
doReturn("key1").when(stringKeyStringValueDto1).getKey();
doReturn("value1").when(stringKeyStringValueDto1).getValue();
StringKeyStringValueDto stringKeyStringValueDto2 = mock(StringKeyStringValueDto.class);
doReturn("key2").when(stringKeyStringValueDto2).getKey();
doReturn("value2").when(stringKeyStringValueDto2).getValue();
stringKeyStringValueDtos.add(stringKeyStringValueDto1);
stringKeyStringValueDtos.add(stringKeyStringValueDto2);
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
doReturn(true).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(true).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(true).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
RepositoryFileDto file = mock(RepositoryFileDto.class);
doReturn(false).when(file).isFolder();
doReturn(true).when(file).isHidden();
doReturn(file).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
List<RepositoryFileAclAceDto> repositoryFileAclAceDtos = new ArrayList<RepositoryFileAclAceDto>();
RepositoryFileAclDto repositoryFileAclDto = mock(RepositoryFileAclDto.class);
doReturn("sessionName").when(repositoryFileAclDto).getOwner();
doReturn(true).when(repositoryFileAclDto).isEntriesInheriting();
doReturn(repositoryFileAclAceDtos).when(repositoryFileAclDto).getAces();
doReturn(repositoryFileAclDto).when(fileService.defaultUnifiedRepositoryWebService).getAcl(anyString());
IPentahoSession pentahoSession = mock(IPentahoSession.class);
doReturn(pentahoSession).when(fileService).getSession();
doReturn("sessionName").when(pentahoSession).getName();
RepositoryFileAclAceDto repositoryFileAclAceDto = mock(RepositoryFileAclAceDto.class);
List<Integer> permissions = new ArrayList<Integer>();
permissions.add(RepositoryFilePermission.ACL_MANAGEMENT.ordinal());
doReturn(permissions).when(repositoryFileAclAceDto).getPermissions();
doReturn("sessionName").when(repositoryFileAclAceDto).getRecipient();
repositoryFileAclAceDtos.add(repositoryFileAclAceDto);
doReturn(repositoryFileAclAceDtos).when(fileService.defaultUnifiedRepositoryWebService).getEffectiveAces(anyString());
Map<String, Serializable> metadata = new HashMap<String, Serializable>();
doReturn(metadata).when(fileService.repository).getFileMetadata(anyString());
RepositoryFile sourceFile = mock(RepositoryFile.class);
doReturn(sourceFile).when(fileService.repository).getFileById(anyString());
RepositoryFileDto destFileDto = mock(RepositoryFileDto.class);
doReturn(destFileDto).when(fileService).toFileDto(sourceFile, null, false);
RepositoryFile destFile = mock(RepositoryFile.class);
doReturn(destFile).when(fileService).toFile(destFileDto);
RepositoryFileAcl acl = mock(RepositoryFileAcl.class);
doReturn(acl).when(fileService.repository).getAcl(acl);
// Test 1 - canManage should be true at start
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 2 - canManage should be false at start
doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
doReturn("sessionName1").when(repositoryFileAclDto).getOwner();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 3 - canManage should be false at start
doReturn(true).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
doReturn("sessionName1").when(repositoryFileAclDto).getOwner();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 4 - canManage should be false at start
doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(true).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
doReturn("sessionName1").when(repositoryFileAclDto).getOwner();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 5 - canManage should be false at start
doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(true).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
doReturn("sessionName1").when(repositoryFileAclDto).getOwner();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 6 - canManage should be false at start
doReturn(true).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(true).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(false).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
doReturn("sessionName1").when(repositoryFileAclDto).getOwner();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 7 - canManage should be false at start
doReturn(false).when(fileService.policy).isAllowed(RepositoryReadAction.NAME);
doReturn(true).when(fileService.policy).isAllowed(RepositoryCreateAction.NAME);
doReturn(true).when(fileService.policy).isAllowed(AdministerSecurityAction.NAME);
doReturn("sessionName1").when(repositoryFileAclDto).getOwner();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 8 - canManage should be false at start
doReturn(true).when(file).isFolder();
doReturn(true).when(file).isHidden();
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
// Test 9
StringKeyStringValueDto stringKeyStringValueDto3 = mock(StringKeyStringValueDto.class);
doReturn("_PERM_HIDDEN").when(stringKeyStringValueDto3).getKey();
doReturn("true").when(stringKeyStringValueDto3).getValue();
stringKeyStringValueDtos.add(stringKeyStringValueDto3);
try {
fileService.doSetMetadata(pathId, stringKeyStringValueDtos);
} catch (GeneralSecurityException e) {
fail();
}
verify(fileService.defaultUnifiedRepositoryWebService, times(9)).getFile(anyString());
verify(fileService.defaultUnifiedRepositoryWebService, times(9)).getAcl(anyString());
verify(repositoryFileAclDto, times(9)).getOwner();
verify(fileService.policy, times(11)).isAllowed(anyString());
verify(fileService.repository, times(9)).getFileMetadata(anyString());
verify(fileService.repository, times(7)).setFileMetadata(anyString(), any(Map.class));
verify(file, times(8)).setHidden(anyBoolean());
verify(fileService.repository, times(8)).getFileById(anyString());
verify(fileService, times(8)).toFileDto(any(RepositoryFile.class), anySet(), anyBoolean());
verify(fileService, times(8)).toFile(any(RepositoryFileDto.class));
verify(destFileDto, times(8)).setHidden(anyBoolean());
verify(fileService.repository, times(8)).getAcl(anyString());
verify(fileService.repository, times(7)).updateFile(any(RepositoryFile.class), any(IRepositoryFileData.class), anyString());
verify(fileService.repository, times(7)).updateAcl(any(RepositoryFileAcl.class));
verify(fileService.repository).updateFolder(any(RepositoryFile.class), anyString());
}
use of org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto in project pentaho-platform by pentaho.
the class FileServiceTest method doGetMetadata.
@Test
public void doGetMetadata() {
String pathId = "path:to:file:file1.ext";
List<StringKeyStringValueDto> stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
StringKeyStringValueDto stringKeyStringValueDto1 = mock(StringKeyStringValueDto.class);
doReturn("key1").when(stringKeyStringValueDto1).getKey();
doReturn("value1").when(stringKeyStringValueDto1).getValue();
StringKeyStringValueDto stringKeyStringValueDto2 = mock(StringKeyStringValueDto.class);
doReturn("key2").when(stringKeyStringValueDto2).getKey();
doReturn("value2").when(stringKeyStringValueDto2).getValue();
stringKeyStringValueDtos.add(stringKeyStringValueDto1);
stringKeyStringValueDtos.add(stringKeyStringValueDto2);
doReturn("/path/to/file/file1.ext").when(fileService).idToPath(pathId);
RepositoryFileDto repositoryFileDto = mock(RepositoryFileDto.class);
doReturn(repositoryFileDto).when(fileService.defaultUnifiedRepositoryWebService).getFile(anyString());
doReturn(true).when(repositoryFileDto).isHidden();
doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(anyString());
// Test 1
try {
List<StringKeyStringValueDto> list = fileService.doGetMetadata(pathId);
assertEquals(4, list.size());
Boolean hasIsHidden = false;
Boolean hasScheduable = false;
for (StringKeyStringValueDto item : list) {
if (item.getKey().equals("_PERM_HIDDEN")) {
hasIsHidden = true;
}
if (item.getKey().equals(RepositoryFile.SCHEDULABLE_KEY)) {
hasScheduable = true;
}
}
assertTrue(hasIsHidden);
assertTrue(hasScheduable);
} catch (FileNotFoundException e) {
fail();
}
stringKeyStringValueDtos = new ArrayList<StringKeyStringValueDto>();
stringKeyStringValueDtos.add(stringKeyStringValueDto1);
stringKeyStringValueDtos.add(stringKeyStringValueDto2);
StringKeyStringValueDto stringKeyStringValueDto3 = mock(StringKeyStringValueDto.class);
doReturn(RepositoryFile.SCHEDULABLE_KEY).when(stringKeyStringValueDto3).getKey();
doReturn("value3").when(stringKeyStringValueDto3).getValue();
stringKeyStringValueDtos.add(stringKeyStringValueDto3);
doReturn(stringKeyStringValueDtos).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(anyString());
// Test 2
try {
List<StringKeyStringValueDto> list = fileService.doGetMetadata(pathId);
assertEquals(4, list.size());
Boolean hasIsHidden = false;
Boolean hasScheduable = false;
for (StringKeyStringValueDto item : list) {
if (item.getKey().equals("_PERM_HIDDEN")) {
hasIsHidden = true;
}
if (item.getKey().equals(RepositoryFile.SCHEDULABLE_KEY)) {
hasScheduable = true;
}
}
assertTrue(hasIsHidden);
assertTrue(hasScheduable);
} catch (FileNotFoundException e) {
fail();
}
doReturn(null).when(fileService.defaultUnifiedRepositoryWebService).getFileMetadata(anyString());
// Test 3
try {
List<StringKeyStringValueDto> list = fileService.doGetMetadata(null);
assertEquals(null, list);
} catch (FileNotFoundException e) {
fail();
}
verify(fileService, times(2)).idToPath(pathId);
verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFile(anyString());
verify(fileService.defaultUnifiedRepositoryWebService, times(3)).getFileMetadata(anyString());
}
use of org.pentaho.platform.api.repository2.unified.webservices.StringKeyStringValueDto 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.api.repository2.unified.webservices.StringKeyStringValueDto 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.StringKeyStringValueDto 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));
}
Aggregations