Java Code Examples for org.springframework.jms.StubTextMessage#setJMSCorrelationID()

The following examples show how to use org.springframework.jms.StubTextMessage#setJMSCorrelationID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void processAndReply() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDefaultResponseDestination(replyDestination);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);
	assertDefaultListenerMethodInvocation();

	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 2
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void processAndReply() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDefaultResponseDestination(replyDestination);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);
	assertDefaultListenerMethodInvocation();

	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 3
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void processAndReply() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDefaultResponseDestination(replyDestination);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);
	assertDefaultListenerMethodInvocation();

	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 4
Source File: MethodJmsListenerEndpointTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener, boolean pubSubDomain) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, "replyDestination", pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, "replyDestination", pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	verify(queueSender).send(reply);
	verify(queueSender).close();
}
 
Example 5
Source File: JmsMessageHeaderAccessorTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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());

}
 
Example 6
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
		String replyDestinationName, boolean pubSubDomain,
		QosSettings replyQosSettings) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	if (replyQosSettings != null) {
		verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(),
				replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
	}
	else {
		verify(queueSender).send(reply);
	}
	verify(queueSender).close();
}
 
Example 7
Source File: JmsMessageHeaderAccessorTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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());

}
 
Example 8
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void processAndReplyWithSendTo(MessagingMessageListenerAdapter listener,
		String replyDestinationName, boolean pubSubDomain,
		QosSettings replyQosSettings) throws JMSException {
	String body = "echo text";
	String correlationId = "link-1234";
	Destination replyDestination = new Destination() {};

	DestinationResolver destinationResolver = mock(DestinationResolver.class);
	TextMessage reply = mock(TextMessage.class);
	QueueSender queueSender = mock(QueueSender.class);
	Session session = mock(Session.class);

	given(destinationResolver.resolveDestinationName(session, replyDestinationName, pubSubDomain))
			.willReturn(replyDestination);
	given(session.createTextMessage(body)).willReturn(reply);
	given(session.createProducer(replyDestination)).willReturn(queueSender);

	listener.setDestinationResolver(destinationResolver);
	StubTextMessage inputMessage = createSimpleJmsTextMessage(body);
	inputMessage.setJMSCorrelationID(correlationId);
	listener.onMessage(inputMessage, session);

	verify(destinationResolver).resolveDestinationName(session, replyDestinationName, pubSubDomain);
	verify(reply).setJMSCorrelationID(correlationId);
	if (replyQosSettings != null) {
		verify(queueSender).send(reply, replyQosSettings.getDeliveryMode(),
				replyQosSettings.getPriority(), replyQosSettings.getTimeToLive());
	}
	else {
		verify(queueSender).send(reply);
	}
	verify(queueSender).close();
}
 
Example 9
Source File: JmsMessageHeaderAccessorTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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());

}