aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-12-11 20:34:44 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-12-12 15:48:55 +0530
commit0d97a835fa2052ded5a31e8921baf641c8e9bb57 (patch)
tree800584529f77c8ff26f05a73abd3fa71205a69a7 /main
parent03c54a40daf75644ec0bcbc73636e3eb427c1604 (diff)
Make Http as separate plugin
Issue-ID: CLI-66 Change-Id: I8ad78f417f6dbb00e29effdd3ed8ec1939aee81d Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'main')
-rw-r--r--main/sample-test-schema-sample.yaml16
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java28
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java53
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCliMainTest.java49
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java4
-rw-r--r--main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java140
-rw-r--r--main/src/test/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand (renamed from main/src/test/resources/META-INF/services/org.onap.cli.fw.OnapCommand)0
-rw-r--r--main/src/test/resources/open-cli-schema/sample-create-schema.yaml73
-rw-r--r--main/src/test/resources/open-cli-schema/sample-test-schema.yaml (renamed from main/src/test/resources/sample-test-schema.yaml)0
9 files changed, 131 insertions, 232 deletions
diff --git a/main/sample-test-schema-sample.yaml b/main/sample-test-schema-sample.yaml
new file mode 100644
index 00000000..3bb7a210
--- /dev/null
+++ b/main/sample-test-schema-sample.yaml
@@ -0,0 +1,16 @@
+open_cli_sample_version: 1.0
+name: sample-test
+version: open-cli
+samples:
+ sample1:
+ name: sample-test
+ input: --string-param test
+ moco: sample-test-schema-moco.json
+ output: |
+ +----------+--------+
+ |property |value |
+ +----------+--------+
+ |output-1 |[] |
+ +----------+--------+
+ |output-2 |[] |
+ +----------+--------+
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 67be81bb..fc1a949c 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -22,20 +22,20 @@ import java.util.Arrays;
import java.util.List;
import org.apache.commons.io.IOUtils;
-import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.OnapCommandRegistrar;
-import org.onap.cli.fw.conf.Constants;
-import org.onap.cli.fw.conf.OnapCommandConfg;
+import org.onap.cli.fw.cmd.OnapCommand;
+import org.onap.cli.fw.conf.OnapCommandConfig;
+import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
import org.onap.cli.fw.error.OnapCommandInvalidSample;
import org.onap.cli.fw.error.OnapCommandWarning;
import org.onap.cli.fw.input.OnapCommandParameter;
+import org.onap.cli.fw.output.OnapCommandPrintDirection;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
-import org.onap.cli.fw.output.PrintDirection;
-import org.onap.cli.fw.output.ResultType;
+import org.onap.cli.fw.output.OnapCommandResultType;
+import org.onap.cli.fw.registrar.OnapCommandRegistrar;
import org.onap.cli.main.conf.OnapCliConstants;
import org.onap.cli.main.interactive.StringCompleter;
import org.onap.cli.main.utils.OnapCliArgsParser;
@@ -147,18 +147,18 @@ public class OnapCli {
public static String getDirectiveHelp() throws OnapCommandHelpFailed {
OnapCommandResult help = new OnapCommandResult();
- help.setType(ResultType.TABLE);
- help.setPrintDirection(PrintDirection.LANDSCAPE);
+ help.setType(OnapCommandResultType.TABLE);
+ help.setPrintDirection(OnapCommandPrintDirection.LANDSCAPE);
OnapCommandResultAttribute attr = new OnapCommandResultAttribute();
- attr.setName(Constants.NAME.toUpperCase());
- attr.setDescription(Constants.DESCRIPTION);
+ attr.setName(OnapCommandConstants.NAME.toUpperCase());
+ attr.setDescription(OnapCommandConstants.DESCRIPTION);
attr.setScope(OnapCommandResultAttributeScope.SHORT);
help.getRecords().add(attr);
OnapCommandResultAttribute attrDesc = new OnapCommandResultAttribute();
- attrDesc.setName(Constants.DESCRIPTION.toUpperCase());
- attrDesc.setDescription(Constants.DESCRIPTION);
+ attrDesc.setName(OnapCommandConstants.DESCRIPTION.toUpperCase());
+ attrDesc.setDescription(OnapCommandConstants.DESCRIPTION);
attrDesc.setScope(OnapCommandResultAttributeScope.SHORT);
help.getRecords().add(attrDesc);
@@ -378,11 +378,11 @@ public class OnapCli {
}
private void generateSmapleYaml(OnapCommand cmd) throws OnapCommandException {
- if (OnapCommandConfg.isSampleGenerateEnabled() && this.getExitCode() == OnapCliConstants.EXIT_SUCCESS) {
+ if (Boolean.parseBoolean(OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_ENABLED)) && this.getExitCode() == OnapCliConstants.EXIT_SUCCESS) {
try {
SampleYamlGenerator.generateSampleYaml(args, cmd.getResult().print(),
OnapCommandRegistrar.getRegistrar().getEnabledProductVersion(),
- OnapCommandConfg.getSampleGenerateTargetFolder() + "/" + cmd.getSchemaName().replaceAll(".yaml", "") + "-sample.yaml",
+ OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_TARGET_FOLDER) + "/" + cmd.getSchemaName().replaceAll(".yaml", "") + "-sample.yaml",
cmd.getResult().isDebug());
} catch (IOException error) {
throw new OnapCommandInvalidSample(args.get(0), error);
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
index 725459e9..fdf6d5b8 100644
--- a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
+++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
@@ -16,26 +16,27 @@
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 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;
+import java.util.Set;
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.fw.input.OnapCommandParameterType;
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;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import net.minidev.json.JSONObject;
/**
* Oclip CLI utilities.
@@ -65,7 +66,7 @@ public class OnapCliArgsParser {
* @throws OnapCommandInvalidParameterValue
* exception
*/
- public static void populateParams(List<OnapCommandParameter> params, List<String> args)
+ public static void populateParams(Set<OnapCommandParameter> params, List<String> args)
throws OnapCommandException {
Map<String, String> shortOptionMap = new HashMap<>();
Map<String, String> longOptionMap = new HashMap<>();
@@ -93,35 +94,35 @@ public class OnapCliArgsParser {
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) {
+ 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)) {
+ if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BOOL)) {
paramMap.get(paramName).setValue("true");
continue;
}
throw new OnapCliArgumentValueMissing(args.get(i));
}
- if (paramMap.get(paramName).getParameterType().equals(ParameterType.JSON)) {
+ if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.JSON)) {
paramMap.get(paramName).setValue(readJsonStringFromUrl(args.get(i + 1),
paramMap.get(paramName).getName()));
i++;
continue;
- } if (paramMap.get(paramName).getParameterType().equals(ParameterType.TEXT)) {
+ } if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.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)) {
+ .equals(OnapCommandParameterType.ARRAY)) {
Object value = paramMap.get(paramName).getValue();
List<String> list;
if (value == "") {
@@ -134,7 +135,7 @@ public class OnapCliArgsParser {
paramMap.get(paramName).setValue(list);
i++;
continue;
- } else if (paramMap.get(paramName).getParameterType().equals(ParameterType.MAP)) {
+ } else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.MAP)) {
Object value = paramMap.get(paramName).getValue();
Map<String, String> map;
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 9d3b036c..f7401904 100644
--- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
+++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
@@ -18,21 +18,12 @@ package org.onap.cli.main;
import static org.junit.Assert.fail;
-import java.io.File;
import java.io.IOException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import org.junit.Ignore;
import org.junit.Test;
-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.OnapCliArgsParser;
+import org.onap.cli.fw.registrar.OnapCommandRegistrar;
import jline.console.ConsoleReader;
import mockit.Invocation;
@@ -73,44 +64,6 @@ public class OnapCliMainTest {
this.handle(new String[] { "sample-test", "--help" });
}
- @Ignore
- @Test
- public void testHandleProfile() {
- this.handle(new String[] { "-c", "test" });
- }
-
- @Ignore
- @Test
- public void testAAICustomerList() {
- this.handle(new String[] { "customer-list", "-u", "AAI", "-p", "AAI", "-m", "https://192.168.17.12:8443" });
- }
-
- @Ignore
- @Test
- public void testAAICloudList() {
- this.handle(new String[] { "cloud-list", "-u", "AAI", "-p", "AAI", "-m", "https://192.168.17.12:8443" });
- }
-
- @Test
- public void testHelpSampleCreateCommand() throws OnapCommandException {
- ClassLoader cl = ClassLoader.getSystemClassLoader();
- URL[] urls = ((URLClassLoader) cl).getURLs();
- for (URL url : urls) {
- if (url.getPath().contains("main/target/test-classes")) {
- File file = new File(url.getPath() + "data");
- if (!file.exists()) {
- file.mkdirs();
- }
- break;
- }
- }
- this.handle(new String[] { "sample-create", "--help" });
- OnapCommand cmd = OnapCommandRegistrar.getRegistrar().get("sample-create");
- List<String> args = new ArrayList<>(Arrays.asList(new String[] { "sample-create", "--service-name", "test-service", "-i", "ip1", "-i",
- "ip2", "-o", "port1=value1", "-o", "port2=value2" }));
- OnapCliArgsParser.populateParams(cmd.getParameters(), args);
- }
-
@Test
public void testHelpSampleCommandShort() {
this.handle(new String[] { "sample-test", "-h" });
diff --git a/main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java b/main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java
index fcaa8236..3ec63ae6 100644
--- a/main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java
+++ b/main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java
@@ -16,9 +16,9 @@
package org.onap.cli.main;
-import org.onap.cli.fw.OnapCommand;
-import org.onap.cli.fw.OnapCommandSchema;
+import org.onap.cli.fw.cmd.OnapCommand;
import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.schema.OnapCommandSchema;
/**
* This command helps to test the Command functionalities.
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 ad1a7ccc..eb2ca294 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
@@ -16,19 +16,21 @@
package org.onap.cli.main.utils;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.junit.Assert;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.input.OnapCommandParameter;
-import org.onap.cli.fw.input.ParameterType;
+import org.onap.cli.fw.input.OnapCommandParameterType;
import org.onap.cli.main.error.OnapCliArgumentValueMissing;
import org.onap.cli.main.error.OnapCliInvalidArgument;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
public class OnapCliUtilsTest {
@Test
@@ -36,25 +38,25 @@ public class OnapCliUtilsTest {
OnapCommandParameter param1 = new OnapCommandParameter();
param1.setLongOption("host-username");
param1.setName("host-username");
- param1.setParameterType(ParameterType.STRING);
+ param1.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param2 = new OnapCommandParameter();
param2.setLongOption("host-password");
param2.setName("host-password");
- param2.setParameterType(ParameterType.STRING);
+ param2.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param3 = new OnapCommandParameter();
param3.setLongOption("host-url");
param3.setName("host-url");
- param3.setParameterType(ParameterType.STRING);
+ param3.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param4 = new OnapCommandParameter();
param4.setLongOption("string-param");
param4.setName("string-param");
- param4.setParameterType(ParameterType.STRING);
+ param4.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param5 = new OnapCommandParameter();
param5.setLongOption("long-opt");
param5.setName("long-opt");
- param5.setParameterType(ParameterType.STRING);
+ param5.setParameterType(OnapCommandParameterType.STRING);
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(param1);
paramslist.add(param2);
paramslist.add(param3);
@@ -78,13 +80,13 @@ public class OnapCliUtilsTest {
public void testpositionalargs() throws OnapCommandException {
OnapCommandParameter paramargs = new OnapCommandParameter();
paramargs.setName("http://localhost:8082/file.txt");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(paramargs);
String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt" };
- paramargs.setParameterType(ParameterType.STRING);
+ paramargs.setParameterType(OnapCommandParameterType.STRING);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertEquals("positional-args", expectedList.get(1), paramslist.iterator().next().getValue());
}
@Test
@@ -92,14 +94,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter boolparam = new OnapCommandParameter();
boolparam.setLongOption("bool");
boolparam.setName("bool-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(boolparam);
String[] args = new String[] { "sample-create", "--bool" };
- boolparam.setParameterType(ParameterType.BOOL);
+ boolparam.setParameterType(OnapCommandParameterType.BOOL);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertNotNull(expectedList.get(1), paramslist.iterator().next().getValue());
}
@@ -108,14 +110,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter boolparam = new OnapCommandParameter();
boolparam.setShortOption("b");
boolparam.setName("bool-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(boolparam);
String[] args = new String[] { "sample-create", "-b", };
- boolparam.setParameterType(ParameterType.BOOL);
+ boolparam.setParameterType(OnapCommandParameterType.BOOL);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertNotNull(expectedList.get(1), paramslist.iterator().next().getValue());
}
@Test
@@ -123,14 +125,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter boolparam = new OnapCommandParameter();
boolparam.setLongOption("text-param");
boolparam.setName("text-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(boolparam);
String[] args = new String[] { "sample-create", "--text-param" , "text"};
- boolparam.setParameterType(ParameterType.TEXT);
+ boolparam.setParameterType(OnapCommandParameterType.TEXT);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertNotNull(expectedList.get(1), paramslist.iterator().next().getValue());
}
@@ -139,14 +141,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter boolparam = new OnapCommandParameter();
boolparam.setShortOption("e");
boolparam.setName("text-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(boolparam);
String[] args = new String[] { "sample-create", "-e" , "text"};
- boolparam.setParameterType(ParameterType.TEXT);
+ boolparam.setParameterType(OnapCommandParameterType.TEXT);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertNotNull(expectedList.get(1), paramslist.iterator().next().getValue());
}
@Test
@@ -154,14 +156,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter jsonparam = new OnapCommandParameter();
jsonparam.setShortOption("j");
jsonparam.setName("json-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(jsonparam);
File resourcesDirectory = new File("src/test/resources/sampletest.json");
String[] args = new String[] { "sample-create", "-j", "file:" + resourcesDirectory };
- jsonparam.setParameterType(ParameterType.JSON);
+ jsonparam.setParameterType(OnapCommandParameterType.JSON);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertNotNull(expectedList.get(1), paramslist.iterator().next().getValue());
}
@Test
@@ -169,14 +171,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter jsonparam = new OnapCommandParameter();
jsonparam.setLongOption("json-param");
jsonparam.setName("json-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(jsonparam);
File resourcesDirectory = new File("src/test/resources/sampletest.json");
String[] args = new String[] { "sample-create", "--json-param", "file:" + resourcesDirectory };
- jsonparam.setParameterType(ParameterType.JSON);
+ jsonparam.setParameterType(OnapCommandParameterType.JSON);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertNotNull(expectedList.get(1), paramslist.iterator().next().getValue());
}
@Test
@@ -185,25 +187,25 @@ public class OnapCliUtilsTest {
OnapCommandParameter param1 = new OnapCommandParameter();
param1.setShortOption("u");
param1.setName("host-username");
- param1.setParameterType(ParameterType.STRING);
+ param1.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param2 = new OnapCommandParameter();
param2.setShortOption("p");
param2.setName("host-password");
- param2.setParameterType(ParameterType.STRING);
+ param2.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param3 = new OnapCommandParameter();
param3.setShortOption("r");
param3.setName("host-url");
- param3.setParameterType(ParameterType.STRING);
+ param3.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param4 = new OnapCommandParameter();
param4.setShortOption("c");
param4.setName("string-param");
- param4.setParameterType(ParameterType.STRING);
+ param4.setParameterType(OnapCommandParameterType.STRING);
OnapCommandParameter param5 = new OnapCommandParameter();
param5.setShortOption("l");
param5.setName("long-opt");
- param5.setParameterType(ParameterType.STRING);
+ param5.setParameterType(OnapCommandParameterType.STRING);
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(param1);
paramslist.add(param2);
paramslist.add(param3);
@@ -230,14 +232,14 @@ public class OnapCliUtilsTest {
arrayval.setName("node-ip");
String[] args = new String[] { "sample-create", "--node-ip", "{}" };
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(arrayval);
- arrayval.setParameterType(ParameterType.ARRAY);
+ arrayval.setParameterType(OnapCommandParameterType.ARRAY);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertNotNull(expectedList.get(1), paramslist.iterator().next().getValue());
}
@Test
@@ -245,15 +247,15 @@ public class OnapCliUtilsTest {
OnapCommandParameter param1 = new OnapCommandParameter();
param1.setLongOption("map");
param1.setName("MAP");
- param1.setParameterType(ParameterType.MAP);
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ param1.setParameterType(OnapCommandParameterType.MAP);
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(param1);
- param1.setParameterType(ParameterType.MAP);
+ param1.setParameterType(OnapCommandParameterType.MAP);
OnapCliArgsParser.populateParams(paramslist,
Arrays.asList("show", "--map", "param1=value1", "--map", "param2=value2"));
- Assert.assertEquals("{\"param1\":\"value1\",\"param2\":\"value2\"}", paramslist.get(0).getValue().toString());
+ Assert.assertEquals("{\"param1\":\"value1\",\"param2\":\"value2\"}", paramslist.iterator().next().getValue().toString());
}
@Test(expected = OnapCliInvalidArgument.class)
@@ -261,13 +263,13 @@ public class OnapCliUtilsTest {
OnapCommandParameter param1 = new OnapCommandParameter();
param1.setLongOption("map");
param1.setName("MAP");
- param1.setParameterType(ParameterType.MAP);
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ param1.setParameterType(OnapCommandParameterType.MAP);
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(param1);
- param1.setParameterType(ParameterType.MAP);
+ param1.setParameterType(OnapCommandParameterType.MAP);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2"));
- Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).getValue().toString());
+ Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.iterator().next().getValue().toString());
}
@Test(expected = OnapCliInvalidArgument.class)
@@ -275,26 +277,26 @@ public class OnapCliUtilsTest {
OnapCommandParameter param1 = new OnapCommandParameter();
param1.setShortOption("o");
param1.setName("node-port");
- param1.setParameterType(ParameterType.MAP);
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ param1.setParameterType(OnapCommandParameterType.MAP);
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(param1);
- param1.setParameterType(ParameterType.MAP);
+ param1.setParameterType(OnapCommandParameterType.MAP);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList("show", "-o", "param1=value1", "-o", "param2"));
- Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).getValue().toString());
+ Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.iterator().next().getValue().toString());
}
@Test(expected = OnapCliInvalidArgument.class)
public void testpositionalargsfails() throws OnapCommandException {
OnapCommandParameter paramargs = new OnapCommandParameter();
paramargs.setName("http://localhost:8082/file.txt");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(paramargs);
String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt",
"http://localhost:8082/file.txt" };
- paramargs.setParameterType(ParameterType.STRING);
+ paramargs.setParameterType(OnapCommandParameterType.STRING);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue());
+ Assert.assertEquals("positional-args", expectedList.get(1), paramslist.iterator().next().getValue());
}
@Test(expected = OnapCliInvalidArgument.class)
@@ -302,14 +304,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter boolparam = new OnapCommandParameter();
boolparam.setShortOption("b");
boolparam.setName("bool-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(boolparam);
String[] args = new String[] { "sample-create", "-b", "-b", "-h" };
- boolparam.setParameterType(ParameterType.BOOL);
+ boolparam.setParameterType(OnapCommandParameterType.BOOL);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertEquals("true", paramslist.get(0).getValue());
+ Assert.assertEquals("true", paramslist.iterator().next().getValue());
}
@Test(expected = OnapCliInvalidArgument.class)
@@ -317,14 +319,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter boolparam = new OnapCommandParameter();
boolparam.setShortOption("bool");
boolparam.setName("bool-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(boolparam);
String[] args = new String[] { "sample-create", "--bool", "--bool", "--help" };
- boolparam.setParameterType(ParameterType.BOOL);
+ boolparam.setParameterType(OnapCommandParameterType.BOOL);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertEquals("true", paramslist.get(0).getValue());
+ Assert.assertEquals("true", paramslist.iterator().next().getValue());
}
@Test(expected = OnapCliArgumentValueMissing.class)
@@ -332,14 +334,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter jsonparam = new OnapCommandParameter();
jsonparam.setLongOption("json-param");
jsonparam.setName("json-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(jsonparam);
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);
+ jsonparam.setParameterType(OnapCommandParameterType.JSON);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertEquals("--json-param", paramslist.get(0).getValue());
+ Assert.assertEquals("--json-param", paramslist.iterator().next().getValue());
}
@@ -348,14 +350,14 @@ public class OnapCliUtilsTest {
OnapCommandParameter jsonparam = new OnapCommandParameter();
jsonparam.setShortOption("j");
jsonparam.setName("json-param");
- List<OnapCommandParameter> paramslist = new ArrayList<>();
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
paramslist.add(jsonparam);
File resourcesDirectory = new File("src/test/resources/sampletest.json");
String[] args = new String[] { "sample-create", "-j", "file:" + resourcesDirectory, "-j" };
- jsonparam.setParameterType(ParameterType.JSON);
+ jsonparam.setParameterType(OnapCommandParameterType.JSON);
OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
List<String> expectedList = Arrays.asList(args);
- Assert.assertEquals("--json-param", paramslist.get(0).getValue());
+ Assert.assertEquals("--json-param", paramslist.iterator().next().getValue());
}
} \ No newline at end of file
diff --git a/main/src/test/resources/META-INF/services/org.onap.cli.fw.OnapCommand b/main/src/test/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand
index 16dd879a..16dd879a 100644
--- a/main/src/test/resources/META-INF/services/org.onap.cli.fw.OnapCommand
+++ b/main/src/test/resources/META-INF/services/org.onap.cli.fw.cmd.OnapCommand
diff --git a/main/src/test/resources/open-cli-schema/sample-create-schema.yaml b/main/src/test/resources/open-cli-schema/sample-create-schema.yaml
deleted file mode 100644
index 05f93cda..00000000
--- a/main/src/test/resources/open-cli-schema/sample-create-schema.yaml
+++ /dev/null
@@ -1,73 +0,0 @@
-open_cli_schema_version: 1.0
-name: sample-create
-description: Sample create into Onap
-info:
- product: open-cli
- service: test
- type: cmd
- author: Kanagaraj Manickam kanagaraj.manickam@huawei.com
-
-parameters:
- - name: service-name
- description: Oclip service name
- type: string
- short_option: x
- long_option: service-name
- is_optional: false
- - name: node-ip
- description: Oclip service running node IP
- type: array
- short_option: i
- long_option: node-ip
- - name: node-port
- description: Oclip service running node port
- type: map
- short_option: o
- long_option: node-port
-results:
- direction: portrait
- attributes:
- - name: name
- description: Oclip service name
- scope: short
- type: string
- - name: version
- description: Oclip service version
- scope: short
- type: string
- - name: url
- description: Oclip service base url
- scope: short
- type: url
- - name: status
- description: Oclip service status
- scope: short
- type: digit
- - name: nodes
- description: Oclip service running nodes
- scope: long
- type: string
- - name: location
- description: Oclip service location
- scope: long
- type: url
-http:
- request:
- uri: /services
- method: POST
- body: '{"serviceName":"${service-name}","nodeIp":"${node-ip}","nodePort":"${node-port}"}'
- headers:
- queries:
- success_codes:
- - 201
- - 200
- result_map:
- name: $b{$.serviceName}
- version: $b{$.version}
- url: $b{$.url}
- status: $b{$.status}
- nodes: $b{$.nodes[*].ip}:$b{$.nodes[*].port}
- location: $h{Location}
-
- sample_response:
- body: {"serviceName":"test","version":"v1","url":"/api/test/v1","protocol":"REST","visualRange":"1","lb_policy":"hash","nodes":[{"ip":"127.0.0.1","port":"8012","ttl":0,"nodeId":"test_127.0.0.1_8012","expiration":"2017-02-10T05:33:25Z","created_at":"2017-02-10T05:33:25Z","updated_at":"2017-02-10T05:33:25Z"}],"status":"1"} \ No newline at end of file
diff --git a/main/src/test/resources/sample-test-schema.yaml b/main/src/test/resources/open-cli-schema/sample-test-schema.yaml
index 584eec87..584eec87 100644
--- a/main/src/test/resources/sample-test-schema.yaml
+++ b/main/src/test/resources/open-cli-schema/sample-test-schema.yaml