View Javadoc

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