1   /*
2    * $Id: AbstractStockQuoteFunctionalTestCase.java 11134 2008-02-29 18:00:10Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.stockquote;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.util.StringUtils;
17  
18  import java.util.Locale;
19  
20  public abstract class AbstractStockQuoteFunctionalTestCase extends FunctionalTestCase
21  {
22  
23      public void testStockQuoteExample() throws Exception
24      {
25          MuleClient client = new MuleClient();
26          MuleMessage response = client.send("vm://stockquote", "HRB", null);
27      
28          if (null == response)
29          { 
30              fail("No response message.");
31          }
32          else
33          {
34              if (null == response.getExceptionPayload())
35              {
36                  String text = response.getPayloadAsString();
37                  assertNotNull("Null response", text);
38                  assertTrue("Stock quote should contain \"BLOCK\": " + text, StringUtils.contains(text, "BLOCK"));
39                  if (Locale.getDefault().getISO3Language().equalsIgnoreCase("eng"))
40                  {
41                      // the stockquote message is localized ...
42                      assertTrue("Stock quote should start with \"StockQuote[\":" + text, text.startsWith("StockQuote["));
43                  }
44                  logger.debug("**********");
45                  logger.debug(response.getPayload());
46                  logger.debug(response.getPayloadAsString());
47                  logger.debug("**********");
48              }
49              else
50              {
51                  fail("Exception occurred: " + response.getExceptionPayload());
52              }
53          }
54      }
55  
56  }