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.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.transport.DispatchException;
12  import org.mule.module.client.MuleClient;
13  import org.mule.tck.junit4.FunctionalTestCase;
14  import org.mule.tck.junit4.rule.DynamicPort;
15  import org.mule.tck.testmodels.services.TestComponent;
16  import org.mule.tck.testmodels.services.TestComponentException;
17  
18  import org.junit.Rule;
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  import static org.junit.Assert.fail;
25  
26  public class AxisExceptionTestCase extends FunctionalTestCase
27  {
28  
29      @Rule
30      public DynamicPort dynamicPort1 = new DynamicPort("port1");
31  
32      @Rule
33      public DynamicPort dynamicPort2 = new DynamicPort("port2");
34      
35      @Override
36      protected String getConfigResources()
37      {
38          return "axis-using-cxf-config.xml";
39      }
40  
41      @Test
42      public void testSuccessCall() throws Exception
43      {
44          MuleClient client = new MuleClient(muleContext);
45          MuleMessage reply = client.send("axis:http://localhost:" + dynamicPort1.getNumber() + "/services/AxisService?method=receive",
46              new DefaultMuleMessage("test", muleContext));
47  
48          assertNotNull(reply);
49          assertNotNull(reply.getPayload());
50          assertTrue(reply.getPayload() instanceof String);
51          assertEquals("Received: test", reply.getPayloadAsString());
52      }
53  
54      @Test
55      public void testExceptionCall() throws Exception
56      {
57          MuleClient client = new MuleClient(muleContext);
58          try
59          {
60              client.send("axis:http://localhost:" + dynamicPort1.getNumber() + "/services/AxisService?method=throwsException", new DefaultMuleMessage("test", muleContext));
61              fail("should have thrown exception");
62          }
63          catch (DispatchException e)
64          {
65              assertEquals(TestComponentException.class.getName() + ": "
66                           + TestComponentException.MESSAGE_PREFIX + TestComponent.EXCEPTION_MESSAGE, e.getCause().getMessage());
67          }
68      }
69  
70      @Test
71      public void testExceptionBasedRoutingForAxis() throws Exception
72      {
73          MuleClient client = new MuleClient(muleContext);
74          MuleMessage reply = client.send("vm://localhost.test", new DefaultMuleMessage("test", muleContext));
75  
76          assertNotNull(reply);
77          assertNotNull(reply.getPayload());
78          assertTrue(reply.getPayload() instanceof String);
79          assertEquals("Received: test", reply.getPayloadAsString());
80      }
81  
82  }