01: /*
02: * $Id: AbstractLoanBrokerTestCase.java 11179 2008-03-05 13:46:23Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.example.loanbroker.tests;
12:
13: import org.mule.api.MuleMessage;
14: import org.mule.example.loanbroker.messages.Customer;
15: import org.mule.example.loanbroker.messages.CustomerQuoteRequest;
16: import org.mule.example.loanbroker.messages.LoanQuote;
17: import org.mule.module.client.MuleClient;
18: import org.mule.tck.FunctionalTestCase;
19: import org.mule.transport.NullPayload;
20:
21: public abstract class AbstractLoanBrokerTestCase extends
22: FunctionalTestCase {
23:
24: protected int getNumberOfRequests() {
25: return 10;
26: }
27:
28: public void testSingleLoanRequest() throws Exception {
29: MuleClient client = new MuleClient();
30: Customer c = new Customer("Ross Mason", 1234);
31: CustomerQuoteRequest request = new CustomerQuoteRequest(c,
32: 100000, 48);
33: MuleMessage result = client.send("CustomerRequests", request,
34: null);
35: assertNotNull("Result is null", result);
36: assertFalse("Result is null",
37: result.getPayload() instanceof NullPayload);
38: assertTrue("Result should be LoanQuote but is "
39: + result.getPayload().getClass().getName(), result
40: .getPayload() instanceof LoanQuote);
41: LoanQuote quote = (LoanQuote) result.getPayload();
42: assertTrue(quote.getInterestRate() > 0);
43: }
44:
45: public void testLotsOfLoanRequests() throws Exception {
46: MuleClient client = new MuleClient();
47: Customer c = new Customer("Ross Mason", 1234);
48: CustomerQuoteRequest[] requests = new CustomerQuoteRequest[3];
49: requests[0] = new CustomerQuoteRequest(c, 100000, 48);
50: requests[1] = new CustomerQuoteRequest(c, 1000, 12);
51: requests[2] = new CustomerQuoteRequest(c, 10, 24);
52:
53: long start = System.currentTimeMillis();
54:
55: int numRequests = getNumberOfRequests();
56: int i = 0;
57: try {
58: for (; i < numRequests; i++) {
59: CustomerQuoteRequest loanRequest = requests[i % 3];
60:
61: MuleMessage result = client.send("CustomerRequests",
62: loanRequest, null);
63: assertNotNull(result);
64: assertFalse("received a NullPayload", result
65: .getPayload() instanceof NullPayload);
66: assertTrue("did not receive a LoanQuote but: "
67: + result.getPayload(),
68: result.getPayload() instanceof LoanQuote);
69: LoanQuote quote = (LoanQuote) result.getPayload();
70: assertTrue(quote.getInterestRate() > 0);
71: }
72: } finally {
73: long el = System.currentTimeMillis() - start;
74: System.out.println("Total running time was: " + el + "ms");
75: System.out.println("Requests processed was: " + i);
76: int mps = (int) (numRequests / ((double) el / (double) 1000));
77: System.out.println("Msg/sec: " + mps + " (no warm up)");
78: }
79: }
80: }
|