1   /*
2    * $Id: AbstractWebappTestCase.java 7976 2007-08-21 14:26:13Z 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.examples.webapp;
12  
13  import org.mule.examples.loanbroker.messages.Customer;
14  import org.mule.examples.loanbroker.messages.CustomerQuoteRequest;
15  import org.mule.examples.loanbroker.messages.LoanQuote;
16  import org.mule.extras.client.MuleClient;
17  import org.mule.tck.AbstractMuleTestCase;
18  import org.mule.umo.UMOMessage;
19  import org.mule.util.StringUtils;
20  
21  public abstract class AbstractWebappTestCase extends AbstractMuleTestCase
22  {
23      public void testSanity() throws Exception
24      {
25          new MuleClient();
26      }
27      
28      public void testEchoExample() throws Exception
29      {
30          MuleClient client = new MuleClient();
31          UMOMessage response = client.send("vm://echo", "Is anybody in there?", null);
32          assertEquals("Is anybody in there?", response.getPayload());
33      }
34      
35      public void testHelloExample() throws Exception
36      {
37          MuleClient client = new MuleClient();
38          UMOMessage response = client.send("vm://greeter", "Julius Caesar", null);
39          assertEquals("Hello Julius Caesar, how are you?", response.getPayloadAsString());
40      }
41      
42      public void testStockQuoteExample() throws Exception
43      {
44          MuleClient client = new MuleClient();
45          UMOMessage response = client.send("vm://stockquote", "HRB", null);
46      
47          if(response != null) 
48          { 
49              if (response.getExceptionPayload() == null) 
50              {            
51                  assertTrue("Stock quote should contain \"BLOCK\": " + response.getPayload(), 
52                              StringUtils.contains(response.getPayloadAsString(), "BLOCK"));
53              }
54              else
55              {
56                  fail("Exception occurred: " + response.getExceptionPayload());
57              }
58          }
59          else
60          {
61              fail("No response message.");
62          }
63       }
64  
65      public void testLoanBrokerExample() throws Exception
66      {
67          MuleClient client = new MuleClient();
68          CustomerQuoteRequest loanRequest = new CustomerQuoteRequest(new Customer("I.M. Broke", 1234), 50000, 60);
69          UMOMessage response = client.send("CustomerRequests", loanRequest, null);
70          assertNotNull("Result is null", response);
71          assertTrue("Result should be LoanQuote but is " + response.getPayload().getClass().getName(), 
72                      response.getPayload() instanceof LoanQuote);
73          LoanQuote quote = (LoanQuote) response.getPayload();
74          assertTrue("Interest rate is missing.", quote.getInterestRate() > 0);
75      }
76  }