use of com.adaptris.util.GuidGenerator 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.util.GuidGenerator in project interlok by adaptris.
the class FsMessageProducerTest method testProduceWithNoCreateDir.
@Test
public void testProduceWithNoCreateDir() throws Exception {
String subdir = new GuidGenerator().safeUUID();
FsProducer fs = createProducer(subdir);
fs.setCreateDirs(false);
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
try {
start(fs);
fs.produce(new DefaultMessageFactory().newMessage(TEXT));
fail();
} catch (ProduceException expected) {
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
stop(fs);
}
}
use of com.adaptris.util.GuidGenerator 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.util.GuidGenerator in project interlok by adaptris.
the class MovingDeletingFsConsumerTest method testConsume.
@Test
public void testConsume() throws Exception {
final File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
final String subDir = new GuidGenerator().safeUUID();
final File baseDir = new File(parentDir, subDir);
final File procDir = new File(parentDir, "proc");
final MockMessageListener stub = new MockMessageListener(10);
final MovingNonDeletingFsConsumer fs = createConsumer(subDir, "testConsume");
fs.setPoller(new FixedIntervalPoller(new TimeInterval(300L, TimeUnit.MILLISECONDS)));
fs.setProcessedPath(procDir.getAbsolutePath());
final StandaloneConsumer sc = new StandaloneConsumer(fs);
sc.registerAdaptrisMessageListener(stub);
final int count = 10;
List<File> files = null;
try {
LifecycleHelper.init(sc);
files = createFiles(baseDir, ".xml", count);
LifecycleHelper.start(sc);
waitForMessages(stub, count);
assertMessages(stub.getMessages(), count, baseDir.listFiles((FilenameFilter) new Perl5FilenameFilter(".*\\.xml")));
} catch (final Exception e) {
log.warn(e.getMessage(), e);
fail();
} finally {
stop(sc);
if (files != null) {
for (final File f : files) {
boolean found = false;
for (final String n : procDir.list()) {
if (f.getName().equals(n)) {
found = true;
}
}
if (!found) {
fail("Couldn't find file " + f.getName() + " in processed directory");
}
}
}
FileUtils.deleteQuietly(baseDir);
FileUtils.deleteQuietly(procDir);
}
}
use of com.adaptris.util.GuidGenerator in project interlok by adaptris.
the class MultiPayloadMessageSplitterTest method testNonCloneableMessage.
@Test
@SuppressWarnings("serial")
public void testNonCloneableMessage() {
List<AdaptrisMessage> response = (List<AdaptrisMessage>) splitter.splitMessage(new MultiPayloadAdaptrisMessageImp("bacon", new GuidGenerator(), DefaultMessageFactory.getDefaultInstance(), PAYLOAD_1.getBytes()) {
@Override
public MessageLifecycleEvent getMessageLifecycleEvent() {
return new MessageLifecycleEvent() {
@Override
public List<MleMarker> getMleMarkers() {
List<MleMarker> list = new ArrayList<>();
list.add(new MleMarker() {
@Override
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException();
}
});
return list;
}
};
}
});
assertEquals(0, response.size());
}
Aggregations