View Javadoc

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