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