use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class StandaloneConsumerTest method testPollingConsumerContinueProcessing.
@Test
public void testPollingConsumerContinueProcessing() throws Exception {
AdaptrisPollingConsumer consumer = new AdaptrisPollingConsumer() {
@Override
public void prepareConsumer() throws CoreException {
}
@Override
protected int processMessages() {
return 0;
}
@Override
protected String newThreadName() {
return "testPollingConsumerContinueProcessing";
}
};
consumer.setPoller(new FixedIntervalPoller(new TimeInterval(1L, TimeUnit.DAYS)));
consumer.setMaxMessagesPerPoll(10);
consumer.setReacquireLockBetweenMessages(false);
StandaloneConsumer sc = new StandaloneConsumer(consumer);
sc.registerAdaptrisMessageListener(new MockMessageListener());
// Not started, so should always return false.
assertFalse(consumer.continueProcessingMessages(1));
LifecycleHelper.initAndStart(sc);
assertTrue(consumer.continueProcessingMessages(5));
assertFalse(consumer.continueProcessingMessages(11));
assertFalse(consumer.continueProcessingMessages(10));
LifecycleHelper.stopAndClose(sc);
consumer.setReacquireLockBetweenMessages(true);
assertFalse(consumer.continueProcessingMessages(1));
LifecycleHelper.initAndStart(sc);
assertTrue(consumer.continueProcessingMessages(5));
assertFalse(consumer.continueProcessingMessages(11));
assertFalse(consumer.continueProcessingMessages(10));
LifecycleHelper.stopAndClose(sc);
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class RelaxedFtpCase method testConsume_EncryptedPassword.
@Test
public void testConsume_EncryptedPassword() throws Exception {
if (areTestsEnabled()) {
MockMessageListener listener = new MockMessageListener();
RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
ftpConsumer.setFtpEndpoint(getDestinationString());
ftpConsumer.setQuietInterval(DEFAULT_QUIET_PERIOD);
ftpConsumer.registerAdaptrisMessageListener(listener);
ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
start(sc);
int count = 1;
try {
FileTransferConnectionUsingPassword conn = createConnection();
String pw = conn.getDefaultPassword();
String decodedPw = Password.decode(pw);
if (pw.equals(decodedPw)) {
// The password was never encrypted!
conn.setDefaultPassword(Password.encode(conn.getDefaultPassword(), Password.PORTABLE_PASSWORD));
}
produce(new StandaloneProducer(conn, createFtpProducer()), count);
waitForMessages(listener, count);
assertMessages(listener.getMessages(), count);
} finally {
stop(sc);
}
}
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class RelaxedFtpCase method testConsumeWithNonMatchingFilter.
@Test
public void testConsumeWithNonMatchingFilter() throws Exception {
if (areTestsEnabled()) {
MockMessageListener listener = new MockMessageListener();
RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
ftpConsumer.setFtpEndpoint(getDestinationString());
ftpConsumer.setQuietInterval(DEFAULT_QUIET_PERIOD);
ftpConsumer.setFileFilterImp(GlobFilenameFilter.class.getCanonicalName());
ftpConsumer.registerAdaptrisMessageListener(listener);
ftpConsumer.setFilterExpression(".xml");
ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?"));
StandaloneConsumer sc = new StandaloneConsumer(createConnection(), ftpConsumer);
start(sc);
int count = 1;
try {
produce(new StandaloneProducer(createConnection(), createFtpProducer()), count);
try {
Thread.sleep(1500);
} catch (Exception e) {
;
}
assertMessages(listener.getMessages(), 0);
} finally {
stop(sc);
}
}
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class RelaxedFtpCase method testConsume_OverrideUrl.
@Test
public void testConsume_OverrideUrl() throws Exception {
if (areTestsEnabled()) {
MockMessageListener listener = new MockMessageListener();
RelaxedFtpConsumer ftpConsumer = new RelaxedFtpConsumer();
ftpConsumer.setFtpEndpoint(getDestinationStringWithOverride());
ftpConsumer.setQuietInterval(DEFAULT_QUIET_PERIOD);
ftpConsumer.registerAdaptrisMessageListener(listener);
// Pass in a QuartzId so we don't print out the uname+password.
ftpConsumer.setPoller(new QuartzCronPoller("*/1 * * * * ?", "testBasicConsumeWithOverride"));
FileTransferConnectionUsingPassword con = createConnection();
con.setDefaultPassword(null);
con.setDefaultUserName(null);
StandaloneConsumer sc = new StandaloneConsumer(con, ftpConsumer);
start(sc);
int count = 1;
try {
produce(new StandaloneProducer(createConnection(), createFtpProducer()), count);
waitForMessages(listener, count);
assertMessages(listener.getMessages(), count);
} finally {
stop(sc);
}
}
}
use of com.adaptris.core.stubs.MockMessageListener in project interlok by adaptris.
the class RelaxedFtpConsumerTest method setUp.
@Before
public void setUp() throws Exception {
consumer = new RelaxedFtpConsumer();
MockitoAnnotations.initMocks(this);
consumeDestination = "myDestination";
consumer.setFtpEndpoint(consumeDestination);
consumer.registerConnection(mockFtpConnection);
consumer.setPoller(new FixedIntervalPoller(new TimeInterval(1L, TimeUnit.SECONDS)));
consumer.setReacquireLockBetweenMessages(true);
messageListener = new MockMessageListener(10);
standaloneConsumer = new StandaloneConsumer(consumer);
standaloneConsumer.registerAdaptrisMessageListener(messageListener);
standaloneConsumer.setConnection(mockFtpConnection);
when(mockFtpConnection.retrieveConnection(FileTransferConnection.class)).thenReturn(mockFtpConnection);
when(mockFtpConnection.connect(consumeDestination)).thenReturn(mockFileTransferClient);
when(mockFtpConnection.getDirectoryRoot(consumeDestination)).thenReturn(DIR_ROOT);
calendarNow = new GregorianCalendar();
calendarOneYearAgo = new GregorianCalendar();
calendarOneYearAgo.add(Calendar.DAY_OF_YEAR, -1);
}
Aggregations