Search in sources :

Example 31 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class TaskServiceImpl method validateActions.

private Set<TaskError> validateActions(Task task) {
    LOGGER.debug("Validating all actions in task: {} with ID: {}", task.getName(), task.getId());
    Set<TaskError> errors = new HashSet<>();
    for (TaskActionInformation action : task.getActions()) {
        Channel channel = channelService.getChannel(action.getModuleName());
        errors.addAll(validateAction(task, channel, action));
    }
    logResultOfValidation("actions", task.getName(), errors);
    return errors;
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) HandlerPredicates.tasksWithRegisteredChannel(org.motechproject.tasks.service.util.HandlerPredicates.tasksWithRegisteredChannel) TaskError(org.motechproject.tasks.domain.mds.task.TaskError) TaskActionInformation(org.motechproject.tasks.domain.mds.task.TaskActionInformation) HashSet(java.util.HashSet)

Example 32 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class ChannelServiceImplTest method shouldGetChannelByChannelInfo.

@Test
public void shouldGetChannelByChannelInfo() {
    String displayName = "Test";
    String moduleName = "test-1";
    Channel expected = new Channel();
    expected.setDisplayName(displayName);
    expected.setModuleName(moduleName);
    expected.setModuleVersion(VERSION);
    when(channelsDataService.findByModuleName(moduleName)).thenReturn(expected);
    when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
    when(bundle.getSymbolicName()).thenReturn(moduleName);
    Channel actual = channelService.getChannel(moduleName);
    assertNotNull(actual);
    assertEquals(expected, actual);
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) Test(org.junit.Test)

Example 33 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class ChannelServiceImplTest method shouldRegisterChannelFromChannelRequest.

@Test
public void shouldRegisterChannelFromChannelRequest() {
    List<ActionEventRequest> actionEventRequests = asList(new TestActionEventRequestBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<ActionParameterRequest>()).setPostActionParameters(new TreeSet<ActionParameterRequest>()).createActionEventRequest());
    List<TriggerEventRequest> triggerEventsRequest = asList(new TriggerEventRequest("displayName", "subject.foo", "description", asList(new EventParameterRequest("displayName", "eventKey"))));
    ChannelRequest channelRequest = new ChannelRequest(BUNDLE_SYMBOLIC_NAME, BUNDLE_SYMBOLIC_NAME, VERSION, "", triggerEventsRequest, actionEventRequests);
    channelService.registerChannel(channelRequest);
    ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
    verify(channelsDataService).create(captor.capture());
    Channel channelToBeCreated = captor.getValue();
    assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getDisplayName());
    assertEquals(BUNDLE_SYMBOLIC_NAME, channelToBeCreated.getModuleName());
    assertEquals(VERSION, channelToBeCreated.getModuleVersion());
    assertEquals(1, channelToBeCreated.getTriggerTaskEvents().size());
    TriggerEvent expectedTrigger = new TriggerEvent("displayName", "subject.foo", "description", asList(new EventParameter("displayName", "eventKey")), "");
    TriggerEvent actualTrigger = channelToBeCreated.getTriggerTaskEvents().get(0);
    assertEquals(expectedTrigger, actualTrigger);
    assertEquals(1, channelToBeCreated.getActionTaskEvents().size());
    ActionEvent expectedAction = new ActionEventBuilder().setDisplayName("actionName").setSubject("subject.foo").setDescription("action description").setServiceInterface("some.interface").setServiceMethod("method").setActionParameters(new TreeSet<>()).setPostActionParameters(new TreeSet<>()).build();
    ActionEvent actualAction = channelToBeCreated.getActionTaskEvents().get(0);
    assertEquals(expectedAction, actualAction);
}
Also used : ChannelRequest(org.motechproject.tasks.contract.ChannelRequest) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) ActionEvent(org.motechproject.tasks.domain.mds.channel.ActionEvent) EventParameterRequest(org.motechproject.tasks.contract.EventParameterRequest) Channel(org.motechproject.tasks.domain.mds.channel.Channel) ActionEventBuilder(org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder) ActionEventRequest(org.motechproject.tasks.contract.ActionEventRequest) TestActionEventRequestBuilder(org.motechproject.tasks.contract.builder.TestActionEventRequestBuilder) EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TriggerEventRequest(org.motechproject.tasks.contract.TriggerEventRequest) TreeSet(java.util.TreeSet) ActionParameterRequest(org.motechproject.tasks.contract.ActionParameterRequest) Test(org.junit.Test)

Example 34 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class ChannelServiceImplTest method shouldRegisterChannel.

@Test
public void shouldRegisterChannel() {
    String triggerEvent = "{ displayName: 'displayName', subject: 'subject', eventParameters: [{ displayName: 'displayName', eventKey: 'eventKey' }] }";
    String channel = String.format("{displayName: %s, triggerTaskEvents: [%s]}", BUNDLE_SYMBOLIC_NAME, triggerEvent);
    InputStream stream = new ByteArrayInputStream(channel.getBytes(Charset.forName("UTF-8")));
    channelService.registerChannel(stream, BUNDLE_SYMBOLIC_NAME, VERSION);
    ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
    verify(channelsDataService).create(captor.capture());
    Channel c = captor.getValue();
    assertEquals(BUNDLE_SYMBOLIC_NAME, c.getDisplayName());
    assertEquals(BUNDLE_SYMBOLIC_NAME, c.getModuleName());
    assertEquals(VERSION, c.getModuleVersion());
    assertEquals(1, c.getTriggerTaskEvents().size());
    assertEquals(new TriggerEvent("displayName", "subject", null, asList(new EventParameter("displayName", "eventKey")), ""), c.getTriggerTaskEvents().get(0));
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) Test(org.junit.Test)

Example 35 with Channel

use of org.motechproject.tasks.domain.mds.channel.Channel in project motech by motech.

the class ChannelServiceImplTest method shouldSendEventWhenChannelWasDeleted.

@Test
public void shouldSendEventWhenChannelWasDeleted() {
    Channel channel = new Channel("displayName", BUNDLE_SYMBOLIC_NAME, VERSION);
    when(channelsDataService.findByModuleName(channel.getModuleName())).thenReturn(channel);
    when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
    when(bundle.getSymbolicName()).thenReturn(BUNDLE_SYMBOLIC_NAME);
    ArgumentCaptor<MotechEvent> captor = ArgumentCaptor.forClass(MotechEvent.class);
    Channel deletedChannel = new Channel("displayName2", BUNDLE_SYMBOLIC_NAME, VERSION);
    channelService.delete(deletedChannel.getModuleName());
    verify(channelsDataService).delete(channel);
    verify(eventRelay).sendEventMessage(captor.capture());
    MotechEvent event = captor.getValue();
    assertEquals(CHANNEL_DEREGISTER_SUBJECT, event.getSubject());
    assertEquals(BUNDLE_SYMBOLIC_NAME, event.getParameters().get(CHANNEL_MODULE_NAME));
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Aggregations

Channel (org.motechproject.tasks.domain.mds.channel.Channel)35 Test (org.junit.Test)25 ActionEventBuilder (org.motechproject.tasks.domain.mds.channel.builder.ActionEventBuilder)14 EventParameter (org.motechproject.tasks.domain.mds.channel.EventParameter)13 TriggerEvent (org.motechproject.tasks.domain.mds.channel.TriggerEvent)13 Task (org.motechproject.tasks.domain.mds.task.Task)12 TaskConfig (org.motechproject.tasks.domain.mds.task.TaskConfig)9 ArrayList (java.util.ArrayList)8 ActionEvent (org.motechproject.tasks.domain.mds.channel.ActionEvent)8 TaskDataProviderObject (org.motechproject.tasks.domain.mds.task.TaskDataProviderObject)8 TaskError (org.motechproject.tasks.domain.mds.task.TaskError)8 HashSet (java.util.HashSet)6 QueryExecution (org.motechproject.mds.query.QueryExecution)6 TaskDataProvider (org.motechproject.tasks.domain.mds.task.TaskDataProvider)6 DataSource (org.motechproject.tasks.domain.mds.task.DataSource)5 Lookup (org.motechproject.tasks.domain.mds.task.Lookup)5 LookupFieldsParameter (org.motechproject.tasks.domain.mds.task.LookupFieldsParameter)5 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 TaskChannel (org.motechproject.tasks.annotations.TaskChannel)4