Ejemplo n.º 1
0
  @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);
  }
 @Test
 public void queueReferenceChannel() {
   assertEquals(JmsDestinationBackedMessageChannel.class, queueReferenceChannel.getClass());
   JmsDestinationBackedMessageChannel channel =
       (JmsDestinationBackedMessageChannel) queueReferenceChannel;
   DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
   JmsTemplate jmsTemplate = (JmsTemplate) accessor.getPropertyValue("jmsTemplate");
   AbstractMessageListenerContainer container =
       (AbstractMessageListenerContainer) accessor.getPropertyValue("container");
   assertEquals(queue, jmsTemplate.getDefaultDestination());
   assertEquals(queue, container.getDestination());
 }