use of com.adaptris.core.MetadataFileNameCreator 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.MetadataFileNameCreator in project interlok by adaptris.
the class FsMessageProducerTest method testProduceFileAlreadyExists_OverwriteIfExists.
@Test
public void testProduceFileAlreadyExists_OverwriteIfExists() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
fs.setFsWorker(new OverwriteIfExistsWorker());
fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File dir = new File(parentDir, subdir);
start(fs);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata("targetFilename", new GuidGenerator().safeUUID());
dir.mkdirs();
File targetFile = new File(dir, msg.getMetadataValue("targetFilename"));
targetFile.createNewFile();
fs.produce(msg);
assertEquals(1, dir.listFiles().length);
assertEquals(OverwriteIfExistsWorker.class, fs.getFsWorker().getClass());
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.
the class FsMessageProducerTest method testProduceFileAlreadyExists_NioWorker.
@Test
public void testProduceFileAlreadyExists_NioWorker() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
fs.setFsWorker(new NioWorker());
fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
File dir = new File(parentDir, subdir);
start(fs);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
msg.addMetadata("targetFilename", new GuidGenerator().safeUUID());
dir.mkdirs();
File targetFile = new File(dir, msg.getMetadataValue("targetFilename"));
targetFile.createNewFile();
fs.produce(msg);
fail();
} catch (ProduceException expected) {
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.
the class FtpProducerTest method testSetFilenameCreator.
@Test
public void testSetFilenameCreator() throws Exception {
FtpProducer ftpProducer = new FtpProducer();
assertEquals(FormattedFilenameCreator.class, ftpProducer.filenameCreatorToUse().getClass());
ftpProducer.setFilenameCreator(new MetadataFileNameCreator());
assertEquals(MetadataFileNameCreator.class, ftpProducer.getFilenameCreator().getClass());
assertEquals(MetadataFileNameCreator.class, ftpProducer.filenameCreatorToUse().getClass());
}
use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.
the class RelaxedFtpProducerTest method testSetFilenameCreator.
@Test
public void testSetFilenameCreator() throws Exception {
RelaxedFtpProducer ftpProducer = new RelaxedFtpProducer();
assertEquals(FormattedFilenameCreator.class, ftpProducer.filenameCreator().getClass());
ftpProducer.setFilenameCreator(new MetadataFileNameCreator());
assertEquals(MetadataFileNameCreator.class, ftpProducer.getFilenameCreator().getClass());
assertEquals(MetadataFileNameCreator.class, ftpProducer.filenameCreator().getClass());
}
Aggregations