View Javadoc

1   /*
2    * $Id: ScriptingExampleTestCase.java 22620 2011-08-09 10:02:17Z 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.junit4.FunctionalTestCase;
14  
15  import org.apache.commons.httpclient.HttpClient;
16  import org.apache.commons.httpclient.methods.GetMethod;
17  import org.junit.Test;
18  
19  import static org.junit.Assert.assertEquals;
20  
21  public class ScriptingExampleTestCase extends FunctionalTestCase
22  {
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:47493/change-machine?amount=%1f&currency=%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  }