Search in sources :

Example 66 with StandaloneConsumer

use of com.adaptris.core.StandaloneConsumer in project interlok by adaptris.

the class SftpConsumerTest method createConsumerExamples.

private List createConsumerExamples(FileTransferConnection conn, Poller... pollers) {
    List<StandaloneConsumer> result = new ArrayList();
    try {
        for (Poller p : pollers) {
            FtpConsumer ftp = new FtpConsumer();
            ftp.setProcDirectory("/proc");
            ftp.setFtpEndpoint("sftp://overrideuser@hostname:port/path/to/directory");
            ftp.setFilterExpression("*.xml");
            ftp.setPoller(p);
            result.add(new StandaloneConsumer(conn, ftp));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Poller(com.adaptris.core.Poller)

Example 67 with StandaloneConsumer

use of com.adaptris.core.StandaloneConsumer 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 68 with StandaloneConsumer

use of com.adaptris.core.StandaloneConsumer 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 69 with StandaloneConsumer

use of com.adaptris.core.StandaloneConsumer 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 70 with StandaloneConsumer

use of com.adaptris.core.StandaloneConsumer 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

StandaloneConsumer (com.adaptris.core.StandaloneConsumer)188 Test (org.junit.Test)164 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)160 StandaloneProducer (com.adaptris.core.StandaloneProducer)91 TimeInterval (com.adaptris.util.TimeInterval)49 FixedIntervalPoller (com.adaptris.core.FixedIntervalPoller)37 File (java.io.File)31 GuidGenerator (com.adaptris.util.GuidGenerator)30 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)30 PtpConsumer (com.adaptris.core.jms.PtpConsumer)24 FilenameFilter (java.io.FilenameFilter)24 RandomAccessFile (java.io.RandomAccessFile)24 Perl5FilenameFilter (org.apache.oro.io.Perl5FilenameFilter)24 PtpProducer (com.adaptris.core.jms.PtpProducer)23 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)22 QuartzCronPoller (com.adaptris.core.QuartzCronPoller)17 CoreException (com.adaptris.core.CoreException)16 PasProducer (com.adaptris.core.jms.PasProducer)15 LargeFsConsumer (com.adaptris.core.lms.LargeFsConsumer)15 PasConsumer (com.adaptris.core.jms.PasConsumer)14