1   /*
2    * $Id: MuleClientRemotingAxisTestCase.java 11377 2008-03-16 18:18:33Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.client;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.module.client.RemoteDispatcher;
16  import org.mule.module.xml.transformer.wire.XStreamWireFormat;
17  import org.mule.tck.FunctionalTestCase;
18  import org.mule.tck.testmodels.services.Person;
19  
20  public class MuleClientRemotingAxisTestCase extends FunctionalTestCase
21  {
22  
23      protected String getConfigResources()
24      {
25          return "org/mule/test/integration/client/axis-client-test-mule-config.xml";
26      }
27  
28      public void testRequestResponse() throws Throwable
29      {
30          MuleClient client = new MuleClient();
31          RemoteDispatcher dispatcher = client.getRemoteDispatcher("remoteEndpoint");
32          try
33          {
34              MuleMessage result = dispatcher.sendRemote(
35                  "axis:http://localhost:38104/mule/services/mycomponent2?method=echo", "test", null);
36              assertNotNull(result);
37              assertEquals("test", result.getPayloadAsString());
38          }
39          finally
40          {
41              client.dispose();
42          }
43      }
44  
45      public void testRequestResponseComplex() throws Exception
46      {
47          MuleClient client = new MuleClient();
48          RemoteDispatcher dispatcher = client.getRemoteDispatcher("remoteEndpoint");
49          dispatcher.setWireFormat(new XStreamWireFormat());
50  
51          try
52          {
53              MuleMessage result = dispatcher.sendRemote(
54                  "axis:http://localhost:38104/mule/services/mycomponent3?method=getPerson", "Fred", null);
55              assertNotNull(result);
56              logger.debug(result.getPayload());
57              assertTrue(result.getPayload() instanceof Person);
58              assertEquals("Fred", ((Person)result.getPayload()).getFirstName());
59              assertEquals("Flintstone", ((Person)result.getPayload()).getLastName());
60          }
61          finally
62          {
63              client.dispose();
64          }
65      }
66  
67      public void testRequestResponseComplex2() throws Exception
68      {
69          MuleClient client = new MuleClient();
70          RemoteDispatcher dispatcher = client.getRemoteDispatcher("remoteEndpoint");
71          dispatcher.setWireFormat(new XStreamWireFormat());
72  
73          try
74          {
75              String[] args = new String[]{"Betty", "Rubble"};
76              MuleMessage result = dispatcher.sendRemote(
77                  "axis:http://localhost:38104/mule/services/mycomponent3?method=addPerson", args, null);
78              assertNotNull(result);
79              assertTrue(result.getPayload() instanceof Person);
80              assertEquals("Betty", ((Person)result.getPayload()).getFirstName());
81              assertEquals("Rubble", ((Person)result.getPayload()).getLastName());
82  
83              // do a receive
84              result = client.send("axis:http://localhost:38104/mule/services/mycomponent3?method=getPerson",
85                  "Betty", null);
86              assertNotNull(result);
87              assertTrue(result.getPayload() instanceof Person);
88              assertEquals("Betty", ((Person)result.getPayload()).getFirstName());
89              assertEquals("Rubble", ((Person)result.getPayload()).getLastName());
90          }
91          finally
92          {
93              client.dispose();
94          }
95      }
96  }