use of com.adaptris.fs.AppendingFsWorker 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);
}
}
Aggregations