use of jakarta.jms.Session in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method resolveJmsMessageHeaderAccessor.
@Test
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();
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method resolveHeaders.
@Test
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();
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method validatePayloadInvalid.
@Test
void validatePayloadInvalid() throws JMSException {
DefaultMessageHandlerMethodFactory customFactory = new DefaultMessageHandlerMethodFactory();
customFactory.setValidator(testValidator("invalid value"));
Method method = getListenerMethod("validatePayload", String.class);
MessagingMessageListenerAdapter listener = createInstance(customFactory, method);
Session session = mock(Session.class);
// test is an invalid value
assertThatExceptionOfType(ListenerExecutionFailedException.class).isThrownBy(() -> listener.onMessage(createSimpleJmsTextMessage("invalid value"), session));
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method resolveObjectPayload.
@Test
void resolveObjectPayload() throws JMSException {
MessagingMessageListenerAdapter listener = createDefaultInstance(MyBean.class);
MyBean myBean = new MyBean();
myBean.name = "myBean name";
Session session = mock(Session.class);
ObjectMessage message = mock(ObjectMessage.class);
given(message.getObject()).willReturn(myBean);
listener.onMessage(message, session);
assertDefaultListenerMethodInvocation();
}
use of jakarta.jms.Session in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionRollback.
@Test
public void testTransactionRollback() throws JMSException {
ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
JmsTemplate jt = new JmsTemplate(cf);
jt.execute((SessionCallback<Void>) sess -> {
assertThat(session).isSameAs(sess);
return null;
});
tm.rollback(ts);
verify(session).rollback();
verify(session).close();
verify(con).close();
}
Aggregations