View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport.soap.axis;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.transport.MuleMessageFactory;
11  import org.mule.transport.AbstractMuleMessageFactoryTestCase;
12  import org.mule.transport.soap.axis.mock.MockAxisEngine;
13  import org.mule.transport.soap.axis.mock.MockEngineConfiguration;
14  
15  import org.apache.axis.EngineConfiguration;
16  import org.apache.axis.Message;
17  import org.apache.axis.MessageContext;
18  import org.junit.Test;
19  
20  import static org.junit.Assert.assertEquals;
21  
22  public class AxisMuleMessageFactoryTestCase extends AbstractMuleMessageFactoryTestCase
23  {
24      private static final String XML_WITH_HEADERS =
25            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
26          + "    <soapenv:Header>"
27          + "        <mule:header soapenv:actor=\"http://www.muleumo.org/providers/soap/1.0\" soapenv:mustUnderstand=\"0\" xmlns:mule=\"http://www.muleumo.org/providers/soap/1.0\">"        
28          + "            <mule:MULE_REPLYTO>replyTo</mule:MULE_REPLYTO>"
29          + "            <mule:MULE_CORRELATION_ID>004a1cf9-3e7e-44b3-9b7f-778fae4fa0d2</mule:MULE_CORRELATION_ID>"
30          + "            <mule:MULE_CORRELATION_GROUP_SIZE>42</mule:MULE_CORRELATION_GROUP_SIZE>"
31          + "            <mule:MULE_CORRELATION_SEQUENCE>-42</mule:MULE_CORRELATION_SEQUENCE>"
32          + "        </mule:header>"
33          + "    </soapenv:Header>"
34          + "    <soapenv:Body>"
35          + "        <echo soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
36          + "            <value0 xsi:type=\"soapenc:string\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">"
37          + "                Hello"
38          + "            </value0>"
39          + "        </echo>"
40          + "    </soapenv:Body>"
41          + "</soapenv:Envelope>";
42      
43      public AxisMuleMessageFactoryTestCase()
44      {
45          super();
46          runUnsuppoprtedTransportMessageTest = false;
47      }
48      
49      @Override
50      protected void doSetUp() throws Exception
51      {
52          super.doSetUp();
53          setupAxisMessageContext();
54      }
55  
56      @Override
57      protected MuleMessageFactory doCreateMuleMessageFactory()
58      {
59          return new AxisMuleMessageFactory(muleContext);
60      }
61  
62      @Override
63      protected Object getValidTransportMessage() throws Exception
64      {
65          return new Message(XML_WITH_HEADERS);
66      }
67  
68      @Test
69      public void testSoapHeaders() throws Exception
70      {
71          MuleMessageFactory factory = createMuleMessageFactory();
72          Object payload = getValidTransportMessage();
73          MuleMessage message = factory.create(payload, encoding);
74          assertEquals(payload, message.getPayload());
75          assertEquals("replyTo", message.getReplyTo());
76          assertEquals(42, message.getCorrelationGroupSize());
77          assertEquals(-42, message.getCorrelationSequence());
78          assertEquals("004a1cf9-3e7e-44b3-9b7f-778fae4fa0d2", message.getCorrelationId());
79      }
80      
81      private void setupAxisMessageContext()
82      {
83          EngineConfiguration configuration = new MockEngineConfiguration();
84          MockAxisEngine engine = new MockAxisEngine(configuration);
85          MessageContext messageContext = new MessageContext(engine);
86          MockAxisEngine.setCurrentMessageContext(messageContext);
87          
88          Message soapMessage = new Message(XML_WITH_HEADERS);
89          messageContext.setMessage(soapMessage);        
90      }
91  }