Search in sources :

Example 16 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupUpdateExistingMemberStatus.

@Test
public void synchronizeGroupUpdateExistingMemberStatus() throws Exception {
    System.out.println(CLASS_NAME + "synchronizeGroupUpdateExistingMemberStatus");
    when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
    Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
    attr.setValue(extSource.getName());
    attributesManagerBl.setAttribute(sess, group, attr);
    List<Map<String, String>> subjects = new ArrayList<>();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("login", "metodej");
    subjects.add(attributes);
    Candidate candidate = setUpCandidate();
    member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    perun.getMembersManagerBl().setStatus(sess, member, Status.DISABLED);
    groupsManagerBl.addMember(sess, group, member);
    when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
    when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
    assertEquals(Status.DISABLED, groupsManagerBl.getGroupMembers(sess, group).get(0).getStatus());
    groupsManagerBl.synchronizeGroup(sess, group);
    assertEquals(Status.VALID, groupsManagerBl.getGroupMembers(sess, group).get(0).getStatus());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Attribute(cz.metacentrum.perun.core.api.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CandidateSync(cz.metacentrum.perun.core.api.CandidateSync) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) LinkedHashMap(java.util.LinkedHashMap) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 17 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class GroupAndGroupStructureSynchronizationIntegrationTest method setUpCandidate.

private Candidate setUpCandidate() {
    String userFirstName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    String userLastName = Long.toHexString(Double.doubleToLongBits(Math.random()));
    String extLogin = Long.toHexString(Double.doubleToLongBits(Math.random()));
    Candidate candidate = new Candidate();
    candidate.setFirstName(userFirstName);
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName(userLastName);
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    final UserExtSource userExtSource = new UserExtSource(extSourceForUserCreation, extLogin);
    candidate.setUserExtSource(userExtSource);
    candidate.setAttributes(new HashMap<>());
    return candidate;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

Example 18 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupUpdateFirstNameOfMember.

@Test
public void synchronizeGroupUpdateFirstNameOfMember() throws Exception {
    System.out.println(CLASS_NAME + "synchronizeGroupUpdateFirstNameOfMember");
    when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
    Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
    attr.setValue(extSource.getName());
    attributesManagerBl.setAttribute(sess, group, attr);
    List<Map<String, String>> subjects = new ArrayList<>();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("login", "metodej");
    subjects.add(attributes);
    Candidate candidate = setUpCandidate();
    member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    groupsManagerBl.addMember(sess, group, member);
    candidate.setFirstName("metodej");
    Attribute attribute = perun.getAttributesManagerBl().getAttribute(sess, perun.getUsersManagerBl().getUserByMember(sess, member), AttributesManager.NS_USER_ATTR_CORE + ":firstName");
    Map<String, String> candidateAttrs = new HashMap<>();
    candidateAttrs.put(attribute.getName(), attribute.valueAsString());
    candidate.setAttributes(candidateAttrs);
    Map<String, String> map = new HashMap<>();
    map.put("overwriteUserAttributes", attribute.getName());
    when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
    when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
    doReturn(map).when(extSourceManagerBl).getAttributes((ExtSourceLdap) essa);
    assertNotEquals(candidate.getFirstName(), perun.getUsersManagerBl().getUserByMember(sess, member).getFirstName());
    groupsManagerBl.synchronizeGroup(sess, group);
    assertEquals(candidate.getFirstName(), perun.getUsersManagerBl().getUserByMember(sess, member).getFirstName());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Attribute(cz.metacentrum.perun.core.api.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CandidateSync(cz.metacentrum.perun.core.api.CandidateSync) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) LinkedHashMap(java.util.LinkedHashMap) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 19 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupMergeMemberAttributeValue.

@Test
public void synchronizeGroupMergeMemberAttributeValue() throws Exception {
    System.out.println(CLASS_NAME + "synchronizeGroupMergeMemberAttributeValue");
    when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
    Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
    attr.setValue(extSource.getName());
    attributesManagerBl.setAttribute(sess, group, attr);
    List<Map<String, String>> subjects = new ArrayList<>();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("login", "metodej");
    subjects.add(attributes);
    Candidate candidate = setUpCandidate();
    member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    groupsManagerBl.addMember(sess, group, member);
    candidate.setFirstName("metodej");
    Attribute attribute = new Attribute();
    String namespace = "member-test-unique-attribute:specialNamespace";
    attribute.setNamespace(AttributesManager.NS_MEMBER_ATTR_DEF);
    attribute.setFriendlyName(namespace + "1");
    attribute.setType(ArrayList.class.getName());
    attribute.setValue(Stream.of("value1", "value2").collect(Collectors.toList()));
    assertNotNull("unable to create member attribute", attributesManagerBl.createAttribute(sess, attribute));
    Map<String, String> candidateAttrs = new HashMap<>();
    candidateAttrs.put(attribute.getName(), "value2,value3");
    candidate.setAttributes(candidateAttrs);
    attributesManagerBl.setAttribute(sess, member, attribute);
    Map<String, String> map = new HashMap<>();
    map.put("mergeMemberAttributes", attribute.getName());
    when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
    when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
    doReturn(map).when(extSourceManagerBl).getAttributes((ExtSourceLdap) essa);
    assertEquals(2, attributesManagerBl.getAttribute(sess, member, attribute.getName()).valueAsList().size());
    groupsManagerBl.synchronizeGroup(sess, group);
    assertEquals(3, attributesManagerBl.getAttribute(sess, member, attribute.getName()).valueAsList().size());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Attribute(cz.metacentrum.perun.core.api.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CandidateSync(cz.metacentrum.perun.core.api.CandidateSync) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) LinkedHashMap(java.util.LinkedHashMap) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 20 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupAddMissingMemberWhileCandidateAlreadyMember.

@Test
public void synchronizeGroupAddMissingMemberWhileCandidateAlreadyMember() throws Exception {
    System.out.println(CLASS_NAME + "synchronizeGroupAddMissingMemberWhileCandidateAlreadyMember");
    when(extSourceManagerBl.getExtSourceByName(sess, ExtSourcesManager.EXTSOURCE_NAME_PERUN)).thenReturn(extSourceForUserCreation);
    Attribute attr = attributesManagerBl.getAttribute(sess, group, GroupsManager.GROUPEXTSOURCE_ATTRNAME);
    attr.setValue(extSource.getName());
    attributesManagerBl.setAttribute(sess, group, attr);
    List<Map<String, String>> subjects = new ArrayList<>();
    Map<String, String> attributes = new HashMap<>();
    attributes.put("login", "metodej");
    subjects.add(attributes);
    Candidate candidate = setUpCandidate();
    member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    when(extSourceManagerBl.getCandidate(sess, attributes, (ExtSourceLdap) essa, "metodej")).thenReturn(new CandidateSync(candidate));
    when(essa.getGroupSubjects(anyMap())).thenReturn(subjects);
    assertEquals(0, groupsManagerBl.getGroupMembers(sess, group).size());
    groupsManagerBl.synchronizeGroup(sess, group);
    assertEquals(1, groupsManagerBl.getGroupMembers(sess, group).size());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Attribute(cz.metacentrum.perun.core.api.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CandidateSync(cz.metacentrum.perun.core.api.CandidateSync) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) LinkedHashMap(java.util.LinkedHashMap) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Candidate (cz.metacentrum.perun.core.api.Candidate)100 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)52 Test (org.junit.Test)41 Member (cz.metacentrum.perun.core.api.Member)37 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)30 ExtSource (cz.metacentrum.perun.core.api.ExtSource)25 RichMember (cz.metacentrum.perun.core.api.RichMember)24 User (cz.metacentrum.perun.core.api.User)23 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)21 Group (cz.metacentrum.perun.core.api.Group)15 Attribute (cz.metacentrum.perun.core.api.Attribute)14 Map (java.util.Map)12 MemberCandidate (cz.metacentrum.perun.core.api.MemberCandidate)11 RichUser (cz.metacentrum.perun.core.api.RichUser)11 Vo (cz.metacentrum.perun.core.api.Vo)11 LinkedHashMap (java.util.LinkedHashMap)11 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)9 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)9 CandidateNotExistsException (cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)8