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