View Javadoc

1   /*
2    * $Id: MethodEntryPointsTestCase.java 22735 2011-08-25 16:02:35Z dfeist $
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 static org.junit.Assert.assertEquals;
14  import static org.junit.Assert.assertNotNull;
15  import static org.junit.Assert.assertTrue;
16  
17  import org.mule.DefaultMuleMessage;
18  import org.mule.api.MuleMessage;
19  import org.mule.api.config.MuleProperties;
20  import org.mule.model.resolvers.EntryPointNotFoundException;
21  import org.mule.module.client.MuleClient;
22  import org.mule.tck.AbstractServiceAndFlowTestCase;
23  import org.mule.util.ExceptionUtils;
24  
25  import java.util.Arrays;
26  import java.util.Collection;
27  import java.util.HashMap;
28  import java.util.Map;
29  
30  import org.junit.Test;
31  import org.junit.runners.Parameterized.Parameters;
32  
33  public class MethodEntryPointsTestCase extends AbstractServiceAndFlowTestCase
34  {
35      @Parameters
36      public static Collection<Object[]> parameters()
37      {
38          return Arrays.asList(new Object[][]{
39              {ConfigVariant.SERVICE, "org/mule/test/integration/resolvers/method-entrypoints-config-service.xml"},
40              {ConfigVariant.FLOW, "org/mule/test/integration/resolvers/method-entrypoints-config-flow.xml"}
41          });
42      }
43  
44      public MethodEntryPointsTestCase(ConfigVariant variant, String configResources)
45      {
46          super(variant, configResources);
47      }
48  
49      @Test
50      public void testTooManySatisfiableMethods() throws Exception
51      {
52          MuleMessage message = muleContext.getClient().send("vm://service", "hello", null);
53          assertNotNull(message);
54          assertNotNull(message.getExceptionPayload());
55          assertEquals(EntryPointNotFoundException.class, message.getExceptionPayload()
56              .getRootException()
57              .getClass());
58          assertTrue(ExceptionUtils.getRootCauseMessage(message.getExceptionPayload().getException()).indexOf(
59              "Found too many possible methods on object") > -1);
60      }
61  
62      @Test
63      public void testBadMethodName() throws Exception
64      {
65          MuleMessage message = muleContext.getClient().send("vm://service?method=foo", "hello", null);
66          assertNotNull(message);
67          assertNotNull(message.getExceptionPayload());
68          assertEquals(EntryPointNotFoundException.class, message.getExceptionPayload()
69              .getRootException()
70              .getClass());
71      }
72  
73      @Test
74      public void testValidCallToReverse() throws Exception
75      {
76          MuleClient client = new MuleClient(muleContext);
77          DefaultMuleMessage msg = new DefaultMuleMessage("hello", muleContext);
78          msg.setOutboundProperty("method", "reverseString");
79          MuleMessage message = client.send("vm://service", msg);
80          assertNotNull(message);
81          assertEquals("olleh", message.getPayloadAsString());
82      }
83  
84      @Test
85      public void testValidCallToUpperCase() throws Exception
86      {
87          MuleClient client = new MuleClient(muleContext);
88          DefaultMuleMessage msg = new DefaultMuleMessage("hello", muleContext);
89          msg.setOutboundProperty("method", "upperCaseString");
90          MuleMessage message = client.send("vm://service", msg);
91          assertNotNull(message);
92          assertEquals("HELLO", message.getPayloadAsString());
93      }
94  
95      @Test
96      public void testValidCallToReverseMethodSetOnEndpoint() throws Exception
97      {
98          MuleClient client = new MuleClient(muleContext);
99          MuleMessage message = client.send("vm://service2-reverseString", "hello", null);
100         assertNotNull(message);
101         assertEquals("olleh", message.getPayloadAsString());
102     }
103 
104     @Test
105     public void testValidCallToUpperCaseMethodSetOnEndpoint() throws Exception
106     {
107         MuleClient client = new MuleClient(muleContext);
108         MuleMessage message = client.send("vm://service2-upperCaseString", "hello", null);
109         assertNotNull(message);
110         assertEquals(message.getPayloadAsString(), "HELLO");
111     }
112 
113     @Test
114     public void testValidCallToReverseMethodSetAsHeader() throws Exception
115     {
116         MuleClient client = new MuleClient(muleContext);
117         Map<String, Object> props = new HashMap<String, Object>();
118         props.put(MuleProperties.MULE_METHOD_PROPERTY, "reverseString");
119         MuleMessage message = client.send("vm://service", "hello", props);
120         assertNotNull(message);
121         assertEquals("olleh", message.getPayloadAsString());
122     }
123 
124     @Test
125     public void testValidCallToUpperCaseMethodSetAsHeader() throws Exception
126     {
127         MuleClient client = new MuleClient(muleContext);
128         Map<String, Object> props = new HashMap<String, Object>();
129         props.put(MuleProperties.MULE_METHOD_PROPERTY, "upperCaseString");
130         MuleMessage message = client.send("vm://service", "hello", props);
131         assertNotNull(message);
132         assertEquals("HELLO", message.getPayloadAsString());
133     }
134 
135 }