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.test.integration.transport.cxf;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.module.cxf.support.OutputPayloadInterceptor;
12  import org.mule.tck.junit4.FunctionalTestCase;
13  import org.mule.tck.testmodels.mule.TestExceptionStrategy;
14  import org.mule.tck.testmodels.mule.TestExceptionStrategy.ExceptionCallback;
15  import org.mule.util.concurrent.Latch;
16  
17  import java.util.concurrent.atomic.AtomicInteger;
18  
19  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
20  import org.junit.Test;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertFalse;
24  import static org.junit.Assert.assertNotNull;
25  
26  public class CxfAndXslTransformerOnSoapTestCase extends FunctionalTestCase
27  {
28      private static final String msg = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:emop=\"http://www.wcs.com/2010/07/14/emop\">"
29                         + "  <soapenv:Header>\n"
30                         + "    <header UserName=\"nothing\" Password=\"important\"/>\n"
31                         + "  </soapenv:Header>\n"
32                         + "  <soapenv:Body>\n"
33                         + "    <emop:ScratchcardValidateAndPayRequestBody>\n"
34                         + "       <ScratchcardNumber>1</ScratchcardNumber>\n"
35                         + "       <VirnNumber>2</VirnNumber>\n"
36                         + "    </emop:ScratchcardValidateAndPayRequestBody>\n"
37                         + "  </soapenv:Body>\n"
38                         + "</soapenv:Envelope>";
39  
40      private final AtomicInteger connectorExceptionCounter = new AtomicInteger();
41  
42      @Override
43      protected void doSetUp() throws Exception
44      {
45          super.doSetUp();
46          connectorExceptionCounter.set(0);
47      }
48  
49      @Override
50      protected String getConfigResources()
51      {
52          return "org/mule/test/integration/transport/cxf/scratchcard-service-v1.xml";
53      }
54  
55      /**
56       * This test fails without the change involving the
57       * {@link OutputPayloadInterceptor#cleanUpPayload(Object)}. It is a fix for issue
58       * MULE-5030.
59       * 
60       * @throws Exception
61       */
62      @Test
63      public void testUsesTransformersCorrectly() throws Exception
64      {
65          TestExceptionStrategy exceptionStrategy = new TestExceptionStrategy();
66          muleContext.setExceptionListener(exceptionStrategy);
67  
68          MuleClient client = new MuleClient(muleContext);
69          MuleMessage result = client.send("http://localhost:28181/ScratchCardServiceV1", msg, null);
70          assertNotNull("The result shouln't have been null", result);
71          final String payloadAsString = result.getPayloadAsString();
72          assertNotNull("The payloadAsString shouln't have been null", payloadAsString);
73          assertFalse("There shouldn't be a fault in the payload: " + payloadAsString,
74              payloadAsString.contains("<soap:Fault>"));
75  
76          final Latch latch = new Latch();
77          exceptionStrategy.setExceptionCallback(new ExceptionCallback()
78          {
79              public void onException(Throwable t)
80              {
81                  connectorExceptionCounter.incrementAndGet();
82                  latch.countDown();
83              }
84          });
85  
86          latch.await(500, TimeUnit.MILLISECONDS);
87          assertEquals("There shouldn't have been any exceptions", 0, connectorExceptionCounter.get());
88      }
89  }
90  
91