Search in sources :

Example 76 with AdaptrisMessage

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

the class MetadataTokenWriterTest method testApply_NoAdditionalData.

@Test
public void testApply_NoAdditionalData() throws Exception {
    AccessToken token = new AccessToken("Bearer", "token");
    MetadataAccessTokenWriter writer = new MetadataAccessTokenWriter().withTokenKey("access_token").withTokenExpiryKey("expiry_token").withRefreshTokenKey("refresh_token");
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    try {
        LifecycleHelper.initAndStart(writer);
        writer.apply(token, msg);
        assertTrue(msg.headersContainsKey("access_token"));
        assertEquals("Bearer token", msg.getMetadataValue("access_token"));
        assertFalse(msg.headersContainsKey("expiry_token"));
        assertFalse(msg.headersContainsKey("refresh_token"));
    } finally {
        LifecycleHelper.stopAndClose(writer);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 77 with AdaptrisMessage

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

the class FtpRecursiveConsumerTest method testBasicConsume.

@Test
public void testBasicConsume() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener();
    FakeFtpServer server = helper.createAndStart(createFilesystem(helper, count));
    StandaloneConsumer sc = null;
    try {
        FtpRecursiveConsumer ftpConsumer = createForTests(listener);
        FtpConnection consumeConnection = create(server);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        // INTERLOK-3329 For coverage so the prepare() warning is executed 2x
        LifecycleHelper.prepare(sc);
        start(sc);
        // account for files in sub directories
        waitForMessages(listener, count + (count * subDirectories.length));
        List<AdaptrisMessage> messages = listener.getMessages();
        helper.assertMessages(messages, count + (count * subDirectories.length));
        for (AdaptrisMessage message : messages) {
            assertTrue(message.headersContainsKey(CoreConstants.FS_CONSUME_PARENT_DIR));
            String path = message.getMetadataValue(CoreConstants.FS_CONSUME_DIRECTORY);
            assertEquals(new File(path).getName(), message.getMetadataValue(CoreConstants.FS_CONSUME_PARENT_DIR));
        }
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) File(java.io.File) Test(org.junit.Test)

Example 78 with AdaptrisMessage

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

the class FtpRecursiveConsumerTest method testConsumeWithEncoder.

@Test
public void testConsumeWithEncoder() throws Exception {
    int count = 1;
    EmbeddedFtpServer helper = new EmbeddedFtpServer();
    MockMessageListener listener = new MockMessageListener(100);
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(PAYLOAD);
    byte[] bytes = new MimeEncoder().encode(msg);
    FileSystem filesystem = helper.createFilesystem_DirsOnly();
    for (int i = 0; i < count; i++) {
        FileEntry entry = new FileEntry(DEFAULT_WORK_DIR_CANONICAL + SLASH + DEFAULT_FILENAME + i + ".txt");
        entry.setContents(bytes);
        filesystem.add(entry);
    }
    FakeFtpServer server = helper.createAndStart(filesystem);
    StandaloneConsumer sc = null;
    try {
        FtpRecursiveConsumer ftpConsumer = createForTests(listener);
        ftpConsumer.setEncoder(new MimeEncoder());
        FtpConnection consumeConnection = create(server);
        sc = new StandaloneConsumer(consumeConnection, ftpConsumer);
        start(sc);
        waitForMessages(listener, count);
        helper.assertMessages(listener.getMessages(), count);
    } catch (Exception e) {
        throw e;
    } finally {
        stop(sc);
        server.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MimeEncoder(com.adaptris.core.MimeEncoder) MockMessageListener(com.adaptris.core.stubs.MockMessageListener) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) StandaloneConsumer(com.adaptris.core.StandaloneConsumer) Test(org.junit.Test)

Example 79 with AdaptrisMessage

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

the class StoredProcedureProducerTest method testMultipleExecutions.

@Test
public void testMultipleExecutions() throws Exception {
    if (areTestsEnabled()) {
        JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
        spp.setProcedureName(("one_in_one_out"));
        AdaptrisMessage message = createMessage(XML_PAYLOAD);
        AdaptrisMessage message2 = createMessage(XML_PAYLOAD);
        JdbcXPathParameter inParameter = new JdbcXPathParameter();
        inParameter.setXpath("/head/body/element1");
        inParameter.setName("xType");
        inParameter.setType(ParameterValueType.VARCHAR);
        InParameters inParameters = new InParameters();
        inParameters.add(inParameter);
        JdbcMetadataParameter outParameter = new JdbcMetadataParameter();
        outParameter.setMetadataKey("result");
        outParameter.setName("transferCount");
        outParameter.setType(ParameterValueType.INTEGER);
        OutParameters outParameters = new OutParameters();
        outParameters.add(outParameter);
        spp.setInParameters(inParameters);
        spp.setOutParameters(outParameters);
        StandaloneProducer producer = configureForTests(spp, true);
        try {
            // INTERLOK-3329 For coverage so the prepare() warning is executed 2x
            LifecycleHelper.prepare(producer);
            start(producer);
            assertEquals(0, message.getMetadata().size());
            producer.doService(message);
            assertEquals(1, message.getMetadata().size());
            assertEquals("15", message.getMetadataValue("result"));
            assertEquals(0, message2.getMetadata().size());
            producer.doService(message2);
            assertEquals(1, message2.getMetadata().size());
            assertEquals("15", message2.getMetadataValue("result"));
        } finally {
            stop(producer);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 80 with AdaptrisMessage

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

the class StoredProcedureProducerTest method testOneObjectMetadataParamIn.

@Test
public void testOneObjectMetadataParamIn() throws Exception {
    if (areTestsEnabled()) {
        JdbcStoredProcedureProducer spp = new JdbcStoredProcedureProducer();
        spp.setProcedureName(("one_in"));
        JdbcObjectMetadataParameter inParameter = new JdbcObjectMetadataParameter();
        inParameter.setMetadataKey("xType");
        inParameter.setName("xType");
        inParameter.setType(ParameterValueType.VARCHAR);
        AdaptrisMessage message = createMessage();
        message.addObjectHeader("xType", "Sold");
        InParameters inParameters = new InParameters();
        inParameters.add(inParameter);
        spp.setInParameters(inParameters);
        Map<Object, Object> objectMetadata = message.getObjectHeaders();
        assertEquals(1, objectMetadata.size());
        StandaloneProducer producer = configureForTests(spp, true);
        try {
            start(producer);
            producer.doService(message);
            objectMetadata = message.getObjectHeaders();
            assertEquals(1, objectMetadata.size());
        } finally {
            stop(producer);
        }
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1495 Test (org.junit.Test)1362 ServiceException (com.adaptris.core.ServiceException)171 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)158 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)156 StandaloneProducer (com.adaptris.core.StandaloneProducer)125 Channel (com.adaptris.core.Channel)122 MetadataElement (com.adaptris.core.MetadataElement)94 File (java.io.File)89 TimeInterval (com.adaptris.util.TimeInterval)77 CoreException (com.adaptris.core.CoreException)67 Session (javax.jms.Session)62 StandardWorkflow (com.adaptris.core.StandardWorkflow)57 GuidGenerator (com.adaptris.util.GuidGenerator)56 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)49 Message (javax.jms.Message)47 XPath (com.adaptris.util.text.xml.XPath)45 ServiceList (com.adaptris.core.ServiceList)43 Document (org.w3c.dom.Document)40