Search in sources :

Example 1 with StandaloneConsumer

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

the class FtpRecursiveConsumerTest method testBasicConsume_WithFileBackedMessage.

@Test
public void testBasicConsume_WithFileBackedMessage() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener();
    FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
    StandaloneConsumer sc = null;
    try {
        FtpRecursiveConsumer ftpConsumer = createForTests(listener);
        ftpConsumer.setMessageFactory(new FileBackedMessageFactory());
        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 : FileBackedMessageFactory(com.adaptris.core.lms.FileBackedMessageFactory) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 2 with StandaloneConsumer

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

the class FtpRecursiveConsumerTest method testActiveModeConsume.

@Test
public void testActiveModeConsume() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    FakeFtpServer server = helper.createAndStart(createFilesystem(helper, count));
    StandaloneConsumer sc = null;
    try {
        FtpRecursiveConsumer ftpConsumer = createForTests(listener);
        FtpConnection consumeConnection = create(server);
        consumeConnection.setFtpDataMode(FtpDataMode.ACTIVE);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        waitForMessages(listener, count + (count * subDirectories.length));
        helper.assertMessages(listener.getMessages(), count + (count * subDirectories.length));
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 3 with StandaloneConsumer

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

the class FtpRecursiveConsumerTest method testBasicConsume.

@Test
public void testBasicConsume() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener();
    FakeFtpServer server = helper.createAndStart(createFilesystem(helper, count));
    StandaloneConsumer sc = null;
    try {
        FtpRecursiveConsumer ftpConsumer = createForTests(listener);
        FtpConnection consumeConnection = create(server);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        // INTERLOK-3329 For coverage so the prepare() warning is executed 2x
        LifecycleHelper.prepare(sc);
        start(sc);
        // account for files in sub directories
        waitForMessages(listener, count + (count * subDirectories.length));
        List<AdaptrisMessage> messages = listener.getMessages();
        helper.assertMessages(messages, count + (count * subDirectories.length));
        for (AdaptrisMessage message : messages) {
            assertTrue(message.headersContainsKey(CoreConstants.FS_CONSUME_PARENT_DIR));
            String path = message.getMetadataValue(CoreConstants.FS_CONSUME_DIRECTORY);
            assertEquals(new File(path).getName(), message.getMetadataValue(CoreConstants.FS_CONSUME_PARENT_DIR));
        }
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) File(java.io.File) Test(org.junit.Test)

Example 4 with StandaloneConsumer

use of com.adaptris.core.StandaloneConsumer 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 5 with StandaloneConsumer

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

the class FtpRecursiveConsumerTest method testPassiveModeConsume.

@Test
public void testPassiveModeConsume() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    FakeFtpServer server = helper.createAndStart(createFilesystem(helper, count));
    StandaloneConsumer sc = null;
    try {
        FtpRecursiveConsumer ftpConsumer = createForTests(listener);
        FtpConnection consumeConnection = create(server);
        consumeConnection.setFtpDataMode(FtpDataMode.PASSIVE);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        waitForMessages(listener, count + (count * subDirectories.length));
        helper.assertMessages(listener.getMessages(), count + (count * subDirectories.length));
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Aggregations

StandaloneConsumer (com.adaptris.core.StandaloneConsumer)188 Test (org.junit.Test)164 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)160 StandaloneProducer (com.adaptris.core.StandaloneProducer)91 TimeInterval (com.adaptris.util.TimeInterval)49 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)37 File (java.io.File)31 GuidGenerator (com.adaptris.util.GuidGenerator)30 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)30 PtpConsumer (com.adaptris.core.jms.PtpConsumer)24 FilenameFilter (java.io.FilenameFilter)24 RandomAccessFile (java.io.RandomAccessFile)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 PtpProducer (com.adaptris.core.jms.PtpProducer)23 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)22 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)17 CoreException (com.adaptris.core.CoreException)16 PasProducer (com.adaptris.core.jms.PasProducer)15 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 PasConsumer (com.adaptris.core.jms.PasConsumer)14