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.routing.nested;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.module.client.MuleClient;
11  import org.mule.tck.junit4.FunctionalTestCase;
12  
13  import org.junit.Test;
14  
15  import static org.junit.Assert.assertEquals;
16  import static org.junit.Assert.assertNotNull;
17  import static org.junit.Assert.assertNull;
18  import static org.junit.Assert.assertTrue;
19  
20  public class BindingReturnTypeTestCase extends FunctionalTestCase
21  {
22  
23      private static final String PROCESSED = "Processed";
24      private static final int MAGIC_NUMBER = 0xC0DE;
25  
26      @Override
27      protected String getConfigResources()
28      {
29          return "org/mule/test/integration/routing/nested/binding-returns-message.xml";
30      }
31  
32      @Test
33      public void testInvokeBinding() throws Exception
34      {
35          MuleClient client = new MuleClient(muleContext);
36          MuleMessage response = client.send("vm://invoker.in", TEST_MESSAGE, null);
37          assertNotNull(response);
38          assertNull(response.getExceptionPayload());
39          //TODO MULE-4990 this should really be in the inbound scope 
40          assertTrue(response.getInboundProperty(PROCESSED, false));
41          //assertTrue(response.getOutboundProperty(PROCESSED, false));
42          String expected = "Hello " + TEST_MESSAGE + " " + MAGIC_NUMBER;
43          assertEquals(expected, response.getPayload());
44      }
45  
46      public static class Component
47      {
48          private BindingInterface binding;
49  
50          public Object invoke(String s)
51          {
52              MuleMessage result = binding.process(s, new Integer(MAGIC_NUMBER));
53              result.setOutboundProperty(PROCESSED, Boolean.TRUE);
54              return result;
55          }
56          
57          public void setBindingInterface(BindingInterface hello)
58          {
59              this.binding = hello;
60          }
61  
62          public BindingInterface getBindingInterface()
63          {
64              return binding;
65          }
66      }
67      
68      public interface BindingInterface
69      {
70          MuleMessage process(String s, Integer v);
71      }
72      
73  }
74  
75