1
2
3
4
5
6
7
8
9
10
11 package org.mule.model.resolvers;
12
13 import org.mule.api.MuleEventContext;
14 import org.mule.api.model.InvocationResult;
15 import org.mule.tck.junit4.AbstractMuleTestCase;
16
17 import java.lang.reflect.Method;
18
19 import junit.framework.AssertionFailedError;
20 import org.junit.Test;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.mockito.Mockito.mock;
24
25 public class EntryPointResolverMethodCacheTestCase extends AbstractMuleTestCase
26 {
27
28 private static final String METHOD = "aMethod";
29
30 @Test
31 public void testMethodCaching() throws Exception
32 {
33 Method method = this.getClass().getMethod(METHOD, new Class[] { String.class});
34 Method anotherMethod = AnotherClass.class.getMethod(METHOD, new Class[] { String.class});
35
36 MuleEventContext eventContext = mock(MuleEventContext.class);
37 MockEntryPointResolver epResolver = new MockEntryPointResolver();
38
39 epResolver.addMethodByName(this, method, eventContext);
40 Method method1 = epResolver.getMethodByName(this, METHOD, eventContext);
41 assertEquals(method, method1);
42 assertEquals(this.getClass(), method1.getDeclaringClass());
43
44 AnotherClass anotherObject = new AnotherClass();
45 epResolver.addMethodByName(anotherObject, anotherMethod, eventContext);
46 Method anotherMethod1 = epResolver.getMethodByName(anotherObject, METHOD, eventContext);
47 assertEquals(anotherMethod, anotherMethod1);
48 assertEquals(AnotherClass.class, anotherMethod.getDeclaringClass());
49
50 }
51
52 public void aMethod(String payload)
53 {
54
55 }
56
57 private static class MockEntryPointResolver extends AbstractEntryPointResolver
58 {
59 public InvocationResult invoke(Object component, MuleEventContext context) throws Exception
60 {
61 throw new AssertionFailedError("do not invoke this method");
62 }
63 }
64
65 private static class AnotherClass
66 {
67 public void aMethod(String payload)
68 {
69
70 }
71 }
72
73 }
74
75