Search in sources :

Example 66 with MockMessageListener

use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.

the class FtpConsumerTest method testConsumeWithQuietPeriod.

@Test
public void testConsumeWithQuietPeriod() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener();
    FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
    StandaloneConsumer sc = null;
    try {
        FtpConsumer ftpConsumer = createForTests(listener);
        ftpConsumer.setQuietInterval(new TimeInterval(1L, TimeUnit.SECONDS));
        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) TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 67 with MockMessageListener

use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.

the class FtpConsumerTest method testConsume_ForceRelativePath.

@Test
public void testConsume_ForceRelativePath() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
    StandaloneConsumer sc = null;
    try {
        FtpConsumer ftpConsumer = createForTests(listener);
        ftpConsumer.setWorkDirectory(SLASH + DEFAULT_WORK_DIR_NAME);
        FtpConnection consumeConnection = create(server);
        consumeConnection.setForceRelativePath(Boolean.TRUE);
        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) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 68 with MockMessageListener

use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.

the class FtpConsumerTest method testActiveModeConsume.

@Test
public void testActiveModeConsume() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
    StandaloneConsumer sc = null;
    try {
        FtpConsumer ftpConsumer = createForTests(listener);
        FtpConnection consumeConnection = create(server);
        consumeConnection.setFtpDataMode(FtpDataMode.ACTIVE);
        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) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 69 with MockMessageListener

use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.

the class FtpConsumerTest method testConsumeWithOverride.

@Test
public void testConsumeWithOverride() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener();
    FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
    StandaloneConsumer sc = null;
    try {
        FtpConsumer ftpConsumer = createForTests(listener, DESTINATION_URL_OVERRIDE);
        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) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 70 with MockMessageListener

use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.

the class FtpConsumerTest method testConsume_IgnoresWipFiles.

@Test
public void testConsume_IgnoresWipFiles() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    FtpConsumer ftpConsumer = createForTests(listener);
    FileSystem filesystem = helper.createFilesystem_DirsOnly();
    for (int i = 0; i < count; i++) {
        filesystem.add(new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + i + ".txt", PAYLOAD));
    }
    // Now create some files that have a _wip extension.
    filesystem.add(new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + "shouldBeIgnored.txt" + ftpConsumer.wipSuffix(), PAYLOAD));
    FakeFtpServer server = helper.createAndStart(filesystem);
    StandaloneConsumer sc = null;
    try {
        FtpConnection consumeConnection = create(server);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        waitForMessages(listener, count);
        helper.assertMessages(listener.getMessages(), count);
        // allow the consumer to consume the single message, should be 1 file left - the .wip file.
        Thread.sleep(2000);
        assertTrue(filesystem.listFiles(DEFAULT_WORK_DIR_CANONICAL).size() > 0);
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) 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