View Javadoc

1   /*
2    * $Id: ExplicitMethodEntryPointResolverTestCase.java 20321 2010-11-24 15:21:24Z 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  package org.mule.mule.model;
11  
12  import org.mule.api.MuleEventContext;
13  import org.mule.api.model.InvocationResult;
14  import org.mule.model.resolvers.ExplicitMethodEntryPointResolver;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.tck.testmodels.fruit.Apple;
17  import org.mule.tck.testmodels.fruit.Fruit;
18  
19  public class ExplicitMethodEntryPointResolverTestCase extends AbstractMuleTestCase
20  {
21      public void testMethodSetPass() throws Exception
22      {
23          ExplicitMethodEntryPointResolver resolver = new ExplicitMethodEntryPointResolver();
24          resolver.addMethod("someBusinessMethod");
25          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), getTestEventContext("blah"));
26          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
27      }
28  
29      public void testMethodSetMatchFirst() throws Exception
30      {
31          ExplicitMethodEntryPointResolver resolver = new ExplicitMethodEntryPointResolver();
32          resolver.addMethod("someBusinessMethod");
33          resolver.addMethod("someSetter");
34          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), getTestEventContext("blah"));
35          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
36      }
37  
38      public void testMethodNotFound() throws Exception
39      {
40          ExplicitMethodEntryPointResolver resolver = new ExplicitMethodEntryPointResolver();
41          resolver.addMethod("noMethod");
42          resolver.addMethod("noMethod2");
43          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), getTestEventContext("blah"));
44          assertEquals(result.getState(), InvocationResult.State.FAILED);
45      }
46  
47      public void testNoMethodSet() throws Exception
48      {
49          ExplicitMethodEntryPointResolver resolver = new ExplicitMethodEntryPointResolver();
50          try
51          {
52              resolver.invoke(new MultiplePayloadsTestObject(), getTestEventContext("blah"));
53              fail("method property is not set, this should cause an error");
54          }
55          catch (IllegalStateException e)
56          {
57              //Expected
58          }
59      }
60      
61      /**
62       * If a method with correct name is available then it should be used is the
63       * parameter type is assignable from the payload type and not just if there is an
64       * exact match. See MULE-3636.
65       * 
66       * @throws Exception
67       */
68      public void testMethodPropertyParameterAssignableFromPayload() throws Exception
69      {
70          ExplicitMethodEntryPointResolver resolver = new ExplicitMethodEntryPointResolver();
71          resolver.addMethod("wash");
72          MuleEventContext ctx = getTestEventContext(new Apple());
73          InvocationResult result = resolver.invoke(new TestFruitCleaner(), ctx);
74          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
75      }
76  
77      public static class TestFruitCleaner
78      {
79          public void wash(Fruit fruit)
80          {
81              // dummy
82          }
83  
84          public void polish(Fruit fruit)
85          {
86              // dummy
87          }
88      }
89  }