use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromUserAndFacility.
@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromUserAndFacility() throws Exception {
System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromUserAndFacility");
// Prepare attribute, create it and set it with testing value
Attribute attribute = setAttributeInNamespace(AttributesManager.NS_GROUP_ATTR_DEF);
perun.getAttributesManagerBl().setAttribute(sess, group1InVo2, attribute);
perun.getAttributesManagerBl().setAttribute(sess, group2InVo2, attribute);
// Prepare richAttribute with holders (attribute is not needed but holders are needed)
RichAttribute richAttr = new RichAttribute();
richAttr.setPrimaryHolder(user2);
richAttr.setSecondaryHolder(facility2);
List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
assertTrue("return two groups", listOfRichAttributes.size() == 2);
assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Group);
assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
List<Group> groups = new ArrayList<>();
for (RichAttribute ra : listOfRichAttributes) {
groups.add((Group) ra.getPrimaryHolder());
}
assertTrue("groups contains group1InVo2", groups.contains(group1InVo2));
assertTrue("groups contains group2InVo2", groups.contains(group2InVo2));
assertTrue("richObject have in Attribute our attribute, which was set before", listOfRichAttributes.get(0).getAttribute().equals(attribute));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getUserExtSourceAttributesByKey.
@SuppressWarnings({ "unchecked" })
@IfProfileValue(name = "default")
@Test
public void getUserExtSourceAttributesByKey() throws Exception {
System.out.println(CLASS_NAME + "getUserExtSourceAttributesByKey");
setAttributesForUESAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getUserExtSourceAttributes", PerunSession.class, AttributeDefinition.class);
// find all test UES attributes
List<RichAttribute> ra_all = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, ues_test_atr_def);
List<Attribute> attrs_all = new ArrayList<>();
ra_all.forEach(ra -> attrs_all.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 6, attrs_all.size());
assertTrue(attrs_all.contains(ues1_test_atr));
assertTrue(attrs_all.contains(ues2_test_atr));
assertTrue(attrs_all.contains(ues3_test_atr));
// contains three internal ues attributes
assertTrue(attrs_all.contains(internal_ues_atr));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getResourceAttributesByMemberGroup.
@SuppressWarnings({ "unchecked" })
@Test
public void getResourceAttributesByMemberGroup() throws Exception {
System.out.println(CLASS_NAME + "getResourceAttributesByMemberGroup");
setAttributesForResourceAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getResourceAttributes", PerunSession.class, Member.class, Group.class, AttributeDefinition.class);
// find test resource attributes for member2OfUser3 and group2InVo2
List<RichAttribute> ra_mem2U3_group2Vo2 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member2OfUser3, group2InVo2, resource_test_atr_def);
List<Attribute> attrs_mem2U3_group2Vo2 = new ArrayList<>();
ra_mem2U3_group2Vo2.forEach(ra -> attrs_mem2U3_group2Vo2.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 2, attrs_mem2U3_group2Vo2.size());
assertTrue(attrs_mem2U3_group2Vo2.contains(resource1InVo2_test_atr));
assertTrue(attrs_mem2U3_group2Vo2.contains(resource2InVo2_test_atr));
// find test resource attributes for member2OfUser1 and group1InVo1
List<RichAttribute> ra_mem2U1_group1Vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member2OfUser1, group1InVo1, resource_test_atr_def);
List<Attribute> attrs_mem2U1_group1Vo1 = new ArrayList<>();
ra_mem2U1_group1Vo1.forEach(ra -> attrs_mem2U1_group1Vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 0, attrs_mem2U1_group1Vo1.size());
// find test resource attributes for member1OfUser1 and group1InVo1
List<RichAttribute> ra_mem1U1_group1Vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member1OfUser1, group1InVo1, resource_test_atr_def);
List<Attribute> attrs_mem1U1_group1Vo1 = new ArrayList<>();
ra_mem1U1_group1Vo1.forEach(ra -> attrs_mem1U1_group1Vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 1, attrs_mem1U1_group1Vo1.size());
assertTrue(attrs_mem1U1_group1Vo1.contains(resource1InVo1_test_atr));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getGroupAttributesByVo.
@SuppressWarnings({ "unchecked" })
@Test
public void getGroupAttributesByVo() throws Exception {
System.out.println(CLASS_NAME + "getGroupAttributesByVo");
setAttributesForGroupAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getGroupAttributes", PerunSession.class, Vo.class, AttributeDefinition.class);
// find email group attributes by vo1
List<RichAttribute> ra_vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, vo1, group_fromEmail_atr_def);
List<Attribute> attrs_vo1 = new ArrayList<>();
ra_vo1.forEach(ra -> attrs_vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 3, attrs_vo1.size());
assertTrue(attrs_vo1.contains(group1InVo1_email_atr));
assertTrue(attrs_vo1.contains(group2InVo1_email_atr));
assertTrue(attrs_vo1.contains(membersGroupOfVo1_email_atr));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getUserFacilityAttributesByVo.
@SuppressWarnings({ "unchecked" })
@Test
public void getUserFacilityAttributesByVo() throws Exception {
System.out.println(CLASS_NAME + "getUserFacilityAttributesByVo");
setAttributesForUserFacilityTest();
Method testedMethod = getPrivateMethodFromAtrManager("getUserFacilityAttributes", PerunSession.class, Vo.class, AttributeDefinition.class);
// find all test user-facility attributes for vo1
List<RichAttribute> ra_vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, vo1, userFacility_test_atr_def);
List<Attribute> attrs_vo1 = new ArrayList<>();
ra_vo1.forEach(ra -> attrs_vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 3, attrs_vo1.size());
assertTrue(attrs_vo1.contains(user1Facility1_test_attribute));
assertTrue(attrs_vo1.contains(user1Facility2_test_attribute));
assertTrue(attrs_vo1.contains(user3Facility1_test_attribute));
// find all test user-facility attributes for vo2
List<RichAttribute> ra_vo2 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, vo2, userFacility_test_atr_def);
List<Attribute> attrs_vo2 = new ArrayList<>();
ra_vo2.forEach(ra -> attrs_vo2.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 4, attrs_vo2.size());
assertTrue(attrs_vo2.contains(user2Facility2_test_attribute));
assertTrue(attrs_vo2.contains(user2Facility3_test_attribute));
assertTrue(attrs_vo2.contains(user3Facility2_test_attribute));
assertTrue(attrs_vo2.contains(user3Facility3_test_attribute));
}
Aggregations