use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class MessageTypeTranslatorCase method start.
public static void start(MessageTypeTranslatorImp trans, Session session) throws Exception {
trans.registerSession(session);
trans.registerMessageFactory(new DefaultMessageFactory());
LifecycleHelper.init(trans);
LifecycleHelper.start(trans);
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class FsMessageProducerTest method testProduceWithTempDir.
@Test
public void testProduceWithTempDir() throws Exception {
String subdir = new GuidGenerator().safeUUID();
String tmpDir = new GuidGenerator().safeUUID();
String tempDir = PROPERTIES.getProperty(BASE_TEMP_DIR) + "/" + tmpDir;
FsProducer producer = createProducer(subdir);
File parentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_KEY), true));
File tmpParentDir = FsHelper.createFileReference(FsHelper.createUrlFromString(PROPERTIES.getProperty(BASE_TEMP_DIR), true));
try {
producer.setTempDirectory(tempDir);
StandaloneProducer sp = new StandaloneProducer(producer);
ServiceCase.execute(sp, new DefaultMessageFactory().newMessage(TEXT));
File f = new File(tmpParentDir, tmpDir);
assertTrue(f.exists());
assertTrue(f.isDirectory());
assertEquals(1, new File(parentDir, subdir).listFiles().length);
assertEquals(0, new File(tmpParentDir, tmpDir).listFiles().length);
} finally {
FileUtils.deleteQuietly(new File(parentDir, subdir));
FileUtils.deleteQuietly(new File(tmpParentDir, tmpDir));
}
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class AggregatingFsConsumeServiceTest method testService.
@Test
public void testService() throws Exception {
Object o = new Object();
File tempFile = TempFileUtils.createTrackedFile(o);
String url = "file://localhost/" + tempFile.getCanonicalPath().replaceAll("\\\\", "/");
AggregatingFsConsumer afc = createConsumer(url, null, new ReplaceWithFirstMessage());
AggregatingFsConsumeService service = createAggregatingService(afc);
File wipFile = new File(tempFile.getParent(), tempFile.getName() + afc.wipSuffix());
try {
writeDataMessage(tempFile);
start(service);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(INITIAL_PAYLOAD);
service.doService(msg);
assertNotSame(INITIAL_PAYLOAD, msg.getContent());
assertEquals(DATA_PAYLOAD, msg.getContent());
assertFalse(tempFile.exists());
assertFalse(wipFile.exists());
} finally {
stop(service);
}
}
use of com.adaptris.core.DefaultMessageFactory in project interlok by adaptris.
the class AggregatingFsConsumeServiceTest method testServiceNonDeleting.
@Test
public void testServiceNonDeleting() throws Exception {
Object o = new Object();
File tempFile = TempFileUtils.createTrackedFile(o);
String url = "file://localhost/" + tempFile.getCanonicalPath().replaceAll("\\\\", "/");
AggregatingFsConsumer afc = createConsumer(url, null, new ReplaceWithFirstMessage());
afc.setDeleteAggregatedFiles(false);
AggregatingFsConsumeService service = createAggregatingService(afc);
File wipFile = new File(tempFile.getParent(), tempFile.getName() + afc.wipSuffix());
try {
writeDataMessage(tempFile);
start(service);
AdaptrisMessage msg = new DefaultMessageFactory().newMessage(INITIAL_PAYLOAD);
service.doService(msg);
assertNotSame(INITIAL_PAYLOAD, msg.getContent());
assertEquals(DATA_PAYLOAD, msg.getContent());
assertTrue(tempFile.exists());
assertFalse(wipFile.exists());
} finally {
stop(service);
}
}
use of com.adaptris.core.DefaultMessageFactory 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