Search in sources :

Example 6 with TaskActionInformation

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

the class TaskContextTest method testGetTriggerKey.

@Test
public void testGetTriggerKey() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    TaskContext taskContext = new TaskContext(task, null, null, activityService);
    KeyInformation key = parse(String.format("%s.%s", TRIGGER_PREFIX, EVENT_KEY));
    assertEquals(null, taskContext.getTriggerValue(key.getKey()));
    Map<String, String> child = new HashMap<>();
    child.put("key", EVENT_KEY_VALUE);
    parameters.put("event", child);
    taskContext = new TaskContext(task, parameters, null, activityService);
    assertEquals(EVENT_KEY_VALUE, taskContext.getTriggerValue(key.getKey()));
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) KeyInformation(org.motechproject.tasks.domain.KeyInformation) Test(org.junit.Test)

Example 7 with TaskActionInformation

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

the class TaskContextTest method shouldNotThrowExceptionWhenDataSourceIsNull_IfFailNotFoundIsFalse.

@Test
public void shouldNotThrowExceptionWhenDataSourceIsNull_IfFailNotFoundIsFalse() throws Exception {
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    TaskContext taskContext = new TaskContext(task, null, null, activityService);
    taskContext.addDataSourceObject("1", null, false);
    KeyInformation key = parse("ad.1.Integer#1.id");
    assertNull(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 8 with TaskActionInformation

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

the class TaskContextTest method testGetNullTriggerKey.

@Test
public void testGetNullTriggerKey() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    MotechEvent event = mock(MotechEvent.class);
    KeyInformation key = parse(String.format("%s.%s", TRIGGER_PREFIX, EVENT_KEY));
    Map<String, String> child = new HashMap<>();
    child.put("key", null);
    parameters.put("event", child);
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    assertEquals(null, new TaskContext(task, parameters, null, activityService).getTriggerValue(key.getKey()));
    // should not throw any exceptions
    assertNull(new TaskContext(task, parameters, null, activityService).getTriggerValue(key.getKey()));
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) Task(org.motechproject.tasks.domain.mds.task.Task) HashMap(java.util.HashMap) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) MotechEvent(org.motechproject.event.MotechEvent) KeyInformation(org.motechproject.tasks.domain.KeyInformation) Test(org.junit.Test)

Example 9 with TaskActionInformation

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

the class TaskContextTest method shouldNotThrowExceptionWhenDataSourceFieldValueEvaluationThrowsException_IfFailNotFoundIsFalse.

@Test
public void shouldNotThrowExceptionWhenDataSourceFieldValueEvaluationThrowsException_IfFailNotFoundIsFalse() throws Exception {
    Task task = new TaskBuilder().addAction(new TaskActionInformation()).build();
    TaskContext taskContext = new TaskContext(task, null, null, activityService);
    taskContext.addDataSourceObject("1", new TestDataSourceObject(), false);
    KeyInformation key = parse("ad.1.Integer#1.providerId");
    assertNull(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 10 with TaskActionInformation

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

the class TaskBuilderTest method shouldReturnEmptyTaskObject.

@Test
public void shouldReturnEmptyTaskObject() throws Exception {
    TaskBuilder builder = new TaskBuilder();
    Task task = builder.withName(TASK_NAME).withDescription(TASK_DESCRIPTION).isEnabled(isEnabled).withTrigger(new TaskTriggerInformation()).addAction(new TaskActionInformation()).withTaskConfig(new TaskConfig()).addFilterSet(new FilterSet()).addDataSource(new DataSource()).clear().build();
    assertNotNull(task);
    assertTrue(task.getName().isEmpty());
    assertTrue(task.getDescription().isEmpty());
    assertEquals(false, task.isEnabled());
    assertNull(task.getTrigger());
    assertNotNull(task.getActions());
    assertTrue(task.getActions().isEmpty());
    assertNotNull(task.getTaskConfig());
    assertTrue(task.getTaskConfig().getSteps().isEmpty());
}
Also used : TaskBuilder(org.motechproject.tasks.domain.mds.task.builder.TaskBuilder) TaskTriggerInformation(org.motechproject.tasks.domain.mds.task.TaskTriggerInformation) Task(org.motechproject.tasks.domain.mds.task.Task) FilterSet(org.motechproject.tasks.domain.mds.task.FilterSet) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) TaskConfig(org.motechproject.tasks.domain.mds.task.TaskConfig) DataSource(org.motechproject.tasks.domain.mds.task.DataSource) 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