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