Skip to content

Instantly share code, notes, and snippets.

@danbev
Created July 13, 2012 06:42
Show Gist options
  • Save danbev/3103193 to your computer and use it in GitHub Desktop.
Save danbev/3103193 to your computer and use it in GitHub Desktop.
SwitchYard Completion Event Notifier
@SwitchYardTestCaseConfig(
config = SwitchYardTestCaseConfig.SWITCHYARD_XML,
mixins = {CDIMixIn.class, HornetQMixIn.class},
scanners = BeanSwitchYardScanner.class)
@RunWith(SwitchYardRunner.class)
public class CamelJMSBindingTest {
private static final String QUEUE_NAME = "GreetingServiceQueue";
private SwitchYardTestKit _testKit;
@Test
public void sendTextMessageToJMSQueue() throws Exception {
final String payload = "dummy payload";
final CompletionNotifier<String> notifier = new CompletionNotifier<String>(String.class);
_testKit.getServiceDomain().addEventObserver(notifier, ExchangeCompletionEvent.class);
sendTextToQueue(payload, QUEUE_NAME);
// Allow for the JMS Message to be processed.
Thread.sleep(3000);
final String recievedMessage = notifier.getMessage();
assertThat(recievedMessage, equalTo("Greeted " + payload));
}
private class CompletionNotifier<T> implements EventObserver {
private T _processed;
private Class<T> _type;
public CompletionNotifier(final Class<T> type) {
_type = type;
}
@Override
public void notify(final EventObject event) {
final Exchange ex = (Exchange) event.getSource();
_processed = ex.getMessage().getContent(_type);
}
public T getMessage() {
return _processed;
}
}
...
}
@Service(GreetingService.class)
public class GreetingServiceBean
implements org.switchyard.quickstarts.camel.jms.binding.GreetingService {
@Override
public final String greet(final String name) {
System.out.println("Hello there " + name + " :-) ");
return "Greeted " + name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment