Search in sources :

Example 86 with RichAttribute

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

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

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

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

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