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);
}
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);
}
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();
}
}
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));
}
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());
}
Aggregations