Search in sources :

Example 26 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method convertSendAndReceiveDefaultDestination.

@Test
public void convertSendAndReceiveDefaultDestination() throws JMSException {
    Destination destination = new Destination() {
    };
    messagingTemplate.setDefaultDestination(destination);
    javax.jms.Message replyJmsMessage = createJmsTextMessage("My reply");
    given(jmsTemplate.sendAndReceive(eq(destination), any())).willReturn(replyJmsMessage);
    String reply = messagingTemplate.convertSendAndReceive("my Payload", String.class);
    verify(jmsTemplate, times(1)).sendAndReceive(eq(destination), any());
    assertEquals("My reply", reply);
}
Also used : Destination(javax.jms.Destination) Test(org.junit.Test)

Example 27 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JmsMessagingTemplateTests method convertInvalidDestinationExceptionOnSendAndReceive.

@Test
public void convertInvalidDestinationExceptionOnSendAndReceive() {
    Destination destination = new Destination() {
    };
    willThrow(InvalidDestinationException.class).given(jmsTemplate).sendAndReceive(eq(destination), any());
    thrown.expect(org.springframework.messaging.core.DestinationResolutionException.class);
    messagingTemplate.sendAndReceive(destination, createTextMessage());
}
Also used : Destination(javax.jms.Destination) Test(org.junit.Test)

Example 28 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JndiDestinationResolverTests method testDoesNotUseCacheIfCachingIsTurnedOff.

@Test
public void testDoesNotUseCacheIfCachingIsTurnedOff() throws Exception {
    Session session = mock(Session.class);
    CountingCannedJndiDestinationResolver resolver = new CountingCannedJndiDestinationResolver();
    resolver.setCache(false);
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertNotNull(destination);
    assertSame(DESTINATION, destination);
    assertEquals(1, resolver.getCallCount());
    destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertNotNull(destination);
    assertSame(DESTINATION, destination);
    assertEquals(2, resolver.getCallCount());
}
Also used : Destination(javax.jms.Destination) Session(javax.jms.Session) Test(org.junit.Test)

Example 29 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JndiDestinationResolverTests method testHitsCacheSecondTimeThrough.

@Test
public void testHitsCacheSecondTimeThrough() throws Exception {
    Session session = mock(Session.class);
    JndiDestinationResolver resolver = new OneTimeLookupJndiDestinationResolver();
    Destination destination = resolver.resolveDestinationName(session, DESTINATION_NAME, true);
    assertNotNull(destination);
    assertSame(DESTINATION, destination);
}
Also used : Destination(javax.jms.Destination) Session(javax.jms.Session) Test(org.junit.Test)

Example 30 with Destination

use of javax.jms.Destination in project spring-framework by spring-projects.

the class JmsMessageHeaderAccessorTests method validateJmsHeaders.

@Test
public void validateJmsHeaders() throws JMSException {
    Destination destination = new Destination() {
    };
    Destination replyTo = new Destination() {
    };
    StubTextMessage jmsMessage = new StubTextMessage("test");
    jmsMessage.setJMSCorrelationID("correlation-1234");
    jmsMessage.setJMSPriority(9);
    jmsMessage.setJMSDestination(destination);
    jmsMessage.setJMSDeliveryMode(1);
    jmsMessage.setJMSExpiration(1234L);
    jmsMessage.setJMSMessageID("abcd-1234");
    jmsMessage.setJMSPriority(9);
    jmsMessage.setJMSReplyTo(replyTo);
    jmsMessage.setJMSRedelivered(true);
    jmsMessage.setJMSType("type");
    jmsMessage.setJMSTimestamp(4567L);
    Map<String, Object> mappedHeaders = new SimpleJmsHeaderMapper().toHeaders(jmsMessage);
    Message<String> message = MessageBuilder.withPayload("test").copyHeaders(mappedHeaders).build();
    JmsMessageHeaderAccessor headerAccessor = JmsMessageHeaderAccessor.wrap(message);
    assertEquals("correlation-1234", headerAccessor.getCorrelationId());
    assertEquals(destination, headerAccessor.getDestination());
    assertEquals(Integer.valueOf(1), headerAccessor.getDeliveryMode());
    assertEquals(1234L, headerAccessor.getExpiration(), 0.0);
    assertEquals("abcd-1234", headerAccessor.getMessageId());
    assertEquals(Integer.valueOf(9), headerAccessor.getPriority());
    assertEquals(replyTo, headerAccessor.getReplyTo());
    assertEquals(true, headerAccessor.getRedelivered());
    assertEquals("type", headerAccessor.getType());
    assertEquals(4567L, headerAccessor.getTimestamp(), 0.0);
    // Making sure replyChannel is not mixed with replyTo
    assertNull(headerAccessor.getReplyChannel());
}
Also used : Destination(javax.jms.Destination) StubTextMessage(org.springframework.jms.StubTextMessage) Test(org.junit.Test)

Aggregations

Destination (javax.jms.Destination)137 Test (org.junit.Test)41 TextMessage (javax.jms.TextMessage)38 JMSException (javax.jms.JMSException)33 Message (javax.jms.Message)27 Session (javax.jms.Session)27 MessageProducer (javax.jms.MessageProducer)22 Connection (javax.jms.Connection)15 ConnectionFactory (javax.jms.ConnectionFactory)15 JMSContext (javax.jms.JMSContext)15 CountDownLatch (java.util.concurrent.CountDownLatch)13 MessageConsumer (javax.jms.MessageConsumer)12 StubTextMessage (org.springframework.jms.StubTextMessage)11 ObjectMessage (javax.jms.ObjectMessage)10 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)10 MapMessage (javax.jms.MapMessage)7 Queue (javax.jms.Queue)7 Map (java.util.Map)6 HashMap (java.util.HashMap)5 JMSConsumer (javax.jms.JMSConsumer)5