View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.mule.model;
8   
9   import org.mule.api.model.InvocationResult;
10  import org.mule.model.resolvers.AbstractArgumentEntryPointResolver;
11  import org.mule.model.resolvers.NoArgumentsEntryPointResolver;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  import org.mule.tck.testmodels.fruit.Apple;
14  import org.mule.tck.testmodels.fruit.InvalidSatsuma;
15  import org.mule.transport.NullPayload;
16  
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  import static org.junit.Assert.assertTrue;
21  
22  public class NoArgsEntryPointResolverTestCase extends AbstractMuleContextTestCase
23  {
24  
25      @Test
26      public void testExplicitMethodMatch() throws Exception
27      {
28          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
29          resolver.addMethod("bite");
30          InvocationResult result = resolver.invoke(new InvalidSatsuma(), getTestEventContext("blah"));
31          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
32      }
33  
34      @Test
35      public void testExplicitMethodMatch2() throws Exception
36      {
37          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
38          resolver.addMethod("wash");
39          InvocationResult result = resolver.invoke(new Apple(), getTestEventContext("blah"));
40          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
41      }
42  
43      @Test
44      public void testDynamicMethodMatchFail() throws Exception
45      {
46          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
47          InvocationResult result = resolver.invoke(new Apple(), getTestEventContext("blah"));
48          assertEquals("Apple service has a number of matching method, so should have failed",
49                  result.getState(), InvocationResult.State.FAILED);
50      }
51  
52      @Test
53      public void testDynamicMethodMatchPass() throws Exception
54      {
55          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
56          InvocationResult result = resolver.invoke(new InvalidSatsuma(), getTestEventContext("blah"));
57          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
58      }
59  
60      @Test
61      public void testDynamicMethodMatchFailOnWildcardMatch() throws Exception
62      {
63          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
64          assertTrue(resolver.removeIgnoredMethod("is*"));
65          InvocationResult result = resolver.invoke(new InvalidSatsuma(), getTestEventContext("blah"));
66          assertEquals("Satsuma service has a number of matching method, so should have failed",
67                  result.getState(), InvocationResult.State.FAILED);
68      }
69  
70      /** Having a null payload should make no difference */
71      @Test
72      public void testExplicitMethodMatchAndNullPayload() throws Exception
73      {
74          AbstractArgumentEntryPointResolver resolver = new NoArgumentsEntryPointResolver();
75          resolver.addMethod("wash");
76          InvocationResult result = resolver.invoke(new Apple(), getTestEventContext(NullPayload.getInstance()));
77          assertEquals(result.getState(), InvocationResult.State.SUCCESSFUL);
78      }
79  }