Coverage Report - org.mule.example.loanbroker.esn.LoanBrokerApp
 
Classes in this File Line Coverage Branch Coverage Complexity
LoanBrokerApp
0%
0/52
0%
0/17
0
 
 1  
 /*
 2  
  * $Id: LoanBrokerApp.java 20321 2010-11-24 15:21:24Z dfeist $
 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.esn;
 12  
 
 13  
 import org.mule.example.loanbroker.AbstractLoanBrokerApp;
 14  
 import org.mule.example.loanbroker.LocaleMessage;
 15  
 import org.mule.example.loanbroker.messages.LoanQuote;
 16  
 import org.mule.util.DateUtils;
 17  
 import org.mule.util.StringMessageUtils;
 18  
 import org.mule.util.StringUtils;
 19  
 import org.mule.util.SystemUtils;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.util.ArrayList;
 23  
 import java.util.Iterator;
 24  
 import java.util.List;
 25  
 import java.util.Map;
 26  
 
 27  
 /**
 28  
  * Runs the LoanBroker ESN example application.
 29  
  */
 30  
 public class LoanBrokerApp extends AbstractLoanBrokerApp
 31  
 {
 32  0
     public static final String CLI_OPTIONS[][] = {
 33  
             { "config", "true", "Configuration File(s)" },
 34  
             { "main", "true", "LoanBrokerApp Class"},
 35  
             { "req", "true", "Number of loan requests to use"},
 36  
             { "sync", "true", "Whether to run in synchronous mode or not"}
 37  
         };
 38  
 
 39  0
     private static boolean synchronous = false;
 40  
 
 41  
     // Needed for webapp version!
 42  
     // TODO Travis ... sadly, it doesn't quite work
 43  
     public LoanBrokerApp() throws Exception
 44  
     {
 45  0
         super();
 46  0
     }
 47  
 
 48  
     public LoanBrokerApp(String config) throws Exception
 49  
     {
 50  0
         super(config);
 51  0
     }
 52  
 
 53  
     public static void main(String[] args) throws Exception
 54  
     {
 55  0
         LoanBrokerApp loanBrokerApp = null;
 56  
         
 57  
         /////////////////////////////////////////
 58  
         // Command-line config
 59  
         /////////////////////////////////////////
 60  0
         Map<String, Object> options = SystemUtils.getCommandLineOptions(args, CLI_OPTIONS);
 61  0
         String config = (String)options.get("config");
 62  0
         if (StringUtils.isNotBlank(config))
 63  
         {
 64  0
             loanBrokerApp = new LoanBrokerApp(config);
 65  
 
 66  0
             int i = 100;
 67  0
             String requests = (String)options.get("req");
 68  0
             if (requests != null)
 69  
             {
 70  0
                 i = Integer.parseInt(requests);
 71  
             }
 72  
 
 73  0
             String sync = (String)options.get("sync");
 74  0
             if (sync != null)
 75  
             {
 76  0
                 synchronous = Boolean.valueOf(sync).booleanValue();
 77  
             }
 78  
 
 79  0
             if (synchronous)
 80  
             {
 81  0
                 long start = System.currentTimeMillis();
 82  0
                 List<Object> results = loanBrokerApp.requestSend(i, "CustomerRequests");
 83  0
                 System.out.println(LocaleMessage.responseNumQuotes(results.size()));
 84  0
                 List<String> output = new ArrayList<String>(results.size());
 85  0
                 int x = 1;
 86  0
                 for (Iterator<Object> iterator = results.iterator(); iterator.hasNext(); x++)
 87  
                 {
 88  0
                     LoanQuote quote = (LoanQuote) iterator.next();
 89  0
                     output.add(x + ". " + quote.toString());
 90  
                 }
 91  
                 
 92  0
                 System.out.println(StringMessageUtils.getBoilerPlate(output, '*', 80));
 93  0
                 long cur = System.currentTimeMillis();
 94  0
                 System.out.println(DateUtils.getFormattedDuration(cur - start));
 95  0
                 System.out.println(LocaleMessage.responseAvgRequest(((cur - start) / x)));
 96  0
             }
 97  
             else
 98  
             {
 99  0
                 loanBrokerApp.requestDispatch(i, "CustomerRequests");
 100  
             }
 101  0
         }
 102  
         /////////////////////////////////////////
 103  
         // Interactive config
 104  
         /////////////////////////////////////////
 105  
         else
 106  
         {
 107  0
             loanBrokerApp = new LoanBrokerApp(getInteractiveConfig());
 108  0
             loanBrokerApp.run(synchronous);
 109  
         }
 110  0
     }
 111  
 
 112  
     protected static String getInteractiveConfig() throws IOException
 113  
     {
 114  0
         System.out.println(StringMessageUtils.getBoilerPlate(LocaleMessage.welcome()));
 115  
                     
 116  0
         int response = 0;
 117  0
         String mode = null;
 118  0
         while (response != 'a' && response != 's')
 119  
         {
 120  0
             System.out.println("\n" + LocaleMessage.menuOptionMode());
 121  0
             response = readCharacter();
 122  0
             switch (response)
 123  
             {
 124  
                 case 'a' :
 125  
                 {
 126  0
                     System.out.println(LocaleMessage.loadingAsync());
 127  0
                     mode = "async";
 128  0
                     break;
 129  
                 }
 130  
 
 131  
                 case 's' :
 132  
                 {
 133  0
                     System.out.println(LocaleMessage.loadingSync());
 134  0
                     mode = "sync";
 135  0
                     break;
 136  
                 }
 137  
             }
 138  
         }
 139  
 
 140  0
         String config = "loan-broker-" + mode + "-config.xml, loan-broker-cxf-endpoints-config.xml";
 141  0
         return config;
 142  
     }
 143  
 }