Search in sources :

Example 41 with TaskActionInformation

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

the class TaskTriggerHandlerTest method setSecondAction.

private void setSecondAction() {
    Map<String, String> actionValues = new HashMap<>();
    actionValues.put("phone", "123456");
    actionValues.put("message", "Hello, world! I'm second action");
    task.addAction(new TaskActionInformation("sms", "SMS", "sms-bundle", "0.15", ACTION_SUBJECT, actionValues));
}
Also used : HashMap(java.util.HashMap) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) Matchers.anyString(org.mockito.Matchers.anyString)

Example 42 with TaskActionInformation

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

the class TaskContextTest method shouldThrowExceptionWhenDataSourceIsNull.

@Test
public void shouldThrowExceptionWhenDataSourceIsNull() throws Exception {
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    TaskContext taskContext = new TaskContext(task, null, null, activityService);
    taskContext.addDataSourceObject("1", null, true);
    KeyInformation key = parse("ad.1.Integer#1.id");
    expectedException.expect(TaskHandlerException.class);
    expectedException.expect(new TaskHandlerExceptionMatcher(TaskFailureCause.DATA_SOURCE, "task.error.objectOfTypeNotFound", key.getObjectType()));
    taskContext.getDataSourceObjectValue(key.getObjectId().toString(), key.getKey(), key.getObjectType());
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) KeyInformation(org.motechproject.tasks.domain.KeyInformation) Test(org.junit.Test)

Example 43 with TaskActionInformation

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

the class TaskContextTest method testGetDataSourceValue.

@Test
public void testGetDataSourceValue() throws Exception {
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    TaskContext taskContext = new TaskContext(task, null, null, activityService);
    taskContext.addDataSourceObject("1", new TestDataSourceObject(), true);
    KeyInformation key = parse("ad.1.Integer#1.id");
    assertEquals(OBJECT_ID.intValue(), taskContext.getDataSourceObjectValue(key.getObjectId().toString(), key.getKey(), key.getObjectType()));
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) KeyInformation(org.motechproject.tasks.domain.KeyInformation) Test(org.junit.Test)

Example 44 with TaskActionInformation

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

the class TaskContextTest method testGetTriggerKeyShouldThrowException.

@Test(expected = IllegalStateException.class)
public void testGetTriggerKeyShouldThrowException() throws Exception {
    MotechEvent event = mock(MotechEvent.class);
    when(event.getParameters()).thenReturn(new HashMap<>());
    KeyInformation key = parse(String.format("%s.%s", TRIGGER_PREFIX, EVENT_KEY));
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    new TaskContext(task, event.getParameters(), null, activityService).getTriggerValue(key.getKey());
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) MotechEvent(org.motechproject.event.MotechEvent) KeyInformation(org.motechproject.tasks.domain.KeyInformation) Test(org.junit.Test)

Aggregations

TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)44 Task (org.motechproject.tasks.domain.mds.task.Task)34 Test (org.junit.Test)32 TaskBuilder (org.motechproject.tasks.domain.mds.task.builder.TaskBuilder)24 HashMap (java.util.HashMap)18 TaskTriggerInformation (org.motechproject.tasks.domain.mds.task.TaskTriggerInformation)14 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)12 KeyInformation (org.motechproject.tasks.domain.KeyInformation)10 TreeSet (java.util.TreeSet)9 ObjectTest (org.motechproject.tasks.domain.ObjectTest)9 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)9 TaskContext (org.motechproject.tasks.service.util.TaskContext)8 MotechEvent (org.motechproject.event.MotechEvent)7 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)6 ArrayList (java.util.ArrayList)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 HashSet (java.util.HashSet)3 FilterSet (org.motechproject.tasks.domain.mds.task.FilterSet)3 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)3