Search in sources :

Example 16 with Facility

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

the class AttributesManagerEntryIntegrationTest method getRequiredFacilityAttributesFromOneServiceWhenFacilityNotExists.

@Test(expected = FacilityNotExistsException.class)
public void getRequiredFacilityAttributesFromOneServiceWhenFacilityNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getRequiredFacilityAttributesFromOneServiceWhenFacilityNotExists");
    service = setUpService();
    attributesManager.getRequiredAttributes(sess, service, new Facility());
// shouldn't find service
}
Also used : Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 17 with Facility

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

the class FacilitiesManagerEntry method removeBan.

public void removeBan(PerunSession sess, int userId, int facilityId) throws InternalErrorException, BanNotExistsException, PrivilegeException {
    Utils.checkPerunSession(sess);
    BanOnFacility ban = this.getFacilitiesManagerBl().getBan(sess, userId, facilityId);
    Facility facility = new Facility();
    facility.setId(ban.getId());
    // Authorization
    if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
        throw new PrivilegeException(sess, "removeBan");
    }
    getFacilitiesManagerBl().removeBan(sess, userId, facilityId);
}
Also used : BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) RichFacility(cz.metacentrum.perun.core.api.RichFacility)

Example 18 with Facility

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

the class FacilitiesManagerEntryIntegrationTest method createFacilityWhenFacilityExists.

@Test(expected = FacilityExistsException.class)
public void createFacilityWhenFacilityExists() throws Exception {
    System.out.println(CLASS_NAME + "createFacilityWhenFacilityExists");
    Facility facility = new Facility();
    facility.setName("FacilitiesManagerTestFacility");
    perun.getFacilitiesManager().createFacility(sess, facility);
// shouldn't create same facility twice
}
Also used : BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 19 with Facility

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

the class FacilitiesManagerEntryIntegrationTest method getOwnersWhenFacilityNotExists.

@Test(expected = FacilityNotExistsException.class)
public void getOwnersWhenFacilityNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getOwnersWhenFacilityNotExists");
    perun.getFacilitiesManager().getOwners(sess, new Facility());
// shouldn't find facility
}
Also used : BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 20 with Facility

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

the class FacilitiesManagerEntryIntegrationTest method addHostSameHostDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addHostSameHostDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostSameHostDifferentAdmin");
    // Initialize host
    Host host = new Host(0, "testHost");
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set up two members
    Member memberOne = setUpMember(vo);
    Member memberTwo = setUpMember(vo);
    // Set users as admins of different facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    User userTwo = perun.getUsersManagerBl().getUserByMember(sess, memberTwo);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userTwo);
    // Sets userOne as actor in this test with role facility admin for facility
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, facility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds host to facility
    facilitiesManagerEntry.addHost(sess, host, facility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, facility).size() == 1);
    // Change actor in this test to userTwo
    authzRoles = new AuthzRoles(Role.FACILITYADMIN, secondFacility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userTwo);
    // Adds same host to secondFacility with different admin -> should throw exception
    facilitiesManagerEntry.addHost(sess, host, secondFacility);
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Host(cz.metacentrum.perun.core.api.Host) BanOnFacility(cz.metacentrum.perun.core.api.BanOnFacility) Facility(cz.metacentrum.perun.core.api.Facility) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Aggregations

Facility (cz.metacentrum.perun.core.api.Facility)188 Test (org.junit.Test)95 User (cz.metacentrum.perun.core.api.User)81 Attribute (cz.metacentrum.perun.core.api.Attribute)75 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)61 Resource (cz.metacentrum.perun.core.api.Resource)52 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)51 ArrayList (java.util.ArrayList)48 Group (cz.metacentrum.perun.core.api.Group)24 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)23 Member (cz.metacentrum.perun.core.api.Member)22 PerunSession (cz.metacentrum.perun.core.api.PerunSession)20 RichFacility (cz.metacentrum.perun.core.api.RichFacility)20 Host (cz.metacentrum.perun.core.api.Host)19 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)18 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)17 RichUser (cz.metacentrum.perun.core.api.RichUser)16 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Vo (cz.metacentrum.perun.core.api.Vo)13