View Javadoc

1   /*
2    * $Id: AxisExceptionTestCase.java 19857 2010-10-06 21:40:07Z dzapata $
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.transport.soap.axis;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.transport.DispatchException;
16  import org.mule.module.client.MuleClient;
17  import org.mule.tck.DynamicPortTestCase;
18  import org.mule.tck.testmodels.services.TestComponent;
19  import org.mule.tck.testmodels.services.TestComponentException;
20  
21  public class AxisExceptionTestCase extends DynamicPortTestCase
22  {
23      @Override
24      protected String getConfigResources()
25      {
26          return "axis-using-cxf-config.xml";
27      }
28  
29      public void testSuccessCall() throws Exception
30      {
31          MuleClient client = new MuleClient(muleContext);
32          MuleMessage reply = client.send("axis:http://localhost:" + getPorts().get(0) + "/services/AxisService?method=receive",
33              new DefaultMuleMessage("test", muleContext));
34  
35          assertNotNull(reply);
36          assertNotNull(reply.getPayload());
37          assertTrue(reply.getPayload() instanceof String);
38          assertEquals("Received: test", reply.getPayloadAsString());
39      }
40  
41      public void testExceptionCall() throws Exception
42      {
43          MuleClient client = new MuleClient(muleContext);
44          try
45          {
46              client.send("axis:http://localhost:" + getPorts().get(0) + "/services/AxisService?method=throwsException", new DefaultMuleMessage("test", muleContext));
47              fail("should have thrown exception");
48          }
49          catch (DispatchException e)
50          {
51              assertEquals(TestComponentException.class.getName() + ": "
52                           + TestComponentException.MESSAGE_PREFIX + TestComponent.EXCEPTION_MESSAGE, e.getCause().getMessage());
53          }
54      }
55  
56      public void testExceptionBasedRoutingForAxis() throws Exception
57      {
58          MuleClient client = new MuleClient(muleContext);
59          MuleMessage reply = client.send("vm://localhost.test", new DefaultMuleMessage("test", muleContext));
60  
61          assertNotNull(reply);
62          assertNotNull(reply.getPayload());
63          assertTrue(reply.getPayload() instanceof String);
64          assertEquals("Received: test", reply.getPayloadAsString());
65      }
66  
67      @Override
68      protected int getNumPortsToFind()
69      {
70          return 2;
71      }
72  }