View Javadoc

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