Search in sources :

Example 6 with CandidateSync

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

the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupAddMissingMember.

@Test
public void synchronizeGroupAddMissingMember() throws Exception {
    System.out.println(CLASS_NAME + "synchronizeGroupAddMissingMember");
    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();
    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)

Example 7 with CandidateSync

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

the class GroupAndGroupStructureSynchronizationIntegrationTest method synchronizeGroupUpdateUserAttributeOfMember.

@Test
public void synchronizeGroupUpdateUserAttributeOfMember() throws Exception {
    System.out.println(CLASS_NAME + "synchronizeGroupUpdateUserAttributeOfMember");
    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);
    Attribute attribute = new Attribute();
    String namespace = "user-test-unique-attribute:specialNamespace";
    attribute.setNamespace(AttributesManager.NS_USER_ATTR_DEF);
    attribute.setFriendlyName(namespace + "1");
    attribute.setType(String.class.getName());
    attribute.setValue("UserAttribute");
    assertNotNull("unable to create user attribute", attributesManagerBl.createAttribute(sess, attribute));
    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);
    User user = perun.getUsersManagerBl().getUserByMember(sess, member);
    assertNotEquals(candidate.getAttributes().get(attribute.getName()), attributesManagerBl.getAttribute(sess, user, attribute.getName()).valueAsString());
    groupsManagerBl.synchronizeGroup(sess, group);
    assertEquals(candidate.getAttributes().get(attribute.getName()), attributesManagerBl.getAttribute(sess, user, attribute.getName()).valueAsString());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) User(cz.metacentrum.perun.core.api.User) 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

CandidateSync (cz.metacentrum.perun.core.api.CandidateSync)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)6 Attribute (cz.metacentrum.perun.core.api.Attribute)6 Candidate (cz.metacentrum.perun.core.api.Candidate)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 Test (org.junit.Test)6 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)6 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)1 User (cz.metacentrum.perun.core.api.User)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 Matcher (java.util.regex.Matcher)1