@Test
  public void testReceiveMessageWithJmsTemplate() {
    JmsMessageReceiver receiver = new JmsMessageReceiver();
    receiver.setJmsTemplate(jmsTemplate);

    Map<String, Object> controlHeaders = new HashMap<String, Object>();
    final Message<String> controlMessage =
        MessageBuilder.withPayload("<TestRequest><Message>Hello World!</Message></TestRequest>")
            .copyHeaders(controlHeaders)
            .build();

    reset(jmsTemplate, connectionFactory, destination);

    jmsTemplate.setReceiveTimeout(5000L);
    expectLastCall().once();

    expect(jmsTemplate.getDefaultDestination()).andReturn(destination).atLeastOnce();

    expect(jmsTemplate.receiveAndConvert()).andReturn(controlMessage);

    replay(jmsTemplate, connectionFactory, destination);

    Message<?> receivedMessage = receiver.receive();
    Assert.assertTrue(receivedMessage.equals(controlMessage));

    verify(jmsTemplate, connectionFactory, destination);
  }
 @After
 @Before
 public void drainQueue() throws Exception {
   container.stop();
   while (jmsTemplate.receiveAndConvert("queue") != null) {
     // do nothing
   }
   processed.clear();
 }
 private List<String> getMessages() {
   String next = "";
   List<String> msgs = new ArrayList<String>();
   while (next != null) {
     next = (String) jmsTemplate.receiveAndConvert("queue");
     if (next != null) msgs.add(next);
   }
   return msgs;
 }
  @Override
  protected String doFilter(String input, Map<String, Object> metaData) {
    String destination = (String) metaData.get("destination");
    String callId = (String) metaData.get("callId");
    LOGGER.info("sending message with callId {} to destination {}", callId, destination);
    sendMessage(destination, input);

    if (ObjectUtils.notEqual(metaData.get("answer"), true)) {
      LOGGER.debug("no answer expected, just returning null");
      return null;
    }
    LOGGER.info("waiting {}ms for response on call with id {}", timeout, callId);
    JmsTemplate createJMSTemplate = createJMSTemplate(destination);
    createJMSTemplate.setReceiveTimeout(timeout);
    Object receiveAndConvert = createJMSTemplate.receiveAndConvert(callId);
    if (receiveAndConvert == null) {
      throw new RuntimeException("JMS Receive Timeout reached");
    }
    LOGGER.info("response for call with id {} received", callId);
    return (String) receiveAndConvert;
  }