1
2
3
4
5
6
7
8
9
10
11 package org.mule.example.stockquote;
12
13 import org.mule.tck.FunctionalTestCase;
14 import org.mule.tck.util.WebServiceOnlineCheck;
15 import org.mule.util.StringUtils;
16
17 import java.util.Locale;
18
19 import org.apache.commons.httpclient.HttpClient;
20 import org.apache.commons.httpclient.methods.GetMethod;
21
22
23 public class StockQuoteFunctionalTestCase extends FunctionalTestCase
24 {
25 public StockQuoteFunctionalTestCase()
26 {
27
28
29 setFailOnTimeout(false);
30 }
31
32
33
34
35
36
37
38
39 @Override
40 protected boolean isDisabledInThisEnvironment()
41 {
42 return (WebServiceOnlineCheck.isWebServiceOnline() == false);
43 }
44
45 @Override
46 protected String getConfigResources()
47 {
48 return "mule-config.xml";
49 }
50
51 public void testREST() throws Exception
52 {
53 runTest("REST");
54 }
55
56 public void testSOAP() throws Exception
57 {
58 runTest("SOAP");
59 }
60
61 public void testWSDL() throws Exception
62 {
63 runTest("WSDL");
64 }
65
66 private void runTest(String method) throws Exception
67 {
68 String url = String.format("http://localhost:48309/stockquote?symbol=CSCO&method=%1s", method);
69 GetMethod request = new GetMethod(url);
70 int responseCode = new HttpClient().executeMethod(request);
71
72 String text = request.getResponseBodyAsString();
73
74
75
76 if(responseCode == 200)
77 {
78 assertTrue("Stock quote should contain \"CISCO\": " + text, StringUtils.containsIgnoreCase(text, "CISCO"));
79
80 if (Locale.getDefault().getISO3Language().equalsIgnoreCase("eng"))
81 {
82 assertTrue("Stock quote should start with \"StockQuote[\":" + text, text.startsWith("StockQuote["));
83 }
84 }
85
86 }
87 }