use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getHostAttributesByKey.
@SuppressWarnings({ "unchecked" })
@Test
public void getHostAttributesByKey() throws Exception {
System.out.println(CLASS_NAME + "getHostAttributesByKey");
setAttributesForHostAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getHostAttributes", PerunSession.class, AttributeDefinition.class);
// find all test host attributes
List<RichAttribute> ra_all = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, host_test_atr_def);
List<Attribute> attrs_all = new ArrayList<>();
ra_all.forEach(ra -> attrs_all.add(ra.getAttribute()));
assertTrue("Invalid number of attributes found", 6 <= attrs_all.size());
assertTrue(attrs_all.contains(host1F1_test_atr));
assertTrue(attrs_all.contains(host2F1_test_atr));
assertTrue(attrs_all.contains(host1F2_test_atr));
assertTrue(attrs_all.contains(host2F2_test_atr));
assertTrue(attrs_all.contains(host1F3_test_atr));
assertTrue(attrs_all.contains(host2F3_test_atr));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getResourceAttributesByGroup.
@SuppressWarnings({ "unchecked" })
@Test
public void getResourceAttributesByGroup() throws Exception {
System.out.println(CLASS_NAME + "getResourceAttributesByGroup");
setAttributesForResourceAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getResourceAttributes", PerunSession.class, Group.class, AttributeDefinition.class);
// find test resource attributes for group2InVo1
List<RichAttribute> ra_group2InVo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, group2InVo1, resource_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(resource1InVo1_test_atr));
assertTrue(attrs_group2InVo1.contains(resource2InVo1_test_atr));
// find test resource attributes for membersGroupOfVo1
List<RichAttribute> ra_membersGroupOfVo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, membersGroupOfVo1, resource_test_atr_def);
List<Attribute> attrs_membersGroupOfVo1 = new ArrayList<>();
ra_membersGroupOfVo1.forEach(ra -> attrs_membersGroupOfVo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 0, attrs_membersGroupOfVo1.size());
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getResourceAttributesByMemberResource.
@SuppressWarnings({ "unchecked" })
@Test
public void getResourceAttributesByMemberResource() throws Exception {
System.out.println(CLASS_NAME + "getResourceAttributesByMemberResource");
setAttributesForResourceAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getResourceAttributes", PerunSession.class, Member.class, Resource.class, AttributeDefinition.class);
// find test resource attributes for member2OfUser3 and resource2InVo2
List<RichAttribute> ra_mem2U3_res2Vo2 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member2OfUser3, resource2InVo2, resource_test_atr_def);
List<Attribute> attrs_mem2U3_res2Vo2 = new ArrayList<>();
ra_mem2U3_res2Vo2.forEach(ra -> attrs_mem2U3_res2Vo2.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 1, attrs_mem2U3_res2Vo2.size());
assertTrue(attrs_mem2U3_res2Vo2.contains(resource2InVo2_test_atr));
// find test resource attributes for member2OfUser1 and resource1InVo1
List<RichAttribute> ra_mem2U1_res1Vo1 = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, member2OfUser1, resource1InVo1, resource_test_atr_def);
List<Attribute> attrs_mem2U1_res1Vo1 = new ArrayList<>();
ra_mem2U1_res1Vo1.forEach(ra -> attrs_mem2U1_res1Vo1.add(ra.getAttribute()));
assertEquals("Invalid number of attributes found", 0, attrs_mem2U1_res1Vo1.size());
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetVosFromFacility.
@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetVosFromFacility() throws Exception {
System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetVosFromFacility");
// Prepare attribute, create it and set it with testing value
Attribute attribute = setAttributeInNamespace(AttributesManager.NS_VO_ATTR_DEF);
perun.getAttributesManagerBl().setAttribute(sess, vo2, attribute);
// Prepare richAttribute with holders (attribute is not needed but holders are needed)
RichAttribute richAttr = new RichAttribute();
richAttr.setPrimaryHolder(facility3);
List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
// Return facilities Administrator too if exists
assertTrue("return at least 1 vos", listOfRichAttributes.size() >= 1);
assertTrue("return max 2 vos", listOfRichAttributes.size() <= 2);
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 vo2", returnedVos.contains(vo2));
assertTrue("returned vos not contains vo1", !returnedVos.contains(vo1));
}
use of cz.metacentrum.perun.core.api.RichAttribute in project perun by CESNET.
the class AttributesManagerEntryIntegrationTest method getVoAttributesByKey.
@SuppressWarnings({ "unchecked" })
@Test
public void getVoAttributesByKey() throws Exception {
System.out.println(CLASS_NAME + "getVoAttributesByKey");
setAttributesForVoAttributesTest();
Method testedMethod = getPrivateMethodFromAtrManager("getVoAttributes", PerunSession.class, AttributeDefinition.class);
// get all vo_toEmail_def attributes
List<RichAttribute> ra_all = (List<RichAttribute>) testedMethod.invoke(attributesManagerBl, sess, vo_toEmail_def);
List<Attribute> attrs_all = new ArrayList<>();
ra_all.forEach(ra -> attrs_all.add(ra.getAttribute()));
assertTrue("Found invalid number of attributes", 2 <= attrs_all.size());
assertTrue(attrs_all.contains(vo1_toEmail_attribute));
assertTrue(attrs_all.contains(vo2_toEmail_attribute));
}
Aggregations