1
2
3
4
5
6
7
8
9
10
11 package org.mule.example.webapp;
12
13 import org.mule.api.MuleMessage;
14 import org.mule.example.loanbroker.messages.Customer;
15 import org.mule.example.loanbroker.messages.CustomerQuoteRequest;
16 import org.mule.example.loanbroker.messages.LoanQuote;
17 import org.mule.module.client.MuleClient;
18 import org.mule.tck.AbstractMuleTestCase;
19 import org.mule.util.StringUtils;
20
21 public abstract class AbstractWebappTestCase extends AbstractMuleTestCase
22 {
23
24 public void testSanity() throws Exception
25 {
26 new MuleClient();
27 }
28
29 public void testEchoExample() throws Exception
30 {
31 MuleClient client = new MuleClient();
32 MuleMessage response = client.send("vm://echo", "Is anybody in there?", null);
33 assertEquals("Is anybody in there?", response.getPayload());
34 }
35
36 public void testHelloExample() throws Exception
37 {
38 MuleClient client = new MuleClient();
39 MuleMessage response = client.send("vm://greeter", "Julius Caesar", null);
40
41 assertTrue(response.getPayloadAsString().indexOf("Julius Caesar") > -1);
42 }
43
44 public void testStockQuoteExample() throws Exception
45 {
46 MuleClient client = new MuleClient();
47 MuleMessage response = client.send("vm://stockquote", "HRB", null);
48
49 if (null == response)
50 {
51 fail("No response message.");
52 }
53 else
54 {
55 if (null == response.getExceptionPayload())
56 {
57 String text = response.getPayloadAsString();
58 assertNotNull("Null response", text);
59 assertTrue("Stock quote should contain \"BLOCK\": " + text, StringUtils.contains(text, "BLOCK"));
60 assertTrue("Stock quote should start with \"StockQuote[\":" + text, text.startsWith("StockQuote["));
61 logger.debug("**********");
62 logger.debug(response.getPayload());
63 logger.debug(response.getPayloadAsString());
64 logger.debug("**********");
65 }
66 else
67 {
68 fail("Exception occurred: " + response.getExceptionPayload());
69 }
70 }
71 }
72 public void testLoanBrokerExample() throws Exception
73 {
74 MuleClient client = new MuleClient();
75 CustomerQuoteRequest loanRequest = new CustomerQuoteRequest(new Customer("I.M. Broke", 1234), 50000, 60);
76 MuleMessage response = client.send("CustomerRequests", loanRequest, null);
77 assertNotNull("Result is null", response);
78 assertTrue("Result should be LoanQuote but is " + response.getPayload().getClass().getName(),
79 response.getPayload() instanceof LoanQuote);
80 LoanQuote quote = (LoanQuote) response.getPayload();
81 assertTrue("Interest rate is missing.", quote.getInterestRate() > 0);
82 }
83 }