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