use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class JmxNotificationConsumerTest method testConsumer_NoUserData.
@Test
public void testConsumer_NoUserData() throws Exception {
MBeanServer mbeanServer = JmxHelper.findMBeanServer();
String myObjectName = "com.adaptris:type=Junit,id=" + getName();
StubNotificationBroadcaster broadcast = new StubNotificationBroadcaster();
MockMessageListener listener = new MockMessageListener();
JmxNotificationConsumer consumer = new JmxNotificationConsumer();
consumer.setObjectName(myObjectName);
StandaloneConsumer sc = wrap(new JmxConnection(), consumer, listener);
try {
mbeanServer.registerMBean(broadcast, ObjectName.getInstance(myObjectName));
start(sc);
broadcast.sendNotification(getName(), null);
waitForMessages(listener, 1);
assertEquals(1, listener.messageCount());
assertNull(listener.getMessages().get(0).getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
} finally {
stop(sc);
}
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class JmxNotificationConsumerTest method testNotFound.
@Test
public void testNotFound() throws Exception {
MBeanServer mbeanServer = JmxHelper.findMBeanServer();
String myObjectName = "com.adaptris:type=Junit,id=" + getName();
StubNotificationBroadcaster broadcast = new StubNotificationBroadcaster();
MockMessageListener listener = new MockMessageListener();
JmxNotificationConsumer consumer = new JmxNotificationConsumer();
consumer.setObjectName(myObjectName);
StandaloneConsumer sc = wrap(new JmxConnection(), consumer, listener);
try {
start(sc);
fail();
} catch (CoreException e) {
} finally {
stop(sc);
}
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class JmxNotificationConsumerTest method testNotFound_Retry.
@Test
public void testNotFound_Retry() throws Exception {
final MBeanServer mbeanServer = JmxHelper.findMBeanServer();
final String myObjectName = "com.adaptris:type=Junit,id=" + getName();
final StubNotificationBroadcaster broadcast = new StubNotificationBroadcaster();
MockMessageListener listener = new MockMessageListener();
JmxNotificationConsumer consumer = new JmxNotificationConsumer();
consumer.setFailIfNotFound(false);
consumer.setRetryInterval(new TimeInterval(1L, TimeUnit.SECONDS));
consumer.setObjectName(myObjectName);
StandaloneConsumer sc = wrap(new JmxConnection(), consumer, listener);
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ManagedThreadFactory(getClass().getSimpleName()));
try {
start(sc);
scheduler.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
if (!mbeanServer.isRegistered(ObjectName.getInstance(myObjectName))) {
mbeanServer.registerMBean(broadcast, ObjectName.getInstance(myObjectName));
}
broadcast.sendNotification(getName(), new Object());
} catch (Exception e) {
throw new RuntimeException();
}
}
}, 3, 1, TimeUnit.SECONDS);
waitForMessages(listener, 1);
assertTrue(listener.messageCount() >= 1);
assertNotNull(listener.getMessages().get(0).getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
} catch (CoreException e) {
} finally {
stop(sc);
ManagedThreadFactory.shutdownQuietly(scheduler, 100L);
}
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class BasicActiveMqProducerTest method testQueueProduceAndConsume_CustomMessageFactory.
@Test
public void testQueueProduceAndConsume_CustomMessageFactory() throws Exception {
PtpConsumer consumer = new PtpConsumer().withQueue(getName());
consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
consumer.setMessageFactory(new StubMessageFactory());
StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(createVendorImpl()), consumer);
MockMessageListener jms = new MockMessageListener();
standaloneConsumer.registerAdaptrisMessageListener(jms);
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), new PtpProducer().withQueue((getName())));
execute(standaloneConsumer, standaloneProducer, createMessage(), jms);
assertMessages(jms, 1);
assertEquals(AdaptrisMessageStub.class, jms.getMessages().get(0).getClass());
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class BasicActiveMqProducerTest method testTopicProduceAndConsume_WithEncoder.
@Test
public void testTopicProduceAndConsume_WithEncoder() throws Exception {
PasConsumer consumer = new PasConsumer().withTopic(getName());
consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
consumer.setEncoder(new MimeEncoder());
StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(createVendorImpl()), consumer);
MockMessageListener jms = new MockMessageListener();
standaloneConsumer.registerAdaptrisMessageListener(jms);
PasProducer producer = new PasProducer().withTopic(getName());
producer.setEncoder(new MimeEncoder());
StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), producer);
execute(standaloneConsumer, standaloneProducer, createMessage(), jms);
assertMessages(jms, 1);
}
Aggregations