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));
}
}
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);
}
}
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);
}
}
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);
}
}
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));
}
}
Aggregations