View Javadoc

1   /*
2    * $Id: MuleClientRemotingAxisTestCase.java 19943 2010-10-15 15:59:38Z aperepel $
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.test.integration.client;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.endpoint.InboundEndpoint;
15  import org.mule.module.client.MuleClient;
16  import org.mule.module.client.RemoteDispatcher;
17  import org.mule.module.xml.transformer.wire.XStreamWireFormat;
18  import org.mule.tck.DynamicPortTestCase;
19  import org.mule.tck.testmodels.services.Person;
20  
21  public class MuleClientRemotingAxisTestCase extends DynamicPortTestCase
22  {
23  
24      @Override
25      protected String getConfigResources()
26      {
27          return "org/mule/test/integration/client/axis-client-test-mule-config.xml";
28      }
29      
30      /**
31       * Get the Mule address for a Mule client call
32       * 
33       * @param muleClient The MuleClient instance to use
34       * @param inboundEndpointName The inbound endpoint which contains the address
35       * @return A String of the 'Mule' address, which in this case should include
36       *         'axis" + 'http://<url>'
37       */
38      private String getMuleAddress(MuleClient muleClient, String inboundEndpointName)
39      {
40          return ((InboundEndpoint) muleClient.getMuleContext().getRegistry().lookupObject(inboundEndpointName)).getProtocol()
41                 + ":"
42                 + ((InboundEndpoint) muleClient.getMuleContext().getRegistry().lookupObject(
43                     inboundEndpointName)).getAddress();
44      }
45  
46      public void testRequestResponse() throws Throwable
47      {
48          MuleClient client = new MuleClient(muleContext);
49          RemoteDispatcher dispatcher = client.getRemoteDispatcher("remoteEndpoint");
50          try
51          {
52              MuleMessage result = dispatcher.sendRemote(
53                  getMuleAddress(client, "inMyComponent2") + "/mycomponent2?method=echo", "test", null);
54              assertNotNull(result);
55              assertEquals("test", result.getPayloadAsString());
56          }
57          finally
58          {
59              client.dispose();
60          }
61      }
62  
63      // this test is disabled because of MULE-4844
64      public void _testRequestResponseComplex() throws Exception
65      {
66          MuleClient client = new MuleClient(muleContext);
67          RemoteDispatcher dispatcher = client.getRemoteDispatcher("remoteEndpoint");
68          dispatcher.setWireFormat(createObject(XStreamWireFormat.class));
69  
70          try
71          {
72              MuleMessage result = dispatcher.sendRemote(
73                  getMuleAddress(client, "inMyComponent3") + "/mycomponent3?method=getPerson", "Fred", null);
74              assertNotNull(result);
75              assertTrue(result.getPayload() instanceof Person);
76              assertEquals("Fred", ((Person)result.getPayload()).getFirstName());
77              assertEquals("Flintstone", ((Person)result.getPayload()).getLastName());
78          }
79          finally
80          {
81              client.dispose();
82          }
83      }
84  
85      // this test is disabled because of MULE-4844
86      public void _testRequestResponseComplex2() throws Exception
87      {
88          MuleClient client = new MuleClient(muleContext);
89          RemoteDispatcher dispatcher = client.getRemoteDispatcher("remoteEndpoint");
90          dispatcher.setWireFormat(createObject(XStreamWireFormat.class));
91  
92          try
93          {
94              String[] args = new String[]{"Betty", "Rubble"};
95              MuleMessage result = dispatcher.sendRemote(
96                  getMuleAddress(client, "inMyComponent3") + "/mycomponent3?method=addPerson", args, null);
97              assertNotNull(result);
98              assertTrue(result.getPayload() instanceof Person);
99              assertEquals("Betty", ((Person)result.getPayload()).getFirstName());
100             assertEquals("Rubble", ((Person)result.getPayload()).getLastName());
101 
102             // do a receive
103             result = client.send(getMuleAddress(client, "inMyComponent3") + "/mycomponent3?method=getPerson",
104                 "Betty", null);
105             assertNotNull(result);
106             assertTrue(result.getPayload() instanceof Person);
107             assertEquals("Betty", ((Person)result.getPayload()).getFirstName());
108             assertEquals("Rubble", ((Person)result.getPayload()).getLastName());
109         }
110         finally
111         {
112             client.dispose();
113         }
114     }
115 
116     @Override
117     protected int getNumPortsToFind()
118     {
119         return 3;
120     }
121 }