Coverage Report - org.mule.example.loanbroker.bank.Bank
 
Classes in this File Line Coverage Branch Coverage Complexity
Bank
0%
0/30
0%
0/6
1.4
 
 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.bank;
 8  
 
 9  
 import org.mule.api.endpoint.ImmutableEndpoint;
 10  
 import org.mule.api.service.Service;
 11  
 import org.mule.api.service.ServiceAware;
 12  
 import org.mule.example.loanbroker.message.LoanBrokerQuoteRequest;
 13  
 import org.mule.example.loanbroker.model.LoanQuote;
 14  
 import org.mule.service.ServiceCompositeMessageSource;
 15  
 
 16  
 import java.io.Serializable;
 17  
 import java.util.List;
 18  
 
 19  
 import org.apache.commons.logging.Log;
 20  
 import org.apache.commons.logging.LogFactory;
 21  
 
 22  
 /**
 23  
  * <code>Bank</code> is a representation of a bank from which to obtain loan
 24  
  * quotes.
 25  
  */
 26  
 
 27  
 public class Bank implements ServiceAware, Serializable, BankService
 28  
 {
 29  
     /**
 30  
      * Serial version
 31  
      */
 32  
     private static final long serialVersionUID = 4108271137166107769L;
 33  
 
 34  
     /**
 35  
      * logger used by this class
 36  
      */
 37  0
     protected static final Log logger = LogFactory.getLog(Bank.class);
 38  
 
 39  
     private String bankName;
 40  
     private double primeRate;
 41  
     
 42  
     /**
 43  
      * Incoming endpoint for the bank, this is used to create a static recipient list based on a list of banks.
 44  
      */
 45  
     private String endpoint;
 46  
 
 47  
     public Bank()
 48  0
     {
 49  0
         this.primeRate = Math.random() * 10;
 50  0
     }
 51  
 
 52  
     public Bank(String bankname)
 53  
     {
 54  0
         this();
 55  0
         this.bankName = bankname;
 56  
 
 57  
         // For simplicity, the endpoint for the bank is the same as the bank's name.
 58  0
         this.endpoint = bankName;
 59  0
     }
 60  
 
 61  
     // TODO This method doesn't help us with the Static Recipient list because the list of banks is created 
 62  
     // programatically in DefaultLenderService (they should be looked up from the config/registry).
 63  
     public void setService(Service service)
 64  
     {
 65  0
         this.bankName = service.getName(); 
 66  
 
 67  0
         if (!(service.getMessageSource() instanceof ServiceCompositeMessageSource))
 68  
         {
 69  0
             throw new IllegalStateException("Only 'ServiceCompositeMessageSource' is supported");
 70  
         }
 71  
 
 72  0
         List endpoints = ((ServiceCompositeMessageSource) service.getMessageSource()).getEndpoints();
 73  0
         if ((endpoints == null) || (endpoints.size() != 1))
 74  
         {
 75  0
             throw new IllegalArgumentException("Bank is expected to have exactly 1 incoming endpoint.");
 76  
         }
 77  
         // TODO This gives us the endpoint the bank is listening on, but the endpoint for sending to the bank 
 78  
         // is different in the ESB config ("Bank1In" vs. "Bank1")
 79  0
         this.endpoint = ((ImmutableEndpoint) endpoints.get(0)).getName();
 80  0
     }
 81  
 
 82  
     public LoanQuote getLoanQuote(LoanBrokerQuoteRequest request)
 83  
     {
 84  0
         LoanQuote quote = new LoanQuote();
 85  0
         quote.setBankName(getBankName());
 86  0
         quote.setInterestRate(primeRate);
 87  0
         logger.info("Returning Rate is: " + quote);
 88  
 
 89  0
         return quote;
 90  
     }
 91  
 
 92  
     public String getBankName()
 93  
     {
 94  0
         return bankName;
 95  
     }
 96  
 
 97  
     public void setBankName(String bankName)
 98  
     {
 99  0
         this.bankName = bankName;
 100  0
     }
 101  
 
 102  
     public double getPrimeRate()
 103  
     {
 104  0
         return primeRate;
 105  
     }
 106  
 
 107  
     public void setPrimeRate(double primeRate)
 108  
     {
 109  0
         this.primeRate = primeRate;
 110  0
     }
 111  
 
 112  
     public String getEndpoint()
 113  
     {
 114  0
         return endpoint;
 115  
     }
 116  
     public void setEndpoint(String endpoint)
 117  
     {
 118  0
         this.endpoint = endpoint;
 119  0
     }
 120  
 }