Search in sources :

Example 11 with MessageTypeTranslatorImp

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

the class MessageTypeTranslatorCase method testMoveMetadataJmsMessageToAdaptrisMessage.

@Test
public void testMoveMetadataJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator();
    try {
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Message jmsMsg = createMessage(session);
        addProperties(jmsMsg);
        start(trans, session);
        AdaptrisMessage msg = trans.translate(jmsMsg);
        assertMetadata(msg);
    } finally {
        stop(trans);
    }
}
Also used : 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 12 with MessageTypeTranslatorImp

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

the class MessageTypeTranslatorCase method testMoveJmsHeadersJmsMessageToAdaptrisMessage.

@Test
public void testMoveJmsHeadersJmsMessageToAdaptrisMessage() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator();
    try {
        Session session = activeMqBroker.createConnection().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.setMoveJmsHeaders(true);
        start(trans, session);
        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);
    }
}
Also used : 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 13 with MessageTypeTranslatorImp

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

the class MessageTypeTranslatorCase method testSetMoveJmsHeaders.

@Test
public void testSetMoveJmsHeaders() throws Exception {
    MessageTypeTranslatorImp translator = createTranslator();
    assertNull(translator.getMoveJmsHeaders());
    assertFalse(translator.moveJmsHeaders());
    translator.setMoveJmsHeaders(Boolean.TRUE);
    assertEquals(Boolean.TRUE, translator.getMoveJmsHeaders());
    assertTrue(translator.moveJmsHeaders());
    translator.setMoveJmsHeaders(null);
    assertNull(translator.getMoveJmsHeaders());
    assertFalse(translator.moveJmsHeaders());
}
Also used : MessageTypeTranslatorImp(com.adaptris.core.jms.MessageTypeTranslatorImp) Test(org.junit.Test)

Example 14 with MessageTypeTranslatorImp

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

the class MessageTypeTranslatorCase method testMoveMetadata_AdaptrisMessageToJmsMessage_RemoveAll.

@Test
public void testMoveMetadata_AdaptrisMessageToJmsMessage_RemoveAll() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator().withMetadataFilter(new RemoveAllMetadataFilter());
    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);
        assertNull(jmsMsg.getStringProperty(STRING_METADATA));
        assertNull(jmsMsg.getStringProperty(BOOLEAN_METADATA));
        assertNull(jmsMsg.getStringProperty(INTEGER_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)

Example 15 with MessageTypeTranslatorImp

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

the class MessageTypeTranslatorCase method testBug895.

@Test
public void testBug895() throws Exception {
    MessageTypeTranslatorImp trans = createTranslator();
    try {
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        msg.addMetadata(JmsConstants.JMS_PRIORITY, "9");
        msg.addMetadata(JmsConstants.JMS_TYPE, "idaho");
        Session session = activeMqBroker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE);
        trans.setMoveJmsHeaders(true);
        start(trans, session);
        Message jmsMsg = trans.translate(msg);
        assertNotSame("JMS Priorities should be different", jmsMsg.getJMSPriority(), 9);
        assertEquals("JMSType should be equal", "idaho", jmsMsg.getJMSType());
    } finally {
        stop(trans);
    }
}
Also used : 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)

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