Search in sources :

Example 96 with RichAttribute

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));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) 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) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 97 with RichAttribute

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));
}
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) IfProfileValue(org.springframework.test.annotation.IfProfileValue)

Example 98 with RichAttribute

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));
}
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 99 with RichAttribute

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));
}
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 100 with RichAttribute

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));
}
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