Search in sources :

Example 51 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class AnnotationBasedHandlerIT method testRelay.

@Test
public void testRelay() {
    MotechEvent e = new MotechEvent("sub_b", null);
    clear();
    eventRelay.relayQueueEvent(e);
    assertTrue(test);
    e = new MotechEvent("sub_c", null);
    clear();
    eventRelay.relayQueueEvent(e);
    assertTrue(test);
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 52 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class AnnotationBasedHandlerIT method testNamedParamsHappy.

@Test
public void testNamedParamsHappy() {
    clear();
    MotechEvent event = new MotechEvent("named");
    event.getParameters().put("id", "id0012");
    event.getParameters().put("key", "2354");
    eventRelay.relayQueueEvent(event);
    assertTrue(test);
}
Also used : MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 53 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class PasswordReminderEventHandlerTest method prepareEvent.

private void prepareEvent() {
    Map<String, Object> params = new HashMap<>();
    params.put(TEMPLATE_PARAM_USERNAME, user.getUserName());
    params.put(EMAIL_PARAM_TO_ADDRESS, user.getEmail());
    params.put(TEMPLATE_PARAM_EXPIRATION_DATE, user.getSafeLastPasswordChange().plusDays(DAYS_TO_CHANGE_PASSWORD));
    params.put(TEMPLATE_PARAM_LOCALE, user.getLocale());
    params.put(TEMPLATE_PARAM_LAST_PASSWORD_CHANGE, user.getSafeLastPasswordChange());
    params.put(TEMPLATE_PARAM_EXTERNAL_ID, user.getExternalId());
    params.put(TEMPLATE_PARAM_DAYS_TILL_EXPIRE, DAYS_FOR_REMINDER);
    event = new MotechEvent(PASSWORD_CHANGE_REMINDER_EVENT, params);
}
Also used : HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent)

Example 54 with MotechEvent

use of org.motechproject.event.MotechEvent in project motech by motech.

the class EmailSenderImpl method sendEmail.

private void sendEmail(String userEmail, String messageText, String messageSubject) {
    Map<String, Object> params = new HashMap<>();
    params.put(EMAIL_PARAM_FROM_ADDRESS, getSenderAddress());
    params.put(EMAIL_PARAM_TO_ADDRESS, userEmail);
    params.put(EMAIL_PARAM_MESSAGE, messageText);
    params.put(EMAIL_PARAM_SUBJECT, messageSubject);
    MotechEvent emailEvent = new MotechEvent("SendEMail", params);
    eventRelay.sendEventMessage(emailEvent);
    LOGGER.info("Sent email event: {}", emailEvent.getSubject());
}
Also used : HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent)

Example 55 with MotechEvent

use of org.motechproject.event.MotechEvent 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)

Aggregations

MotechEvent (org.motechproject.event.MotechEvent)138 Test (org.junit.Test)87 HashMap (java.util.HashMap)79 CronSchedulableJob (org.motechproject.scheduler.contract.CronSchedulableJob)28 DateTime (org.joda.time.DateTime)25 DateUtil.newDateTime (org.motechproject.commons.date.util.DateUtil.newDateTime)20 ArrayList (java.util.ArrayList)14 RepeatingSchedulableJob (org.motechproject.scheduler.contract.RepeatingSchedulableJob)13 RunOnceSchedulableJob (org.motechproject.scheduler.contract.RunOnceSchedulableJob)11 JobBasicInfo (org.motechproject.scheduler.contract.JobBasicInfo)10 TaskActionInformation (org.motechproject.tasks.domain.mds.task.TaskActionInformation)8 Matchers.anyString (org.mockito.Matchers.anyString)7 EventListener (org.motechproject.event.listener.EventListener)7 CronJobId (org.motechproject.scheduler.contract.CronJobId)7 Task (org.motechproject.tasks.domain.mds.task.Task)7 JobId (org.motechproject.scheduler.contract.JobId)6 RepeatingJobId (org.motechproject.scheduler.contract.RepeatingJobId)6 Time (org.motechproject.commons.date.model.Time)5 DayOfWeekSchedulableJob (org.motechproject.scheduler.contract.DayOfWeekSchedulableJob)5 RepeatingPeriodSchedulableJob (org.motechproject.scheduler.contract.RepeatingPeriodSchedulableJob)5