use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.
the class FsMessageProducerTest method testProduceFileAlreadyExists_AppendingFsWorker.
@Test
public void testProduceFileAlreadyExists_AppendingFsWorker() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
fs.setFsWorker(new AppendingFsWorker());
fs.setFilenameCreator(new MetadataFileNameCreator("targetFilename"));
FsWorker fsWorker = new StandardWorker();
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"));
fsWorker.put(TEXT.getBytes(), targetFile);
fs.produce(msg);
assertEquals(1, dir.listFiles().length);
assertEquals(AppendingFsWorker.class, fs.getFsWorker().getClass());
assertEquals(TEXT + TEXT, new String(fsWorker.get(targetFile)));
} 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_StandardWorker.
@Test
public void testProduceFileAlreadyExists_StandardWorker() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
fs.setFsWorker(new StandardWorker());
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 FsMessageProducerTest method testProduceWithMetadataFilenameCreator.
@Test
public void testProduceWithMetadataFilenameCreator() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(true);
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());
fs.produce(msg);
assertEquals(1, dir.listFiles().length);
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
use of com.adaptris.core.MetadataFileNameCreator in project interlok by adaptris.
the class RelaxedFtpCase method testConsumeWithFilter.
@Test
public void testConsumeWithFilter() throws Exception {
if (areTestsEnabled()) {
MockMessageListener listener = new MockMessageListener();
RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
ftpConsumer.setFtpEndpoint(getDestinationString());
ftpConsumer.setQuietInterval(DEFAULT_QUIET_PERIOD);
ftpConsumer.setFileFilterImp(GlobFilenameFilter.class.getCanonicalName());
ftpConsumer.registerAdaptrisMessageListener(listener);
ftpConsumer.setFilterExpression(".txt");
ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
start(sc);
int count = 1;
try {
RelaxedFtpProducer 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);
waitForMessages(listener, count);
assertMessages(listener.getMessages(), count);
} finally {
stop(sc);
}
}
}
Aggregations