@Test public void testInterpretWithNull(){ ResponseObject result = CommandLinesInterpretor.interpretCommandLines(null); TestCase.assertTrue(result.isSuccess()); TestCase.assertNull(result.getPayload()); }
public static ResponseObject interpretCommandLines(String[] args){ logger.traceEntry("params: {}", args); if (args == null){ return logger.traceExit(new ResponseObject(true, "null arguments!", null)); } if (args.length == 0){ return logger.traceExit(new ResponseObject(true, "empty arguments", null)); } boolean isHelp = false; String configFileName = null; String generateFor = ""; for (int i = 0; i < args.length; i++){ isHelp = isHelp || isHelpArgument(args[i]); if (isConfig(args[i])){ configFileName = args[i].substring(args[i].indexOf("=") + 1); } if(isGenerate(args[i])){ generateFor = args[i].substring(args[i].indexOf("=") + 1); } } if (isHelp){ displayHelp(); return logger.traceExit(new ResponseObject(false, "displayed help", null)); } if (configFileName == null){ return logger.traceExit(new ResponseObject(true, "no file specified", null)); } else { Map<String, Object> properties = parseFileProperties(configFileName); if (properties == null) { System.out.println("Error parsing file! Can not start!"); return logger.traceExit(new ResponseObject(false, "config file parse error", null)); } if(generateFor == null || generateFor.isEmpty()){ return logger.traceExit(new ResponseObject(true, "autostart", properties)); } else{ String[] generateSplit = generateFor.split(";"); if(generateSplit.length !=3){ System.out.println("Error generating! Can not start!"); return logger.traceExit(new ResponseObject(false, "Error generating!", null)); } Integer nrShards = Integer.parseInt(generateSplit[0]); Integer nodesPerShard = Integer.parseInt(generateSplit[1]); Boolean shouldStartAutomatically = Boolean.parseBoolean(generateSplit[2]); Map<Integer, List<String>> shardPrivateKeys = new HashMap<>(); GeneratePrivateKeysPerShard(nrShards, nodesPerShard, shardPrivateKeys); List<String> configs = GenerateConfigFiles(shardPrivateKeys); String fileName = GenerateCommandFile(configs); if(shouldStartAutomatically) { try { Runtime.getRuntime().exec("cmd /c start " + fileName); } catch (IOException e) { e.printStackTrace(); } } return logger.traceExit(new ResponseObject(false, "generate", properties)); } } }
CommandLinesInterpretor { public static ResponseObject interpretCommandLines(String[] args){ logger.traceEntry("params: {}", args); if (args == null){ return logger.traceExit(new ResponseObject(true, "null arguments!", null)); } if (args.length == 0){ return logger.traceExit(new ResponseObject(true, "empty arguments", null)); } boolean isHelp = false; String configFileName = null; String generateFor = ""; for (int i = 0; i < args.length; i++){ isHelp = isHelp || isHelpArgument(args[i]); if (isConfig(args[i])){ configFileName = args[i].substring(args[i].indexOf("=") + 1); } if(isGenerate(args[i])){ generateFor = args[i].substring(args[i].indexOf("=") + 1); } } if (isHelp){ displayHelp(); return logger.traceExit(new ResponseObject(false, "displayed help", null)); } if (configFileName == null){ return logger.traceExit(new ResponseObject(true, "no file specified", null)); } else { Map<String, Object> properties = parseFileProperties(configFileName); if (properties == null) { System.out.println("Error parsing file! Can not start!"); return logger.traceExit(new ResponseObject(false, "config file parse error", null)); } if(generateFor == null || generateFor.isEmpty()){ return logger.traceExit(new ResponseObject(true, "autostart", properties)); } else{ String[] generateSplit = generateFor.split(";"); if(generateSplit.length !=3){ System.out.println("Error generating! Can not start!"); return logger.traceExit(new ResponseObject(false, "Error generating!", null)); } Integer nrShards = Integer.parseInt(generateSplit[0]); Integer nodesPerShard = Integer.parseInt(generateSplit[1]); Boolean shouldStartAutomatically = Boolean.parseBoolean(generateSplit[2]); Map<Integer, List<String>> shardPrivateKeys = new HashMap<>(); GeneratePrivateKeysPerShard(nrShards, nodesPerShard, shardPrivateKeys); List<String> configs = GenerateConfigFiles(shardPrivateKeys); String fileName = GenerateCommandFile(configs); if(shouldStartAutomatically) { try { Runtime.getRuntime().exec("cmd /c start " + fileName); } catch (IOException e) { e.printStackTrace(); } } return logger.traceExit(new ResponseObject(false, "generate", properties)); } } } }
CommandLinesInterpretor { public static ResponseObject interpretCommandLines(String[] args){ logger.traceEntry("params: {}", args); if (args == null){ return logger.traceExit(new ResponseObject(true, "null arguments!", null)); } if (args.length == 0){ return logger.traceExit(new ResponseObject(true, "empty arguments", null)); } boolean isHelp = false; String configFileName = null; String generateFor = ""; for (int i = 0; i < args.length; i++){ isHelp = isHelp || isHelpArgument(args[i]); if (isConfig(args[i])){ configFileName = args[i].substring(args[i].indexOf("=") + 1); } if(isGenerate(args[i])){ generateFor = args[i].substring(args[i].indexOf("=") + 1); } } if (isHelp){ displayHelp(); return logger.traceExit(new ResponseObject(false, "displayed help", null)); } if (configFileName == null){ return logger.traceExit(new ResponseObject(true, "no file specified", null)); } else { Map<String, Object> properties = parseFileProperties(configFileName); if (properties == null) { System.out.println("Error parsing file! Can not start!"); return logger.traceExit(new ResponseObject(false, "config file parse error", null)); } if(generateFor == null || generateFor.isEmpty()){ return logger.traceExit(new ResponseObject(true, "autostart", properties)); } else{ String[] generateSplit = generateFor.split(";"); if(generateSplit.length !=3){ System.out.println("Error generating! Can not start!"); return logger.traceExit(new ResponseObject(false, "Error generating!", null)); } Integer nrShards = Integer.parseInt(generateSplit[0]); Integer nodesPerShard = Integer.parseInt(generateSplit[1]); Boolean shouldStartAutomatically = Boolean.parseBoolean(generateSplit[2]); Map<Integer, List<String>> shardPrivateKeys = new HashMap<>(); GeneratePrivateKeysPerShard(nrShards, nodesPerShard, shardPrivateKeys); List<String> configs = GenerateConfigFiles(shardPrivateKeys); String fileName = GenerateCommandFile(configs); if(shouldStartAutomatically) { try { Runtime.getRuntime().exec("cmd /c start " + fileName); } catch (IOException e) { e.printStackTrace(); } } return logger.traceExit(new ResponseObject(false, "generate", properties)); } } }  }
CommandLinesInterpretor { public static ResponseObject interpretCommandLines(String[] args){ logger.traceEntry("params: {}", args); if (args == null){ return logger.traceExit(new ResponseObject(true, "null arguments!", null)); } if (args.length == 0){ return logger.traceExit(new ResponseObject(true, "empty arguments", null)); } boolean isHelp = false; String configFileName = null; String generateFor = ""; for (int i = 0; i < args.length; i++){ isHelp = isHelp || isHelpArgument(args[i]); if (isConfig(args[i])){ configFileName = args[i].substring(args[i].indexOf("=") + 1); } if(isGenerate(args[i])){ generateFor = args[i].substring(args[i].indexOf("=") + 1); } } if (isHelp){ displayHelp(); return logger.traceExit(new ResponseObject(false, "displayed help", null)); } if (configFileName == null){ return logger.traceExit(new ResponseObject(true, "no file specified", null)); } else { Map<String, Object> properties = parseFileProperties(configFileName); if (properties == null) { System.out.println("Error parsing file! Can not start!"); return logger.traceExit(new ResponseObject(false, "config file parse error", null)); } if(generateFor == null || generateFor.isEmpty()){ return logger.traceExit(new ResponseObject(true, "autostart", properties)); } else{ String[] generateSplit = generateFor.split(";"); if(generateSplit.length !=3){ System.out.println("Error generating! Can not start!"); return logger.traceExit(new ResponseObject(false, "Error generating!", null)); } Integer nrShards = Integer.parseInt(generateSplit[0]); Integer nodesPerShard = Integer.parseInt(generateSplit[1]); Boolean shouldStartAutomatically = Boolean.parseBoolean(generateSplit[2]); Map<Integer, List<String>> shardPrivateKeys = new HashMap<>(); GeneratePrivateKeysPerShard(nrShards, nodesPerShard, shardPrivateKeys); List<String> configs = GenerateConfigFiles(shardPrivateKeys); String fileName = GenerateCommandFile(configs); if(shouldStartAutomatically) { try { Runtime.getRuntime().exec("cmd /c start " + fileName); } catch (IOException e) { e.printStackTrace(); } } return logger.traceExit(new ResponseObject(false, "generate", properties)); } } }  static ResponseObject interpretCommandLines(String[] args); static void GeneratePrivateKeysPerShard(Integer nrShards, Integer nodesPerShard, Map<Integer, List<String>> shardPrivateKeys); }
CommandLinesInterpretor { public static ResponseObject interpretCommandLines(String[] args){ logger.traceEntry("params: {}", args); if (args == null){ return logger.traceExit(new ResponseObject(true, "null arguments!", null)); } if (args.length == 0){ return logger.traceExit(new ResponseObject(true, "empty arguments", null)); } boolean isHelp = false; String configFileName = null; String generateFor = ""; for (int i = 0; i < args.length; i++){ isHelp = isHelp || isHelpArgument(args[i]); if (isConfig(args[i])){ configFileName = args[i].substring(args[i].indexOf("=") + 1); } if(isGenerate(args[i])){ generateFor = args[i].substring(args[i].indexOf("=") + 1); } } if (isHelp){ displayHelp(); return logger.traceExit(new ResponseObject(false, "displayed help", null)); } if (configFileName == null){ return logger.traceExit(new ResponseObject(true, "no file specified", null)); } else { Map<String, Object> properties = parseFileProperties(configFileName); if (properties == null) { System.out.println("Error parsing file! Can not start!"); return logger.traceExit(new ResponseObject(false, "config file parse error", null)); } if(generateFor == null || generateFor.isEmpty()){ return logger.traceExit(new ResponseObject(true, "autostart", properties)); } else{ String[] generateSplit = generateFor.split(";"); if(generateSplit.length !=3){ System.out.println("Error generating! Can not start!"); return logger.traceExit(new ResponseObject(false, "Error generating!", null)); } Integer nrShards = Integer.parseInt(generateSplit[0]); Integer nodesPerShard = Integer.parseInt(generateSplit[1]); Boolean shouldStartAutomatically = Boolean.parseBoolean(generateSplit[2]); Map<Integer, List<String>> shardPrivateKeys = new HashMap<>(); GeneratePrivateKeysPerShard(nrShards, nodesPerShard, shardPrivateKeys); List<String> configs = GenerateConfigFiles(shardPrivateKeys); String fileName = GenerateCommandFile(configs); if(shouldStartAutomatically) { try { Runtime.getRuntime().exec("cmd /c start " + fileName); } catch (IOException e) { e.printStackTrace(); } } return logger.traceExit(new ResponseObject(false, "generate", properties)); } } }  static ResponseObject interpretCommandLines(String[] args); static void GeneratePrivateKeysPerShard(Integer nrShards, Integer nodesPerShard, Map<Integer, List<String>> shardPrivateKeys);  }