From 89cf755a6e80c5ebd4bd989faad85aba60fc7b69 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Fri, 13 Oct 2017 15:36:44 +0530 Subject: Removed the dead codes Swagger client sdk support is removed. Issue-Id: CLI-66 Change-Id: Ic7b23cfd72f2ae29de7ab44d2cffb35af2db701b Signed-off-by: Kanagaraj Manickam k00365106 --- main/src/main/java/org/onap/cli/main/OnapCli.java | 4 +- .../org/onap/cli/main/utils/OnapCliArgsParser.java | 232 ++++++++++++++++ .../java/org/onap/cli/main/utils/OnapCliUtils.java | 295 --------------------- .../java/org/onap/cli/main/OnapCliMainTest.java | 4 +- .../org/onap/cli/main/utils/OnapCliUtilsTest.java | 36 +-- 5 files changed, 254 insertions(+), 317 deletions(-) create mode 100644 main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java delete mode 100644 main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java (limited to 'main') diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java index 77de4408..15f845b6 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -38,7 +38,7 @@ import org.onap.cli.fw.output.PrintDirection; import org.onap.cli.fw.output.ResultType; import org.onap.cli.main.conf.OnapCliConstants; import org.onap.cli.main.interactive.StringCompleter; -import org.onap.cli.main.utils.OnapCliUtils; +import org.onap.cli.main.utils.OnapCliArgsParser; import org.onap.cli.sample.yaml.SampleYamlGenerator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -356,7 +356,7 @@ public class OnapCli { } } - OnapCliUtils.populateParams(cmd.getParameters(), args); + OnapCliArgsParser.populateParams(cmd.getParameters(), args); OnapCommandResult result = cmd.execute(); this.print(result.getDebugInfo()); diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java new file mode 100644 index 00000000..725459e9 --- /dev/null +++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java @@ -0,0 +1,232 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.cli.main.utils; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +import net.minidev.json.JSONObject; + +import org.apache.commons.io.FileUtils; +import org.onap.cli.fw.error.OnapCommandException; +import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; +import org.onap.cli.fw.input.OnapCommandParameter; +import org.onap.cli.fw.input.ParameterType; +import org.onap.cli.main.error.OnapCliArgumentValueMissing; +import org.onap.cli.main.error.OnapCliInvalidArgument; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Oclip CLI utilities. + * + */ +public class OnapCliArgsParser { + + /** + * private Constructor. + */ + private OnapCliArgsParser() { + + } + + /** + * It read thru the args and populate the given params for short optional, long option and postional args the idx of + * positional args, is calculated based on the position at which it present in the params and args. + * + * @param params + * List of command paramters + * @param args + * Array of arguments + * @throws OnapCliArgumentValueMissing + * ArgumentValueMissing exception + * @throws OnapCliInvalidArgument + * Invalid argument exception + * @throws OnapCommandInvalidParameterValue + * exception + */ + public static void populateParams(List params, List args) + throws OnapCommandException { + Map shortOptionMap = new HashMap<>(); + Map longOptionMap = new HashMap<>(); + List positionArgs = new ArrayList<>(); + Map paramMap = new HashMap<>(); + + for (OnapCommandParameter param : params) { + boolean positional = true; + if (param.getShortOption() != null) { + shortOptionMap.put(OnapCommandParameter.printShortOption(param.getShortOption()), param.getName()); + positional = false; + } + if (param.getLongOption() != null) { + longOptionMap.put(OnapCommandParameter.printLongOption(param.getLongOption()), param.getName()); + positional = false; + } + + if (positional) { + positionArgs.add(param.getName()); + } + + paramMap.put(param.getName(), param); + } + + int positionalIdx = 0; + // Skip the first args oclip cmd name, so start from 1 + for (int i = 1; i < args.size(); i++) { + String paramName = null; + if (shortOptionMap.containsKey(args.get(i))) { + paramName = shortOptionMap.get(args.get(i)); + } else if (longOptionMap.containsKey(args.get(i))) { + paramName = longOptionMap.get(args.get(i)); + } + + if (paramName != null) { + // end of the list or if its option rather than a value + if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) { + if (paramMap.get(paramName).getParameterType().equals(ParameterType.BOOL)) { + paramMap.get(paramName).setValue("true"); + continue; + } + throw new OnapCliArgumentValueMissing(args.get(i)); + } + + if (paramMap.get(paramName).getParameterType().equals(ParameterType.JSON)) { + paramMap.get(paramName).setValue(readJsonStringFromUrl(args.get(i + 1), + paramMap.get(paramName).getName())); + i++; + continue; + } if (paramMap.get(paramName).getParameterType().equals(ParameterType.TEXT)) { + paramMap.get(paramName).setValue(readTextStringFromUrl(args.get(i + 1), + paramMap.get(paramName).getName())); + i++; + continue; + } else if (paramMap.get(paramName).getParameterType() + .equals(ParameterType.ARRAY)) { + Object value = paramMap.get(paramName).getValue(); + List list; + if (value == "") { + list = new ArrayList<>(); + } else { + list = convertJsonToListString(paramMap.get(paramName).getName(), + value.toString()); + } + list.add(args.get(i + 1)); + paramMap.get(paramName).setValue(list); + i++; + continue; + } else if (paramMap.get(paramName).getParameterType().equals(ParameterType.MAP)) { + Object value = paramMap.get(paramName).getValue(); + + Map map; + + if (value == "") { + map = new HashMap<>(); + } else { + map = convertJsonToMapString(paramMap.get(paramName).getName(), + value.toString()); + } + + String arg = args.get(i + 1); + String[] argArr = arg.split("="); + + if (argArr.length != 2) { + throw new OnapCliInvalidArgument(paramMap.get(paramName).getName()); + } + + map.put(argArr[0], argArr[1]); + paramMap.get(paramName).setValue(map); + i++; + continue; + } + + paramMap.get(paramName).setValue(args.get(i + 1)); + + i++; + continue; + } + + // it is positional option + // Positional arg is missing from the params + if (positionalIdx >= positionArgs.size()) { + throw new OnapCliInvalidArgument(args.get(i)); + } + + paramMap.get(positionArgs.get(positionalIdx)).setValue(args.get(i)); + positionalIdx++; + } + + params.clear(); + params.addAll(paramMap.values()); + } + + private static String readJsonStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { + ObjectMapper mapper = new ObjectMapper(); + try { + File file = new File(input); + if (file.isFile()) { + return mapper.readValue(file, JSONObject.class).toJSONString(); + } else if (input.startsWith("file:") || input.startsWith("http:") || input.startsWith("ftp:")) { + URL jsonUrl = new URL(input); + return mapper.readValue(jsonUrl, JSONObject.class).toJSONString(); + } else { + return mapper.readValue(input, JSONObject.class).toJSONString(); + } + } catch (IOException e) { + throw new OnapCliInvalidArgument(argName, e); + } + } + + private static String readTextStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { + try { + File file = new File(input); + if (file.isFile()) { + return FileUtils.readFileToString(file); + } else { + return input; + } + + } catch (IOException e) { + throw new OnapCliInvalidArgument(argName, e); + } + } + + private static List convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument { + TypeReference> mapType = new TypeReference>() { + }; + try { + return new ObjectMapper().readValue(json, mapType); + } catch (IOException e) { + throw new OnapCliInvalidArgument(arg, e); + } + } + + private static Map convertJsonToMapString(String arg, String json) throws OnapCliInvalidArgument { + TypeReference> mapType = new TypeReference>() { + }; + try { + return new ObjectMapper().readValue(json, mapType); + } catch (IOException e) { + throw new OnapCliInvalidArgument(arg, e); + } + } +} diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java deleted file mode 100644 index 99cfa7dd..00000000 --- a/main/src/main/java/org/onap/cli/main/utils/OnapCliUtils.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.cli.main.utils; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; - -import net.minidev.json.JSONObject; - -import org.apache.commons.io.FileUtils; -import org.onap.cli.fw.error.OnapCommandException; -import org.onap.cli.fw.error.OnapCommandInvalidParameterValue; -import org.onap.cli.fw.input.OnapCommandParameter; -import org.onap.cli.fw.input.ParameterType; -import org.onap.cli.main.error.OnapCliArgumentValueMissing; -import org.onap.cli.main.error.OnapCliInvalidArgument; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Oclip CLI utilities. - * - */ -public class OnapCliUtils { - - /** - * private Constructor. - */ - private OnapCliUtils() { - - } - - /** - * It read thru the args and populate the given params for short optional, long option and postional args the idx of - * positional args, is calculated based on the position at which it present in the params and args. - * - * @param params - * List of command paramters - * @param args - * Array of arguments - * @throws OnapCliArgumentValueMissing - * ArgumentValueMissing exception - * @throws OnapCliInvalidArgument - * Invalid argument exception - * @throws OnapCommandInvalidParameterValue - * exception - */ - public static void populateParams(List params, List args) - throws OnapCommandException { - Map shortOptionMap = new HashMap<>(); - Map longOptionMap = new HashMap<>(); - List positionArgs = new ArrayList<>(); - Map paramMap = new HashMap<>(); - - for (OnapCommandParameter param : params) { - boolean positional = true; - if (param.getShortOption() != null) { - shortOptionMap.put(OnapCommandParameter.printShortOption(param.getShortOption()), param.getName()); - positional = false; - } - if (param.getLongOption() != null) { - longOptionMap.put(OnapCommandParameter.printLongOption(param.getLongOption()), param.getName()); - positional = false; - } - - if (positional) { - positionArgs.add(param.getName()); - } - - paramMap.put(param.getName(), param); - } - - int positionalIdx = 0; - // Skip the first args oclip cmd name, so start from 1 - for (int i = 1; i < args.size(); i++) { - // check if short option exist - // (mrkanag) Optimize the below code to handle short and long options in one iteration - // now its redundant - if (shortOptionMap.containsKey(args.get(i))) { - // end of the list or if its option rather than a value - if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) { - if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.BOOL)) { - paramMap.get(shortOptionMap.get(args.get(i))).setValue("true"); - continue; - } - throw new OnapCliArgumentValueMissing(args.get(i)); - } - - if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.JSON)) { - paramMap.get(shortOptionMap.get(args.get(i))).setValue(readJsonStringFromUrl(args.get(i + 1), - paramMap.get(shortOptionMap.get(args.get(i))).getName())); - i++; - continue; - } if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.TEXT)) { - paramMap.get(shortOptionMap.get(args.get(i))).setValue(readTextStringFromUrl(args.get(i + 1), - paramMap.get(shortOptionMap.get(args.get(i))).getName())); - i++; - continue; - } else if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType() - .equals(ParameterType.ARRAY)) { - Object value = paramMap.get(shortOptionMap.get(args.get(i))).getValue(); - List list; - if (value == "") { - list = new ArrayList<>(); - } else { - list = convertJsonToListString(paramMap.get(shortOptionMap.get(args.get(i))).getName(), - value.toString()); - } - list.add(args.get(i + 1)); - paramMap.get(shortOptionMap.get(args.get(i))).setValue(list); - i++; - continue; - } else if (paramMap.get(shortOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.MAP)) { - Object value = paramMap.get(shortOptionMap.get(args.get(i))).getValue(); - - Map map; - - if (value == "") { - map = new HashMap<>(); - } else { - map = convertJsonToMapString(paramMap.get(shortOptionMap.get(args.get(i))).getName(), - value.toString()); - } - - String arg = args.get(i + 1); - String[] argArr = arg.split("="); - - if (argArr.length != 2) { - throw new OnapCliInvalidArgument(paramMap.get(shortOptionMap.get(args.get(i))).getName()); - } - - map.put(argArr[0], argArr[1]); - paramMap.get(shortOptionMap.get(args.get(i))).setValue(map); - i++; - continue; - } - - paramMap.get(shortOptionMap.get(args.get(i))).setValue(args.get(i + 1)); - - i++; - continue; - } - - // check if long option exist - if (longOptionMap.containsKey(args.get(i))) { - // end of the list or if its option rather than a value - if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) { - if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.BOOL)) { - paramMap.get(longOptionMap.get(args.get(i))).setValue("true"); - continue; - } - throw new OnapCliArgumentValueMissing(args.get(i)); - } - - if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.JSON)) { - paramMap.get(longOptionMap.get(args.get(i))).setValue(readJsonStringFromUrl(args.get(i + 1), - paramMap.get(longOptionMap.get(args.get(i))).getName())); - i++; - continue; - } else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.TEXT)) { - paramMap.get(longOptionMap.get(args.get(i))).setValue(readTextStringFromUrl(args.get(i + 1), - paramMap.get(longOptionMap.get(args.get(i))).getName())); - i++; - continue; - } else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType() - .equals(ParameterType.ARRAY)) { - Object value = paramMap.get(longOptionMap.get(args.get(i))).getValue(); - List list; - if (value == "") { - list = new ArrayList<>(); - } else { - list = convertJsonToListString(paramMap.get(longOptionMap.get(args.get(i))).getName(), - value.toString()); - } - list.add(args.get(i + 1)); - paramMap.get(longOptionMap.get(args.get(i))).setValue(list); - i++; - continue; - } else if (paramMap.get(longOptionMap.get(args.get(i))).getParameterType().equals(ParameterType.MAP)) { - - Object value = paramMap.get(longOptionMap.get(args.get(i))).getValue(); - - Map map; - - if (value == "") { - map = new HashMap<>(); - } else { - map = convertJsonToMapString(paramMap.get(longOptionMap.get(args.get(i))).getName(), - value.toString()); - } - - String arg = args.get(i + 1); - String[] argArr = arg.split("="); - - if (argArr.length != 2) { - throw new OnapCliInvalidArgument(paramMap.get(longOptionMap.get(args.get(i))).getName()); - } - - map.put(argArr[0], argArr[1]); - paramMap.get(longOptionMap.get(args.get(i))).setValue(map); - i++; - continue; - } - - paramMap.get(longOptionMap.get(args.get(i))).setValue(args.get(i + 1)); - - i++; - continue; - } - - // it is positional option - // Positional arg is missing from the params - if (positionalIdx >= positionArgs.size()) { - throw new OnapCliInvalidArgument(args.get(i)); - } - - paramMap.get(positionArgs.get(positionalIdx)).setValue(args.get(i)); - positionalIdx++; - } - - params.clear(); - params.addAll(paramMap.values()); - } - - private static String readJsonStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { - ObjectMapper mapper = new ObjectMapper(); - try { - File file = new File(input); - if (file.isFile()) { - return mapper.readValue(file, JSONObject.class).toJSONString(); - } else if (input.startsWith("file:") || input.startsWith("http:") || input.startsWith("ftp:")) { - URL jsonUrl = new URL(input); - return mapper.readValue(jsonUrl, JSONObject.class).toJSONString(); - } else { - return mapper.readValue(input, JSONObject.class).toJSONString(); - } - } catch (IOException e) { - throw new OnapCliInvalidArgument(argName, e); - } - } - - private static String readTextStringFromUrl(String input, String argName) throws OnapCliInvalidArgument { - try { - File file = new File(input); - if (file.isFile()) { - return FileUtils.readFileToString(file); - } else { - return input; - } - - } catch (IOException e) { - throw new OnapCliInvalidArgument(argName, e); - } - } - - private static List convertJsonToListString(String arg, String json) throws OnapCliInvalidArgument { - TypeReference> mapType = new TypeReference>() { - }; - try { - return new ObjectMapper().readValue(json, mapType); - } catch (IOException e) { - throw new OnapCliInvalidArgument(arg, e); - } - } - - private static Map convertJsonToMapString(String arg, String json) throws OnapCliInvalidArgument { - TypeReference> mapType = new TypeReference>() { - }; - try { - return new ObjectMapper().readValue(json, mapType); - } catch (IOException e) { - throw new OnapCliInvalidArgument(arg, e); - } - } -} diff --git a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java index 6eb2e11f..d720ed95 100644 --- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java +++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java @@ -31,7 +31,7 @@ import org.onap.cli.fw.OnapCommand; import org.onap.cli.fw.OnapCommandRegistrar; import org.onap.cli.fw.error.OnapCommandException; import org.onap.cli.fw.error.OnapCommandHelpFailed; -import org.onap.cli.main.utils.OnapCliUtils; +import org.onap.cli.main.utils.OnapCliArgsParser; import jline.console.ConsoleReader; import mockit.Invocation; @@ -120,7 +120,7 @@ public class OnapCliMainTest { OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("sample-create"); List args = new ArrayList<>(Arrays.asList(new String[] { "sample-create", "--service-name", "test-service", "-i", "ip1", "-i", "ip2", "-o", "port1=value1", "-o", "port2=value2" })); - OnapCliUtils.populateParams(cmd.getParameters(), args); + OnapCliArgsParser.populateParams(cmd.getParameters(), args); } @Test diff --git a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java index 1ea1a22d..ad1a7ccc 100644 --- a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java +++ b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java @@ -63,7 +63,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "sample-create", "--host-username", "admin", "--host-password", "123", "--host-url", "a@b.com", "--string-param", "blah", "--long-opt", "10" }; - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertEquals("host-username", expectedList.get(2), param1.getValue()); @@ -82,7 +82,7 @@ public class OnapCliUtilsTest { paramslist.add(paramargs); String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt" }; paramargs.setParameterType(ParameterType.STRING); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue()); } @@ -97,7 +97,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "sample-create", "--bool" }; boolparam.setParameterType(ParameterType.BOOL); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue()); @@ -113,7 +113,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "sample-create", "-b", }; boolparam.setParameterType(ParameterType.BOOL); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue()); } @@ -128,7 +128,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "sample-create", "--text-param" , "text"}; boolparam.setParameterType(ParameterType.TEXT); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue()); @@ -144,7 +144,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "sample-create", "-e" , "text"}; boolparam.setParameterType(ParameterType.TEXT); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue()); } @@ -159,7 +159,7 @@ public class OnapCliUtilsTest { File resourcesDirectory = new File("src/test/resources/sampletest.json"); String[] args = new String[] { "sample-create", "-j", "file:" + resourcesDirectory }; jsonparam.setParameterType(ParameterType.JSON); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue()); } @@ -174,7 +174,7 @@ public class OnapCliUtilsTest { File resourcesDirectory = new File("src/test/resources/sampletest.json"); String[] args = new String[] { "sample-create", "--json-param", "file:" + resourcesDirectory }; jsonparam.setParameterType(ParameterType.JSON); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue()); } @@ -212,7 +212,7 @@ public class OnapCliUtilsTest { String[] args11 = new String[] { "sample-create", "-u", "admin", "-p", "123", "-r", "a@b.com", "-c", "blah", "-l", "10", }; - OnapCliUtils.populateParams(paramslist, Arrays.asList(args11)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args11)); List expectedList = Arrays.asList(args11); @@ -234,7 +234,7 @@ public class OnapCliUtilsTest { paramslist.add(arrayval); arrayval.setParameterType(ParameterType.ARRAY); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue()); @@ -250,7 +250,7 @@ public class OnapCliUtilsTest { paramslist.add(param1); param1.setParameterType(ParameterType.MAP); - OnapCliUtils.populateParams(paramslist, + OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2=value2")); Assert.assertEquals("{\"param1\":\"value1\",\"param2\":\"value2\"}", paramslist.get(0).getValue().toString()); @@ -266,7 +266,7 @@ public class OnapCliUtilsTest { paramslist.add(param1); param1.setParameterType(ParameterType.MAP); - OnapCliUtils.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2")); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2")); Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).getValue().toString()); } @@ -279,7 +279,7 @@ public class OnapCliUtilsTest { List paramslist = new ArrayList<>(); paramslist.add(param1); param1.setParameterType(ParameterType.MAP); - OnapCliUtils.populateParams(paramslist, Arrays.asList("show", "-o", "param1=value1", "-o", "param2")); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "-o", "param1=value1", "-o", "param2")); Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).getValue().toString()); } @@ -292,7 +292,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt", "http://localhost:8082/file.txt" }; paramargs.setParameterType(ParameterType.STRING); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue()); } @@ -307,7 +307,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "sample-create", "-b", "-b", "-h" }; boolparam.setParameterType(ParameterType.BOOL); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertEquals("true", paramslist.get(0).getValue()); } @@ -322,7 +322,7 @@ public class OnapCliUtilsTest { String[] args = new String[] { "sample-create", "--bool", "--bool", "--help" }; boolparam.setParameterType(ParameterType.BOOL); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertEquals("true", paramslist.get(0).getValue()); } @@ -337,7 +337,7 @@ public class OnapCliUtilsTest { File resourcesDirectory = new File("src/test/resources/sampletest.json"); String[] args = new String[] { "sample-create", "--json-param", "file:" + resourcesDirectory, "--json-param" }; jsonparam.setParameterType(ParameterType.JSON); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertEquals("--json-param", paramslist.get(0).getValue()); @@ -353,7 +353,7 @@ public class OnapCliUtilsTest { File resourcesDirectory = new File("src/test/resources/sampletest.json"); String[] args = new String[] { "sample-create", "-j", "file:" + resourcesDirectory, "-j" }; jsonparam.setParameterType(ParameterType.JSON); - OnapCliUtils.populateParams(paramslist, Arrays.asList(args)); + OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args)); List expectedList = Arrays.asList(args); Assert.assertEquals("--json-param", paramslist.get(0).getValue()); -- cgit 1.2.3-korg