View Javadoc

1   /*
2    * $Id: NoArgsEntryPointResolverTestCase.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.mule.model;
12  
13  import org.mule.api.model.InvocationResult;
14  import org.mule.model.resolvers.AbstractArgumentEntryPointResolver;
15  import org.mule.model.resolvers.NoArgumentsEntryPointResolver;
16  import org.mule.tck.AbstractMuleTestCase;
17  import org.mule.tck.testmodels.fruit.Apple;
18  import org.mule.tck.testmodels.fruit.InvalidSatsuma;
19  import org.mule.transport.NullPayload;
20  
21  public class NoArgsEntryPointResolverTestCase extends AbstractMuleTestCase
22  {
23      public void testExplicitMethodMatch() throws Exception
24      {
25          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
26          resolver.addMethod("bite");
27          InvocationResult result = resolver.invoke(new InvalidSatsuma(), getTestEventContext("blah"));
28          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
29      }
30  
31      public void testExplicitMethodMatch2() throws Exception
32      {
33          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
34          resolver.addMethod("wash");
35          InvocationResult result = resolver.invoke(new Apple(), getTestEventContext("blah"));
36          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
37      }
38  
39      public void testDynamicMethodMatchFail() throws Exception
40      {
41          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
42          InvocationResult result = resolver.invoke(new Apple(), getTestEventContext("blah"));
43          assertEquals("Apple service has a number of matching method, so should have failed",
44                  result.getState(), InvocationResult.State.FAILED);
45      }
46  
47      public void testDynamicMethodMatchPass() throws Exception
48      {
49          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
50          InvocationResult result = resolver.invoke(new InvalidSatsuma(), getTestEventContext("blah"));
51          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
52      }
53  
54      public void testDynamicMethodMatchFailOnWildcardMatch() throws Exception
55      {
56          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
57          assertTrue(resolver.removeIgnoredMethod("is*"));
58          InvocationResult result = resolver.invoke(new InvalidSatsuma(), getTestEventContext("blah"));
59          assertEquals("Satsuma service has a number of matching method, so should have failed",
60                  result.getState(), InvocationResult.State.FAILED);
61      }
62  
63      /** Having a null payload should make no difference */
64      public void testExplicitMethodMatchAndNullPayload() throws Exception
65      {
66          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
67          resolver.addMethod("wash");
68          InvocationResult result = resolver.invoke(new Apple(), getTestEventContext(NullPayload.getInstance()));
69          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
70      }
71  }