1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck.model; |
12 | |
|
13 | |
import org.mule.impl.NoSatisfiableMethodsException; |
14 | |
import org.mule.impl.RequestContext; |
15 | |
import org.mule.tck.AbstractMuleTestCase; |
16 | |
import org.mule.tck.testmodels.fruit.InvalidSatsuma; |
17 | |
import org.mule.umo.UMODescriptor; |
18 | |
import org.mule.umo.model.UMOEntryPoint; |
19 | |
import org.mule.umo.model.UMOEntryPointResolver; |
20 | |
import org.mule.util.ClassUtils; |
21 | |
|
22 | 22 | public abstract class AbstractEntryPointDiscoveryTestCase extends AbstractMuleTestCase |
23 | |
{ |
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public void testFailEntryPointDiscovery() throws Exception |
29 | |
{ |
30 | 4 | UMOEntryPointResolver epd = getEntryPointResolver(); |
31 | 6 | UMODescriptor descriptor = getTestDescriptor("badSatsuma", InvalidSatsuma.class.getName()); |
32 | |
|
33 | 4 | UMOEntryPoint ep = null; |
34 | |
|
35 | |
try |
36 | |
{ |
37 | 4 | ep = epd.resolveEntryPoint(descriptor); |
38 | |
} |
39 | 0 | catch (NoSatisfiableMethodsException e) |
40 | |
{ |
41 | |
|
42 | 0 | return; |
43 | 4 | } |
44 | |
|
45 | 4 | assertNotNull(ep); |
46 | |
|
47 | |
try |
48 | |
{ |
49 | 4 | RequestContext.setEvent(getTestEvent("Hello")); |
50 | 4 | ep.invoke(new InvalidSatsuma(), RequestContext.getEventContext()); |
51 | 0 | fail("Should have failed to find entrypoint on Satsuma"); |
52 | |
|
53 | |
} |
54 | 4 | catch (Exception e) |
55 | |
{ |
56 | |
|
57 | |
} |
58 | |
finally |
59 | |
{ |
60 | 4 | RequestContext.setEvent(null); |
61 | 4 | } |
62 | |
|
63 | 4 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public void testEntryPointDiscovery() throws Exception |
70 | |
{ |
71 | 4 | ComponentMethodMapping[] mappings = getComponentMappings(); |
72 | |
|
73 | 20 | for (int i = 0; i < mappings.length; i++) |
74 | |
{ |
75 | 16 | if (mappings[i].isShouldFail()) |
76 | |
{ |
77 | 2 | doExpectedFail(mappings[i]); |
78 | |
} |
79 | |
else |
80 | |
{ |
81 | 14 | doExpectedPass(mappings[i]); |
82 | |
} |
83 | |
} |
84 | 4 | } |
85 | |
|
86 | |
private void doExpectedPass(ComponentMethodMapping mapping) throws Exception |
87 | |
{ |
88 | 14 | UMOEntryPointResolver epr = getEntryPointResolver(); |
89 | 14 | UMODescriptor descriptor = getDescriptorToResolve(mapping.getComponentClass().getName()); |
90 | 14 | UMOEntryPoint ep = epr.resolveEntryPoint(descriptor); |
91 | 14 | assertNotNull(ep); |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | 14 | } |
98 | |
|
99 | |
private void doExpectedFail(ComponentMethodMapping mapping) throws Exception |
100 | |
{ |
101 | 2 | UMOEntryPointResolver epr = getEntryPointResolver(); |
102 | 2 | UMODescriptor descriptor = getDescriptorToResolve(mapping.getComponentClass().getName()); |
103 | |
|
104 | |
try |
105 | |
{ |
106 | 2 | UMOEntryPoint ep = epr.resolveEntryPoint(descriptor); |
107 | 2 | ep.invoke(ClassUtils.instanciateClass(mapping.getComponentClass(), ClassUtils.NO_ARGS), |
108 | |
getTestEventContext("blah")); |
109 | 0 | fail("Resolving should have failed for: " + mapping.toString()); |
110 | |
} |
111 | 2 | catch (Exception e) |
112 | |
{ |
113 | |
|
114 | 0 | } |
115 | |
|
116 | 2 | } |
117 | |
|
118 | |
public UMODescriptor getDescriptorToResolve(String className) throws Exception |
119 | |
{ |
120 | 26 | return getTestDescriptor("myComponent", className); |
121 | |
} |
122 | |
|
123 | |
public abstract UMOEntryPointResolver getEntryPointResolver(); |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public abstract ComponentMethodMapping[] getComponentMappings(); |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | 22 | public class ComponentMethodMapping |
137 | |
{ |
138 | |
private Class componentClass; |
139 | |
private Class methodArgumentType; |
140 | |
private String methodName; |
141 | |
private boolean shouldFail; |
142 | |
|
143 | |
public ComponentMethodMapping(Class componentClass, String methodName, Class methodArgumentType) |
144 | |
{ |
145 | 12 | this(componentClass, methodName, methodArgumentType, false); |
146 | 12 | } |
147 | |
|
148 | |
public ComponentMethodMapping(Class componentClass, |
149 | |
String methodName, |
150 | |
Class methodArgumentType, |
151 | |
boolean shouldFail) |
152 | 16 | { |
153 | 16 | this.componentClass = componentClass; |
154 | 16 | this.methodName = methodName; |
155 | 16 | this.methodArgumentType = methodArgumentType; |
156 | 16 | this.shouldFail = shouldFail; |
157 | 16 | } |
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
public Class getComponentClass() |
163 | |
{ |
164 | 18 | return componentClass; |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public String getMethodName() |
171 | |
{ |
172 | 0 | return methodName; |
173 | |
} |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
public Class getMethodArgumentType() |
179 | |
{ |
180 | 0 | return methodArgumentType; |
181 | |
} |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
public boolean isShouldFail() |
187 | |
{ |
188 | 16 | return shouldFail; |
189 | |
} |
190 | |
|
191 | |
|
192 | |
public String toString() |
193 | |
{ |
194 | 0 | return componentClass.getName() + "." + methodName + "(" + methodArgumentType.getName() |
195 | |
+ "), Expected to fail= " + shouldFail; |
196 | |
} |
197 | |
|
198 | |
} |
199 | |
} |