JmsAsyncProducer extends JmsProducer { @Override protected void produce(AdaptrisMessage msg, JmsDestination jmsDest) throws JMSException, CoreException { try { setupSession(msg); Message jmsMsg = translate(msg, jmsDest.getReplyToDestination()); jmsMsg.setStringProperty(ID_HEADER, msg.getUniqueId()); if (!perMessageProperties()) { producerSession().getProducer().send(jmsDest.getDestination(), jmsMsg, getEventHandler()); } else { producerSession().getProducer().send(jmsDest.getDestination(), jmsMsg, calculateDeliveryMode(msg, jmsDest.deliveryMode()), calculatePriority(msg, jmsDest.priority()), calculateTimeToLive(msg, jmsDest.timeToLive()), getEventHandler()); } getEventHandler().addUnAckedMessage(jmsMsg.getStringProperty(ID_HEADER), msg); msg.getObjectHeaders().remove(CoreConstants.OBJ_METADATA_ON_SUCCESS_CALLBACK); msg.getObjectHeaders().remove(CoreConstants.OBJ_METADATA_ON_FAILURE_CALLBACK); captureOutgoingMessageDetails(jmsMsg, msg); log.info("msg produced to destination [{}]", jmsDest); } catch (Throwable ex) { ExceptionHelper.rethrowProduceException(ex); } } JmsAsyncProducer(); @Override void init();  }
@Test public void testSendFails() throws Exception { doThrow(new JMSException("expected")) .when(mockMessageProducer).send(any(), eq(mockMessage), any(CompletionListener.class)); try { producer.produce(adaptrisMessage, mockJmsDestination); fail("Jms producer should have throw an exception on send()"); } catch (Throwable t) { } }
@Test public void testSendPerMessageProperties() throws Exception { producer.produce(adaptrisMessage, mockJmsDestination); verify(mockMessageProducer).send(any(), eq(mockMessage), any(int.class), any(int.class), any(long.class), any(CompletionListener.class)); }
@Test public void testSendNotPerMessageProperties() throws Exception { producer.setPerMessageProperties(false); producer.produce(adaptrisMessage, mockJmsDestination); verify(mockMessageProducer).send(any(), eq(mockMessage), any(JmsAsyncProducerEventHandler.class)); }
@Test public void testCaptureOutgoingMessageProperties() throws Exception { producer.setCaptureOutgoingMessageDetails(true); producer.produce(adaptrisMessage, mockJmsDestination); verify(mockMessage).getJMSMessageID(); verify(mockMessage).getJMSType(); verify(mockMessage).getJMSDeliveryMode(); verify(mockMessage).getJMSPriority(); }
@Test public void testNotCaptureOutgoingMessageProperties() throws Exception { producer.setCaptureOutgoingMessageDetails(false); producer.produce(adaptrisMessage, mockJmsDestination); verify(mockMessage, times(0)).getJMSMessageID(); verify(mockMessage, times(0)).getJMSType(); verify(mockMessage, times(0)).getJMSDeliveryMode(); verify(mockMessage, times(0)).getJMSPriority(); }
@Test public void testExceptionThrown() throws Exception { doThrow(new JMSException("expected")) .when(mockMessageProducer).send(any(), any(), any()); try { producer.setPerMessageProperties(false); producer.produce(adaptrisMessage, mockJmsDestination); fail("Should throw produce exception"); } catch (ProduceException ex) { } }