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