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.AbstractMuleTestCase;
16
17 import java.lang.reflect.Method;
18
19 import junit.framework.AssertionFailedError;
20
21 public class EntryPointResolverMethodCacheTestCase extends AbstractMuleTestCase
22 {
23
24 private static final String METHOD = "aMethod";
25
26 public void testMethodCaching() throws Exception
27 {
28 Method method = this.getClass().getMethod(METHOD, new Class[] { String.class});
29 Method anotherMethod = AnotherClass.class.getMethod(METHOD, new Class[] { String.class});
30
31 MuleEventContext eventContext = getTestEventContext(null);
32 MockEntryPointResolver epResolver = new MockEntryPointResolver();
33
34 epResolver.addMethodByName(this, method, eventContext);
35 Method method1 = epResolver.getMethodByName(this, METHOD, eventContext);
36 assertEquals(method, method1);
37 assertEquals(this.getClass(), method1.getDeclaringClass());
38
39 AnotherClass anotherObject = new AnotherClass();
40 epResolver.addMethodByName(anotherObject, anotherMethod, eventContext);
41 Method anotherMethod1 = epResolver.getMethodByName(anotherObject, METHOD, eventContext);
42 assertEquals(anotherMethod, anotherMethod1);
43 assertEquals(AnotherClass.class, anotherMethod.getDeclaringClass());
44
45 }
46
47 public void aMethod(String payload)
48 {
49
50 }
51
52 private static class MockEntryPointResolver extends AbstractEntryPointResolver
53 {
54 public InvocationResult invoke(Object component, MuleEventContext context) throws Exception
55 {
56 throw new AssertionFailedError("do not invoke this method");
57 }
58 }
59
60 private static class AnotherClass
61 {
62 public void aMethod(String payload)
63 {
64
65 }
66 }
67
68 }
69
70