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