use of cz.metacentrum.perun.core.api.Destination 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.Destination in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method addDestinationSameDestinationDifferentAdmin.
@Test(expected = PrivilegeException.class)
public void addDestinationSameDestinationDifferentAdmin() throws Exception {
System.out.println(CLASS_NAME + "addDestinationSameDestinationDifferentAdmin");
vo = setUpVo();
facility = setUpFacility();
resource = setUpResource();
service = setUpService();
Destination testDestination = new Destination(0, "TestDestination", Destination.DESTINATIONHOSTTYPE);
member = setUpMember();
Member memberTwo = setUpMember();
// 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, member);
perun.getFacilitiesManager().addAdmin(sess, facility, userOne);
User userTwo = perun.getUsersManagerBl().getUserByMember(sess, memberTwo);
perun.getFacilitiesManager().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 destination to facility
perun.getServicesManager().addDestination(sess, service, facility, testDestination);
assertTrue(perun.getServicesManager().getDestinations(sess, service, 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 destination to secondFacility -> should throw exception
perun.getServicesManager().addDestination(sess, service, secondFacility, testDestination);
}
use of cz.metacentrum.perun.core.api.Destination in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method removeAllDestinationsWithFacility.
@Test
public void removeAllDestinationsWithFacility() throws Exception {
System.out.println(CLASS_NAME + "removeAllDestinationsWithFacility");
List<Service> services = setUpServices();
facility = setUpFacility();
destination = setUpDestination();
Destination dest1 = perun.getServicesManager().addDestination(sess, services.get(0), facility, destination);
Destination dest2 = perun.getServicesManager().addDestination(sess, services.get(1), facility, destination);
List<Destination> destinations = perun.getServicesManagerBl().getDestinations(sess, facility);
assertTrue("There need to be dest1", destinations.contains(dest1));
assertTrue("There need to be dest2", destinations.contains(dest2));
perun.getServicesManagerBl().removeAllDestinations(sess, facility);
destinations = perun.getServicesManagerBl().getDestinations(sess, facility);
assertTrue("All destinations should be removed", destinations.isEmpty());
}
use of cz.metacentrum.perun.core.api.Destination in project perun by CESNET.
the class ServicesManagerEntryIntegrationTest method getAllDestinationsWithFacility.
@Test
public void getAllDestinationsWithFacility() throws Exception {
System.out.println(CLASS_NAME + "getAllDestinationsWithFacility");
service = setUpService();
facility = setUpFacility();
destination = setUpDestination();
perun.getServicesManagerBl().addDestination(sess, service, facility, destination);
List<Destination> destinations = perun.getServicesManagerBl().getDestinations(sess, facility);
assertTrue("there shoudl be one detination", !destinations.isEmpty());
Destination dest = destinations.get(0);
assertTrue("there is the right destination in the richDestination", dest.getDestination().equals(destination.getDestination()));
}
use of cz.metacentrum.perun.core.api.Destination in project perun by CESNET.
the class TaskStatusImplTest method getWaitingDestinationsTest.
@Test
public void getWaitingDestinationsTest() throws InternalErrorException {
System.out.println("TaskStatusImpl.getWaitingDestinationsTest");
TaskStatus taskStatus = new TaskStatusImpl(task1);
List<Destination> destinations = taskStatus.getWaitingDestinations();
log.debug("destinations: " + destinations.toString());
Assert.isTrue(destinations.size() == 3, "size == 3");
Assert.isTrue(destinations.contains(destination1), "destination1");
Assert.isTrue(destinations.contains(destination2), "destination2");
Assert.isTrue(destinations.contains(destination3) || destinations.contains(destination4), "destination3 or destination4");
destinations = taskStatus.getWaitingDestinations();
Assert.isTrue(destinations.size() == 1, "size == 1");
taskStatus.setDestinationStatus(destination3, TaskDestinationStatus.DONE);
destinations = taskStatus.getWaitingDestinations();
Assert.isTrue(destinations.size() == 0, "size == 0");
}
Aggregations