Search in sources :

Example 1 with MessageTypeTranslatorImp

use of com.adaptris.core.jms.MessageTypeTranslatorImp in project interlok by adaptris.

the class BlobMessageTranslatorTest method testMoveMetadataAdaptrisMessageToJmsMessage.

@Test
public void testMoveMetadataAdaptrisMessageToJmsMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    JmsConnection conn = null;
    try {
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        start(trans);
        Message jmsMsg = trans.translate(msg);
        assertJmsProperties(jmsMsg);
    } finally {
        stop(trans);
        stop(conn);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) JmsConnection(com.adaptris.core.jms.JmsConnection) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) Test(org.junit.Test)

Example 2 with MessageTypeTranslatorImp

use of com.adaptris.core.jms.MessageTypeTranslatorImp in project interlok by adaptris.

the class BlobMessageTranslatorTest method testMoveJmsHeadersJmsMessageToAdaptrisMessage.

@Test
public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = new BlobMessageTranslator();
    JmsConnection conn = null;
    try {
        conn = activeMqBroker.getJmsConnection(new BasicActiveMqImplementation());
        start(conn);
        Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        jmsMsg.setJMSCorrelationID("ABC");
        jmsMsg.setJMSDeliveryMode(1);
        jmsMsg.setJMSPriority(4);
        addProperties(jmsMsg);
        long timestamp = System.currentTimeMillis();
        jmsMsg.setJMSTimestamp(timestamp);
        trans.registerSession(session);
        trans.registerMessageFactory(new DefaultMessageFactory());
        trans.setMoveJmsHeaders(true);
        start(trans);
        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
        assertEquals("ABC", msg.getMetadataValue(JmsConstants.JMS_CORRELATION_ID));
        assertEquals("1", msg.getMetadataValue(JmsConstants.JMS_DELIVERY_MODE));
        assertEquals("4", msg.getMetadataValue(JmsConstants.JMS_PRIORITY));
        assertEquals(String.valueOf(timestamp), msg.getMetadataValue(JmsConstants.JMS_TIMESTAMP));
    } finally {
        stop(trans);
        stop(conn);
    }
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) JmsConnection(com.adaptris.core.jms.JmsConnection) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.ActiveMQSession) Test(org.junit.Test)

Example 3 with MessageTypeTranslatorImp

use of com.adaptris.core.jms.MessageTypeTranslatorImp in project interlok by adaptris.

the class MessageTypeTranslatorCase method testRoundTrip.

@Test
public void testRoundTrip() throws Exception {
    MessageTypeTranslatorImp translator = createTranslator().withMoveJmsHeaders(true).withMetadataFilter(new NoOpMetadataFilter()).withReportAllErrors(true);
    StandaloneProducer p1 = createProducer(translator);
    StandaloneProducer p2 = roundTrip(p1);
    BaseCase.assertRoundtripEquality(p1, p2);
}
Also used : NoOpMetadataFilter(com.adaptris.core.metadata.NoOpMetadataFilter) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 4 with MessageTypeTranslatorImp

use of com.adaptris.core.jms.MessageTypeTranslatorImp in project interlok by adaptris.

the class MessageTypeTranslatorCase method testMoveMetadata_AdaptrisMessageToJmsMessage_WithFilter.

@Test
public void testMoveMetadata_AdaptrisMessageToJmsMessage_WithFilter() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator();
    RegexMetadataFilter regexp = new RegexMetadataFilter();
    regexp.addExcludePattern("IntegerMetadataKey");
    trans.setMetadataFilter(regexp);
    try {
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        addMetadata(msg);
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        start(trans, session);
        Message jmsMsg = trans.translate(msg);
        assertEquals(STRING_VALUE, jmsMsg.getStringProperty(STRING_METADATA));
        assertEquals(BOOLEAN_VALUE, jmsMsg.getStringProperty(BOOLEAN_METADATA));
        assertEquals(Boolean.valueOf(BOOLEAN_VALUE).booleanValue(), jmsMsg.getBooleanProperty(BOOLEAN_METADATA));
        assertNull(jmsMsg.getStringProperty(INTEGER_METADATA));
    } finally {
        stop(trans);
    }
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) Session(javax.jms.Session) Test(org.junit.Test)

Example 5 with MessageTypeTranslatorImp

use of com.adaptris.core.jms.MessageTypeTranslatorImp in project interlok by adaptris.

the class MessageTypeTranslatorCase method testMoveMetadataJmsMessageToAdaptrisMessage_RemoveAllFilter.

@Test
public void testMoveMetadataJmsMessageToAdaptrisMessage_RemoveAllFilter() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator();
    trans.setMetadataFilter(new RemoveAllMetadataFilter());
    try {
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        addProperties(jmsMsg);
        start(trans, session);
        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertFalse(msg.containsKey(INTEGER_METADATA));
        assertFalse(msg.containsKey(STRING_METADATA));
        assertFalse(msg.containsKey(BOOLEAN_METADATA));
    } finally {
        stop(trans);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Message(javax.jms.Message) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) RemoveAllMetadataFilter(com.adaptris.core.metadata.RemoveAllMetadataFilter) MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

MessageTypeTranslatorImp (com.adaptris.core.jms.MessageTypeTranslatorImp)17 Test (org.junit.Test)17 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)13 Message (javax.jms.Message)13 Session (javax.jms.Session)13 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)4 JmsConnection (com.adaptris.core.jms.JmsConnection)4 ActiveMQSession (org.apache.activemq.ActiveMQSession)4 RegexMetadataFilter (com.adaptris.core.metadata.RegexMetadataFilter)3 RemoveAllMetadataFilter (com.adaptris.core.metadata.RemoveAllMetadataFilter)2 MetadataElement (com.adaptris.core.MetadataElement)1 StandaloneProducer (com.adaptris.core.StandaloneProducer)1 NoOpMetadataFilter (com.adaptris.core.metadata.NoOpMetadataFilter)1