TextMessageTranslator extends MessageTypeTranslatorImp { @Override public Message translate(AdaptrisMessage msg) throws JMSException { return helper.moveMetadata(msg, session.createTextMessage(msg.getContent())); } TextMessageTranslator(); @Override Message translate(AdaptrisMessage msg); @Override AdaptrisMessage translate(Message msg);  }
@Test public void testTextMessageToAdaptrisMessage() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); TextMessageTranslator trans = new TextMessageTranslator(); try { broker.start(); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); Message jmsMsg = createMessage(session); addProperties(jmsMsg); start(trans, session); AdaptrisMessage msg = trans.translate(jmsMsg); assertMetadata(msg); assertEquals(TEXT, msg.getContent()); } finally { stop(trans); broker.destroy(); } }
@Test public void testAdaptrisMessageToTextMessage() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); TextMessageTranslator trans = new TextMessageTranslator(); try { broker.start(); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); start(trans, session); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); addMetadata(msg); Message jmsMsg = trans.translate(msg); assertTrue("jmsMsg instanceof TextMessage", jmsMsg instanceof TextMessage); assertEquals(TEXT, ((TextMessage) jmsMsg).getText()); assertJmsProperties(jmsMsg); } finally { stop(trans); broker.destroy(); } }
@Test public void testAdaptrisMessageToTextMessageWithMetadataFilter() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); TextMessageTranslator trans = new TextMessageTranslator(); RegexMetadataFilter filter = new RegexMetadataFilter(); filter.addExcludePattern(INTEGER_METADATA); trans.setMetadataFilter(filter); try { broker.start(); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); start(trans, session); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT); addMetadata(msg); Message jmsMsg = trans.translate(msg); assertTrue("jmsMsg instanceof TextMessage", jmsMsg instanceof TextMessage); assertEquals(TEXT, ((TextMessage) jmsMsg).getText()); 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); broker.destroy(); } }