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