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