use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method removeBanById.
@Test
public void removeBanById() throws Exception {
System.out.println(CLASS_NAME + "removeBan");
Vo vo = setUpVo();
Resource resource = setUpResource(vo);
Member member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
Group group = setUpGroup(vo, member);
perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource);
BanOnFacility banOnFacility = new BanOnFacility();
banOnFacility.setUserId(user.getId());
banOnFacility.setFacilityId(facility.getId());
banOnFacility.setDescription("Popisek");
banOnFacility.setValidityTo(new Date());
banOnFacility = facilitiesManagerEntry.setBan(sess, banOnFacility);
List<BanOnFacility> bansOnFacility = facilitiesManagerEntry.getBansForFacility(sess, banOnFacility.getFacilityId());
assertTrue(bansOnFacility.size() == 1);
perun.getFacilitiesManagerBl().removeBan(sess, banOnFacility.getId());
bansOnFacility = facilitiesManagerEntry.getBansForFacility(sess, banOnFacility.getFacilityId());
assertTrue(bansOnFacility.isEmpty());
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method removeExpiredBansIfExist.
@Test
public void removeExpiredBansIfExist() throws Exception {
System.out.println(CLASS_NAME + "removeExpiredBansIfExist");
Vo vo = setUpVo();
Resource resource = setUpResource(vo);
Member member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
Group group = setUpGroup(vo, member);
perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource);
BanOnFacility banOnFacility = new BanOnFacility();
banOnFacility.setUserId(user.getId());
banOnFacility.setFacilityId(facility.getId());
banOnFacility.setDescription("Popisek");
Date now = new Date();
Date yesterday = new Date(now.getTime() - (1000 * 60 * 60 * 24));
banOnFacility.setValidityTo(yesterday);
banOnFacility = facilitiesManagerEntry.setBan(sess, banOnFacility);
List<BanOnFacility> bansOnFacility = facilitiesManagerEntry.getBansForFacility(sess, banOnFacility.getFacilityId());
assertTrue(bansOnFacility.size() == 1);
perun.getFacilitiesManagerBl().removeAllExpiredBansOnFacilities(sess);
bansOnFacility = facilitiesManagerEntry.getBansForFacility(sess, banOnFacility.getFacilityId());
assertTrue(bansOnFacility.isEmpty());
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method getBansForFacility.
@Test
public void getBansForFacility() throws Exception {
System.out.println(CLASS_NAME + "getBansForFacility");
Vo vo = setUpVo();
Resource resource = setUpResource(vo);
Member member = setUpMember(vo);
User user = perun.getUsersManagerBl().getUserByMember(sess, member);
Group group = setUpGroup(vo, member);
perun.getResourcesManagerBl().assignGroupToResource(sess, group, resource);
BanOnFacility banOnFacility = new BanOnFacility();
banOnFacility.setUserId(user.getId());
banOnFacility.setFacilityId(facility.getId());
banOnFacility.setDescription("Popisek");
banOnFacility.setValidityTo(new Date());
banOnFacility = facilitiesManagerEntry.setBan(sess, banOnFacility);
List<BanOnFacility> returnedBans = facilitiesManagerEntry.getBansForFacility(sess, banOnFacility.getFacilityId());
assertEquals(banOnFacility, returnedBans.get(0));
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class GroupsManagerEntryIntegrationTest method getAssignedGroupsToFacility.
@Test
public void getAssignedGroupsToFacility() throws Exception {
System.out.println(CLASS_NAME + "getAssignedGroupsToFacility");
// Test that new method returns same data as old behavior
vo = setUpVo();
Vo vo2 = new Vo(0, "facilityTestVo002", "facilityTestVo002");
vo2 = perun.getVosManagerBl().createVo(sess, vo2);
Facility facility = new Facility(0, "groupsTestFacility01", "groupsTestFacility01");
facility = perun.getFacilitiesManager().createFacility(sess, facility);
Resource resource1 = setUpResource(vo, facility);
Resource resource2 = setUpResource(vo2, facility);
Group group11 = new Group("Group11", "testGroup1");
Group group12 = new Group("Group12", "testGroup2");
Group group21 = new Group("Group21", "testGroup3");
Group group22 = new Group("Group22", "testGroup4");
group11 = perun.getGroupsManager().createGroup(sess, vo, group11);
group12 = perun.getGroupsManager().createGroup(sess, vo, group12);
group21 = perun.getGroupsManager().createGroup(sess, vo2, group21);
group22 = perun.getGroupsManager().createGroup(sess, vo2, group22);
perun.getResourcesManager().assignGroupToResource(sess, group11, resource1);
perun.getResourcesManager().assignGroupToResource(sess, group21, resource2);
// test new way - single select
List<Group> groups = perun.getGroupsManagerBl().getAssignedGroupsToFacility(sess, facility);
Assert.notNull(groups);
assertTrue(groups.size() == 2);
assertTrue(groups.contains(group11));
assertTrue(groups.contains(group21));
assertTrue(!groups.contains(group12));
assertTrue(!groups.contains(group22));
// test old way - iterate over resources
List<Resource> resources = perun.getFacilitiesManager().getAssignedResources(sess, facility);
List<Group> oldGroups = new ArrayList<Group>();
for (Resource r : resources) {
oldGroups.addAll(perun.getResourcesManager().getAssignedGroups(sess, r));
}
Assert.notNull(oldGroups);
assertTrue(oldGroups.contains(group11));
assertTrue(oldGroups.contains(group21));
assertTrue(!oldGroups.contains(group12));
assertTrue(!oldGroups.contains(group22));
assertEquals(new HashSet<>(groups), new HashSet<>(oldGroups));
}
use of cz.metacentrum.perun.core.api.Resource in project perun by CESNET.
the class FacilitiesManagerEntryIntegrationTest method getAssignedResourcesWithVoOrServiceFilter.
@Test
public void getAssignedResourcesWithVoOrServiceFilter() throws Exception {
System.out.println(CLASS_NAME + "getAssignedResourcesWithVoOrServiceFilter");
// Test that new method returns same data as old behavior
Vo vo2 = new Vo(0, "facilityTestVo002", "facilityTestVo002");
vo2 = perun.getVosManagerBl().createVo(sess, vo2);
Member member11 = setUpMember(vo);
Member member12 = setUpMember(vo);
Member member21 = setUpMember(vo2);
Member member22 = setUpMember(vo2);
Resource resource1 = setUpResource(vo);
Resource resource2 = setUpResource(vo2);
Group group1 = setUpGroup(vo, member11);
Group group2 = setUpGroup(vo2, member21);
// make them not-allowed
perun.getMembersManager().setStatus(sess, member12, Status.INVALID);
perun.getMembersManager().setStatus(sess, member22, Status.DISABLED);
perun.getGroupsManager().addMember(sess, group1, member12);
perun.getGroupsManager().addMember(sess, group2, member22);
perun.getResourcesManager().assignGroupToResource(sess, group1, resource1);
perun.getResourcesManager().assignGroupToResource(sess, group2, resource2);
// test new way - single select
List<Member> members = perun.getFacilitiesManagerBl().getAllowedMembers(sess, facility);
Assert.notNull(members);
assertTrue(members.size() == 2);
assertTrue(members.contains(member11));
assertTrue(members.contains(member21));
assertTrue(!members.contains(member12));
assertTrue(!members.contains(member22));
// check getting all
List<Resource> resources = perun.getFacilitiesManager().getAssignedResources(sess, facility);
Assert.notNull(resources);
assertTrue(resources.size() == 2);
assertTrue(resources.contains(resource1));
assertTrue(resources.contains(resource2));
// check getting by VO
resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, vo, null);
Assert.notNull(resources);
assertTrue(resources.size() == 1);
assertTrue(resources.contains(resource1));
assertTrue(!resources.contains(resource2));
Service service = new Service(0, "TestService01");
service = perun.getServicesManager().createService(sess, service);
perun.getResourcesManager().assignService(sess, resource1, service);
// service should be only on 1 resource
resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, null, service);
Assert.notNull(resources);
assertTrue(resources.size() == 1);
assertTrue(resources.contains(resource1));
assertTrue(!resources.contains(resource2));
// vo-service should by only for 1 resource
resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, vo, service);
Assert.notNull(resources);
assertTrue(resources.size() == 1);
assertTrue(resources.contains(resource1));
assertTrue(!resources.contains(resource2));
// vo2-service shouldn't be assigned
resources = perun.getFacilitiesManagerBl().getAssignedResources(sess, facility, vo2, service);
Assert.notNull(resources);
assertTrue(resources.isEmpty());
}
Aggregations