Search in sources :

Example 86 with Candidate

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));
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) Group(cz.metacentrum.perun.core.api.Group) RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) BanOnVo(cz.metacentrum.perun.core.api.BanOnVo) Vo(cz.metacentrum.perun.core.api.Vo) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 87 with Candidate

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));
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) Group(cz.metacentrum.perun.core.api.Group) RichUser(cz.metacentrum.perun.core.api.RichUser) User(cz.metacentrum.perun.core.api.User) MemberCandidate(cz.metacentrum.perun.core.api.MemberCandidate) RichUser(cz.metacentrum.perun.core.api.RichUser) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 88 with Candidate

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.");
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 89 with Candidate

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");
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 90 with Candidate

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);
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Candidate (cz.metacentrum.perun.core.api.Candidate)100 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)52 Test (org.junit.Test)41 Member (cz.metacentrum.perun.core.api.Member)37 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)30 ExtSource (cz.metacentrum.perun.core.api.ExtSource)25 RichMember (cz.metacentrum.perun.core.api.RichMember)24 User (cz.metacentrum.perun.core.api.User)23 HashMap (java.util.HashMap)23 ArrayList (java.util.ArrayList)21 Group (cz.metacentrum.perun.core.api.Group)15 Attribute (cz.metacentrum.perun.core.api.Attribute)14 Map (java.util.Map)12 MemberCandidate (cz.metacentrum.perun.core.api.MemberCandidate)11 RichUser (cz.metacentrum.perun.core.api.RichUser)11 Vo (cz.metacentrum.perun.core.api.Vo)11 LinkedHashMap (java.util.LinkedHashMap)11 RichUserExtSource (cz.metacentrum.perun.core.api.RichUserExtSource)9 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)9 CandidateNotExistsException (cz.metacentrum.perun.core.api.exceptions.CandidateNotExistsException)8