Search in sources :

Example 96 with Candidate

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

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

Example 98 with Candidate

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);
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate)

Example 99 with Candidate

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());
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CandidateSync(cz.metacentrum.perun.core.api.CandidateSync) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ArgumentMatchers.anyMap(org.mockito.ArgumentMatchers.anyMap) LinkedHashMap(java.util.LinkedHashMap) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 100 with Candidate

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;
}
Also used : Candidate(cz.metacentrum.perun.core.api.Candidate) Member(cz.metacentrum.perun.core.api.Member)

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