Search in sources :

Example 1 with ActionNotFoundException

use of org.motechproject.tasks.exception.ActionNotFoundException in project motech by motech.

the class TaskTriggerHandlerTest method shouldHandleErrorWhenActionIsNotFound.

@Test
public void shouldHandleErrorWhenActionIsNotFound() throws Exception {
    setTriggerEvent();
    when(taskService.findActiveTasksForTriggerSubject(TRIGGER_SUBJECT)).thenReturn(tasks);
    when(taskService.getActionEventFor(task.getActions().get(0))).thenThrow(new ActionNotFoundException(""));
    handler.handle(createEvent());
    verifyErrorHandling("task.error.actionNotFound");
}
Also used : ActionNotFoundException(org.motechproject.tasks.exception.ActionNotFoundException) Test(org.junit.Test)

Example 2 with ActionNotFoundException

use of org.motechproject.tasks.exception.ActionNotFoundException in project motech by motech.

the class TaskServiceImpl method getActionEventFor.

@Override
@Transactional
public ActionEvent getActionEventFor(TaskActionInformation taskActionInformation) throws ActionNotFoundException {
    Channel channel = channelService.getChannel(taskActionInformation.getModuleName());
    ActionEvent event = null;
    for (ActionEvent action : channel.getActionTaskEvents()) {
        if (action.accept(taskActionInformation)) {
            event = action;
            break;
        }
    }
    if (event == null) {
        throw new ActionNotFoundException(format("Cant find action on the basic of information: %s", taskActionInformation));
    }
    return event;
}
Also used : ActionNotFoundException(org.motechproject.tasks.exception.ActionNotFoundException) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) HandlerPredicates.tasksWithRegisteredChannel(org.motechproject.tasks.service.util.HandlerPredicates.tasksWithRegisteredChannel) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ActionNotFoundException (org.motechproject.tasks.exception.ActionNotFoundException)2 Test (org.junit.Test)1 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)1 Channel (org.motechproject.tasks.domain.mds.channel.Channel)1 HandlerPredicates.tasksWithRegisteredChannel (org.motechproject.tasks.service.util.HandlerPredicates.tasksWithRegisteredChannel)1 Transactional (org.springframework.transaction.annotation.Transactional)1