Search in sources :

Example 1 with TaskActivity

use of org.motechproject.tasks.domain.mds.task.TaskActivity in project motech by motech.

the class TaskActivityServiceImplTest method shouldAddTaskWarningActivityWithGivenException.

@Test
public void shouldAddTaskWarningActivityWithGivenException() {
    TaskHandlerException exception = new TaskHandlerException(TRIGGER, "trigger.exception", new TaskHandlerException(TRIGGER, "task.exception"));
    String messageKey = "warning.manipulation";
    ArgumentCaptor<TaskActivity> captor = ArgumentCaptor.forClass(TaskActivity.class);
    activityService.addWarningWithException(task, messageKey, ERROR_FIELD.get(0), exception);
    verify(taskActivitiesDataService).create(captor.capture());
    assertActivity(messageKey, ERROR_FIELD, TASK_ID, TaskActivityType.WARNING, getStackTrace(exception.getCause()), null, captor.getValue());
}
Also used : TaskHandlerException(org.motechproject.tasks.exception.TaskHandlerException) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Test(org.junit.Test)

Example 2 with TaskActivity

use of org.motechproject.tasks.domain.mds.task.TaskActivity in project motech by motech.

the class TaskActivityServiceImplTest method shouldReturnPaginatedActivitiesForGivenTask.

@Test
public void shouldReturnPaginatedActivitiesForGivenTask() {
    Set<TaskActivityType> types = new HashSet<>();
    types.addAll(Arrays.asList(TaskActivityType.values()));
    Set<Long> activitiesIds = new HashSet<>();
    QueryParams queryParams = new QueryParams((Order) null);
    boolean lastExecution = false;
    when(taskActivitiesDataService.byTaskAndActivityTypesAndIds(TASK_ID, types, activitiesIds, queryParams)).thenReturn(activities);
    List<TaskActivity> actual = activityService.getTaskActivities(TASK_ID, types, queryParams, lastExecution);
    assertNotNull(actual);
    assertEquals(activities, actual);
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with TaskActivity

use of org.motechproject.tasks.domain.mds.task.TaskActivity in project motech by motech.

the class TasksTestBase method setTaskActivities.

protected void setTaskActivities() {
    taskActivities = new ArrayList<>(5);
    taskActivities.add(new TaskActivity("Error1", task.getId(), ERROR));
    taskActivities.add(new TaskActivity("Error2", task.getId(), ERROR));
    taskActivities.add(new TaskActivity("Error3", task.getId(), ERROR));
    taskActivities.add(new TaskActivity("Error4", task.getId(), ERROR));
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity)

Example 4 with TaskActivity

use of org.motechproject.tasks.domain.mds.task.TaskActivity in project motech by motech.

the class ActionParametersBundleIT method hasTaskExecuted.

private boolean hasTaskExecuted(Long taskID) {
    Set<TaskActivityType> activityTypes = new HashSet<>();
    Set<Long> activityIds = new HashSet<>();
    activityTypes.add(TaskActivityType.SUCCESS);
    QueryParams queryParams = new QueryParams((Order) null);
    List<TaskActivity> taskActivities = taskActivitiesDataService.byTaskAndActivityTypesAndIds(taskID, activityTypes, activityIds, queryParams);
    return taskActivities.size() == 1;
}
Also used : TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) TaskActivityType(org.motechproject.tasks.domain.enums.TaskActivityType) QueryParams(org.motechproject.mds.query.QueryParams) HashSet(java.util.HashSet)

Example 5 with TaskActivity

use of org.motechproject.tasks.domain.mds.task.TaskActivity in project motech by motech.

the class TaskActivitiesDataServiceBundleIT method shouldFindTaskActivitiesByTaskId.

@Test
public void shouldFindTaskActivitiesByTaskId() {
    TaskActivity errorMsg = new TaskActivity(ERROR.getValue(), FIELD, TASK_ID_1, ERROR, new TaskExecutionProgress(1));
    TaskActivity successMsg = new TaskActivity(SUCCESS.getValue(), TASK_ID_1, SUCCESS);
    TaskActivity warningMsg = new TaskActivity(WARNING.getValue(), TASK_ID_2, WARNING);
    taskActivitiesDataService.create(errorMsg);
    taskActivitiesDataService.create(warningMsg);
    taskActivitiesDataService.create(successMsg);
    assertEquals(asList(errorMsg, warningMsg, successMsg), taskActivitiesDataService.retrieveAll());
    List<TaskActivity> messages = taskActivitiesDataService.byTask(TASK_ID_1);
    assertEquals(asList(errorMsg, successMsg), messages);
    assertEquals(ERROR, messages.get(0).getActivityType());
    assertEquals(TASK_ID_1, messages.get(0).getTask());
    assertEquals(ERROR.getValue(), messages.get(0).getMessage());
    assertEquals(FIELD, messages.get(0).getFields());
    assertEquals(SUCCESS, messages.get(1).getActivityType());
    assertEquals(TASK_ID_1, messages.get(1).getTask());
    assertEquals(SUCCESS.getValue(), messages.get(1).getMessage());
    messages = taskActivitiesDataService.byTask(TASK_ID_2);
    assertEquals(asList(warningMsg), messages);
    assertEquals(WARNING, messages.get(0).getActivityType());
    assertEquals(TASK_ID_2, messages.get(0).getTask());
    assertEquals(WARNING.getValue(), messages.get(0).getMessage());
}
Also used : TaskExecutionProgress(org.motechproject.tasks.domain.mds.task.TaskExecutionProgress) TaskActivity(org.motechproject.tasks.domain.mds.task.TaskActivity) Test(org.junit.Test)

Aggregations

TaskActivity (org.motechproject.tasks.domain.mds.task.TaskActivity)16 Test (org.junit.Test)6 Transactional (org.springframework.transaction.annotation.Transactional)6 TaskExecutionProgress (org.motechproject.tasks.domain.mds.task.TaskExecutionProgress)4 QueryParams (org.motechproject.mds.query.QueryParams)3 TaskHandlerException (org.motechproject.tasks.exception.TaskHandlerException)3 HashSet (java.util.HashSet)2 DateTime (org.joda.time.DateTime)2 TaskActivityType (org.motechproject.tasks.domain.enums.TaskActivityType)2 Order (org.motechproject.mds.util.Order)1