Coverage Report - org.mule.example.loanbroker.DefaultLoanBroker
 
Classes in this File Line Coverage Branch Coverage Complexity
DefaultLoanBroker
0%
0/25
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: DefaultLoanBroker.java 19514 2010-09-09 19:33:13Z aperepel $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.example.loanbroker;
 12  
 
 13  
 import org.mule.example.loanbroker.bank.Bank;
 14  
 import org.mule.example.loanbroker.creditagency.CreditAgencyService;
 15  
 import org.mule.example.loanbroker.message.CustomerQuoteRequest;
 16  
 import org.mule.example.loanbroker.message.LoanBrokerQuoteRequest;
 17  
 import org.mule.example.loanbroker.model.CreditProfile;
 18  
 
 19  
 /**
 20  
  * <code>SyncLoanBroker</code> is a synchronous Loan Broker that makes the calls to
 21  
  * various components through the event context synchronously.
 22  
  */
 23  0
 public class DefaultLoanBroker extends AbstractLoanBroker
 24  
 {
 25  
     //A proxy for this object gets injected via the <nested-router> element configured on this service.
 26  
     //The proxy will then call out to an endpoint and return the result.
 27  
     //The transformers configured on the endpoint control how data is marshalled into and out of the call.
 28  
     private CreditAgencyService creditAgency;
 29  
 
 30  
     @Override
 31  
     public Object getLoanQuote(CustomerQuoteRequest request) throws LoanBrokerException
 32  
     {
 33  0
         super.getLoanQuote(request);
 34  0
         LoanBrokerQuoteRequest bqr = new LoanBrokerQuoteRequest();
 35  0
         bqr.setCustomerRequest(request);
 36  
 
 37  
         //This calls out to the CreditAgency service (see above)
 38  0
         CreditProfile cp = creditAgency.getCreditProfile(request.getCustomer());
 39  0
         bqr.setCreditProfile(cp);
 40  
 
 41  0
         setLenderList(bqr);
 42  
         
 43  0
         return bqr;
 44  
     }
 45  
     
 46  
     /**
 47  
      * Sets the list of lenders on the LoanBrokerQuoteRequest and returns it.
 48  
      */
 49  
     public void setLenderList(LoanBrokerQuoteRequest request)
 50  
     {
 51  0
         Bank[] lenders = getLenders(request.getCreditProfile(), request.getCustomerRequest()
 52  
                 .getLoanAmount());
 53  0
         request.setLenders(lenders);
 54  0
     }
 55  
 
 56  
     /**
 57  
      * {@inheritDoc}
 58  
      */
 59  
     public Bank[] getLenders(CreditProfile creditProfile, Double loanAmount)
 60  
     {
 61  
         // TODO Add creditProfile info. to the logic below.
 62  
         // TODO Look up the existing banks from the config/registry instead of
 63  
         // creating them programatically here.
 64  
         Bank[] lenders;
 65  0
         if ((loanAmount >= 20000))
 66  
         {
 67  0
             lenders = new Bank[2];
 68  0
             lenders[0] = new Bank("Bank1");
 69  0
             lenders[1] = new Bank("Bank2");
 70  
         }
 71  0
         else if (((loanAmount >= 10000) && (loanAmount <= 19999)))
 72  
         {
 73  0
             lenders = new Bank[2];
 74  0
             lenders[0] = new Bank("Bank3");
 75  0
             lenders[1] = new Bank("Bank4");
 76  
         }
 77  
         else
 78  
         {
 79  0
             lenders = new Bank[1];
 80  0
             lenders[0] = new Bank("Bank5");
 81  
         }
 82  
 
 83  0
         return lenders;
 84  
     }
 85  
 
 86  
     public CreditAgencyService getCreditAgency()
 87  
     {
 88  0
         return creditAgency;
 89  
     }
 90  
 
 91  
     public void setCreditAgency(CreditAgencyService creditAgency)
 92  
     {
 93  0
         this.creditAgency = creditAgency;
 94  0
     }
 95  
 }