Search in sources :

Example 81 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class VosManagerEntryIntegrationTest method getCompleteCandidatesFromGroupWithNullVo.

@Test
public void getCompleteCandidatesFromGroupWithNullVo() throws Exception {
    System.out.println(CLASS_NAME + "getCompleteCandidatesFromGroupWithNullVo");
    // 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("Josef", es);
    User userNotToContain1 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
    candidate = prepareCandidateWithExtSource("Jana", extSource);
    RichUser userToContain2 = perun.getUsersManagerBl().getRichUser(sess, perun.getUsersManagerBl().createUser(sess, candidate));
    List<MemberCandidate> completeCandidates = perun.getVosManagerBl().getCompleteCandidates(sess, null, returnedGroup, null, "jan", Arrays.asList(es));
    List<RichUser> usersOfCompleteCandidates = completeCandidates.stream().map(MemberCandidate::getRichUser).collect(Collectors.toList());
    assertEquals("Three users should have been returned.", 2, usersOfCompleteCandidates.size());
    assertTrue("User should've been returned.", usersOfCompleteCandidates.contains(userToContain1));
    assertTrue("User should've been returned.", usersOfCompleteCandidates.contains(userToContain2));
    assertFalse("User shouldn't have been returned.", usersOfCompleteCandidates.contains(userNotToContain1));
}
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) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 82 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class UsersManagerEntryIntegrationTest method testCreateServiceUserFailsForAlreadyExistingUes.

@Test
public void testCreateServiceUserFailsForAlreadyExistingUes() throws Exception {
    System.out.println(CLASS_NAME + "testCreateServiceUserFailsForAlreadyExistingUes");
    Candidate candidate = setUpCandidateForSpecificUser1();
    usersManager.createServiceUser(sess, candidate, Collections.emptyList());
    assertThatExceptionOfType(UserExtSourceExistsException.class).isThrownBy(() -> usersManager.createServiceUser(sess, candidate, Collections.emptyList()));
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) UserExtSourceExistsException(cz.metacentrum.perun.core.api.exceptions.UserExtSourceExistsException) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 83 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class ServicesManagerEntryIntegrationTest method setUpMember.

private Member setUpMember() throws Exception {
    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()));
    Candidate candidate;
    // Mockito.mock(Candidate.class);
    candidate = new Candidate();
    candidate.setFirstName(userFirstName);
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName(userLastName);
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    UserExtSource ues = new UserExtSource(new ExtSource(0, "testExtSource", "cz.metacentrum.perun.core.impl.ExtSourceInternal"), extLogin);
    candidate.setUserExtSource(ues);
    candidate.setAttributes(new HashMap<>());
    Member createdMember = perun.getMembersManagerBl().createMemberSync(sess, vo, candidate);
    assertNotNull("No member created", createdMember);
    usersForDeletion.add(perun.getUsersManager().getUserByMember(sess, createdMember));
    // save user for deletion after test
    return createdMember;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) Member(cz.metacentrum.perun.core.api.Member)

Example 84 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class UsersManagerEntryIntegrationTest method setUpMember.

private Member setUpMember(Vo vo) throws Exception {
    // List<Candidate> candidates = perun.getVosManager().findCandidates(sess, vo, extLogin);
    // find candidates from ext source based on extLogin
    // assertTrue(candidates.size() > 0);
    Candidate candidate = setUpCandidate();
    // candidates.get(0)
    Member member = perun.getMembersManagerBl().createMember(sess, vo, candidate);
    perun.getMembersManagerBl().validateMember(sess, member);
    // set first candidate as member of test VO
    assertNotNull("No member created", member);
    usersForDeletion.add(usersManager.getUserByMember(sess, member));
    // save user for deletion after test
    return member;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Member(cz.metacentrum.perun.core.api.Member)

Example 85 with Candidate

use of cz.metacentrum.perun.core.api.Candidate in project perun by CESNET.

the class UsersManagerEntryIntegrationTest method setUpCandidateForSpecificUser1.

private Candidate setUpCandidateForSpecificUser1() {
    // Mockito.mock(Candidate.class);
    Candidate candidate = new Candidate();
    candidate.setFirstName("(Service)");
    candidate.setId(0);
    candidate.setMiddleName("");
    candidate.setLastName("testingServiceUser01");
    candidate.setTitleBefore("");
    candidate.setTitleAfter("");
    candidate.setServiceUser(true);
    final UserExtSource userExtSource = new UserExtSource(extSource, Long.toHexString(Double.doubleToLongBits(Math.random())));
    candidate.setUserExtSource(userExtSource);
    candidate.setAttributes(new HashMap<>());
    return candidate;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) RichUserExtSource(cz.metacentrum.perun.core.api.RichUserExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource)

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