use of org.molgenis.data.security.PackageIdentity in project molgenis by molgenis.
the class PermissionManagerControllerTest method setUp.
@BeforeMethod
public void setUp() {
config.resetMocks();
mockMvc = MockMvcBuilders.standaloneSetup(permissionManagerController).setMessageConverters(gsonHttpMessageConverter).build();
user1 = when(mock(User.class).getId()).thenReturn("1").getMock();
when(user1.isSuperuser()).thenReturn(true);
when(user1.getUsername()).thenReturn("Ipsum");
userSid = new PrincipalSid("Ipsum");
user2 = when(mock(User.class).getId()).thenReturn("2").getMock();
group1 = when(mock(Group.class).getId()).thenReturn("1").getMock();
groupSid = new GrantedAuthoritySid("ROLE_1");
group2 = when(mock(Group.class).getId()).thenReturn("2").getMock();
plugin1 = when(mock(Plugin.class).getId()).thenReturn("1").getMock();
plugin2 = when(mock(Plugin.class).getId()).thenReturn("2").getMock();
pluginIdentity1 = new PluginIdentity(plugin1);
pluginIdentity2 = new PluginIdentity(plugin2);
entityType1 = when(mock(EntityType.class).getId()).thenReturn("1").getMock();
entityType2 = when(mock(EntityType.class).getId()).thenReturn("2").getMock();
entityType3 = when(mock(EntityType.class).getId()).thenReturn("3").getMock();
when(entityType1.getLabel()).thenReturn("label1");
when(entityType2.getLabel()).thenReturn("label2");
when(entityType3.getLabel()).thenReturn("label3");
entityIdentity1 = new EntityTypeIdentity(entityType1);
entityIdentity2 = new EntityTypeIdentity(entityType2);
entityIdentity3 = new EntityTypeIdentity(entityType3);
package1 = when(mock(Package.class).getId()).thenReturn("1").getMock();
package2 = when(mock(Package.class).getId()).thenReturn("2").getMock();
package3 = when(mock(Package.class).getId()).thenReturn("3").getMock();
packageIdentity1 = new PackageIdentity(package1);
packageIdentity2 = new PackageIdentity(package2);
packageIdentity3 = new PackageIdentity(package3);
when(dataService.findAll(USER, User.class)).thenReturn(Stream.of(user1, user2));
when(dataService.findAll(GROUP, Group.class)).thenReturn(Stream.of(group1, group2));
when(dataService.findOneById(GROUP, "1", Group.class)).thenReturn(group1);
when(dataService.findOneById(USER, "1", User.class)).thenReturn(user1);
when(dataService.findAll(PLUGIN, Plugin.class)).thenReturn(Stream.of(plugin1, plugin2));
when(dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class)).thenReturn(Stream.of(entityType1, entityType2, entityType3));
when(dataService.findAll(PACKAGE, Package.class)).thenReturn(Stream.of(package1, package2, package3));
pluginPermissionRead = PluginPermission.READ;
cumulativeEntityPermissionWritemeta = new CumulativePermission();
cumulativeEntityPermissionWritemeta.set(EntityTypePermission.WRITEMETA).set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
cumulativeEntityPermissionWrite = new CumulativePermission();
cumulativeEntityPermissionWrite.set(EntityTypePermission.WRITE).set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
cumulativeEntityPermissionRead = new CumulativePermission();
cumulativeEntityPermissionRead.set(EntityTypePermission.READ).set(EntityTypePermission.COUNT);
cumulativeEntityPermissionCount = new CumulativePermission();
cumulativeEntityPermissionCount.set(EntityTypePermission.COUNT);
}
use of org.molgenis.data.security.PackageIdentity in project molgenis by molgenis.
the class PackageRepositorySecurityDecoratorTest method testUpdate.
@Test
public void testUpdate() {
Package pack = mock(Package.class);
Package parent = mock(Package.class);
when(pack.getId()).thenReturn("1");
when(parent.getId()).thenReturn("2");
when(pack.getParent()).thenReturn(parent);
MutableAcl acl = mock(MutableAcl.class);
MutableAcl parentAcl = mock(MutableAcl.class);
when(mutableAclService.readAclById(any())).thenAnswer(invocation -> {
Object argument = invocation.getArguments()[0];
if (argument.equals(new PackageIdentity("1"))) {
return acl;
} else if (argument.equals(new PackageIdentity("2"))) {
return parentAcl;
}
return null;
});
repo.update(pack);
verify(mutableAclService).updateAcl(acl);
verify(delegateRepository).update(pack);
}
use of org.molgenis.data.security.PackageIdentity in project molgenis by molgenis.
the class PackageRepositorySecurityDecoratorTest method testDelete.
@Test
public void testDelete() {
Package pack = mock(Package.class);
when(pack.getId()).thenReturn("1");
repo.delete(pack);
verify(mutableAclService).deleteAcl(new PackageIdentity("1"), true);
verify(delegateRepository).delete(pack);
}
use of org.molgenis.data.security.PackageIdentity in project molgenis by molgenis.
the class PackageRepositorySecurityDecoratorTest method testDeleteById.
@Test
public void testDeleteById() {
repo.deleteById("1");
verify(mutableAclService).deleteAcl(new PackageIdentity("1"), true);
verify(delegateRepository).deleteById("1");
}
use of org.molgenis.data.security.PackageIdentity in project molgenis by molgenis.
the class PackageRepositorySecurityDecoratorTest method testAdd.
@Test
public void testAdd() {
Package pack = mock(Package.class);
Package parent = mock(Package.class);
when(pack.getId()).thenReturn("1");
when(parent.getId()).thenReturn("2");
when(pack.getParent()).thenReturn(parent);
MutableAcl acl = mock(MutableAcl.class);
MutableAcl parentAcl = mock(MutableAcl.class);
when(mutableAclService.createAcl(new PackageIdentity("1"))).thenReturn(acl);
when(mutableAclService.readAclById(new PackageIdentity("2"))).thenReturn(parentAcl);
repo.add(pack);
verify(mutableAclService).createAcl(new PackageIdentity("1"));
verify(mutableAclService).updateAcl(acl);
verify(delegateRepository).add(pack);
}
Aggregations