View Javadoc

1   /*
2    * $Id: UnwrapsComponentExceptionTestCase.java 22728 2011-08-24 15:51:41Z pablo.kraan $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, 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.module.cxf.functional;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.client.LocalMuleClient;
16  import org.mule.module.cxf.example.HelloWorld;
17  import org.mule.tck.junit4.FunctionalTestCase;
18  import org.mule.tck.junit4.rule.DynamicPort;
19  
20  import java.util.Map;
21  
22  import javax.jws.WebService;
23  
24  import org.junit.Rule;
25  import org.junit.Test;
26  
27  import static org.junit.Assert.assertTrue;
28  
29  public class UnwrapsComponentExceptionTestCase extends FunctionalTestCase
30  {
31  
32      public static final String ERROR_MESSAGE = "Changos!!!";
33  
34      private static final String requestPayload =
35              "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
36              "           xmlns:hi=\"http://example.cxf.module.mule.org/\">\n" +
37              "<soap:Body>\n" +
38              "<hi:sayHi>\n" +
39              "    <arg0>Hello</arg0>\n" +
40              "</hi:sayHi>\n" +
41              "</soap:Body>\n" +
42              "</soap:Envelope>";
43  
44      @Rule
45      public DynamicPort dynamicPort = new DynamicPort("port1");
46  
47      @Override
48      protected String getConfigResources()
49      {
50          return "unwraps-component-exception-config.xml";
51      }
52  
53      @Test
54      public void testReceivesComponentExceptionMessage() throws Exception
55      {
56          MuleMessage request = new DefaultMuleMessage(requestPayload, (Map<String, Object>) null, muleContext);
57          LocalMuleClient client = muleContext.getClient();
58          MuleMessage received = client.send("http://localhost:" + dynamicPort.getNumber() + "/hello", request);
59  
60          assertTrue("Component exception was not managed", received.getPayloadAsString().contains(ERROR_MESSAGE));
61      }
62  
63      @WebService(endpointInterface = "org.mule.module.cxf.example.HelloWorld", serviceName = "HelloWorld")
64      public static class HelloWorldImpl implements HelloWorld
65      {
66  
67          public String sayHi(String text)
68          {
69              throw new RuntimeException(ERROR_MESSAGE);
70          }
71      }
72  }