Search in sources :

Example 11 with ExecService

use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.

the class EventExecServiceResolverTest method parseEventTest.

@Test
public void parseEventTest() throws ServiceNotExistsException, InvalidEventMessageException, InternalErrorException, PrivilegeException {
    System.out.println("EventExecServiceResolver.parseEventTest()");
    String message = member1.serializeToString() + " added to " + group1.serializeToString() + ".";
    Event event = new Event();
    event.setTimeStamp(System.currentTimeMillis());
    event.setHeader("portishead");
    event.setData(message);
    Map<Facility, Set<ExecService>> resolvedServices = eventExecServiceResolver.parseEvent(event.toString());
    Assert.assertTrue("We should resolved only one facility-service", resolvedServices.size() == 1);
    Set<ExecService> resolved = resolvedServices.get(facility1);
    Assert.assertTrue("We should have 2 exec services", resolved.size() == 2);
    Assert.assertTrue("Our exec service 1 is missing", resolved.contains(execservice1));
    Assert.assertTrue("Our exec service 2 is missing", resolved.contains(execservice2));
}
Also used : Set(java.util.Set) ExecService(cz.metacentrum.perun.taskslib.model.ExecService) Event(cz.metacentrum.perun.dispatcher.model.Event) Facility(cz.metacentrum.perun.core.api.Facility) AbstractDispatcherTest(cz.metacentrum.perun.dispatcher.AbstractDispatcherTest) Test(org.junit.Test)

Example 12 with ExecService

use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.

the class ExecServiceDaoTest method testRemoveExecService.

@Test
public void testRemoveExecService() {
    System.out.println("ExecServiceDao.removeExecService");
    try {
        log.debug("testRemoveExecService: Inserting execServices...");
        // Test ExecService #1 (Parent:testService1)
        ExecService execService = new ExecService();
        execService.setDefaultDelay(1);
        execService.setDefaultRecurrence(1);
        execService.setEnabled(true);
        execService.setService(testService1);
        execService.setScript("/hellish/test/script");
        execService.setExecServiceType(ExecServiceType.GENERATE);
        execService.setId(execServiceDao.insertExecService(execService));
        // Test ExecService #2 (Parent:testService1)
        ExecService execService2 = new ExecService();
        execService2.setDefaultDelay(2);
        execService2.setDefaultRecurrence(2);
        execService2.setEnabled(true);
        execService2.setService(testService1);
        execService2.setScript("/hellish/test/script2");
        execService2.setExecServiceType(ExecServiceType.SEND);
        execService2.setId(execServiceDao.insertExecService(execService2));
        // Test ExecService #3 (Parent:testService2)
        ExecService execService3 = new ExecService();
        execService3.setDefaultDelay(3);
        execService3.setDefaultRecurrence(3);
        execService3.setEnabled(true);
        execService3.setService(testService2);
        execService3.setScript("/hellish/test/script3");
        execService3.setExecServiceType(ExecServiceType.SEND);
        execService3.setId(execServiceDao.insertExecService(execService3));
        log.debug("testRemoveExecService: Deleting one of the execExecServices...");
        ExecService execServiceToBeDeleted = execServiceDao.getExecService(execService2.getId());
        execServiceDao.deleteExecService(execServiceToBeDeleted.getId());
        assertEquals(execServiceDao.getExecService(execService.getId()), execService);
        assertEquals(execServiceDao.getExecService(execService2.getId()), null);
        assertEquals(execServiceDao.getExecService(execService3.getId()), execService3);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        fail();
    }
}
Also used : ExecService(cz.metacentrum.perun.taskslib.model.ExecService) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ServiceExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceExistsException) OwnerNotExistsException(cz.metacentrum.perun.core.api.exceptions.OwnerNotExistsException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Test(org.junit.Test)

Example 13 with ExecService

use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.

the class ExecServiceDaoTest method testUpdateExecService.

@Test
public void testUpdateExecService() {
    System.out.println("ExecServiceDao.updateExecService");
    try {
        log.debug("testUpdateExecService: Inserting execExecService...");
        // Test ExecService #1 (Parent:testService1)
        ExecService execService = new ExecService();
        execService.setDefaultDelay(1);
        execService.setDefaultRecurrence(1);
        execService.setEnabled(true);
        execService.setService(testService1);
        execService.setScript("/hellish/test/script");
        execService.setExecServiceType(ExecServiceType.GENERATE);
        execService.setId(execServiceDao.insertExecService(execService));
        log.debug("testUpdateExecService: Updating execService...");
        execService.setDefaultDelay(2);
        execService.setDefaultRecurrence(2);
        execService.setEnabled(true);
        execService.setScript("/hellish/test/script2");
        execService.setExecServiceType(ExecServiceType.GENERATE);
        execServiceDao.updateExecService(execService);
        ExecService retrievedExecService = execServiceDao.getExecService(execService.getId());
        assertEquals(retrievedExecService.getDefaultDelay(), execService.getDefaultDelay());
        assertEquals(retrievedExecService.getDefaultRecurrence(), execService.getDefaultRecurrence());
        assertEquals(retrievedExecService.getScript(), execService.getScript());
        assertEquals(retrievedExecService.getExecServiceType(), execService.getExecServiceType());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        fail();
    }
}
Also used : ExecService(cz.metacentrum.perun.taskslib.model.ExecService) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ServiceExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceExistsException) OwnerNotExistsException(cz.metacentrum.perun.core.api.exceptions.OwnerNotExistsException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Test(org.junit.Test)

Example 14 with ExecService

use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.

the class ExecServiceDaoTest method testListExecServices.

@Test
public void testListExecServices() {
    System.out.println("ExecServiceDao.listExecServices");
    try {
        log.debug("testListExecServices: Inserting execServices...");
        int originalNumberOfExecServices = execServiceDao.countExecServices();
        // Test ExecService #1 (Parent:testService1)
        ExecService execService = new ExecService();
        execService.setDefaultDelay(1);
        execService.setDefaultRecurrence(1);
        execService.setEnabled(true);
        execService.setService(testService1);
        execService.setScript("/hellish/test/script");
        execService.setExecServiceType(ExecServiceType.GENERATE);
        execServiceDao.insertExecService(execService);
        // Test ExecService #2 (Parent:testService1)
        ExecService execService2 = new ExecService();
        execService2.setDefaultDelay(2);
        execService2.setDefaultRecurrence(2);
        execService2.setEnabled(true);
        execService2.setService(testService1);
        execService2.setScript("/hellish/test/script2");
        execService2.setExecServiceType(ExecServiceType.SEND);
        execServiceDao.insertExecService(execService2);
        // Test ExecService #3 (Parent:testService2)
        ExecService execService3 = new ExecService();
        execService3.setDefaultDelay(3);
        execService3.setDefaultRecurrence(3);
        execService3.setEnabled(true);
        execService3.setService(testService2);
        execService3.setScript("/hellish/test/script3");
        execService3.setExecServiceType(ExecServiceType.SEND);
        execServiceDao.insertExecService(execService3);
        log.debug("testListExecServices: Retrieving all execExecServices...");
        List<ExecService> execServices = execServiceDao.listExecServices();
        assertNotNull(execServices);
        for (ExecService s : execServices) {
            log.debug("\tID:" + s.getId());
            log.debug("\tDefDELAY:" + s.getDefaultDelay());
            log.debug("\tDefRecurrence:" + s.getDefaultRecurrence());
            log.debug("\tENABLED:" + s.isEnabled());
            log.debug("\tSERVICE:" + s.getService().getName());
            log.debug("\tSCRIPT:" + s.getScript());
            log.debug("\tTYPE:" + s.getExecServiceType().toString());
        }
        assertEquals(execServices.size(), originalNumberOfExecServices + 3);
    } catch (Exception e) {
        log.error("testListExecServices: " + e.getMessage(), e);
        fail();
    }
}
Also used : ExecService(cz.metacentrum.perun.taskslib.model.ExecService) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ServiceExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceExistsException) OwnerNotExistsException(cz.metacentrum.perun.core.api.exceptions.OwnerNotExistsException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Test(org.junit.Test)

Example 15 with ExecService

use of cz.metacentrum.perun.taskslib.model.ExecService in project perun by CESNET.

the class ExecServiceDenialDaoTest method testListDenialsForDestination.

@Test
public void testListDenialsForDestination() {
    System.out.println("ExecServiceDenialDao.listDenialsForDestination");
    try {
        log.debug("testListDenialsForDestination: Inserting a new denial...");
        execServiceDenialDao.banExecServiceOnDestination(testExecService1.getId(), testDestinationId1);
        execServiceDenialDao.banExecServiceOnDestination(testExecService2.getId(), testDestinationId1);
        log.debug("testListDenialsForDestination: Listing all denials (denied services) for the destination...");
        List<ExecService> deniedExecServices = execServiceDenialDao.listDenialsForDestination(testDestinationId1);
        assertNotNull(deniedExecServices);
        for (ExecService deniedExecService : deniedExecServices) {
            log.debug("\tDESTINATION:" + testDestinationId1);
            log.debug("\tID:" + deniedExecService.getId());
            log.debug("\tDefDELAY:" + deniedExecService.getDefaultDelay());
            log.debug("\tDefRecurrence:" + deniedExecService.getDefaultRecurrence());
            log.debug("\tENABLED:" + deniedExecService.isEnabled());
            log.debug("\tService:" + deniedExecService.getService().getName());
            log.debug("\tSCRIPT:" + deniedExecService.getScript());
            log.debug("\tTYPE:" + deniedExecService.getExecServiceType().toString());
        }
        assertEquals(deniedExecServices.size(), 2);
        assertEquals(execServiceDenialDao.listDenialsForDestination(testDestinationId2).size(), 0);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        fail();
    }
}
Also used : ExecService(cz.metacentrum.perun.taskslib.model.ExecService) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) ServiceExistsException(cz.metacentrum.perun.core.api.exceptions.ServiceExistsException) OwnerNotExistsException(cz.metacentrum.perun.core.api.exceptions.OwnerNotExistsException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) Test(org.junit.Test)

Aggregations

ExecService (cz.metacentrum.perun.taskslib.model.ExecService)38 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)19 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)16 Test (org.junit.Test)14 ServiceExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceExistsException)13 Task (cz.metacentrum.perun.taskslib.model.Task)10 Facility (cz.metacentrum.perun.core.api.Facility)8 OwnerNotExistsException (cz.metacentrum.perun.core.api.exceptions.OwnerNotExistsException)8 Date (java.util.Date)8 Service (cz.metacentrum.perun.core.api.Service)7 ArrayList (java.util.ArrayList)7 ServiceNotExistsException (cz.metacentrum.perun.core.api.exceptions.ServiceNotExistsException)5 FacilityNotExistsException (cz.metacentrum.perun.core.api.exceptions.FacilityNotExistsException)4 PerunBean (cz.metacentrum.perun.core.api.PerunBean)3 PerunClient (cz.metacentrum.perun.core.api.PerunClient)3 PerunPrincipal (cz.metacentrum.perun.core.api.PerunPrincipal)3 Before (org.junit.Before)3 Destination (cz.metacentrum.perun.core.api.Destination)2 Owner (cz.metacentrum.perun.core.api.Owner)2 Matcher (java.util.regex.Matcher)2