1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.api.transport.DispatchException;
15 import org.mule.config.i18n.Message;
16 import org.mule.module.client.MuleClient;
17 import org.mule.tck.FunctionalTestCase;
18 import org.mule.transport.rmi.i18n.RmiMessages;
19
20 import java.util.HashMap;
21
22 public abstract class AbstractFunctionalTestCase extends FunctionalTestCase
23 {
24 private String prefix;
25 private String config;
26
27 public AbstractFunctionalTestCase(String prefix, String config)
28 {
29 this.prefix = prefix;
30 this.config = config;
31 }
32
33
34
35 public void testCase() throws Exception
36 {
37 MuleClient client = new MuleClient(muleContext);
38
39
40 MuleMessage message = client.send("vm://testin", 12, null);
41 assertNotNull(message);
42 Integer payload = (Integer)message.getPayload();
43 assertEquals(payload, new Integer(22));
44
45
46 message = client.send("vm://testin", "test matching component first time", null);
47 assertNotNull(message);
48 assertEquals((String)message.getPayload(), "emit tsrif tnenopmoc gnihctam tset");
49
50
51 message = client.send("vm://testin", "test mathching component second time", null);
52 assertNotNull(message);
53 assertEquals((String)message.getPayload(), "emit dnoces tnenopmoc gnihchtam tset");
54
55
56 message = client.send("vm://testin", 15, null);
57 assertNotNull(message);
58 payload = (Integer)message.getPayload();
59 assertEquals(payload, new Integer(25));
60 }
61
62
63
64 private MuleMessage send(String uri, String message) throws Exception
65 {
66 MuleClient client = new MuleClient(muleContext);
67 return client.send(prefix + uri, message, new HashMap());
68 }
69
70 public void testReverseString() throws Exception
71 {
72 MuleMessage message = send("://localhost/TestService?method=reverseString", "hello");
73 assertNotNull(message.getPayload());
74 assertEquals("olleh", message.getPayloadAsString());
75 }
76
77 public void testUpperCaseString() throws Exception
78 {
79 MuleMessage message = send("://localhost/TestService?method=upperCaseString", "hello");
80 assertNotNull(message.getPayload());
81 assertEquals("HELLO", message.getPayloadAsString());
82 }
83
84 public void testNoMethodSet() throws Exception
85 {
86 try
87 {
88 send("://localhost/TestService", "hello");
89 }
90 catch (Exception e)
91 {
92 assertTrue(e instanceof DispatchException);
93
94 Message message = RmiMessages.messageParamServiceMethodNotSet();
95 assertTrue("Expected to start with: " + message.toString() + "\n but was: " + e.getCause().getMessage(), e.getCause().getMessage().startsWith(message.toString()));
96 }
97 }
98
99 public void testBadMethodName() throws Exception
100 {
101 try
102 {
103 send("://localhost/TestService?method=foo", "hello");
104 fail("exception expected");
105 }
106 catch (DispatchException e)
107 {
108 assertTrue(e.getCause() instanceof NoSuchMethodException);
109 }
110 }
111
112 protected String getConfigResources()
113 {
114 return config;
115 }
116
117 public void testBadMethodType() throws Exception
118 {
119 try
120 {
121 new MuleClient(muleContext).send("BadType", "hello", null);
122 fail("exception expected");
123 }
124 catch (DispatchException e)
125 {
126 assertTrue(e.getCause() instanceof NoSuchMethodException);
127 }
128 }
129
130 public void testCorrectMethodType() throws Exception
131 {
132 MuleMessage message = new MuleClient(muleContext).send("GoodType", "hello", null);
133 assertNotNull(message);
134 assertEquals("olleh", message.getPayloadAsString());
135 }
136 }