Search in sources :

Example 61 with MockMessageListener

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);
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) Test(org.junit.Test)

Example 62 with MockMessageListener

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);
        }
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 63 with MockMessageListener

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);
        }
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) GlobFilenameFilter(org.apache.oro.io.GlobFilenameFilter) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 64 with MockMessageListener

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);
        }
    }
}
Also used : QuartzCronPoller(com.adaptris.core.QuartzCronPoller) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 65 with MockMessageListener

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);
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) GregorianCalendar(java.util.GregorianCalendar) FixedIntervalPoller(com.adaptris.core.FixedIntervalPoller) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Before(org.junit.Before)

Aggregations

MockMessageListener (com.adaptris.core.stubs.MockMessageListener)173 Test (org.junit.Test)171 StandaloneConsumer (com.adaptris.core.StandaloneConsumer)160 StandaloneProducer (com.adaptris.core.StandaloneProducer)91 TimeInterval (com.adaptris.util.TimeInterval)42 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)36 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)32 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)28 File (java.io.File)28 GuidGenerator (com.adaptris.util.GuidGenerator)27 FilenameFilter (java.io.FilenameFilter)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 PtpProducer (com.adaptris.core.jms.PtpProducer)23 PtpConsumer (com.adaptris.core.jms.PtpConsumer)22 RandomAccessFile (java.io.RandomAccessFile)21 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)16 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)16 PasProducer (com.adaptris.core.jms.PasProducer)15 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 CoreException (com.adaptris.core.CoreException)14