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