use of com.adaptris.core.services.aggregator.ReplaceWithFirstMessage in project interlok by adaptris.
the class AggregatingFtpConsumeServiceTest method testInit.
@Test
public void testInit() throws Exception {
AggregatingFtpConsumeService service = new AggregatingFtpConsumeService();
try {
LifecycleHelper.prepare(service);
LifecycleHelper.init(service);
fail();
} catch (CoreException expected) {
}
service = new AggregatingFtpConsumeService();
service.setConnection(new FtpConnection());
try {
LifecycleHelper.prepare(service);
LifecycleHelper.init(service);
fail();
} catch (CoreException expected) {
}
service = new AggregatingFtpConsumeService();
service.setConsumer(new AggregatingFtpConsumer());
try {
LifecycleHelper.prepare(service);
LifecycleHelper.init(service);
fail();
} catch (CoreException expected) {
}
service = new AggregatingFtpConsumeService(new FtpConnection(), createConsumer("ftp://localhost/work", null, new ReplaceWithFirstMessage()));
LifecycleHelper.prepare(service);
LifecycleHelper.init(service);
LifecycleHelper.close(service);
}
use of com.adaptris.core.services.aggregator.ReplaceWithFirstMessage in project interlok by adaptris.
the class AggregatingFtpConsumeServiceTest method testService_SingleFile.
@Test
public void testService_SingleFile() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener();
FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
try {
// should be ftp://localhost/home/user/work/file0 which is created when you
// create the filesystem.
String ftpConsumeUrl = "ftp://localhost" + DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + 0;
FtpConnection conn = createConnection(server);
AggregatingFtpConsumer consumer = createConsumer(ftpConsumeUrl, null, new ReplaceWithFirstMessage());
AggregatingFtpConsumeService service = new AggregatingFtpConsumeService(conn, consumer);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
execute(service, msg);
assertEquals(PAYLOAD, msg.getContent());
} finally {
server.stop();
}
}
use of com.adaptris.core.services.aggregator.ReplaceWithFirstMessage in project interlok by adaptris.
the class AggregatingFtpConsumeServiceTest method testService_SingleFile_Failure.
@Test
public void testService_SingleFile_Failure() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener();
FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
try {
// should be ftp://localhost/home/user/work/file0 which is created when you
// create the filesystem.
String ftpConsumeUrl = "ftp://localhost" + DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + 0;
FtpConnection conn = createConnection(server);
AggregatingFtpConsumer consumer = createConsumer(ftpConsumeUrl, null, new ReplaceWithFirstMessage());
AggregatingFtpConsumeService service = new AggregatingFtpConsumeService(conn, consumer);
AdaptrisMessage msg = new DefectiveMessageFactory().newMessage();
try {
execute(service, msg);
fail();
} catch (ServiceException expected) {
}
} finally {
server.stop();
}
}
use of com.adaptris.core.services.aggregator.ReplaceWithFirstMessage in project interlok by adaptris.
the class AggregatingFtpConsumeServiceTest method testService_Single_NoDelete.
@Test
public void testService_Single_NoDelete() throws Exception {
int count = 1;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener();
FileSystem filesystem = helper.createFilesystem(count);
FakeFtpServer server = helper.createAndStart(filesystem);
try {
// should be ftp://localhost/home/user/work/file0 which is created when you
// create the filesystem.
String ftpConsumeUrl = "ftp://localhost" + DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + 0;
FtpConnection conn = createConnection(server);
conn.setAdditionalDebug(false);
AggregatingFtpConsumer consumer = createConsumer(ftpConsumeUrl, null, new ReplaceWithFirstMessage());
consumer.setDeleteAggregatedFiles(Boolean.FALSE);
AggregatingFtpConsumeService service = new AggregatingFtpConsumeService(conn, consumer);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
execute(service, msg);
assertEquals(PAYLOAD, msg.getContent());
// didn't get dleted so should still exist.
assertEquals(count, filesystem.listFiles(DEFAULT_WORK_DIR_CANONICAL).size());
} finally {
server.stop();
}
}
use of com.adaptris.core.services.aggregator.ReplaceWithFirstMessage 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);
}
}
Aggregations