Coverage Report - org.mule.examples.loanbroker.bank.Bank
 
Classes in this File Line Coverage Branch Coverage Complexity
Bank
0%
0/28
0%
0/1
1.2
 
 1  
 /*
 2  
  * $Id: Bank.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.examples.loanbroker.bank;
 12  
 
 13  
 import org.mule.config.ConfigurationException;
 14  
 import org.mule.config.i18n.MessageFactory;
 15  
 import org.mule.examples.loanbroker.LocaleMessage;
 16  
 import org.mule.examples.loanbroker.messages.LoanBrokerQuoteRequest;
 17  
 import org.mule.examples.loanbroker.messages.LoanQuote;
 18  
 import org.mule.impl.UMODescriptorAware;
 19  
 import org.mule.umo.UMODescriptor;
 20  
 import org.mule.umo.endpoint.UMOEndpoint;
 21  
 
 22  
 import java.io.Serializable;
 23  
 import java.util.List;
 24  
 
 25  
 import org.apache.commons.logging.Log;
 26  
 import org.apache.commons.logging.LogFactory;
 27  
 
 28  
 /**
 29  
  * <code>Bank</code> is a representation of a bank form which to obtain loan
 30  
  * quotes.
 31  
  * 
 32  
  * @author Gregor Hohpe, Bobby Wolfe, et al. EI Patterns
 33  
  */
 34  
 
 35  
 public class Bank implements UMODescriptorAware, Serializable, BankService
 36  
 {
 37  
     /**
 38  
      * Serial version
 39  
      */
 40  
     private static final long serialVersionUID = 4108271137166107769L;
 41  
 
 42  
     /**
 43  
      * logger used by this class
 44  
      */
 45  0
     protected static transient Log logger = LogFactory.getLog(Bank.class);
 46  
 
 47  
     private String bankName;
 48  
     private double primeRate;
 49  
     
 50  
     /**
 51  
      * Incoming endpoint for the bank, this is used to create a static recipient list based on a list of banks.
 52  
      */
 53  
     private String endpoint;
 54  
 
 55  
     public Bank()
 56  0
     {
 57  0
         this.primeRate = Math.random() * 10;
 58  0
     }
 59  
 
 60  
     public Bank(String bankname)
 61  
     {
 62  0
         this();
 63  0
         this.bankName = bankname;
 64  
 
 65  
         // For simplicity, the endpoint for the bank is the same as the bank's name.
 66  0
         this.endpoint = bankName;
 67  0
     }
 68  
 
 69  
     // TODO This method doesn't help us with the Static Recipient list because the list of banks is created 
 70  
     // programatically in DefaultLenderService (they should be looked up from the config/registry).
 71  
     public void setDescriptor(UMODescriptor descriptor) throws ConfigurationException 
 72  
     {
 73  0
         this.bankName = descriptor.getName();
 74  
 
 75  0
         List endpoints = descriptor.getInboundRouter().getEndpoints();
 76  0
         if ((endpoints == null) || (endpoints.size() != 1))
 77  
         {
 78  0
             throw new ConfigurationException(MessageFactory.createStaticMessage("Bank is expected to have exactly 1 incoming endpoint."));
 79  
         }
 80  
         // TODO This gives us the endpoint the bank is listening on, but the endpoint for sending to the bank 
 81  
         // is different in the ESB config ("Bank1In" vs. "Bank1")
 82  0
         this.endpoint = ((UMOEndpoint) endpoints.get(0)).getName();
 83  0
     }
 84  
 
 85  
     public LoanQuote getLoanQuote(LoanBrokerQuoteRequest request)
 86  
     {
 87  0
         LoanQuote quote = new LoanQuote();
 88  0
         quote.setBankName(getBankName());
 89  0
         quote.setInterestRate(primeRate);
 90  0
         logger.info(LocaleMessage.receivedRate(quote));
 91  
         
 92  0
         return quote;
 93  
     }
 94  
 
 95  
     public String getBankName()
 96  
     {
 97  0
         return bankName;
 98  
     }
 99  
 
 100  
     public void setBankName(String bankName)
 101  
     {
 102  0
         this.bankName = bankName;
 103  0
     }
 104  
 
 105  
     public double getPrimeRate()
 106  
     {
 107  0
         return primeRate;
 108  
     }
 109  
 
 110  
     public void setPrimeRate(double primeRate)
 111  
     {
 112  0
         this.primeRate = primeRate;
 113  0
     }
 114  
 
 115  
     public String getEndpoint()
 116  
     {
 117  0
         return endpoint;
 118  
     }
 119  
     public void setEndpoint(String endpoint)
 120  
     {
 121  0
         this.endpoint = endpoint;
 122  0
     }
 123  
 }