Coverage Report - org.mule.example.loanbroker.routers.BankQuotesAggregationLogic
 
Classes in this File Line Coverage Branch Coverage Complexity
BankQuotesAggregationLogic
0%
0/19
0%
0/8
6
 
 1  
 /*
 2  
  * $Id: BankQuotesAggregationLogic.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.routers;
 12  
 
 13  
 import org.mule.DefaultMuleEvent;
 14  
 import org.mule.DefaultMuleMessage;
 15  
 import org.mule.api.MuleEvent;
 16  
 import org.mule.example.loanbroker.LocaleMessage;
 17  
 import org.mule.example.loanbroker.messages.LoanQuote;
 18  
 import org.mule.routing.EventGroup;
 19  
 
 20  
 import java.util.Iterator;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  0
 public class BankQuotesAggregationLogic
 26  
 {
 27  
     /**
 28  
      * logger used by this class
 29  
      */
 30  0
     protected static final Log logger = LogFactory.getLog(BankQuotesAggregationLogic.class);
 31  
     
 32  
     public static MuleEvent aggregateEvents(EventGroup events) throws Exception
 33  
     {
 34  0
         LoanQuote lowestQuote = null;
 35  0
         LoanQuote quote = null;
 36  0
         MuleEvent event = null;
 37  
 
 38  0
         for (Iterator iterator = events.iterator(); iterator.hasNext();)
 39  
         {
 40  0
             event = (MuleEvent)iterator.next();
 41  0
             Object o = event.getMessage().getPayload();
 42  0
             if(o instanceof LoanQuote)
 43  
             {
 44  0
                 quote = (LoanQuote)o;
 45  
             }
 46  
             else
 47  
             {
 48  0
                 throw new IllegalArgumentException("Object received by Aggregator is not of expected type. Wanted: "
 49  
                         + LoanQuote.class.getName() + " Got: " + o);
 50  
             }
 51  0
             logger.info(LocaleMessage.processingQuote(quote));
 52  
 
 53  0
             if (lowestQuote == null)
 54  
             {
 55  0
                 lowestQuote = quote;
 56  
             }
 57  
             else
 58  
             {
 59  0
                 if (quote.getInterestRate() < lowestQuote.getInterestRate())
 60  
                 {
 61  0
                     lowestQuote = quote;
 62  
                 }
 63  
             }
 64  0
         }
 65  
 
 66  0
         logger.info(LocaleMessage.lowestQuote(lowestQuote));
 67  0
         return new DefaultMuleEvent(new DefaultMuleMessage(lowestQuote, event.getMessage(),
 68  
             event.getMuleContext()), event);
 69  
     }
 70  
 }