View Javadoc

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