Search in sources :

Example 1 with AssignedMember

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

the class ResourcesManagerEntryIntegrationTest method getAssignedMembersWithStatus.

@Test
public void getAssignedMembersWithStatus() throws Exception {
    System.out.println(CLASS_NAME + "getAssignedMembersWithStatus");
    vo = setUpVo();
    facility = setUpFacility();
    resource = setUpResource();
    // active
    Group group1 = perun.getGroupsManager().createGroup(sess, vo, new Group("group1", "group1"));
    // inactive
    Group group2 = perun.getGroupsManager().createGroup(sess, vo, new Group("group2", "group2"));
    // not assigned
    Group group3 = perun.getGroupsManager().createGroup(sess, vo, new Group("group3", "group3"));
    Member member1 = setUpMember(vo);
    Member member2 = setUpMember(vo);
    Member notAssignedMember = setUpMember(vo);
    perun.getGroupsManager().addMember(sess, group1, member1);
    perun.getGroupsManager().addMember(sess, group2, member1);
    perun.getGroupsManager().addMember(sess, group3, member1);
    perun.getGroupsManager().addMember(sess, group2, member2);
    perun.getGroupsManager().addMember(sess, group3, notAssignedMember);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group1, resource, false, false, false);
    perun.getResourcesManagerBl().assignGroupToResource(sess, group2, resource, false, false, false);
    perun.getResourcesManagerBl().deactivateGroupResourceAssignment(sess, group2, resource);
    List<AssignedMember> assignedMembers = perun.getResourcesManagerBl().getAssignedMembersWithStatus(sess, resource);
    List<Member> members = assignedMembers.stream().map(AssignedMember::getRichMember).collect(toList());
    // contains member1 and member2
    assertTrue(members.size() == 2);
    assertTrue(members.containsAll(List.of(member1, member2)));
    assertFalse(members.contains(notAssignedMember));
    AssignedMember assignedMem1 = assignedMembers.stream().filter(m -> m.getRichMember().equals(member1)).findAny().get();
    AssignedMember assignedMem2 = assignedMembers.stream().filter(m -> m.getRichMember().equals(member2)).findAny().get();
    // statuses are correctly prioritized
    assertTrue(assignedMem1.getStatus().equals(GroupResourceStatus.ACTIVE));
    assertTrue(assignedMem2.getStatus().equals(GroupResourceStatus.INACTIVE));
}
Also used : AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) EnrichedGroup(cz.metacentrum.perun.core.api.EnrichedGroup) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) Group(cz.metacentrum.perun.core.api.Group) AssignedMember(cz.metacentrum.perun.core.api.AssignedMember) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)1 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)1 AssignedMember (cz.metacentrum.perun.core.api.AssignedMember)1 EnrichedGroup (cz.metacentrum.perun.core.api.EnrichedGroup)1 Group (cz.metacentrum.perun.core.api.Group)1 Member (cz.metacentrum.perun.core.api.Member)1 Test (org.junit.Test)1