use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class VosManagerEntryIntegrationTest method getAdmins.
@Test
public void getAdmins() throws Exception {
System.out.println(CLASS_NAME + "getAdmins");
final Vo createdVo = vosManagerEntry.createVo(sess, myVo);
// set up first user
final Member member = createMemberFromExtSource(createdVo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
vosManagerEntry.addAdmin(sess, createdVo, user);
// set up authorized group
Group authorizedGroup = new Group("authorizedGroup", "testovaciGroup");
Group returnedGroup = perun.getGroupsManager().createGroup(sess, createdVo, authorizedGroup);
vosManagerEntry.addAdmin(sess, createdVo, 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, createdVo, candidate);
User user2 = perun.getUsersManagerBl().getUserByMember(sess, member2);
perun.getGroupsManager().addMember(sess, returnedGroup, member2);
// test
List<User> admins = vosManagerEntry.getAdmins(sess, createdVo);
assertTrue("should have 2 admins", admins.size() == 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 VosManagerEntryIntegrationTest method getCompleteCandidatesFromGroup.
@Test
public void getCompleteCandidatesFromGroup() throws Exception {
System.out.println(CLASS_NAME + "getCompleteCandidatesFromGroup");
// create group and vo
myVo = perun.getVosManagerBl().createVo(sess, myVo);
Group group = new Group("testGroup", "testingGroup");
Group returnedGroup = perun.getGroupsManager().createGroup(sess, myVo, group);
// prepare second extSource
ExtSource extSource = new ExtSource("testExtSource", ExtSourcesManager.EXTSOURCE_INTERNAL);
extSource = perun.getExtSourcesManagerBl().createExtSource(sess, extSource, null);
// prepare users to be returned by getCompleteCandidates
Candidate candidate = prepareCandidateWithExtSource("Jan", es);
User userToContain1 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
candidate = prepareCandidateWithExtSource("Jana", es);
User userToContain2 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
candidate = prepareCandidateWithExtSource("Josef", es);
User userNotToContain1 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
candidate = prepareCandidateWithExtSource("Jan", extSource);
RichUser userNotToContain2 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
candidate = prepareCandidateWithExtSource("Jana", extSource);
RichUser userToContain3 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
Member member = perun.getMembersManagerBl().createMember(sess, myVo, candidate);
List<MemberCandidate> completeCandidates = perun.getVosManagerBl().getCompleteCandidates(sess, myVo, returnedGroup, null, "jan", Arrays.asList(es));
List<RichUser> usersOfCompleteCandidates = completeCandidates.stream().map(MemberCandidate::getRichUser).collect(Collectors.toList());
assertEquals("Three users should have been returned.", 3, usersOfCompleteCandidates.size());
assertTrue("User should've been returned.", usersOfCompleteCandidates.contains(userToContain1));
assertTrue("User should've been returned.", usersOfCompleteCandidates.contains(userToContain2));
assertTrue("User should've been returned.", usersOfCompleteCandidates.contains(userToContain3));
assertFalse("User shouldn't have been returned.", usersOfCompleteCandidates.contains(userNotToContain1));
assertFalse("User shouldn't have been returned.", usersOfCompleteCandidates.contains(userNotToContain2));
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class RegistrarManagerImplUnitTest method testParseNamesIfTheMiddleNameEqualsFirstNameReversePattern.
@Test
public void testParseNamesIfTheMiddleNameEqualsFirstNameReversePattern() {
Candidate candidate = new Candidate();
Map<String, String> attributes = new HashMap<>();
attributes.put(URN_USER_DISPLAY_NAME, "Bc. Hejda Hejda Jakub Dis.");
Map<String, String> fedData = new HashMap<>();
fedData.put("givenName", "Jakub");
fedData.put("sn", "Hejda");
registrarManager.parseNamesFromDisplayNameAndFedInfo(candidate, attributes, fedData);
assertThat(candidate.getTitleBefore()).isEqualTo("Bc.");
assertThat(candidate.getFirstName()).isEqualTo("Jakub");
assertThat(candidate.getMiddleName()).isEqualTo("Hejda");
assertThat(candidate.getLastName()).isEqualTo("Hejda");
assertThat(candidate.getTitleAfter()).isEqualTo("Dis.");
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class RegistrarManagerImplUnitTest method testDisplayNameReverseWithMiddleNameAndFedData.
@Test
public void testDisplayNameReverseWithMiddleNameAndFedData() {
Candidate candidate = new Candidate();
Map<String, String> attributes = new HashMap<>();
attributes.put(URN_USER_DISPLAY_NAME, "Bc. Sassmann Jan Vojtech Dis.");
Map<String, String> fedData = new HashMap<>();
fedData.put("givenName", "Vojtech");
fedData.put("sn", "Sassmann");
registrarManager.parseNamesFromDisplayNameAndFedInfo(candidate, attributes, fedData);
assertThat(candidate.getTitleBefore()).isEqualTo("Bc.");
assertThat(candidate.getTitleAfter()).isEqualTo("Dis.");
assertThat(candidate.getFirstName()).isEqualTo("Vojtech");
assertThat(candidate.getLastName()).isEqualTo("Sassmann");
assertThat(candidate.getMiddleName()).isEqualTo("Jan");
}
use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.
the class RegistrarManagerImplUnitTest method testDisplayNameReverseAndFedData.
@Test
public void testDisplayNameReverseAndFedData() {
Candidate candidate = new Candidate();
Map<String, String> attributes = new HashMap<>();
attributes.put(URN_USER_DISPLAY_NAME, "Bc. Sassmann Vojtech Dis.");
Map<String, String> fedData = new HashMap<>();
fedData.put("givenName", "Vojtech");
fedData.put("sn", "Sassmann");
registrarManager.parseNamesFromDisplayNameAndFedInfo(candidate, attributes, fedData);
assertThat(candidate.getTitleBefore()).isEqualTo("Bc.");
assertThat(candidate.getTitleAfter()).isEqualTo("Dis.");
assertThat(candidate.getFirstName()).isEqualTo("Vojtech");
assertThat(candidate.getLastName()).isEqualTo("Sassmann");
assertThat(candidate.getMiddleName()).isEqualTo(null);
}
Aggregations