Search in sources :

Example 81 with MockMessageListener

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);
    }
}
Also used : MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 82 with MockMessageListener

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);
    }
}
Also used : CoreException(com.adaptris.core.CoreException) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 83 with MockMessageListener

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);
    }
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) CoreException(com.adaptris.core.CoreException) ManagedThreadFactory(com.adaptris.core.util.ManagedThreadFactory) CoreException(com.adaptris.core.CoreException) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MBeanServer(javax.management.MBeanServer) Test(org.junit.Test)

Example 84 with MockMessageListener

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());
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) StubMessageFactory(com.adaptris.core.stubs.StubMessageFactory) PtpProducer(com.adaptris.core.jms.PtpProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 85 with MockMessageListener

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);
}
Also used : PasConsumer(com.adaptris.core.jms.PasConsumer) MimeEncoder(com.adaptris.core.MimeEncoder) PasProducer(com.adaptris.core.jms.PasProducer) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

MockMessageListener (com.adaptris.core.stubs.MockMessageListener)173 Test (org.junit.Test)171 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)160 StandaloneProducer (com.adaptris.core.StandaloneProducer)91 TimeInterval (com.adaptris.util.TimeInterval)42 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)36 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)32 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)28 File (java.io.File)28 GuidGenerator (com.adaptris.util.GuidGenerator)27 FilenameFilter (java.io.FilenameFilter)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 PtpProducer (com.adaptris.core.jms.PtpProducer)23 PtpConsumer (com.adaptris.core.jms.PtpConsumer)22 RandomAccessFile (java.io.RandomAccessFile)21 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)16 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)16 PasProducer (com.adaptris.core.jms.PasProducer)15 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 CoreException (com.adaptris.core.CoreException)14