View Javadoc

1   /*
2    * $Id: AbstractLoanBrokerTestCase.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.loanbroker.tests;
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.providers.NullPayload;
18  import org.mule.tck.FunctionalTestCase;
19  import org.mule.umo.UMOMessage;
20  
21  public abstract class AbstractLoanBrokerTestCase extends FunctionalTestCase
22  {
23      public AbstractLoanBrokerTestCase()
24      {
25          super();
26          setDisposeManagerPerSuite(true);
27      }
28  
29      protected int getNumberOfRequests()
30      {
31          return 10;
32      }
33  
34      public void testSingleLoanRequest() throws Exception
35      {
36          MuleClient client = new MuleClient();
37          Customer c = new Customer("Ross Mason", 1234);
38          CustomerQuoteRequest request = new CustomerQuoteRequest(c, 100000, 48);
39          UMOMessage result = client.send("CustomerRequests", request, null);
40          assertNotNull("Result is null", result);
41          assertFalse("Result is null", result.getPayload() instanceof NullPayload);
42          assertTrue("Result should be LoanQuote but is " + result.getPayload().getClass().getName(), 
43                      result.getPayload() instanceof LoanQuote);
44          LoanQuote quote = (LoanQuote)result.getPayload();
45          assertTrue(quote.getInterestRate() > 0);
46      }
47  
48      public void testLotsOfLoanRequests() throws Exception
49      {
50          MuleClient client = new MuleClient();
51          Customer c = new Customer("Ross Mason", 1234);
52          CustomerQuoteRequest[] requests = new CustomerQuoteRequest[3];
53          requests[0] = new CustomerQuoteRequest(c, 100000, 48);
54          requests[1] = new CustomerQuoteRequest(c, 1000, 12);
55          requests[2] = new CustomerQuoteRequest(c, 10, 24);
56  
57          long start = System.currentTimeMillis();
58  
59          int numRequests = getNumberOfRequests();
60          int i = 0;
61          try
62          {
63              for (; i < numRequests; i++)
64              {
65                  CustomerQuoteRequest loanRequest = requests[i % 3];
66  
67                  UMOMessage result = client.send("CustomerRequests", loanRequest, null);
68                  assertNotNull(result);
69                  assertFalse("received a NullPayload", result.getPayload() instanceof NullPayload);
70                  assertTrue("did not receive a LoanQuote but: " + result.getPayload(),
71                      result.getPayload() instanceof LoanQuote);
72                  LoanQuote quote = (LoanQuote)result.getPayload();
73                  assertTrue(quote.getInterestRate() > 0);
74              }
75          }
76          finally
77          {
78              long el = System.currentTimeMillis() - start;
79              System.out.println("Total running time was: " + el + "ms");
80              System.out.println("Requests processed was: " + i);
81              int mps = (int)(numRequests/((double)el/(double)1000));
82              System.out.println("Msg/sec: " + mps + " (no warm up)");
83          }
84      }    
85  }