use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method setUpCandidate.
private Candidate setUpCandidate() {
String userFirstName = Long.toHexString(Double.doubleToLongBits(Math.random()));
String userLastName = Long.toHexString(Double.doubleToLongBits(Math.random()));
// his login in external source
String extLogin = Long.toHexString(Double.doubleToLongBits(Math.random()));
// Mockito.mock(Candidate.class);
Candidate candidate = new Candidate();
candidate.setFirstName(userFirstName);
candidate.setId(0);
candidate.setMiddleName("");
candidate.setLastName(userLastName);
candidate.setTitleBefore("");
candidate.setTitleAfter("");
ExtSource extSource = new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal");
UserExtSource userExtSource = new UserExtSource(extSource, 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 FacilitiesManagerEntryIntegrationTest method getAdmins.
@Test
public void getAdmins() throws Exception {
System.out.println(CLASS_NAME + "getAdmins");
// set up first user
final Member member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
facilitiesManagerEntry.addAdmin(sess, facility, user);
// set up authorized group
Group authorizedGroup = new Group("authorizedGroup", "testovaciGroup");
Group returnedGroup = perun.getGroupsManager().createGroup(sess, vo, authorizedGroup);
facilitiesManagerEntry.addAdmin(sess, facility, returnedGroup);
// set up second user
// Mockito.mock(Candidate.class);
Candidate candidate = new Candidate();
candidate.setFirstName("Josef");
candidate.setId(4);
candidate.setMiddleName("");
candidate.setLastName("Novak");
candidate.setTitleBefore("");
candidate.setTitleAfter("");
UserExtSource userExtSource = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), Long.toHexString(Double.doubleToLongBits(Math.random())));
candidate.setUserExtSource(userExtSource);
candidate.setAttributes(new HashMap<>());
Member member2 = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
User user2 = perun.getUsersManagerBl().getUserByMember(sess, member2);
perun.getGroupsManager().addMember(sess, returnedGroup, member2);
// test
List<User> admins = facilitiesManagerEntry.getAdmins(sess, facility);
// assertTrue("group shoud have 2 admins",admins.size() == 2);
assertThat("facility should have 2 admins", admins.size(), is(2));
assertTrue("our member as direct user should be admin", admins.contains(user));
assertTrue("our member as member of admin group should be admin", admins.contains(user2));
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class GroupAndGroupStructureSynchronizationIntegrationTest method setUpMember.
private void setUpMember(Vo vo) throws Exception {
Candidate candidate = setUpCandidate();
member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
assertNotNull("No member created", member);
}
use of cz.metacentrum.perun.core.api.Candidate 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());
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method setUpMember.
private Member setUpMember(Vo vo) throws Exception {
Candidate candidate = setUpCandidate();
Member member = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
// set first candidate as member of test VO
assertNotNull("No member created", member);
assertEquals("Memer don't have VALID status.", Status.VALID, member.getStatus());
usersForDeletion.add(perun.getUsersManager().getUserByMember(sess, member));
// save user for deletion after test
return member;
}
Aggregations