Search in sources :

Example 1 with MotechEvent

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

the class SettingsServiceImpl method savePlatformSettings.

@Override
public void savePlatformSettings(Settings settings) {
    for (SettingsOption option : settings.getSettings()) {
        Object val = option.getValue();
        configurationService.setPlatformSetting(option.getKey(), val == null ? null : String.valueOf(val));
    }
    Map<String, Object> params = new HashMap<>();
    params.put(ConfigurationConstants.SETTINGS, settings);
    MotechEvent platformSettingsChangedEvent = new MotechEvent(ConfigurationConstants.BUNDLE_SETTINGS_CHANGED_EVENT_SUBJECT, params);
    eventRelay.sendEventMessage(platformSettingsChangedEvent);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MotechEvent(org.motechproject.event.MotechEvent) SettingsOption(org.motechproject.admin.settings.SettingsOption)

Example 2 with MotechEvent

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

the class SettingsServiceImpl method saveSettingsFile.

@Override
public void saveSettingsFile(MultipartFile configFile) {
    Properties settings = loadMultipartFileIntoProperties(configFile);
    configurationService.savePlatformSettings(settings);
    Map<String, Object> params = new HashMap<>();
    params.put(ConfigurationConstants.SETTINGS, settings);
    MotechEvent platformSettingsChangedEvent = new MotechEvent(ConfigurationConstants.PLATFORM_SETTINGS_CHANGED_EVENT_SUBJECT, params);
    eventRelay.sendEventMessage(platformSettingsChangedEvent);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Properties(java.util.Properties) MotechEvent(org.motechproject.event.MotechEvent)

Example 3 with MotechEvent

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

the class EmailChannelBundleIT method testEmailSentOnSendEmailEvent.

@Test
public void testEmailSentOnSendEmailEvent() throws MessagingException, IOException, InterruptedException {
    SMTPServer smtpServer = new SMTPServer(new SimpleMessageListenerAdapter(this));
    new Wait(new ContextPublishedWaitCondition(bundleContext, "org.motechproject.motech-platform-event"), 5000).start();
    new Wait(new ContextPublishedWaitCondition(bundleContext), 5000).start();
    try {
        smtpServer.setPort(8099);
        smtpServer.start();
        String messageText = "test message";
        String from = "testfromaddress";
        String to = "testtoaddress";
        String subject = "test subject";
        Map<String, Object> values = new HashMap<>();
        values.put("fromAddress", from);
        values.put("toAddress", to);
        values.put("message", messageText);
        values.put("subject", subject);
        eventRelay.sendEventMessage(new MotechEvent(SendEmailConstants.SEND_EMAIL_SUBJECT, values));
        new Wait(lock, this, 100, 60000).start();
        assertTrue("Message not received", messageReceived);
        assertNotNull(receivedMessageText);
        assertEquals(messageText, receivedMessageText.trim());
    } finally {
        smtpServer.stop();
    }
}
Also used : ContextPublishedWaitCondition(org.motechproject.testing.osgi.wait.ContextPublishedWaitCondition) HashMap(java.util.HashMap) SMTPServer(org.subethamail.smtp.server.SMTPServer) SimpleMessageListenerAdapter(org.subethamail.smtp.helper.SimpleMessageListenerAdapter) Wait(org.motechproject.testing.osgi.wait.Wait) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 4 with MotechEvent

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

the class ServerEventRelayTest method shouldRetryEventHandlingWhenRelyingTopicEvent.

@Test
public void shouldRetryEventHandlingWhenRelyingTopicEvent() {
    final BooleanValue handled = new BooleanValue(false);
    when(motechEventConfig.getMessageMaxRedeliveryCount()).thenReturn(2);
    when(eventListener.getIdentifier()).thenReturn("retrying");
    doThrow(new RuntimeException()).doThrow(new RuntimeException()).doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            handled.setValue(true);
            return null;
        }
    }).when(eventListener).handle(any(MotechEvent.class));
    setUpListeners(SUBJECT, eventListener);
    eventRelay.relayTopicEvent(new MotechEvent(SUBJECT));
    verify(eventListener, times(3)).handle(any(MotechEvent.class));
    assertTrue(handled.getValue());
    verify(eventAdmin, never()).postEvent(any(Event.class));
    verify(eventAdmin, never()).sendEvent(any(Event.class));
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) MotechEvent(org.motechproject.event.MotechEvent) Event(org.osgi.service.event.Event) MotechEvent(org.motechproject.event.MotechEvent) Test(org.junit.Test)

Example 5 with MotechEvent

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

the class ServerEventRelayTest method shouldProxyBroadcastEventsInOSGi.

@Test
public void shouldProxyBroadcastEventsInOSGi() {
    Map<String, Object> params = new HashMap<>();
    params.put("proxy-in-osgi", true);
    MotechEvent event = new MotechEvent("subject", params);
    eventRelay.relayTopicEvent(event);
    ArgumentCaptor<Event> captor = ArgumentCaptor.forClass(Event.class);
    verify(eventAdmin).postEvent(captor.capture());
    assertEquals("subject", captor.getValue().getTopic());
}
Also used : HashMap(java.util.HashMap) MotechEvent(org.motechproject.event.MotechEvent) Event(org.osgi.service.event.Event) 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