1
2
3
4
5
6
7
8
9
10
11 package org.mule.impl;
12
13 import org.mule.components.simple.NoArgsCallWrapper;
14 import org.mule.config.builders.QuickConfigurationBuilder;
15 import org.mule.impl.endpoint.MuleEndpoint;
16 import org.mule.tck.AbstractMuleTestCase;
17 import org.mule.tck.testmodels.fruit.Apple;
18 import org.mule.umo.UMOComponent;
19 import org.mule.umo.UMOEvent;
20 import org.mule.umo.UMOException;
21 import org.mule.umo.UMOMessage;
22 import org.mule.umo.lifecycle.InitialisationException;
23 import org.mule.util.ExceptionUtils;
24
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 public class NoArgsCallWrapperTestCase extends AbstractMuleTestCase
30 {
31
32 public void testNoArgsCallWrapper() throws Exception
33 {
34 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
35 Map properties = new HashMap();
36 properties.put("delegateClass", Apple.class.getName());
37 properties.put("delegateMethod", "toString");
38
39 UMOComponent comp = builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, properties);
40 builder.createStartedManager(true, "");
41
42 UMOEvent event = getTestEvent("Test", (MuleDescriptor) comp.getDescriptor(), new MuleEndpoint("test://in", true));
43 UMOMessage reply = comp.sendEvent(event);
44 assertNotNull(reply);
45 assertNull(reply.getExceptionPayload());
46 assertEquals("Just an apple.", reply.getPayload());
47 }
48
49 public void testVoidReturnType() throws Exception
50 {
51 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
52 Map properties = new HashMap();
53 properties.put("delegateClass", Apple.class.getName());
54 properties.put("delegateMethod", "wash");
55
56 UMOComponent comp = builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, properties);
57 builder.createStartedManager(true, "");
58
59 UMOEvent event = getTestEvent("Test", (MuleDescriptor) comp.getDescriptor(), new MuleEndpoint("test://in", true));
60 UMOMessage reply = comp.sendEvent(event);
61 assertNotNull(reply);
62 assertNull(reply.getExceptionPayload());
63
64 assertEquals("Test", reply.getPayload());
65 }
66
67 public void testNullReturnType() throws Exception
68 {
69 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
70 Map properties = new HashMap();
71 properties.put("delegateClass", Apple.class.getName());
72 properties.put("delegateMethod", "methodReturningNull");
73
74 UMOComponent comp = builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, properties);
75 builder.createStartedManager(true, "");
76
77 UMOEvent event = getTestEvent("Test", (MuleDescriptor) comp.getDescriptor(), new MuleEndpoint("test://in", true));
78 UMOMessage reply = comp.sendEvent(event);
79 assertNull(reply);
80 }
81
82
83 public void testNoConfigurationProvided() throws Exception
84 {
85 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
86 builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, Collections.EMPTY_MAP);
87 try
88 {
89 builder.createStartedManager(true, "");
90 }
91 catch (UMOException e)
92 {
93 Throwable t = ExceptionUtils.getRootCause(e);
94 assertNotNull(t);
95 assertTrue(t instanceof InitialisationException);
96 assertTrue("Wrong exception?", t.getMessage().indexOf("Both \"delegateClass\" and") > -1);
97 }
98 }
99
100 public void testOnlyDelegateClassProvided() throws Exception
101 {
102 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
103 Map properties = new HashMap();
104 properties.put("delegateClass", Apple.class.getName());
105 builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, properties);
106 try
107 {
108 builder.createStartedManager(true, "");
109 }
110 catch (UMOException e)
111 {
112 Throwable t = ExceptionUtils.getRootCause(e);
113 assertNotNull(t);
114 assertTrue(t instanceof InitialisationException);
115 assertTrue("Wrong exception?", t.getMessage().indexOf("Both \"delegateClass\" and") > -1);
116 }
117 }
118
119 public void testOnlyDelegateMethodProvided() throws Exception
120 {
121 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
122 Map properties = new HashMap();
123 properties.put("delegateMethod", "someMethod");
124 builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, properties);
125 try
126 {
127 builder.createStartedManager(true, "");
128 }
129 catch (UMOException e)
130 {
131 Throwable t = ExceptionUtils.getRootCause(e);
132 assertNotNull(t);
133 assertTrue(t instanceof InitialisationException);
134 assertTrue("Wrong exception?", t.getMessage().indexOf("Both \"delegateClass\" and") > -1);
135 }
136 }
137
138 public void testDelegateInstanceAndClassProvided() throws Exception
139 {
140 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
141
142 Map properties = new HashMap();
143 properties.put("delegateClass", Apple.class.getName());
144 properties.put("delegateInstance", new Apple());
145
146 builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, properties);
147 try
148 {
149 builder.createStartedManager(true, "");
150 }
151 catch (UMOException e)
152 {
153 Throwable t = ExceptionUtils.getRootCause(e);
154 assertNotNull(t);
155 assertTrue(t instanceof InitialisationException);
156 assertTrue("Wrong exception?", t.getMessage().indexOf("No \"delegateClass\" must be specified") > -1);
157 }
158 }
159
160 public void testDelegateInstanceWithoutMethodProvided() throws Exception
161 {
162 QuickConfigurationBuilder builder = new QuickConfigurationBuilder(true);
163
164 Map properties = new HashMap();
165 properties.put("delegateInstance", new Apple());
166
167 builder.registerComponent(NoArgsCallWrapper.class.getName(), "WrapperUMO", "test://in", null, properties);
168 try
169 {
170 builder.createStartedManager(true, "");
171 }
172 catch (UMOException e)
173 {
174 Throwable t = ExceptionUtils.getRootCause(e);
175 assertNotNull(t);
176 assertTrue(t instanceof InitialisationException);
177 assertTrue("Wrong exception?", t.getMessage().indexOf("The required object/property") > -1);
178 }
179 }
180
181 }