1
2
3
4
5
6
7
8
9
10
11 package org.mule.providers.jnp;
12
13 import org.mule.config.ConfigurationBuilder;
14 import org.mule.config.builders.QuickConfigurationBuilder;
15 import org.mule.config.i18n.Message;
16 import org.mule.impl.ImmutableMuleEndpoint;
17 import org.mule.impl.endpoint.MuleEndpoint;
18 import org.mule.impl.jndi.MuleInitialContextFactory;
19 import org.mule.providers.rmi.RmiConnector;
20 import org.mule.providers.rmi.i18n.RmiMessages;
21 import org.mule.tck.FunctionalTestCase;
22 import org.mule.tck.services.MatchingMethodsComponent;
23 import org.mule.umo.UMOException;
24 import org.mule.umo.UMOMessage;
25 import org.mule.umo.endpoint.UMOEndpoint;
26 import org.mule.umo.endpoint.UMOImmutableEndpoint;
27 import org.mule.umo.provider.DispatchException;
28
29 import java.util.Hashtable;
30
31 import javax.naming.Context;
32 import javax.naming.InitialContext;
33
34
35
36
37 public class JnpInvocationTestCase extends FunctionalTestCase
38 {
39
40 JnpConnector jnpConnector;
41
42 protected String getConfigResources()
43 {
44 return null;
45 }
46
47 protected ConfigurationBuilder getBuilder() throws Exception
48 {
49 QuickConfigurationBuilder builder = new QuickConfigurationBuilder();
50 builder.disableAdminAgent();
51
52
53 jnpConnector = new JnpConnector();
54 jnpConnector.setName("jnp");
55 jnpConnector.setJndiInitialFactory(MuleInitialContextFactory.class.getName());
56 jnpConnector.setSecurityPolicy("rmi.policy");
57
58
59
60
61
62 Hashtable env = new Hashtable();
63
64 env.put(Context.INITIAL_CONTEXT_FACTORY, MuleInitialContextFactory.class.getName());
65 InitialContext ic = new InitialContext(env);
66
67 ic.bind("TestService", new MatchingMethodsComponent());
68
69 jnpConnector.setJndiContext(ic);
70 builder.getManager().registerConnector(jnpConnector);
71 return builder;
72 }
73
74 public void testReverseString() throws Exception
75 {
76 UMOImmutableEndpoint ep = new ImmutableMuleEndpoint(
77 "jnp://localhost/TestService?method=reverseString", false);
78 UMOMessage message = ep.send(getTestEvent("hello", ep));
79 assertNotNull(message.getPayload());
80 assertEquals("olleh", message.getPayloadAsString());
81 }
82
83 public void testUpperCaseString() throws Exception
84 {
85 UMOImmutableEndpoint ep = new ImmutableMuleEndpoint(
86 "jnp://localhost/TestService?method=upperCaseString", false);
87 UMOMessage message = ep.send(getTestEvent("hello", ep));
88 assertNotNull(message.getPayload());
89 assertEquals("HELLO", message.getPayloadAsString());
90 }
91
92 public void testNoMethodSet() throws Exception
93 {
94 UMOImmutableEndpoint ep = new ImmutableMuleEndpoint("jnp://localhost/TestService", false);
95 try
96 {
97 ep.send(getTestEvent("hello", ep));
98 }
99 catch (UMOException e)
100 {
101 assertTrue(e instanceof DispatchException);
102
103 Message message = RmiMessages.messageParamServiceMethodNotSet();
104 assertTrue(e.getMessage().startsWith(message.toString()));
105 }
106 }
107
108 public void testBadMethodName() throws Exception
109 {
110 UMOImmutableEndpoint ep = new ImmutableMuleEndpoint("jnp://localhost/TestService?method=foo", false);
111 try
112 {
113 ep.send(getTestEvent("hello", ep));
114 }
115 catch (UMOException e)
116 {
117 assertTrue(e.getCause() instanceof NoSuchMethodException);
118 }
119 }
120
121 public void testBadMethodType() throws Exception
122 {
123 UMOEndpoint ep = new MuleEndpoint("jnp://localhost/TestService?method=reverseString", false);
124 ep.setProperty(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, StringBuffer.class.getName());
125 try
126 {
127 ep.send(getTestEvent("hello", ep));
128 }
129 catch (UMOException e)
130 {
131 assertTrue(e.getCause() instanceof NoSuchMethodException);
132 }
133 }
134
135 public void testCorrectMethodType() throws Exception
136 {
137 UMOEndpoint ep = new MuleEndpoint("jnp://localhost/TestService?method=reverseString", false);
138 ep.setProperty(RmiConnector.PROPERTY_SERVICE_METHOD_PARAM_TYPES, String.class.getName());
139 try
140 {
141 ep.send(getTestEvent("hello", ep));
142 }
143 catch (UMOException e)
144 {
145 assertTrue(e.getCause() instanceof NoSuchMethodException);
146 }
147 }
148
149 }