Search in sources :

Example 31 with Resource

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());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member) Date(java.util.Date) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 32 with Resource

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());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member) Date(java.util.Date) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 33 with Resource

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));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member) Date(java.util.Date) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 34 with Resource

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));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) Resource(cz.metacentrum.perun.core.api.Resource) ArrayList(java.util.ArrayList) Vo(cz.metacentrum.perun.core.api.Vo) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 35 with Resource

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());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ContactGroup(cz.metacentrum.perun.core.api.ContactGroup) Resource(cz.metacentrum.perun.core.api.Resource) RichResource(cz.metacentrum.perun.core.api.RichResource) Vo(cz.metacentrum.perun.core.api.Vo) Service(cz.metacentrum.perun.core.api.Service) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Resource (cz.metacentrum.perun.core.api.Resource)176 Test (org.junit.Test)110 Attribute (cz.metacentrum.perun.core.api.Attribute)82 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)79 Facility (cz.metacentrum.perun.core.api.Facility)56 User (cz.metacentrum.perun.core.api.User)55 Group (cz.metacentrum.perun.core.api.Group)49 ArrayList (java.util.ArrayList)41 Vo (cz.metacentrum.perun.core.api.Vo)31 Member (cz.metacentrum.perun.core.api.Member)29 PerunSession (cz.metacentrum.perun.core.api.PerunSession)29 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)26 RichResource (cz.metacentrum.perun.core.api.RichResource)25 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)20 RichUser (cz.metacentrum.perun.core.api.RichUser)18 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)18 ContactGroup (cz.metacentrum.perun.core.api.ContactGroup)17 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)17 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)15 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)14