1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.ejb;
12
13 import org.mule.api.MuleException;
14 import org.mule.api.MuleMessage;
15 import org.mule.api.endpoint.EndpointBuilder;
16 import org.mule.api.endpoint.OutboundEndpoint;
17 import org.mule.api.transport.DispatchException;
18 import org.mule.config.i18n.Message;
19 import org.mule.endpoint.EndpointURIEndpointBuilder;
20 import org.mule.module.client.MuleClient;
21 import org.mule.tck.FunctionalTestCase;
22 import org.mule.transport.rmi.RmiConnector;
23 import org.mule.transport.rmi.i18n.RmiMessages;
24
25 import java.util.HashMap;
26 import java.util.Properties;
27
28
29
30
31 public class EjbFunctionalTestCase extends FunctionalTestCase
32 {
33
34 protected String getConfigResources()
35 {
36 return "ejb-functional-test.xml";
37 }
38
39 private MuleMessage send(String uri, String message) throws Exception
40 {
41 MuleClient client = new MuleClient();
42 return client.send(uri, message, new HashMap());
43 }
44
45 public void testReverseString() throws Exception
46 {
47 MuleMessage message = send("ejb://localhost/TestService?method=reverseString", "hello");
48 assertNotNull(message.getPayload());
49 assertEquals("olleh", message.getPayloadAsString());
50 }
51
52 public void testUpperCaseString() throws Exception
53 {
54 MuleMessage message = send("ejb://localhost/TestService?method=upperCaseString", "hello");
55 assertNotNull(message.getPayload());
56 assertEquals("HELLO", message.getPayloadAsString());
57 }
58
59 public void testNoMethodSet() throws Exception
60 {
61 try
62 {
63 send("ejb://localhost/TestService", "hello");
64
65 }
66 catch (MuleException e)
67 {
68 assertTrue(e instanceof DispatchException);
69
70 Message message = RmiMessages.messageParamServiceMethodNotSet();
71 assertTrue(e.getMessage().startsWith(message.toString()));
72 }
73 }
74
75 public void testBadMethodName() throws Exception
76 {
77 try
78 {
79 send("ejb://localhost/TestService?method=foo", "hello");
80 }
81 catch (MuleException e)
82 {
83 assertTrue(e.getCause() instanceof NoSuchMethodException);
84 }
85 }
86
87 public void testBadMethodType() throws Exception
88 {
89
90
91 EndpointBuilder builder = new EndpointURIEndpointBuilder("ejb://localhost/TestService?method=reverseString",
92 muleContext);
93 Properties props = new Properties();
94 props.put(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, StringBuffer.class.getName());
95 builder.setProperties(props);
96
97 OutboundEndpoint ep = muleContext.getRegistry().lookupEndpointFactory().getOutboundEndpoint(
98 builder);
99 try
100 {
101 ep.send(getTestEvent("hello", ep));
102 }
103 catch (MuleException e)
104 {
105 assertTrue(e.getCause() instanceof NoSuchMethodException);
106 }
107 }
108
109 public void testCorrectMethodType() throws Exception
110 {
111
112
113 EndpointBuilder builder = new EndpointURIEndpointBuilder("ejb://localhost/TestService?method=reverseString",
114 muleContext);
115 Properties props = new Properties();
116 props.put(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, StringBuffer.class.getName());
117 builder.setProperties(props);
118
119 OutboundEndpoint ep = muleContext.getRegistry().lookupEndpointFactory().getOutboundEndpoint(
120 builder);
121
122 try
123 {
124 ep.send(getTestEvent("hello", ep));
125 }
126 catch (MuleException e)
127 {
128 assertTrue(e.getCause() instanceof NoSuchMethodException);
129 }
130 }
131
132 }