Search in sources :

Example 21 with Facility

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

the class FacilitiesManagerEntryIntegrationTest method getAssignedRichResourcesWhenFacilityNotExists.

@Test(expected = FacilityNotExistsException.class)
public void getAssignedRichResourcesWhenFacilityNotExists() throws Exception {
    System.out.println(CLASS_NAME + "getAssignedRichResourcesWhenFacilityNotExists");
    perun.getFacilitiesManager().getAssignedRichResources(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 22 with Facility

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

the class FacilitiesManagerEntryIntegrationTest method getFacilitiesByHostName.

@Test
public void getFacilitiesByHostName() throws Exception {
    System.out.println(CLASS_NAME + "getFacilitiesByHostname");
    String hostname = "testHostname";
    Host host = new Host(15, hostname);
    perun.getFacilitiesManagerBl().addHost(sess, host, facility);
    List<Facility> facilities = perun.getFacilitiesManager().getFacilitiesByHostName(sess, hostname);
    assertNotNull("unable to get facilities by Hostname", facilities);
    assertEquals("There is only one facility with host with specific hostname", 1, facilities.size());
}
Also used : Host(cz.metacentrum.perun.core.api.Host) 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 23 with Facility

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

the class FacilitiesManagerEntryIntegrationTest method addHostAndDestinationSameNameSameAdmin.

@Test
public void addHostAndDestinationSameNameSameAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostAndDestinationSameNameSameAdmin");
    // Initialize host, destination and service
    String hostName = "TestHost";
    Host hostOne = new Host(0, hostName);
    Destination destination = new Destination(0, hostName, Destination.DESTINATIONHOSTTYPE);
    Service service = new Service(0, "testService");
    ServicesManager servicesManagerEntry = perun.getServicesManager();
    service = servicesManagerEntry.createService(sess, service);
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // Set up two members
    Member memberOne = setUpMember(vo);
    // Set userOne as admin for both facilities
    User userOne = perun.getUsersManagerBl().getUserByMember(sess, memberOne);
    facilitiesManagerEntry.addAdmin(sess, facility, userOne);
    facilitiesManagerEntry.addAdmin(sess, secondFacility, userOne);
    // Sets userOne as actor in this test with role facility admin for facility
    List<PerunBean> list = new ArrayList<PerunBean>();
    list.add(facility);
    list.add(secondFacility);
    AuthzRoles authzRoles = new AuthzRoles(Role.FACILITYADMIN, list);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userOne);
    // Adds host to facility
    facilitiesManagerEntry.addHost(sess, hostOne, facility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, facility).size() == 1);
    // Adds destination with same name as host to facility
    servicesManagerEntry.addDestination(sess, service, facility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, facility).size() == 1);
    // Adds same host to second facility
    facilitiesManagerEntry.addHost(sess, hostOne, secondFacility);
    assertTrue(facilitiesManagerEntry.getHosts(sess, secondFacility).size() == 1);
    // Adds destination with same name as host to secondFacility
    servicesManagerEntry.addDestination(sess, service, secondFacility, destination);
    assertTrue(servicesManagerEntry.getDestinations(sess, service, secondFacility).size() == 1);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) PerunBean(cz.metacentrum.perun.core.api.PerunBean) User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ServicesManager(cz.metacentrum.perun.core.api.ServicesManager) ArrayList(java.util.ArrayList) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) Service(cz.metacentrum.perun.core.api.Service) 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)

Example 24 with Facility

use of cz.metacentrum.perun.core.api.Facility 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 25 with Facility

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

the class FacilitiesManagerEntryIntegrationTest method addHostsStringsSameHostsDifferentAdmin.

@Test(expected = PrivilegeException.class)
public void addHostsStringsSameHostsDifferentAdmin() throws Exception {
    System.out.println(CLASS_NAME + "addHostsStringsSameHostsDifferentAdmin");
    // Sets list of hostnames
    String hostName = "testHostOne";
    List<String> listOfHosts = new ArrayList<String>();
    listOfHosts.add(hostName);
    hostName = "testHostTwo";
    listOfHosts.add(hostName);
    // Set up two members
    Member memberOne = setUpMember(vo);
    Member memberTwo = setUpMember(vo);
    // Creates second facility
    Facility secondFacility = new Facility(0, "TestSecondFacility", "TestDescriptionText");
    assertNotNull(perun.getFacilitiesManager().createFacility(sess, secondFacility));
    // 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 hosts to facility
    facilitiesManagerEntry.addHosts(sess, facility, listOfHosts);
    // Change actor in this test to userTwo
    authzRoles = new AuthzRoles(Role.FACILITYADMIN, secondFacility);
    sess.getPerunPrincipal().setRoles(authzRoles);
    sess.getPerunPrincipal().setUser(userTwo);
    // Adds same hosts to secondFacility with different admin -> should throw exception
    facilitiesManagerEntry.addHosts(sess, secondFacility, listOfHosts);
}
Also used : User(cz.metacentrum.perun.core.api.User) RichUser(cz.metacentrum.perun.core.api.RichUser) ArrayList(java.util.ArrayList) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) 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