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