use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class JmxNotificationConsumerTest method testConsumer.
@Test
public void testConsumer() throws Exception {
MBeanServer mbeanServer = JmxHelper.findMBeanServer();
String myObjectName = "com.adaptris:type=Junit,id=" + getName();
StubNotificationBroadcaster broadcast = new StubNotificationBroadcaster();
MockMessageListener listener = new MockMessageListener();
JmxNotificationConsumer consumer = new JmxNotificationConsumer();
consumer.setObjectName(myObjectName);
StandaloneConsumer sc = wrap(new JmxConnection(), consumer, listener);
try {
mbeanServer.registerMBean(broadcast, ObjectName.getInstance(myObjectName));
// INTERLOK-3329 For coverage so the prepare() warning is executed 2x
LifecycleHelper.prepare(sc);
start(sc);
broadcast.sendNotification(getName(), new Object());
waitForMessages(listener, 1);
assertEquals(1, listener.messageCount());
assertNotNull(listener.getMessages().get(0).getObjectHeaders().get(NotificationSerializer.OBJ_METADATA_USERDATA));
} finally {
stop(sc);
}
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class AggregatingFtpConsumeServiceTest method testService_MultipleFiles.
@Test
public void testService_MultipleFiles() throws Exception {
int count = 5;
EmbeddedFtpServer helper = new EmbeddedFtpServer();
MockMessageListener listener = new MockMessageListener();
FakeFtpServer server = helper.createAndStart(helper.createFilesystem(count));
try {
// should be ftp://localhost/home/user/work/ which is created when you
// create the filesystem.
String ftpConsumeUrl = "ftp://localhost" + DEFAULT_WORK_DIR_CANONICAL;
FtpConnection conn = createConnection(server);
AggregatingFtpConsumer consumer = createConsumer(ftpConsumeUrl, ".*", new IgnoreOriginalMimeAggregator());
AggregatingFtpConsumeService service = new AggregatingFtpConsumeService(conn, consumer);
AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
execute(service, msg);
BodyPartIterator input = MimeHelper.createBodyPartIterator(msg);
assertEquals(count, input.size());
} finally {
server.stop();
}
}
use of com.adaptris.core.stubs.MockMessageListener 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.stubs.MockMessageListener 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.stubs.MockMessageListener 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();
}
}
Aggregations