Search in sources :

Example 91 with RichAttribute

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));
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 92 with RichAttribute

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());
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 93 with RichAttribute

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());
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 94 with RichAttribute

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));
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 95 with RichAttribute

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));
}
Also used : RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)321 ArrayList (java.util.ArrayList)284 Attribute (cz.metacentrum.perun.core.api.Attribute)220 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)154 Test (org.junit.Test)154 Method (java.lang.reflect.Method)140 List (java.util.List)140 HashSet (java.util.HashSet)94 AllAttributesRemovedForMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForMember)34 AllAttributesRemovedForResourceAndMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForResourceAndMember)34 AttributeRemovedForMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForMember)34 AttributeRemovedForResourceAndMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForResourceAndMember)34 AttributeSetForMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForMember)34 AttributeSetForResourceAndMember (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForResourceAndMember)34 Member (cz.metacentrum.perun.core.api.Member)34 AttributeRemovedForFacility (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeRemovedForFacility)32 AttributeSetForFacility (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeSetForFacility)32 Facility (cz.metacentrum.perun.core.api.Facility)32 AllAttributesRemovedForFacilityAndUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForFacilityAndUser)31 AllAttributesRemovedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AllAttributesRemovedForUser)31