View Javadoc

1   /*
2    * $Id: ScriptingExampleTestCase.java 19366 2010-09-04 03:26:47Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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&currency=%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  }