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.resolvers;
8   
9   import org.mule.DefaultMuleMessage;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.config.MuleProperties;
12  import org.mule.model.resolvers.EntryPointNotFoundException;
13  import org.mule.module.client.MuleClient;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  
16  import java.util.HashMap;
17  import java.util.Map;
18  
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertEquals;
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  public class MethodEntryPointsTestCase extends FunctionalTestCase
26  {
27  
28      @Override
29      protected String getConfigResources()
30      {
31          return "org/mule/test/integration/resolvers/method-entrypoints-config.xml";
32      }
33  
34      @Test
35      public void testTooManySatisfiableMethods() throws Exception
36      {
37          MuleClient client = new MuleClient(muleContext);
38          MuleMessage message = client.send("vm://service", "hello", null);
39          assertNotNull(message.getExceptionPayload());
40          assertTrue(message.getExceptionPayload().getException().getCause() instanceof EntryPointNotFoundException);
41          assertTrue(message.getExceptionPayload().getException().getCause().getMessage().indexOf("Found too many possible methods on object") > -1);
42      }
43  
44      @Test
45      public void testBadMethodName() throws Exception
46      {
47          MuleClient client = new MuleClient(muleContext);
48          MuleMessage message = client.send("vm://service?method=foo", "hello", null);
49          assertNotNull(message.getExceptionPayload());
50          assertTrue(message.getExceptionPayload().getException().getCause() instanceof EntryPointNotFoundException);
51      }
52  
53      @Test
54      public void testValidCallToReverse() throws Exception
55      {
56          MuleClient client = new MuleClient(muleContext);
57          DefaultMuleMessage msg = new DefaultMuleMessage("hello", muleContext);
58          msg.setOutboundProperty("method", "reverseString");
59          MuleMessage message = client.send("vm://service", msg);
60          assertNotNull(message);
61          assertEquals("olleh", message.getPayloadAsString());
62      }
63  
64      @Test
65      public void testValidCallToUpperCase() throws Exception
66      {
67          MuleClient client = new MuleClient(muleContext);
68          DefaultMuleMessage msg = new DefaultMuleMessage("hello", muleContext);
69          msg.setOutboundProperty("method", "upperCaseString");
70          MuleMessage message = client.send("vm://service", msg);
71          assertNotNull(message);
72          assertEquals("HELLO", message.getPayloadAsString());
73      }
74  
75  
76      @Test
77      public void testValidCallToReverseMethodSetOnEndpoint() throws Exception
78      {
79          MuleClient client = new MuleClient(muleContext);
80          MuleMessage message = client.send("vm://service2-reverseString", "hello", null);
81          assertNotNull(message);
82          assertEquals("olleh", message.getPayloadAsString());
83      }
84  
85      @Test
86      public void testValidCallToUpperCaseMethodSetOnEndpoint() throws Exception
87      {
88          MuleClient client = new MuleClient(muleContext);
89          MuleMessage message = client.send("vm://service2-upperCaseString", "hello", null);
90          assertNotNull(message);
91          assertEquals(message.getPayloadAsString(), "HELLO");
92      }
93  
94      @Test
95      public void testValidCallToReverseMethodSetAsHeader() throws Exception
96      {
97          MuleClient client = new MuleClient(muleContext);
98          Map props = new HashMap();
99          props.put(MuleProperties.MULE_METHOD_PROPERTY, "reverseString");
100         MuleMessage message = client.send("vm://service", "hello", props);
101         assertNotNull(message);
102         assertEquals("olleh", message.getPayloadAsString());
103     }
104 
105     @Test
106     public void testValidCallToUpperCaseMethodSetAsHeader() throws Exception
107     {
108         MuleClient client = new MuleClient(muleContext);
109         Map props = new HashMap();
110         props.put(MuleProperties.MULE_METHOD_PROPERTY, "upperCaseString");
111         MuleMessage message = client.send("vm://service", "hello", props);
112         assertNotNull(message);
113         assertEquals("HELLO", message.getPayloadAsString());
114     }
115 
116 }