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