use of org.apache.axis2.description.TransportOutDescription in project wso2-axis2-transports by wso2.
the class JMSSenderTestCase method testTransactionCommandParameter.
/**
* Test case for EI-1244.
* test transport.jms.TransactionCommand parameter in transport url when sending the message.
* This will verify the fixes which prevent possible OOM issue when publishing messages to a broker using jms.
*
* @throws Exception
*/
public void testTransactionCommandParameter() throws Exception {
JMSSender jmsSender = PowerMockito.spy(new JMSSender());
JMSOutTransportInfo jmsOutTransportInfo = Mockito.mock(JMSOutTransportInfo.class);
JMSMessageSender jmsMessageSender = Mockito.mock(JMSMessageSender.class);
Session session = Mockito.mock(Session.class);
Mockito.doReturn(session).when(jmsMessageSender).getSession();
PowerMockito.whenNew(JMSOutTransportInfo.class).withArguments(any(String.class)).thenReturn(jmsOutTransportInfo);
Mockito.doReturn(jmsMessageSender).when(jmsOutTransportInfo).createJMSSender(any(MessageContext.class));
PowerMockito.doReturn(new JMSReplyMessage()).when(jmsSender, "sendOverJMS", ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any());
jmsSender.init(new ConfigurationContext(new AxisConfiguration()), new TransportOutDescription("jms"));
MessageContext messageContext = new MessageContext();
// append the transport.jms.TransactionCommand
String targetAddress = "jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=" + "QueueConnectionFactory&transport.jms.TransactionCommand=begin" + "&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory";
Transaction transaction = new TestJMSTransaction();
messageContext.setProperty(JMSConstants.JMS_XA_TRANSACTION, transaction);
jmsSender.sendMessage(messageContext, targetAddress, null);
Map<Transaction, ArrayList<JMSMessageSender>> jmsMessageSenderMap = Whitebox.getInternalState(JMSSender.class, "jmsMessageSenderMap");
Assert.assertEquals("Transaction not added to map", 1, jmsMessageSenderMap.size());
List senderList = jmsMessageSenderMap.get(transaction);
Assert.assertNotNull("List is null", senderList);
Assert.assertEquals("List is empty", 1, senderList.size());
}
Aggregations