Java Code Examples for org.springframework.jms.StubTextMessage

The following examples show how to use org.springframework.jms.StubTextMessage. These examples are extracted from open source projects. 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 Project: java-technology-stack   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void attemptToReadDisallowedUserPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public Object getObjectProperty(String name) throws JMSException {
			if (name.equals("fail")) {
				throw new JMSException("illegal property");
			}
			else {
				return super.getObjectProperty(name);
			}
		}
	};
	jmsMessage.setBooleanProperty("fail", true);
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, "fail");
}
 
Example 2
Source Project: java-technology-stack   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void attemptToWriteDisallowedTypePropertyIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.TYPE, "someType")
			.setHeader("foo", "bar")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setJMSType(String type) throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSType());
	assertNotNull(jmsMessage.getStringProperty("foo"));
	assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
 
Example 3
Source Project: java-technology-stack   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void attemptToWriteDisallowedCorrelationIdNumberPropertyIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.CORRELATION_ID, 123)
			.setHeader("foo", "bar")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setJMSCorrelationID(String correlationId) throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSCorrelationID());
	assertNotNull(jmsMessage.getStringProperty("foo"));
	assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
 
Example 4
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void attemptToReadDisallowedUserPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public Object getObjectProperty(String name) throws JMSException {
			if (name.equals("fail")) {
				throw new JMSException("illegal property");
			}
			else {
				return super.getObjectProperty(name);
			}
		}
	};
	jmsMessage.setBooleanProperty("fail", true);
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, "fail");
}
 
Example 5
@Test
public void attemptToWriteDisallowedTypePropertyIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.TYPE, "someType")
			.setHeader("foo", "bar")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setJMSType(String type) throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSType());
	assertNotNull(jmsMessage.getStringProperty("foo"));
	assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
 
Example 6
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void illegalArgumentExceptionIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader("foo", 123)
			.setHeader("bad", 456)
			.setHeader("bar", 789)
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setObjectProperty(String name, Object value) throws JMSException {
			if (name.equals("bad")) {
				throw new IllegalArgumentException("illegal property");
			}
			super.setObjectProperty(name, value);
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	Object foo = jmsMessage.getObjectProperty("foo");
	assertNotNull(foo);
	Object bar = jmsMessage.getObjectProperty("bar");
	assertNotNull(bar);
	Object bad = jmsMessage.getObjectProperty("bad");
	assertNull(bad);
}
 
Example 7
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void attemptToWriteDisallowedReplyToPropertyIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.REPLY_TO, new Destination() {})
			.setHeader("foo", "bar")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setJMSReplyTo(Destination replyTo) throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSReplyTo());
	assertNotNull(jmsMessage.getStringProperty("foo"));
	assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
 
Example 8
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void attemptToWriteDisallowedTypePropertyIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.TYPE, "someType")
			.setHeader("foo", "bar")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setJMSType(String type) throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSType());
	assertNotNull(jmsMessage.getStringProperty("foo"));
	assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
 
Example 9
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void attemptToWriteDisallowedCorrelationIdStringPropertyIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.CORRELATION_ID, "abc")
			.setHeader("foo", "bar")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setJMSCorrelationID(String correlationId) throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSCorrelationID());
	assertNotNull(jmsMessage.getStringProperty("foo"));
	assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
 
Example 10
@Test
public void jmsReadOnlyPropertiesNotMapped() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.DESTINATION, new Destination() {})
			.setHeader(JmsHeaders.DELIVERY_MODE, DeliveryMode.NON_PERSISTENT)
			.setHeader(JmsHeaders.EXPIRATION, 1000L)
			.setHeader(JmsHeaders.MESSAGE_ID, "abc-123")
			.setHeader(JmsHeaders.PRIORITY, 9)
			.setHeader(JmsHeaders.REDELIVERED, true)
			.setHeader(JmsHeaders.TIMESTAMP, System.currentTimeMillis())
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSDestination());
	assertEquals(DeliveryMode.PERSISTENT, jmsMessage.getJMSDeliveryMode());
	assertEquals(0, jmsMessage.getJMSExpiration());
	assertNull(jmsMessage.getJMSMessageID());
	assertEquals(javax.jms.Message.DEFAULT_PRIORITY, jmsMessage.getJMSPriority());
	assertFalse(jmsMessage.getJMSRedelivered());
	assertEquals(0, jmsMessage.getJMSTimestamp());
}
 
Example 11
@Test
public void attemptToWriteDisallowedCorrelationIdNumberPropertyIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.CORRELATION_ID, 123)
			.setHeader("foo", "bar")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setJMSCorrelationID(String correlationId) throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSCorrelationID());
	assertNotNull(jmsMessage.getStringProperty("foo"));
	assertEquals("bar", jmsMessage.getStringProperty("foo"));
}
 
Example 12
@Test
public void buildMessageWithStandardMessage() throws JMSException {
	Destination replyTo = new Destination() {};
	Message<String> result = MessageBuilder.withPayload("Response")
			.setHeader("foo", "bar")
			.setHeader(JmsHeaders.TYPE, "msg_type")
			.setHeader(JmsHeaders.REPLY_TO, replyTo)
			.build();

	Session session = mock(Session.class);
	given(session.createTextMessage("Response")).willReturn(new StubTextMessage("Response"));
	MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
	javax.jms.Message replyMessage = listener.buildMessage(session, result);

	verify(session).createTextMessage("Response");
	assertNotNull("reply should never be null", replyMessage);
	assertEquals("Response", ((TextMessage) replyMessage).getText());
	assertEquals("custom header not copied", "bar", replyMessage.getStringProperty("foo"));
	assertEquals("type header not copied", "msg_type", replyMessage.getJMSType());
	assertEquals("replyTo header not copied", replyTo, replyMessage.getJMSReplyTo());
}
 
Example 13
Source Project: java-technology-stack   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 6 votes vote down vote up
@Test
public void illegalArgumentExceptionIsNotFatal() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader("foo", 123)
			.setHeader("bad", 456)
			.setHeader("bar", 789)
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public void setObjectProperty(String name, Object value) throws JMSException {
			if (name.equals("bad")) {
				throw new IllegalArgumentException("illegal property");
			}
			super.setObjectProperty(name, value);
		}
	};
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	Object foo = jmsMessage.getObjectProperty("foo");
	assertNotNull(foo);
	Object bar = jmsMessage.getObjectProperty("bar");
	assertNotNull(bar);
	Object bad = jmsMessage.getObjectProperty("bad");
	assertNull(bad);
}
 
Example 14
@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 15
@Test
public void userDefinedPropertyWithUnsupportedType() throws JMSException {
	Destination destination = new Destination() {};
	Message<String> message = initBuilder()
			.setHeader("destination", destination)
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	Object value = jmsMessage.getObjectProperty("destination");
	assertNull(value);
}
 
Example 16
@Test
public void jmsTypeIgnoredIfIncorrectType() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.TYPE, 123).build();
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNull(jmsMessage.getJMSType());
}
 
Example 17
Source Project: java-technology-stack   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 5 votes vote down vote up
@Test
public void attemptToReadDisallowedReplyToPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public Destination getJMSReplyTo() throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, JmsHeaders.REPLY_TO);
}
 
Example 18
@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 19
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 5 votes vote down vote up
@Test
public void jmsReplyToMappedFromHeader() throws JMSException {
	Destination replyTo = new Destination() {};
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.REPLY_TO, replyTo).build();

	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNotNull(jmsMessage.getJMSReplyTo());
	assertSame(replyTo, jmsMessage.getJMSReplyTo());
}
 
Example 20
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
	Session mock = mock(Session.class);
	given(mock.createTextMessage(BDDMockito.<String> any())).willAnswer(
			new Answer<TextMessage>() {
		@Override
		public TextMessage answer(InvocationOnMock invocation) throws Throwable {
			return new StubTextMessage((String) invocation.getArguments()[0]);
		}
	});
	javax.jms.Message message = creator.createMessage(mock);
	verify(mock).createTextMessage(BDDMockito.<String> any());
	return TextMessage.class.cast(message);
}
 
Example 21
@Test
public void resolveJmsMessageHeaderAccessor() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(JmsMessageHeaderAccessor.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setBooleanProperty("customBoolean", true);
	message.setJMSPriority(9);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example 22
@Test
public void jmsTypeMappedFromHeader() throws JMSException {
	String jmsType = "testing";
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.TYPE, jmsType).build();
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNotNull(jmsMessage.getJMSType());
	assertEquals(jmsType, jmsMessage.getJMSType());
}
 
Example 23
@Test
public void jmsReplyToMappedFromHeader() throws JMSException {
	Destination replyTo = new Destination() {};
	Message<String> message = initBuilder()
			.setHeader(JmsHeaders.REPLY_TO, replyTo).build();

	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	assertNotNull(jmsMessage.getJMSReplyTo());
	assertSame(replyTo, jmsMessage.getJMSReplyTo());
}
 
Example 24
Source Project: java-technology-stack   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 5 votes vote down vote up
@Test
public void attemptToReadDisallowedDeliveryModePropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public int getJMSDeliveryMode() throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, JmsHeaders.DELIVERY_MODE);
}
 
Example 25
@Test
public void userDefinedPropertyMappedFromHeaderWithCustomPrefix() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader("foo", 123)
			.build();
	mapper.setOutboundPrefix("custom_");
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	Object value = jmsMessage.getObjectProperty("custom_foo");
	assertNotNull(value);
	assertEquals(Integer.class, value.getClass());
	assertEquals(123, ((Integer) value).intValue());
}
 
Example 26
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 5 votes vote down vote up
@Test
public void contentTypePropertyMappedFromHeader() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader(MessageHeaders.CONTENT_TYPE, "foo")
			.build();
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	Object value = jmsMessage.getObjectProperty(JmsHeaderMapper.CONTENT_TYPE_PROPERTY);
	assertNotNull(value);
	assertEquals("foo", value);
}
 
Example 27
@Test
public void attemptToReadDisallowedTimestampPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public long getJMSTimestamp() throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, JmsHeaders.TIMESTAMP);
}
 
Example 28
Source Project: spring-analysis-note   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 5 votes vote down vote up
@Test
public void userDefinedPropertyMappedFromHeaderWithCustomPrefix() throws JMSException {
	Message<String> message = initBuilder()
			.setHeader("foo", 123)
			.build();
	mapper.setOutboundPrefix("custom_");
	javax.jms.Message jmsMessage = new StubTextMessage();
	mapper.fromHeaders(message.getHeaders(), jmsMessage);
	Object value = jmsMessage.getObjectProperty("custom_foo");
	assertNotNull(value);
	assertEquals(Integer.class, value.getClass());
	assertEquals(123, ((Integer) value).intValue());
}
 
Example 29
Source Project: java-technology-stack   Source File: SimpleJmsHeaderMapperTests.java    License: MIT License 5 votes vote down vote up
@Test
public void jmsMessageIdMappedToHeader() throws JMSException {
	String messageId = "ID:ABC-123";
	javax.jms.Message jmsMessage = new StubTextMessage();
	jmsMessage.setJMSMessageID(messageId);
	assertInboundHeader(jmsMessage, JmsHeaders.MESSAGE_ID, messageId);
}
 
Example 30
@Test
public void replyUsesMessageConverterForPayload() throws JMSException {
	Session session = mock(Session.class);
	MessageConverter messageConverter = mock(MessageConverter.class);
	given(messageConverter.toMessage("Response", session)).willReturn(new StubTextMessage("Response"));

	Message<String> result = MessageBuilder.withPayload("Response").build();
	MessagingMessageListenerAdapter listener = getSimpleInstance("echo", Message.class);
	listener.setMessageConverter(messageConverter);
	javax.jms.Message replyMessage = listener.buildMessage(session, result);

	verify(messageConverter, times(1)).toMessage("Response", session);
	assertNotNull("reply should never be null", replyMessage);
	assertEquals("Response", ((TextMessage) replyMessage).getText());
}