org.springframework.jms.StubTextMessage Java Examples

The following examples show how to use org.springframework.jms.StubTextMessage. 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: SimpleJmsHeaderMapperTests.java    From spring-analysis-note with 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 #2
Source File: SimpleJmsHeaderMapperTests.java    From spring-analysis-note with 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 #3
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 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 File: MessagingMessageListenerAdapterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: SimpleJmsHeaderMapperTests.java    From java-technology-stack with 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 #6
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 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 #7
Source File: SimpleJmsHeaderMapperTests.java    From java-technology-stack with 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 #8
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: SimpleJmsHeaderMapperTests.java    From java-technology-stack with 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 #10
Source File: SimpleJmsHeaderMapperTests.java    From spring-analysis-note with 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 #11
Source File: SimpleJmsHeaderMapperTests.java    From spring-analysis-note with 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 #12
Source File: SimpleJmsHeaderMapperTests.java    From spring-analysis-note with 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 #13
Source File: SimpleJmsHeaderMapperTests.java    From java-technology-stack with 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 #14
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 #15
Source File: JmsMessagingTemplateTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private javax.jms.Message createJmsTextMessage(String payload) {
	try {
		StubTextMessage jmsMessage = new StubTextMessage(payload);
		jmsMessage.setStringProperty("foo", "bar");
		return jmsMessage;
	}
	catch (JMSException e) {
		throw new IllegalStateException("Should not happen", e);
	}
}
 
Example #16
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void jmsExpirationMappedToHeader() throws JMSException {
	long expiration = 1000L;
	javax.jms.Message jmsMessage = new StubTextMessage();
	jmsMessage.setJMSExpiration(expiration);
	assertInboundHeader(jmsMessage, JmsHeaders.EXPIRATION, expiration);
}
 
Example #17
Source File: MethodJmsListenerEndpointTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolveHeaderAndPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("myCounter", 55);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example #18
Source File: SimpleJmsHeaderMapperTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void attemptToReadDisallowedMessageIdPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public String getJMSMessageID() throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, JmsHeaders.MESSAGE_ID);
}
 
Example #19
Source File: JmsListenerContainerFactoryIntegrationTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void parameterAnnotationWithJdkProxy() throws JMSException {
	ProxyFactory pf = new ProxyFactory(sample);
	listener = (JmsEndpointSampleInterface) pf.getProxy();

	containerFactory.setMessageConverter(new UpperCaseMessageConverter());

	MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(
			JmsEndpointSampleInterface.class, "handleIt", String.class, String.class);
	Message message = new StubTextMessage("foo-bar");
	message.setStringProperty("my-header", "my-value");

	invokeListener(endpoint, message);
	assertListenerMethodInvocation("handleIt");
}
 
Example #20
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 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 #21
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void attemptToReadDisallowedDestinationPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public Destination getJMSDestination() throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, JmsHeaders.DESTINATION);
}
 
Example #22
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void userDefinedPropertyMappedToHeaderWithCustomPrefix() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage();
	jmsMessage.setIntProperty("foo", 123);
	mapper.setInboundPrefix("custom_");
	assertInboundHeader(jmsMessage, "custom_foo", 123);
}
 
Example #23
Source File: SimpleJmsHeaderMapperTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void attemptToReadDisallowedPriorityPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public int getJMSPriority() throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, JmsHeaders.PRIORITY);
}
 
Example #24
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void attemptToReadDisallowedPriorityPropertyIsNotFatal() throws JMSException {
	javax.jms.Message jmsMessage = new StubTextMessage() {
		@Override
		public int getJMSPriority() throws JMSException {
			throw new JMSException("illegal property");
		}
	};
	assertAttemptReadDisallowedPropertyIsNotFatal(jmsMessage, JmsHeaders.PRIORITY);
}
 
Example #25
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@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 #26
Source File: JmsMessagingTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private javax.jms.Message createJmsTextMessage(String payload) {
	try {
		StubTextMessage jmsMessage = new StubTextMessage(payload);
		jmsMessage.setStringProperty("foo", "bar");
		return jmsMessage;
	}
	catch (JMSException e) {
		throw new IllegalStateException("Should not happen", e);
	}
}
 
Example #27
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resolveHeaders() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, Map.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("customInt", 1234);
	message.setJMSMessageID("abcd-1234");
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example #28
Source File: SimpleJmsHeaderMapperTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void jmsCorrelationIdMappedToHeader() throws JMSException {
	String correlationId = "ABC-123";
	javax.jms.Message jmsMessage = new StubTextMessage();
	jmsMessage.setJMSCorrelationID(correlationId);
	assertInboundHeader(jmsMessage, JmsHeaders.CORRELATION_ID, correlationId);
}
 
Example #29
Source File: MethodJmsListenerEndpointTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resolveCustomHeaderNameAndPayload() throws JMSException {
	MessagingMessageListenerAdapter listener = createDefaultInstance(String.class, int.class);

	Session session = mock(Session.class);
	StubTextMessage message = createSimpleJmsTextMessage("my payload");
	message.setIntProperty("myCounter", 24);
	listener.onMessage(message, session);
	assertDefaultListenerMethodInvocation();
}
 
Example #30
Source File: JmsMessagingTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
	Session mock = mock(Session.class);
	given(mock.createTextMessage(BDDMockito.any())).willAnswer(
			(Answer<TextMessage>) invocation ->
					new StubTextMessage((String) invocation.getArguments()[0]));
	javax.jms.Message message = creator.createMessage(mock);
	verify(mock).createTextMessage(BDDMockito.any());
	return TextMessage.class.cast(message);
}