use of cz.metacentrum.perun.core.api.Service 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.Service 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());
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method getHierarchicalDataWhenServiceNotExists.
@Test(expected = ServiceNotExistsException.class)
public void getHierarchicalDataWhenServiceNotExists() throws Exception {
System.out.println(CLASS_NAME + "getHierarchicalDataWhenServiceNotExists");
facility = setUpFacility();
perun.getServicesManager().getHierarchicalData(sess, new Service(), facility);
// shouldn't find service
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method getAssignedResourcesWhenServiceNotExists.
@Test(expected = ServiceNotExistsException.class)
public void getAssignedResourcesWhenServiceNotExists() throws Exception {
System.out.println(CLASS_NAME + "getAssignedResourcesWhenServiceNotExists");
perun.getServicesManager().getAssignedResources(sess, new Service());
// shouldn't find service
}
use of cz.metacentrum.perun.core.api.Service in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method addServiceToServicesPackageWhenServiceNotExists.
@Test(expected = ServiceNotExistsException.class)
public void addServiceToServicesPackageWhenServiceNotExists() throws Exception {
System.out.println(CLASS_NAME + "addServiceToServicesPackageWhenServiceNotExists");
ServicesPackage servicesPackage = new ServicesPackage();
servicesPackage.setName("ServicesManagerTestSP");
servicesPackage.setDescription("TestingPackage");
perun.getServicesManager().createServicesPackage(sess, servicesPackage);
perun.getServicesManager().addServiceToServicesPackage(sess, servicesPackage, new Service());
// shouldn't find services package
}
Aggregations