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