Search in sources :

Example 1 with ReplaceWithFirstMessage

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);
}
Also used : CoreException(com.adaptris.core.CoreException) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Example 2 with ReplaceWithFirstMessage

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();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Example 3 with ReplaceWithFirstMessage

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();
    }
}
Also used : DefectiveMessageFactory(com.adaptris.core.stubs.DefectiveMessageFactory) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Example 4 with ReplaceWithFirstMessage

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();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Example 5 with ReplaceWithFirstMessage

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);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) File(java.io.File) ReplaceWithFirstMessage(com.adaptris.core.services.aggregator.ReplaceWithFirstMessage) Test(org.junit.Test)

Aggregations

ReplaceWithFirstMessage (com.adaptris.core.services.aggregator.ReplaceWithFirstMessage)8 Test (org.junit.Test)6 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)5 MockMessageListener (com.adaptris.core.stubs.MockMessageListener)3 FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)3 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)2 File (java.io.File)2 CoreException (com.adaptris.core.CoreException)1 ServiceException (com.adaptris.core.ServiceException)1 BasicActiveMqImplementation (com.adaptris.core.jms.activemq.BasicActiveMqImplementation)1 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)1 TimeInterval (com.adaptris.util.TimeInterval)1 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)1