View Javadoc

1   /*
2    * $Id: CxfAndXslTransformerOnSoapTestCase.java 22431 2011-07-18 07:40:35Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.test.integration.transport.cxf;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.module.cxf.support.OutputPayloadInterceptor;
16  import org.mule.tck.AbstractServiceAndFlowTestCase;
17  import org.mule.tck.testmodels.mule.TestExceptionStrategy;
18  import org.mule.tck.testmodels.mule.TestExceptionStrategy.ExceptionCallback;
19  import org.mule.util.concurrent.Latch;
20  
21  import java.util.Arrays;
22  import java.util.Collection;
23  import java.util.concurrent.TimeUnit;
24  import java.util.concurrent.atomic.AtomicInteger;
25  
26  import org.junit.Test;
27  import org.junit.runners.Parameterized.Parameters;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.assertFalse;
31  import static org.junit.Assert.assertNotNull;
32  
33  public class CxfAndXslTransformerOnSoapTestCase extends AbstractServiceAndFlowTestCase
34  {
35      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\">"
36                         + "  <soapenv:Header>\n"
37                         + "    <header UserName=\"nothing\" Password=\"important\"/>\n"
38                         + "  </soapenv:Header>\n"
39                         + "  <soapenv:Body>\n"
40                         + "    <emop:ScratchcardValidateAndPayRequestBody>\n"
41                         + "       <ScratchcardNumber>1</ScratchcardNumber>\n"
42                         + "       <VirnNumber>2</VirnNumber>\n"
43                         + "    </emop:ScratchcardValidateAndPayRequestBody>\n"
44                         + "  </soapenv:Body>\n"
45                         + "</soapenv:Envelope>";
46  
47      private final AtomicInteger connectorExceptionCounter = new AtomicInteger();
48  
49      @Parameters
50      public static Collection<Object[]> parameters()
51      {
52          return Arrays.asList(new Object[][]{
53              {ConfigVariant.SERVICE,
54                  "org/mule/test/integration/transport/cxf/scratchcard-service-v1-service.xml"},
55              {ConfigVariant.FLOW, "org/mule/test/integration/transport/cxf/scratchcard-service-v1-flow.xml"}});
56      }
57  
58      public CxfAndXslTransformerOnSoapTestCase(ConfigVariant variant, String configResources)
59      {
60          super(variant, configResources);
61      }
62  
63      @Override
64      protected void doSetUp() throws Exception
65      {
66          super.doSetUp();
67          connectorExceptionCounter.set(0);
68      }
69  
70      /**
71       * This test fails without the change involving the
72       * {@link OutputPayloadInterceptor#cleanUpPayload(Object)}. It is a fix for issue
73       * MULE-5030.
74       *
75       * @throws Exception
76       */
77      @Test
78      public void testUsesTransformersCorrectly() throws Exception
79      {
80          TestExceptionStrategy exceptionStrategy = new TestExceptionStrategy();
81          muleContext.setExceptionListener(exceptionStrategy);
82  
83          MuleClient client = new MuleClient(muleContext);
84          MuleMessage result = client.send("http://localhost:28181/ScratchCardServiceV1", msg, null);
85          assertNotNull("The result shouln't have been null", result);
86          final String payloadAsString = result.getPayloadAsString();
87          assertNotNull("The payloadAsString shouln't have been null", payloadAsString);
88          assertFalse("There shouldn't be a fault in the payload: " + payloadAsString,
89              payloadAsString.contains("<soap:Fault>"));
90  
91          final Latch latch = new Latch();
92          exceptionStrategy.setExceptionCallback(new ExceptionCallback()
93          {
94              @Override
95              public void onException(Throwable t)
96              {
97                  connectorExceptionCounter.incrementAndGet();
98                  latch.countDown();
99              }
100         });
101 
102         latch.await(500, TimeUnit.MILLISECONDS);
103         assertEquals("There shouldn't have been any exceptions", 0, connectorExceptionCounter.get());
104     }
105 }