Search in sources :

Example 1 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class FtpRecursiveConsumerTest method testConsumeWithEncoder.

@Test
public void testConsumeWithEncoder() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD);
    byte[] bytes = new MimeEncoder().encode(msg);
    FileSystem filesystem = helper.createFilesystem_DirsOnly();
    for (int i = 0; i < count; i++) {
        FileEntry entry = new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + i + ".txt");
        entry.setContents(bytes);
        filesystem.add(entry);
    }
    FakeFtpServer server = helper.createAndStart(filesystem);
    StandaloneConsumer sc = null;
    try {
        FtpRecursiveConsumer ftpConsumer = createForTests(listener);
        ftpConsumer.setEncoder(new MimeEncoder());
        FtpConnection consumeConnection = create(server);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        waitForMessages(listener, count);
        helper.assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 2 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class BasicActiveMqProducerTest method testQueueProduceAndConsume_WithEncoder.

@Test
public void testQueueProduceAndConsume_WithEncoder() throws Exception {
    PtpConsumer consumer = new PtpConsumer().withQueue(getName());
    consumer.setEncoder(new MimeEncoder());
    consumer.setAcknowledgeMode("AUTO_ACKNOWLEDGE");
    StandaloneConsumer standaloneConsumer = new StandaloneConsumer(activeMqBroker.getJmsConnection(createVendorImpl()), consumer);
    MockMessageListener jms = new MockMessageListener();
    standaloneConsumer.registerAdaptrisMessageListener(jms);
    PtpProducer producer = new PtpProducer().withQueue((getName()));
    producer.setEncoder(new MimeEncoder());
    StandaloneProducer standaloneProducer = new StandaloneProducer(activeMqBroker.getJmsConnection(createVendorImpl()), producer);
    execute(standaloneConsumer, standaloneProducer, createMessage(), jms);
    assertMessages(jms, 1);
}
Also used : PtpConsumer(com.adaptris.core.jms.PtpConsumer) MimeEncoder(com.adaptris.core.MimeEncoder) 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 3 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class LargeFsMessageProducerTest method testProduce_WithUnsupportedEncoder.

@Test
public void testProduce_WithUnsupportedEncoder() throws Exception {
    LargeFsProducer producer = create();
    producer.setEncoder(new MimeEncoder());
    try {
        start(producer);
        AdaptrisMessage msg = new FileBackedMessageFactory().newMessage("dummy");
        producer.produce(msg);
        FileBackedMimeEncoder encoder = new FileBackedMimeEncoder();
        encoder.setRetainUniqueId(true);
        File writtenFile = new File(destDir, msg.getUniqueId());
        // Won't work.
        AdaptrisMessage result = encoder.readMessage(writtenFile);
        fail();
    } catch (Exception expected) {
    } finally {
        stop(producer);
    }
}
Also used : MimeEncoder(com.adaptris.core.MimeEncoder) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) File(java.io.File) Test(org.junit.Test)

Example 4 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class DefaultFailedMessageRetrierJmxTest method testMBean_Retry_File_WorkflowNotFound.

@Test
public void testMBean_Retry_File_WorkflowNotFound() throws Exception {
    Adapter adapter = createAdapter(getName());
    Channel c = createChannel(getName());
    StandardWorkflow wf = createWorkflow(getName());
    MockMessageProducer mock = new MockMessageProducer();
    wf.setProducer(mock);
    c.getWorkflowList().add(wf);
    adapter.getChannelList().add(c);
    DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
    adapter.setFailedMessageRetrier(retrier);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@BLAHBLAH");
    File fileToRetry = writeFile(msg, new MimeEncoder());
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        adapterManager.requestStart();
        ObjectName retrierObjName = createRetrierObjectName(adapterManager);
        DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
        assertFalse(jmxBean.retryMessage(fileToRetry));
        assertEquals(0, mock.messageCount());
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : DefaultFailedMessageRetrierJmxMBean(com.adaptris.core.DefaultFailedMessageRetrierJmxMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) File(java.io.File) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 5 with MimeEncoder

use of com.adaptris.core.MimeEncoder in project interlok by adaptris.

the class DefaultFailedMessageRetrierJmxTest method testMBean_Retry_File_NotFoundException.

@Test
public void testMBean_Retry_File_NotFoundException() throws Exception {
    Adapter adapter = createAdapter(getName());
    Channel c = createChannel(getName());
    StandardWorkflow wf = createWorkflow(getName());
    MockMessageProducer mock = new MockMessageProducer();
    wf.setProducer(mock);
    c.getWorkflowList().add(wf);
    adapter.getChannelList().add(c);
    DefaultFailedMessageRetrier retrier = new DefaultFailedMessageRetrier();
    adapter.setFailedMessageRetrier(retrier);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(Workflow.WORKFLOW_ID_KEY, getName() + "@BLAHBLAH");
    File fileToRetry = writeFile(msg, new MimeEncoder());
    fileToRetry.delete();
    AdapterManager adapterManager = new AdapterManager(adapter);
    try {
        adapterManager.registerMBean();
        adapterManager.requestStart();
        ObjectName retrierObjName = createRetrierObjectName(adapterManager);
        DefaultFailedMessageRetrierJmxMBean jmxBean = JMX.newMBeanProxy(mBeanServer, retrierObjName, DefaultFailedMessageRetrierJmxMBean.class);
        try {
            jmxBean.retryMessage(fileToRetry);
            fail();
        } catch (IOException expected) {
        }
    } finally {
        adapterManager.requestClose();
        adapterManager.unregisterMBean();
    }
}
Also used : DefaultFailedMessageRetrierJmxMBean(com.adaptris.core.DefaultFailedMessageRetrierJmxMBean) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) Channel(com.adaptris.core.Channel) Adapter(com.adaptris.core.Adapter) DefaultFailedMessageRetrier(com.adaptris.core.DefaultFailedMessageRetrier) IOException(java.io.IOException) File(java.io.File) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

MimeEncoder (com.adaptris.core.MimeEncoder)21 Test (org.junit.Test)18 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)13 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)7 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)7 StandaloneProducer (com.adaptris.core.StandaloneProducer)6 File (java.io.File)5 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)4 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)4 Adapter (com.adaptris.core.Adapter)3 Channel (com.adaptris.core.Channel)3 DefaultFailedMessageRetrier (com.adaptris.core.DefaultFailedMessageRetrier)3 DefaultFailedMessageRetrierJmxMBean (com.adaptris.core.DefaultFailedMessageRetrierJmxMBean)3 StandardWorkflow (com.adaptris.core.StandardWorkflow)3 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)3 ObjectName (javax.management.ObjectName)3 CoreException (com.adaptris.core.CoreException)2 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)2 TimeInterval (com.adaptris.util.TimeInterval)2 FileEntry (org.mockftpserver.fake.filesystem.FileEntry)2