package com.net2plan.cli.plugins;

import com.net2plan.utils.StringUtils;
import org.apache.commons.cli.ParseException;
import org.junit.Test;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by Jorge San Emeterio on 22/03/17.
 */
public class CLINetworkDesignTest
{
    private final static String DEFAULT_PACKAGE = "com.net2plan.examples";
    private final static String DEFAULT_ALGORITHM = "Offline_Example_Algorithm";
    private final static String DEFAULT_OUTPUT = "out.n2p";

    private final static CLINetworkDesign networkDesign = new CLINetworkDesign();

    @Test(expected = ParseException.class)
    public void launchNoOptionParam() throws ParseException
    {
        final Map<String, String> paramMap = new HashMap<>();

        paramMap.put("--class-name", DEFAULT_ALGORITHM);
        paramMap.put("--output-file", DEFAULT_OUTPUT);

        final List<String> args = new LinkedList<>();
        for (Map.Entry<String, String> entry : paramMap.entrySet())
        {
            args.add(entry.getKey());
            args.add(entry.getValue());
        }

        networkDesign.executeFromCommandLine(StringUtils.toArray(args));
    }

    @Test(expected = ParseException.class)
    public void launchNoClassNameParam() throws ParseException
    {
        final Map<String, String> paramMap = new HashMap<>();

        paramMap.put("--package-name", DEFAULT_PACKAGE);
        paramMap.put("--output-file", DEFAULT_OUTPUT);

        final List<String> args = new LinkedList<>();
        for (Map.Entry<String, String> entry : paramMap.entrySet())
        {
            args.add(entry.getKey());
            args.add(entry.getValue());
        }

        networkDesign.executeFromCommandLine(StringUtils.toArray(args));
    }

    @Test(expected = ParseException.class)
    public void launchNoOutputFileParam() throws ParseException
    {
        final Map<String, String> paramMap = new HashMap<>();

        paramMap.put("--package-name", DEFAULT_PACKAGE);
        paramMap.put("--class-name", DEFAULT_ALGORITHM);

        final List<String> args = new LinkedList<>();
        for (Map.Entry<String, String> entry : paramMap.entrySet())
        {
            args.add(entry.getKey());
            args.add(entry.getValue());
        }

        networkDesign.executeFromCommandLine(StringUtils.toArray(args));
    }

    @Test(expected = RuntimeException.class)
    public void launchBothOptionParam() throws ParseException
    {
        final Map<String, String> paramMap = new HashMap<>();

        paramMap.put("--class-file", "null");
        paramMap.put("--package-name", DEFAULT_PACKAGE);
        paramMap.put("--class-name", DEFAULT_ALGORITHM);
        paramMap.put("--output-file", DEFAULT_OUTPUT);

        final List<String> args = new LinkedList<>();
        for (Map.Entry<String, String> entry : paramMap.entrySet())
        {
            args.add(entry.getKey());
            args.add(entry.getValue());
        }

        networkDesign.executeFromCommandLine(StringUtils.toArray(args));
    }
}

@@ -141,109 +141,8 @@
 t;%0A%0A
-import java.util.HashMap;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A
 /**%0A
@@ -256,788 +256,261 @@
 tic 
-String DEFAULT_PACKAGE = %22com.net2plan.examples%22;%0A    private final static String DEFAULT_ALGORITHM = %22Offline_Example_Algorithm%22;%0A    private final static String DEFAULT_OUTPUT = %22out.n2p%22;%0A%0A    private final static CLINetworkDesign networkDesign = new CLINetworkDesign();%0A%0A    @Test(expected = ParseException.class)%0A    public void launchNoOptionParam() throws ParseException%0A    %7B%0A        final Map%3CString, String%3E paramMap = new HashMap%3C%3E();%0A%0A        paramMap.put(%22--class-name%22, DEFAULT_ALGORITHM);%0A        paramMap.put(%22--output-file%22, DEFAULT_OUTPUT);%0A%0A        final List%3CString%3E args = new LinkedList%3C%3E();%0A        for (Map.Entry%3CString, String%3E entry : paramMap.entrySet())%0A        %7B%0A            args.add(entry.getKey());%0A            args.add(entry.getValue());%0A        %7D%0A
+CLINetworkDesign networkDesign = new CLINetworkDesign();%0A%0A    @Test(expected = ParseException.class)%0A    public void launchNoOptionParam() throws ParseException%0A    %7B%0A        String%5B%5D args = StringUtils.arrayOf(%22--class-name%22, %22 %22, %22--output-file%22, %22%22);
 %0A   
@@ -555,34 +555,13 @@
 ine(
-StringUtils.toArray(
 args)
-)
 ;%0A  
@@ -689,396 +689,88 @@
     
-final Map%3CString, String%3E paramMap = new HashMap%3C%3E();%0A%0A        paramMap.put(%22--package-name%22, DEFAULT_PACKAGE);%0A        paramMap.put(%22--output-file%22, DEFAULT_OUTPUT);%0A%0A        final List%3CString%3E args = new LinkedList%3C%3E();%0A        for (Map.Entry%3CString, String%3E entry : paramMap.entrySet())%0A        %7B%0A            args.add(entry.getKey());%0A            args.add(entry.getValue());%0A        %7D%0A
+String%5B%5D args = StringUtils.arrayOf(%22--package-name%22, %22 %22, %22--output-file%22, %22%22);
 %0A   
@@ -815,34 +815,13 @@
 ine(
-StringUtils.toArray(
 args)
-)
 ;%0A  
@@ -950,398 +950,87 @@
     
-final Map%3CString, String%3E paramMap = new HashMap%3C%3E();%0A%0A        paramMap.put(%22--package-name%22, DEFAULT_PACKAGE);%0A        paramMap.put(%22--class-name%22, DEFAULT_ALGORITHM);%0A%0A        final List%3CString%3E args = new LinkedList%3C%3E();%0A        for (Map.Entry%3CString, String%3E entry : paramMap.entrySet())%0A        %7B%0A            args.add(entry.getKey());%0A            args.add(entry.getValue());%0A        %7D%0A
+String%5B%5D args = StringUtils.arrayOf(%22--package-name%22, %22 %22, %22--class-name%22, %22%22);
 %0A   
@@ -1075,34 +1075,13 @@
 ine(
-StringUtils.toArray(
 args)
-)
 ;%0A  
@@ -1210,499 +1210,130 @@
     
-final Map%3CString, String%3E paramMap = new HashMap%3C%3E();%0A%0A        paramMap.put(%22--class-file%22, %22null%22);%0A        paramMap.put(%22--package-name%22, DEFAULT_PACKAGE);%0A        paramMap.put(%22--class-name%22, DEFAULT_ALGORITHM);%0A        paramMap.put(%22--output-file%22, DEFAULT_OUTPUT);%0A%0A        final List%3CString%3E args = new LinkedList%3C%3E();%0A        for (Map.Entry%3CString, String%3E entry : paramMap.entrySet())%0A        %7B%0A            args.add(entry.getKey());%0A            args.add(entry.getValue());%0A        %7D%0A
+String%5B%5D args = StringUtils.arrayOf(%22--class-file%22, %22 %22, %22--package-name%22, %22 %22, %22--class-name%22, %22 %22, %22--output-file%22, %22%22);
 %0A   
@@ -1378,34 +1378,13 @@
 ine(
-StringUtils.toArray(
 args)
-)
 ;%0A  

Simplify test