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.module.cxf.payload;
8   
9   import org.mule.api.MuleContext;
10  import org.mule.api.MuleException;
11  import org.mule.api.MuleMessage;
12  import org.mule.module.client.MuleClient;
13  
14  import static org.junit.Assert.assertEquals;
15  
16  class CallAndExpectPayloadResult implements CallAndExpect
17  {
18      private Object expectedPayloadResult;
19      private String outputEndpointName;
20      private Object payload;
21      private final MuleContext muleContext;
22  
23      public CallAndExpectPayloadResult(String outputEndpointName,
24                                        Object payload,
25                                        Object expectedPayloadResult,
26                                        MuleContext muleContext)
27      {
28          this.expectedPayloadResult = expectedPayloadResult;
29          this.outputEndpointName = outputEndpointName;
30          this.payload = payload;
31          this.muleContext = muleContext;
32      }
33  
34      public void callEndpointAndExecuteAsserts() throws MuleException
35      {
36          MuleClient client = new MuleClient(muleContext);
37          MuleMessage result = client.send(outputEndpointName, payload, null);
38  
39          assertEquals(here(), expectedPayloadResult, result.getPayload());
40      }
41  
42      private String here()
43      {
44          return "In [" + outputEndpointName + "," + payload + "," + expectedPayloadResult + "]";
45      }
46  }