1   /*
2    * $Id: AbstractWebappTestCase.java 8040 2007-08-24 11:41:28Z 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          // ATTENTION: thie message is localized, a full comparison cannot be done here
40          assertTrue(response.getPayloadAsString().indexOf("Julius Caesar") > -1);
41      }
42      
43      public void testStockQuoteExample() throws Exception
44      {
45          MuleClient client = new MuleClient();
46          UMOMessage response = client.send("vm://stockquote", "HRB", null);
47      
48          if(response != null) 
49          { 
50              if (response.getExceptionPayload() == null) 
51              {            
52                  assertTrue("Stock quote should contain \"BLOCK\": " + response.getPayload(), 
53                              StringUtils.contains(response.getPayloadAsString(), "BLOCK"));
54              }
55              else
56              {
57                  fail("Exception occurred: " + response.getExceptionPayload());
58              }
59          }
60          else
61          {
62              fail("No response message.");
63          }
64       }
65  
66      public void testLoanBrokerExample() throws Exception
67      {
68          MuleClient client = new MuleClient();
69          CustomerQuoteRequest loanRequest = new CustomerQuoteRequest(new Customer("I.M. Broke", 1234), 50000, 60);
70          UMOMessage response = client.send("CustomerRequests", loanRequest, null);
71          assertNotNull("Result is null", response);
72          assertTrue("Result should be LoanQuote but is " + response.getPayload().getClass().getName(), 
73                      response.getPayload() instanceof LoanQuote);
74          LoanQuote quote = (LoanQuote) response.getPayload();
75          assertTrue("Interest rate is missing.", quote.getInterestRate() > 0);
76      }
77  }