Search in sources :

Example 51 with MockMessageListener

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

the class FsMessageConsumerTest method testConsumeIgnoresWip.

@Test
public void testConsumeIgnoresWip() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener();
    FsConsumer fs = createConsumer(subDir);
    fs.setResetWipFiles(false);
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        baseDir.mkdirs();
        createFiles(baseDir, ".xml", count);
        createFiles(baseDir, ".xml.wip", count);
        start(sc);
        waitForMessages(stub, count);
        Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.wip");
        assertEquals(count, baseDir.listFiles((FilenameFilter) wip).length);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) LargeFsConsumer(com.adaptris.core.lms.LargeFsConsumer) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

Example 52 with MockMessageListener

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

the class FtpCase method testConsume_WithEncoder.

@Test
public void testConsume_WithEncoder() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    MockMessageListener listener = new MockMessageListener();
    FtpConsumer ftpConsumer = new FtpConsumer();
    ftpConsumer.setFtpEndpoint(getDestinationString());
    ftpConsumer.registerAdaptrisMessageListener(listener);
    ftpConsumer.setQuietInterval(new TimeInterval(300l, TimeUnit.MILLISECONDS));
    ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
    ftpConsumer.setEncoder(new MimeEncoder());
    FileTransferConnection consumeConnection = createConnection();
    consumeConnection.setCacheConnection(true);
    StandaloneConsumer sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
    start(sc);
    int count = 10;
    try {
        FileTransferConnection produceConnection = createConnection();
        produceConnection.setCacheConnection(true);
        FtpProducer producer = createFtpProducer();
        producer.setEncoder(new MimeEncoder());
        produce(new StandaloneProducer(produceConnection, producer), count);
        waitForMessages(listener, count);
        assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        stop(sc);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) QuartzCronPoller(com.adaptris.core.QuartzCronPoller) MimeEncoder(com.adaptris.core.MimeEncoder) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 53 with MockMessageListener

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

the class FtpCase method testConsume_CachedConnection.

@Test
public void testConsume_CachedConnection() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    MockMessageListener listener = new MockMessageListener();
    FtpConsumer ftpConsumer = new FtpConsumer();
    ftpConsumer.setFtpEndpoint(getDestinationString());
    ftpConsumer.registerAdaptrisMessageListener(listener);
    ftpConsumer.setQuietInterval(new TimeInterval(300l, TimeUnit.MILLISECONDS));
    ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
    FileTransferConnection consumeConnection = createConnection();
    consumeConnection.setCacheConnection(true);
    StandaloneConsumer sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
    start(sc);
    int count = 10;
    try {
        FileTransferConnection produceConnection = createConnection();
        produceConnection.setCacheConnection(true);
        produce(new StandaloneProducer(produceConnection, createFtpProducer()), count);
        waitForMessages(listener, count);
        assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw e;
    } finally {
        stop(sc);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) QuartzCronPoller(com.adaptris.core.QuartzCronPoller) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 54 with MockMessageListener

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

the class FtpCase method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    MockMessageListener listener = new MockMessageListener();
    FtpConsumer ftpConsumer = new FtpConsumer();
    ftpConsumer.setFtpEndpoint(getDestinationString());
    ftpConsumer.setWorkDirectory(DEFAULT_WORK_DIR);
    ftpConsumer.setFileFilterImp(GlobFilenameFilter.class.getCanonicalName());
    ftpConsumer.setFilterExpression(".txt");
    ftpConsumer.registerAdaptrisMessageListener(listener);
    ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
    StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
    start(sc);
    int count = 1;
    try {
        FtpProducer ftpProducer = createFtpProducer();
        MetadataFileNameCreator mfc = new MetadataFileNameCreator();
        mfc.setDefaultName(new GuidGenerator().getUUID() + ".txt");
        mfc.setMetadataKey(new GuidGenerator().getUUID());
        ftpProducer.setFilenameCreator(mfc);
        produce(new StandaloneProducer(createConnection(), ftpProducer), count);
        Awaitility.await().atMost(Duration.ofSeconds(5)).with().pollInterval(Duration.ofMillis(100)).until(() -> listener.getMessages().size() >= count);
        assertMessages(listener.getMessages(), count);
    } finally {
        stop(sc);
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) GlobFilenameFilter(org.apache.oro.io.GlobFilenameFilter) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) MetadataFileNameCreator(com.adaptris.core.MetadataFileNameCreator) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 55 with MockMessageListener

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

the class NonDeletingFsConsumerTest method testConsumeWithFilter.

@Test
public void testConsumeWithFilter() throws Exception {
    String subDir = new GuidGenerator().safeUUID();
    MockMessageListener stub = new MockMessageListener(10);
    NonDeletingFsConsumer fs = createConsumer(subDir, "testConsumeWithFilter");
    fs.setFilterExpression(".*\\.xml");
    fs.setFileFilterImp(Perl5FilenameFilter.class.getName());
    fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
    StandaloneConsumer sc = new StandaloneConsumer(fs);
    sc.registerAdaptrisMessageListener(stub);
    int count = 10;
    File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
    try {
        File baseDir = new File(parentDir, subDir);
        LifecycleHelper.init(sc);
        createFiles(baseDir, ".xml", count);
        createFiles(baseDir, ".tmp", count);
        LifecycleHelper.start(sc);
        waitForMessages(stub, count);
        Perl5FilenameFilter wip = new Perl5FilenameFilter(".*\\.tmp");
        assertEquals("TMP Files remain", count, baseDir.listFiles((FilenameFilter) wip).length);
        assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
    } finally {
        stop(sc);
        FileUtils.deleteQuietly(new File(parentDir, subDir));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) Perl5FilenameFilter(org.apache.oro.io.Perl5FilenameFilter) TimeInterval(com.adaptris.util.TimeInterval) GuidGenerator(com.adaptris.util.GuidGenerator) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) 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