Search in sources :

Example 41 with TransportOutDescription

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());
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ArrayList(java.util.ArrayList) Transaction(javax.transaction.Transaction) ArrayList(java.util.ArrayList) List(java.util.List) MessageContext(org.apache.axis2.context.MessageContext) Session(javax.jms.Session) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Aggregations

TransportOutDescription (org.apache.axis2.description.TransportOutDescription)28 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)20 Parameter (org.apache.axis2.description.Parameter)17 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)16 MessageContext (org.apache.axis2.context.MessageContext)11 AxisFault (org.apache.axis2.AxisFault)9 QName (javax.xml.namespace.QName)7 OMElement (org.apache.axiom.om.OMElement)6 AxisService (org.apache.axis2.description.AxisService)6 TransportInDescription (org.apache.axis2.description.TransportInDescription)6 IOException (java.io.IOException)4 Map (java.util.Map)4 ServiceContext (org.apache.axis2.context.ServiceContext)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)3 OperationContext (org.apache.axis2.context.OperationContext)3 InOutAxisOperation (org.apache.axis2.description.InOutAxisOperation)3 OutTransportInfo (org.apache.axis2.transport.OutTransportInfo)3 VFSOutTransportInfo (org.apache.synapse.commons.vfs.VFSOutTransportInfo)3