Search in sources :

Example 1 with Channel

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

the class ChannelServiceImplTest method shouldGetAllChannels.

@Test
public void shouldGetAllChannels() {
    List<Channel> expected = new ArrayList<>();
    expected.add(new Channel(null, "symbolic", null));
    expected.add(new Channel(null, "symbolic", null));
    when(bundleContext.getBundles()).thenReturn(new Bundle[] { bundle });
    when(bundle.getSymbolicName()).thenReturn("symbolic");
    when(channelsDataService.executeQuery(any(QueryExecution.class))).thenReturn(expected);
    List<Channel> actual = channelService.getAllChannels();
    assertNotNull(actual);
    assertEquals(expected, actual);
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) ArrayList(java.util.ArrayList) QueryExecution(org.motechproject.mds.query.QueryExecution) Test(org.junit.Test)

Example 2 with Channel

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

the class ChannelServiceImplTest method shouldUnregisterChannel.

@Test
public void shouldUnregisterChannel() {
    Channel channel = new Channel("Channel to delete", 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);
    channelService.unregisterChannel(channel.getModuleName());
    ArgumentCaptor<Channel> captor = ArgumentCaptor.forClass(Channel.class);
    verify(channelsDataService).delete(captor.capture());
    Channel deletedChannel = captor.getValue();
    assertEquals("Channel to delete", deletedChannel.getDisplayName());
    assertEquals(BUNDLE_SYMBOLIC_NAME, deletedChannel.getModuleName());
    assertEquals(VERSION, deletedChannel.getModuleVersion());
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) Test(org.junit.Test)

Example 3 with Channel

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

the class ChannelServiceImplTest method shouldSendEventWhenChannelWasUpdated.

@Test
public void shouldSendEventWhenChannelWasUpdated() {
    Channel channel = new Channel("displayName", BUNDLE_SYMBOLIC_NAME, VERSION);
    EventParameter eventParameter = new EventParameter("displayName", "eventKey");
    TriggerEvent triggerEvent = new TriggerEvent("displayName", "subject", null, Arrays.asList(eventParameter), "");
    channel.getTriggerTaskEvents().add(triggerEvent);
    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 updatedChannel = new Channel("displayName2", BUNDLE_SYMBOLIC_NAME, VERSION);
    updatedChannel.getTriggerTaskEvents().add(triggerEvent);
    channelService.addOrUpdate(updatedChannel);
    verify(channelsDataService).update(channel);
    verify(eventRelay).sendEventMessage(captor.capture());
    MotechEvent event = captor.getValue();
    assertEquals(CHANNEL_UPDATE_SUBJECT, event.getSubject());
    assertEquals(BUNDLE_SYMBOLIC_NAME, event.getParameters().get(CHANNEL_MODULE_NAME));
}
Also used : EventParameter(org.motechproject.tasks.domain.mds.channel.EventParameter) TriggerEvent(org.motechproject.tasks.domain.mds.channel.TriggerEvent) Channel(org.motechproject.tasks.domain.mds.channel.Channel) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 4 with Channel

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

the class ActionParametersBundleIT method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    createAdminUser();
    login();
    Channel channel = loadChannel();
    setUpSecurityContext("motech", "motech", "manageTasks");
    channelService.addOrUpdate(channel);
    waitForChannel(MDS_CHANNEL_NAME);
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) Before(org.junit.Before)

Example 5 with Channel

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

the class TasksBundleIT method testChannelService.

private void testChannelService() throws InterruptedException {
    assertNotNull(fromFileChannel);
    ChannelsDataService channelsDataService = getTasksContext().getBean(ChannelsDataService.class);
    Channel fromDB = channelsDataService.findByModuleName(testBundleName);
    assertNotNull(fromDB);
    assertEquals(fromDB, fromFileChannel);
}
Also used : Channel(org.motechproject.tasks.domain.mds.channel.Channel) ChannelsDataService(org.motechproject.tasks.repository.ChannelsDataService)

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