1
2
3
4
5
6
7
8
9
10
11 package org.mule.mule.model;
12
13 import org.mule.api.MuleEventContext;
14 import org.mule.api.model.InvocationResult;
15 import org.mule.api.transport.PropertyScope;
16 import org.mule.model.resolvers.MethodHeaderPropertyEntryPointResolver;
17 import org.mule.tck.AbstractMuleTestCase;
18 import org.mule.tck.testmodels.fruit.Apple;
19 import org.mule.tck.testmodels.fruit.Fruit;
20 import org.mule.transport.NullPayload;
21
22 public class MethodHeaderEntryPointResolverTestCase extends AbstractMuleTestCase
23 {
24 private MethodHeaderPropertyEntryPointResolver resolver;
25
26 @Override
27 protected void doSetUp() throws Exception
28 {
29 super.doSetUp();
30 resolver = new MethodHeaderPropertyEntryPointResolver();
31 }
32
33 public void testMethodSetPass() throws Exception
34 {
35 MuleEventContext ctx = getTestEventContext("blah");
36 ctx.getMessage().setProperty("method", "someBusinessMethod", PropertyScope.INBOUND);
37
38 InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
39 assertInvocationWasSuccessful(result);
40 }
41
42 public void testMethodSetWithNoArgsPass() throws Exception
43 {
44 MuleEventContext ctx = getTestEventContext(NullPayload.getInstance());
45 ctx.getMessage().setProperty("method", "wash", PropertyScope.INBOUND);
46
47 InvocationResult result = resolver.invoke(new Apple(), ctx);
48 assertInvocationWasSuccessful(result);
49 assertEquals("wash", result.getMethodCalled());
50 }
51
52 public void testCustomMethodProperty() throws Exception
53 {
54 resolver.setMethodProperty("serviceMethod");
55
56 MuleEventContext ctx = getTestEventContext("blah");
57 ctx.getMessage().setProperty("serviceMethod", "someBusinessMethod", PropertyScope.INBOUND);
58
59 InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
60 assertInvocationWasSuccessful(result);
61 }
62
63 public void testCustomMethodPropertyFail() throws Exception
64 {
65 resolver.setMethodProperty("serviceMethod");
66
67 MuleEventContext ctx = getTestEventContext("blah");
68 ctx.getMessage().setProperty("serviceMethod", "noMethod", PropertyScope.INBOUND);
69
70 InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
71 assertInvocationFailed(result);
72 }
73
74 public void testMethodPropertyFail() throws Exception
75 {
76 resolver.setMethodProperty("serviceMethod");
77
78 MuleEventContext ctx = getTestEventContext("blah");
79 ctx.getMessage().setProperty("myMethod", "someBusinessMethod", PropertyScope.INBOUND);
80
81 InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
82 assertInvocationFailed(result);
83 }
84
85 public void testMethodPropertyMismatch() throws Exception
86 {
87 MuleEventContext ctx = getTestEventContext("blah");
88 ctx.getMessage().setProperty("method", "noMethod", PropertyScope.INBOUND);
89
90 InvocationResult result = resolver.invoke(new MultiplePayloadsTestObject(), ctx);
91 assertInvocationFailed(result);
92 }
93
94
95
96
97
98
99 public void testMethodPropertyParameterAssignableFromPayload() throws Exception
100 {
101 MuleEventContext ctx = getTestEventContext(new Apple());
102 ctx.getMessage().setProperty("method", "wash", PropertyScope.INBOUND);
103
104 InvocationResult result = resolver.invoke(new TestFruitCleaner(), ctx);
105 assertInvocationWasSuccessful(result);
106 }
107
108 private void assertInvocationWasSuccessful(InvocationResult result)
109 {
110 assertEquals(InvocationResult.STATE_INVOKED_SUCESSFUL, result.getState());
111 }
112
113 private void assertInvocationFailed(InvocationResult result)
114 {
115 assertEquals(InvocationResult.STATE_INVOKED_FAILED, result.getState());
116 }
117
118 public static class TestFruitCleaner
119 {
120 public void wash(Fruit fruit)
121 {
122
123 }
124
125 public void polish(Fruit fruit)
126 {
127
128 }
129 }
130 }