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