CLINetworkDesign extends ICLIModule { @Override public void executeFromCommandLine(String[] args) throws ParseException { final CommandLineParser parser = new CommandLineParser(); final CommandLine cli = parser.parse(OPTIONS, args); final File classFile = (File) cli.getParsedOptionValue("class-file"); final String className = (String) cli.getParsedOptionValue("class-name"); NetPlan netPlan; if (cli.hasOption("input-file")) { final File inputFile = (File) cli.getParsedOptionValue("input-file"); netPlan = new NetPlan(inputFile); } else { netPlan = new NetPlan(); } if (cli.hasOption("traffic-file")) { NetPlan demands = new NetPlan((File) cli.getParsedOptionValue("traffic-file")); NetworkLayer layer = (cli.hasOption("traffic-layer")) ? netPlan.getNetworkLayerFromId(((Number) cli.getParsedOptionValue("traffic-layer")).longValue()) : netPlan.getNetworkLayerDefault(); netPlan.removeAllDemands(layer); for (Demand demand : demands.getDemands()) { netPlan.addDemand(demand.getIngressNode(), demand.getEgressNode(), demand.getOfferedTraffic(), RoutingType.SOURCE_ROUTING , demand.getAttributes(), layer); } netPlan.removeAllMulticastDemands(layer); for (MulticastDemand demand : demands.getMulticastDemands()) { netPlan.addMulticastDemand(demand.getIngressNode(), demand.getEgressNodes(), demand.getOfferedTraffic(), demand.getAttributes(), layer); } } File outputFile = (File) cli.getParsedOptionValue("output-file"); IAlgorithm algorithm; if (!cli.hasOption("package-name")) { algorithm = ClassLoaderUtils.getInstance(classFile, className, IAlgorithm.class , null); } else { algorithm = findAlgorithm(className, cli.getOptionValue("package-name")); } List<Triple<String, String, String>> defaultAlgorithmParameters = algorithm.getParameters(); Map<String, String> algorithmParameters = CommandLineParser.getParameters(defaultAlgorithmParameters, cli.getOptionProperties("alg-param")); Configuration.updateSolverLibraryNameParameter(algorithmParameters); Map<String, String> net2planParameters = Configuration.getNet2PlanOptions(); System.out.println("Net2Plan parameters"); System.out.println("-----------------------------"); System.out.println(StringUtils.mapToString(net2planParameters, "=", String.format("%n"))); System.out.println(); System.out.println("Algorithm parameters"); System.out.println("-----------------------------"); System.out.println(algorithmParameters.isEmpty() ? "None" : StringUtils.mapToString(algorithmParameters, "=", String.format("%n"))); System.out.println(); System.out.println("Executing algorithm..."); System.out.println(); long init = System.nanoTime(); String out = algorithm.executeAlgorithm(netPlan, algorithmParameters, net2planParameters); netPlan.saveToFile(outputFile); long end = System.nanoTime(); System.out.println(String.format("%n%nAlgorithm finished successfully in %f seconds%nOutput message: %s", (end - init) / 1e9, out)); }  @Override void executeFromCommandLine(String[] args); @Override String getCommandLineHelp(); @Override Options getCommandLineOptions(); @Override String getDescription(); @Override String getModeName(); @Override String getName(); @Override List<Triple<String, String, String>> getParameters(); @Override int getPriority();  }
@Test(expected = ParseException.class) public void launchNoOptionParam() throws ParseException { String[] args = StringUtils.arrayOf("--class-name", " ", "--output-file", ""); networkDesign.executeFromCommandLine(args); }
@Test(expected = ParseException.class) public void launchNoClassNameParam() throws ParseException { String[] args = StringUtils.arrayOf("--package-name", " ", "--output-file", ""); networkDesign.executeFromCommandLine(args); }
@Test(expected = ParseException.class) public void launchNoOutputFileParam() throws ParseException { String[] args = StringUtils.arrayOf("--package-name", " ", "--class-name", ""); networkDesign.executeFromCommandLine(args); }
@Test(expected = RuntimeException.class) public void launchBothOptionParam() throws ParseException { String[] args = StringUtils.arrayOf("--class-file", " ", "--package-name", " ", "--class-name", " ", "--output-file", ""); networkDesign.executeFromCommandLine(args); }