1
2
3
4
5
6
7
8
9
10
11 package org.mule.example.scripting;
12
13 import org.mule.tck.FunctionalTestCase;
14
15 import org.apache.commons.httpclient.HttpClient;
16 import org.apache.commons.httpclient.methods.GetMethod;
17
18 public class ScriptingExampleTestCase extends FunctionalTestCase
19 {
20 @Override
21 protected String getConfigResources()
22 {
23 return "mule-config.xml";
24 }
25
26 public void testDollars() throws Exception
27 {
28 runTest(2.33, "USD", "[9 quarters, 0 dimes, 1 nickels, 3 pennies]");
29 }
30
31 public void testPounds() throws Exception
32 {
33 runTest(1.28, "GBP", "[1 pounds, 1 twenty_pence, 1 five_pence, 1 two_pence, 1 pennies]");
34 }
35
36 private void runTest(double amount, String currency, String expectedResult) throws Exception
37 {
38 String url = String.format("http://localhost:47493/change-machine?amount=%1f¤cy=%2s",
39 amount, currency);
40 GetMethod httpGet = new GetMethod(url);
41 new HttpClient().executeMethod(httpGet);
42 String result = httpGet.getResponseBodyAsString();
43 assertEquals(expectedResult, result);
44 }
45 }