use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getGroupAttributesByMemberResource.
@SuppressWarnings({ "unchecked" })
@Test
public void getGroupAttributesByMemberResource() throws Exception {
System.out.println(CLASS_NAME + "getGroupAttributesByMemberGroup");
setAttributesForGroupAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getGroupAttributes", PerunSession.class, Member.class, Resource.class, AttributeDefinition.class);
// find email group attributes by member1OfUser1 and resource1InVo1
List<RichAttribute> ra_member1U1_res1Vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member1OfUser1, resource1InVo1, group_fromEmail_atr_def);
List<Attribute> attrs_member1U1_res1Vo1 = new ArrayList<>();
ra_member1U1_res1Vo1.forEach(ra -> attrs_member1U1_res1Vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 2, attrs_member1U1_res1Vo1.size());
assertTrue(attrs_member1U1_res1Vo1.contains(group1InVo1_email_atr));
assertTrue(attrs_member1U1_res1Vo1.contains(group2InVo1_email_atr));
// find email group attributes by member1OfUser3 and resource1InVo1
List<RichAttribute> ra_member1U3_res1Vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member1OfUser3, resource1InVo1, group_fromEmail_atr_def);
List<Attribute> attrs_member1U3_res1Vo1 = new ArrayList<>();
ra_member1U3_res1Vo1.forEach(ra -> attrs_member1U3_res1Vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 1, attrs_member1U3_res1Vo1.size());
assertTrue(attrs_member1U3_res1Vo1.contains(group1InVo1_email_atr));
// find email group attributes by member2OfUser2 and resource1InVo1
List<RichAttribute> ra_member2U2_res1Vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member2OfUser2, resource1InVo1, group_fromEmail_atr_def);
List<Attribute> attrs_member2U2_res1Vo1 = new ArrayList<>();
ra_member2U2_res1Vo1.forEach(ra -> attrs_member2U2_res1Vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 0, attrs_member2U2_res1Vo1.size());
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost.
@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost() throws Exception {
System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromHost");
// Prepare attribute, create it and set it with testing value
Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR_DEF);
perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
perun.getAttributesManagerBl().setAttribute(sess, vo1, attribute);
// Prepare richAttribute with holders (attribute is not needed but holders are needed)
RichAttribute richAttr = new RichAttribute();
richAttr.setPrimaryHolder(host1OnFacility2);
List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
// Return facilities Administrator too if exists
assertTrue("return at least 2 vos", listOfRichAttributes.size() >= 2);
assertTrue("return maximum of 3 vos", listOfRichAttributes.size() <= 3);
assertTrue("primary holder is type of vo", listOfRichAttributes.get(0).getPrimaryHolder() instanceof Vo);
assertTrue("secondary holder is null", listOfRichAttributes.get(0).getSecondaryHolder() == null);
List<Vo> returnedVos = new ArrayList<>();
for (RichAttribute ra : listOfRichAttributes) {
returnedVos.add((Vo) ra.getPrimaryHolder());
}
assertTrue("returned vos contains vo1", returnedVos.contains(vo1));
assertTrue("returned vos contains vo2", returnedVos.contains(vo2));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getUserAttributesByUserExtSource.
@SuppressWarnings({ "unchecked" })
@Test
public void getUserAttributesByUserExtSource() throws Exception {
System.out.println(CLASS_NAME + "getUserAttributesByUserExtSource");
setAttributesForUserAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getUserAttributes", PerunSession.class, UserExtSource.class, AttributeDefinition.class);
// find phone attributes for userExtSource1
List<RichAttribute> ra_phone_userExtSource1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, userExtSource1, user_phone_atr_def);
List<Attribute> attrs_phone_userExtSource1 = new ArrayList<>();
ra_phone_userExtSource1.forEach(ra -> attrs_phone_userExtSource1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 1, attrs_phone_userExtSource1.size());
assertTrue(attrs_phone_userExtSource1.contains(user1_phone_attribute));
// find email attribute for userExtSource2
List<RichAttribute> ra_email_userExtSource2 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, userExtSource2, user_email_atr_def);
List<Attribute> attrs_email_userExtSource2 = new ArrayList<>();
ra_email_userExtSource2.forEach(ra -> attrs_email_userExtSource2.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 1, attrs_email_userExtSource2.size());
assertTrue(attrs_email_userExtSource2.contains(user2_email_attribute));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getUserAttributesByKey.
@SuppressWarnings({ "unchecked" })
@Test
public void getUserAttributesByKey() throws Exception {
System.out.println(CLASS_NAME + "getUserAttributesByKey");
setAttributesForUserAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getUserAttributes", PerunSession.class, AttributeDefinition.class);
// find all phone user attributes
List<RichAttribute> ra_all = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, user_phone_atr_def);
List<Attribute> attrs_all = new ArrayList<>();
ra_all.forEach(ra -> attrs_all.add(ra.getAttribute()));
// actually contains 4 user attributes because of test user John Doe
assertTrue("Invalid number of attributes found", 4 <= attrs_all.size());
assertTrue(attrs_all.contains(user1_phone_attribute));
assertTrue(attrs_all.contains(user2_phone_attribute));
// contains empty user3 attribute
assertTrue(attrs_all.contains(new Attribute(user_phone_atr_def)));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getMemberResourceAttributesByGroup.
@SuppressWarnings({ "unchecked" })
@Test
public void getMemberResourceAttributesByGroup() throws Exception {
System.out.println(CLASS_NAME + "getMemberResourceAttributesByGroup");
setAttributesForMemberResourceTest();
Method testedMethod = getPrivateMethodFromAtrManager("getMemberResourceAttributes", PerunSession.class, Group.class, AttributeDefinition.class);
// find all test member-group attributes for group2InVo2
List<RichAttribute> ra_group2InVo2 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, group2InVo2, memberResource_test_atr_def);
List<Attribute> attrs_group2InVo2 = new ArrayList<>();
ra_group2InVo2.forEach(ra -> attrs_group2InVo2.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 4, attrs_group2InVo2.size());
assertTrue(attrs_group2InVo2.contains(member1U2Res1Vo2_test_attribute));
assertTrue(attrs_group2InVo2.contains(member1U2Res2Vo2_test_attribute));
assertTrue(attrs_group2InVo2.contains(member2U3Res1Vo2_test_attribute));
assertTrue(attrs_group2InVo2.contains(member2U3Res2Vo2_test_attribute));
// find all test member-group attributes for group2InVo1
List<RichAttribute> ra_group2InVo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, group2InVo1, memberResource_test_atr_def);
List<Attribute> attrs_group2InVo1 = new ArrayList<>();
ra_group2InVo1.forEach(ra -> attrs_group2InVo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 2, attrs_group2InVo1.size());
assertTrue(attrs_group2InVo1.contains(member1U1Res1Vo1_test_attribute));
assertTrue(attrs_group2InVo1.contains(member1U1Res2Vo1_test_attribute));
}
Aggregations