Search in sources :

Example 1 with Destination

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);
}
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 2 with Destination

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);
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) User(cz.metacentrum.perun.core.api.User) AuthzRoles(cz.metacentrum.perun.core.impl.AuthzRoles) 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 3 with Destination

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());
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) Service(cz.metacentrum.perun.core.api.Service) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 4 with Destination

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()));
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) RichDestination(cz.metacentrum.perun.core.api.RichDestination) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 5 with Destination

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");
}
Also used : Destination(cz.metacentrum.perun.core.api.Destination) TaskStatusImpl(cz.metacentrum.perun.engine.scheduling.impl.TaskStatusImpl) TaskStatus(cz.metacentrum.perun.engine.scheduling.TaskStatus) Test(org.junit.Test) AbstractEngineTest(cz.metacentrum.perun.engine.AbstractEngineTest)

Aggregations

Destination (cz.metacentrum.perun.core.api.Destination)21 Test (org.junit.Test)10 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)9 RichDestination (cz.metacentrum.perun.core.api.RichDestination)9 Service (cz.metacentrum.perun.core.api.Service)9 Facility (cz.metacentrum.perun.core.api.Facility)8 ArrayList (java.util.ArrayList)8 BanOnFacility (cz.metacentrum.perun.core.api.BanOnFacility)5 Host (cz.metacentrum.perun.core.api.Host)5 Member (cz.metacentrum.perun.core.api.Member)5 User (cz.metacentrum.perun.core.api.User)5 AuthzRoles (cz.metacentrum.perun.core.impl.AuthzRoles)5 RichUser (cz.metacentrum.perun.core.api.RichUser)4 ServicesManager (cz.metacentrum.perun.core.api.ServicesManager)4 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)4 Task (cz.metacentrum.perun.taskslib.model.Task)4 Date (java.util.Date)4 PerunBean (cz.metacentrum.perun.core.api.PerunBean)3 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 ServiceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException)2