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