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