1   /*
2    * $Id: MethodHeaderEntryPointResolverTestCase.java 10489 2008-01-23 17:53:38Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.MethodHeaderPropertyEntryPointResolver;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.tck.testmodels.fruit.Apple;
17  import org.mule.transport.NullPayload;
18  
19  public class MethodHeaderEntryPointResolverTestCase extends AbstractMuleTestCase
20  {
21      public void testMethodSetPass() throws Exception
22      {
23          MethodHeaderPropertyEntryPointResolver resolver = new MethodHeaderPropertyEntryPointResolver();
24          MuleEventContext ctx = getTestEventContext("blah");
25          ctx.getMessage().setProperty("method", "someBusinessMethod");
26          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
27          assertEquals(result.getState(), InvocationResult.STATE_INVOKED_SUCESSFUL);
28      }
29  
30      public void testMethodSetWithNoArgsPass() throws Exception
31      {
32          MethodHeaderPropertyEntryPointResolver resolver = new MethodHeaderPropertyEntryPointResolver();
33          MuleEventContext ctx = getTestEventContext(NullPayload.getInstance());
34          ctx.getMessage().setProperty("method", "wash");
35          InvocationResult result = resolver.invoke(new Apple(), ctx);
36          assertEquals(result.getState(), InvocationResult.STATE_INVOKED_SUCESSFUL);
37          assertEquals("wash", result.getMethodCalled());
38      }
39  
40      public void testCustomMethodProperty() throws Exception
41      {
42          MethodHeaderPropertyEntryPointResolver resolver = new MethodHeaderPropertyEntryPointResolver();
43          resolver.setMethodProperty("serviceMethod");
44          MuleEventContext ctx = getTestEventContext("blah");
45          ctx.getMessage().setProperty("serviceMethod", "someBusinessMethod");
46          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
47          assertEquals(result.getState(), InvocationResult.STATE_INVOKED_SUCESSFUL);
48      }
49  
50      public void testCustomMethodPropertyFail() throws Exception
51      {
52          MethodHeaderPropertyEntryPointResolver resolver = new MethodHeaderPropertyEntryPointResolver();
53          resolver.setMethodProperty("serviceMethod");
54          MuleEventContext ctx = getTestEventContext("blah");
55          ctx.getMessage().setProperty("serviceMethod", "noMethod");
56          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
57          assertEquals(result.getState(), InvocationResult.STATE_INVOKED_FAILED);
58      }
59  
60      public void testMethodPropertyFail() throws Exception
61      {
62          MethodHeaderPropertyEntryPointResolver resolver = new MethodHeaderPropertyEntryPointResolver();
63          resolver.setMethodProperty("serviceMethod");
64          MuleEventContext ctx = getTestEventContext("blah");
65          ctx.getMessage().setProperty("myMethod", "someBusinessMethod");
66          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
67          assertEquals(result.getState(), InvocationResult.STATE_INVOKED_FAILED);
68      }
69  
70      public void testMethodPropertyMismatch() throws Exception
71      {
72          MethodHeaderPropertyEntryPointResolver resolver = new MethodHeaderPropertyEntryPointResolver();
73          MuleEventContext ctx = getTestEventContext("blah");
74          ctx.getMessage().setProperty("method", "noMethod");
75          InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
76          assertEquals(result.getState(), InvocationResult.STATE_INVOKED_FAILED);
77      }
78  
79  }