use of jakarta.jms.JMSException in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionCommit.
@Test
public void testTransactionCommit() 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.commit(ts);
verify(session).commit();
verify(session).close();
verify(con).close();
}
use of jakarta.jms.JMSException in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testParticipatingTransactionWithCommit.
@Test
public void testParticipatingTransactionWithCommit() 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());
final JmsTemplate jt = new JmsTemplate(cf);
jt.execute((SessionCallback<Void>) sess -> {
assertThat(session).isSameAs(sess);
return null;
});
TransactionTemplate tt = new TransactionTemplate(tm);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jt.execute((SessionCallback<Void>) sess -> {
assertThat(session).isSameAs(sess);
return null;
});
}
});
tm.commit(ts);
verify(session).commit();
verify(session).close();
verify(con).close();
}
use of jakarta.jms.JMSException in project spring-framework by spring-projects.
the class JmsTransactionManagerTests method testTransactionSuspension.
@Test
public void testTransactionSuspension() throws JMSException {
final ConnectionFactory cf = mock(ConnectionFactory.class);
Connection con = mock(Connection.class);
final Session session = mock(Session.class);
final Session session2 = mock(Session.class);
given(cf.createConnection()).willReturn(con);
given(con.createSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session, session2);
JmsTransactionManager tm = new JmsTransactionManager(cf);
TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
final JmsTemplate jt = new JmsTemplate(cf);
jt.execute((SessionCallback<Void>) sess -> {
assertThat(session).isSameAs(sess);
return null;
});
TransactionTemplate tt = new TransactionTemplate(tm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
jt.execute((SessionCallback<Void>) sess -> {
assertThat(session).isNotSameAs(sess);
return null;
});
}
});
jt.execute((SessionCallback<Void>) sess -> {
assertThat(session).isSameAs(sess);
return null;
});
tm.commit(ts);
verify(session).commit();
verify(session2).commit();
verify(session).close();
verify(session2).close();
verify(con, times(2)).close();
}
use of jakarta.jms.JMSException in project spring-framework by spring-projects.
the class JmsMessagingTemplateTests method createTextMessage.
protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
Session mock = mock(Session.class);
given(mock.createTextMessage(any())).willAnswer((Answer<TextMessage>) invocation -> new StubTextMessage((String) invocation.getArguments()[0]));
jakarta.jms.Message message = creator.createMessage(mock);
verify(mock).createTextMessage(any());
return (TextMessage) message;
}
use of jakarta.jms.JMSException in project spring-framework by spring-projects.
the class JmsUtils method buildExceptionMessage.
/**
* Build a descriptive exception message for the given JMSException,
* incorporating a linked exception's message if appropriate.
* @param ex the JMSException to build a message for
* @return the descriptive message String
* @see jakarta.jms.JMSException#getLinkedException()
*/
public static String buildExceptionMessage(JMSException ex) {
String message = ex.getMessage();
Exception linkedEx = ex.getLinkedException();
if (linkedEx != null) {
if (message == null) {
message = linkedEx.toString();
} else {
String linkedMessage = linkedEx.getMessage();
if (linkedMessage != null && !message.contains(linkedMessage)) {
message = message + "; nested exception is " + linkedEx;
}
}
}
return message;
}
Aggregations