use of com.adaptris.fs.OverwriteIfExistsWorker in project interlok by adaptris.
the class FsMessageProducerTest method testSetFsWorker.
@Test
public void testSetFsWorker() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer producer = createProducer(subdir);
assertEquals(NioWorker.class, producer.getFsWorker().getClass());
OverwriteIfExistsWorker worker = new OverwriteIfExistsWorker();
producer.setFsWorker(worker);
assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
assertEquals(worker, producer.getFsWorker());
try {
producer.setFsWorker(null);
fail();
} catch (IllegalArgumentException | NullPointerException expected) {
}
assertEquals(OverwriteIfExistsWorker.class, producer.getFsWorker().getClass());
assertEquals(worker, producer.getFsWorker());
}
use of com.adaptris.fs.OverwriteIfExistsWorker 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);
}
}
Aggregations