aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org/onap
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-07-19 15:14:29 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-07-19 15:31:19 +0530
commitb610d2dbfa445e2ed8fd7f9976ae7a776666d630 (patch)
tree6d58385dc197aada4c6a832c922f04d0f4da61ad /main/src/test/java/org/onap
parent20173579de1cd7d8f70fc2cdf17a4f9c0fc6e946 (diff)
Add seed code from Open-Orelease-1.0.0
It migrated the code from Open-O into onap namespace and adds the required framework, main, deployment and some sample plugins for msb. CLI-7 CLI-8 CLI-11 Change-Id: I499e34237daccb971ef74bd10e50f50707baa4d3 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'main/src/test/java/org/onap')
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCliMainTest.java347
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java35
-rw-r--r--main/src/test/java/org/onap/cli/main/conf/OnapCliConstantsTest.java33
-rw-r--r--main/src/test/java/org/onap/cli/main/error/OnapCliArgumentTest.java39
-rw-r--r--main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java48
-rw-r--r--main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java330
6 files changed, 832 insertions, 0 deletions
diff --git a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
new file mode 100644
index 00000000..ca955cc9
--- /dev/null
+++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
@@ -0,0 +1,347 @@
+/*
+ * 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;
+
+import static org.junit.Assert.assertTrue;
+
+import jline.console.ConsoleReader;
+import mockit.Invocation;
+import mockit.Mock;
+import mockit.MockUp;
+
+import org.aspectj.lang.annotation.After;
+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.main.utils.OnapCliUtils;
+
+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 java.util.Map;
+import java.util.Set;
+
+public class OnapCliMainTest {
+
+ OnapCli cli = null;
+
+ /**
+ * Clean up.
+ */
+ @After(value = "")
+ public void cleanup() {
+ if (this.cli != null) {
+ if (cli.getExitCode() != 0) {
+ // Fail test case
+ }
+ }
+ }
+
+ private void handle(String[] args) {
+ cli = new OnapCli(args);
+ cli.handle();
+ }
+
+ @Test
+ public void testHelp() {
+ this.handle(new String[] { "--help" });
+ }
+
+ @Test
+ public void testHelpShort() {
+ this.handle(new String[] { "-h" });
+ }
+
+ @Test
+ public void testVersion() {
+ this.handle(new String[] { "--version" });
+ }
+
+ @Test
+ public void testVersionShort() {
+ this.handle(new String[] { "--v" });
+ }
+
+ @Test
+ public void testHelpSampleCommand() {
+ this.handle(new String[] { "sample-test", "--help" });
+ }
+
+ @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", "-u", "admin", "-p",
+ "Changeme_123", "-m", "http://192.168.99.100:80", "--service-name", "test-service", "-i", "ip1", "-i",
+ "ip2", "-o", "port1=value1", "-o", "port2=value2" }));
+ OnapCliUtils.populateParams(cmd.getParameters(), args);
+ }
+
+ @Test
+ public void testHelpSampleCommandShort() {
+ this.handle(new String[] { "sample-test", "-h" });
+ }
+
+ @Test
+ public void testHelpServiceListCommandShort() {
+ this.handle(new String[] { "microservice-list", "-h" });
+ }
+
+ @Test
+ public void testHelpUserCreateCommand() {
+ this.handle(new String[] { "user-create", "--help" });
+ }
+
+ @Test
+ @Ignore
+ public void testUserCreateCommand() {
+ this.handle(new String[] { "user-create", "-u", "admin", "-p", "Changeme_123", "-m", "http://192.168.99.100:80",
+ "--username", "test", "--password", "sss", "--description", "test user", "-d" });
+ }
+
+ @Test
+ @Ignore
+ public void testHelpVimShowCommand() {
+ this.handle(new String[] { "vim-show", "--help" });
+ }
+
+ @Test
+ @Ignore
+ public void testVimListCommand() {
+ this.handle(new String[] { "vim-list", "-u", "admin", "-p", "Changeme_123", "-m", "http://192.168.99.100:80",
+ "--long", "--format", "table" });
+ }
+
+ @Test
+ public void tesVersionServiceListCommand() {
+ this.handle(new String[] { "microservice-list", "--version" });
+ }
+
+ @Test
+ public void tesVersionServiceListCommandShort() {
+ this.handle(new String[] { "microservice-list", "-v" });
+ }
+
+ @Test
+ @Ignore
+ public void testServiceListCommand() {
+ this.handle(new String[] { "microservice-list", "-u", "root1", "-p", "root123", "-m", "http://192.168.4.47:80",
+ "--long", "--no-title", "true", "-d" });
+ }
+
+ @Test
+ @Ignore
+ public void testServiceCreateCommand() {
+ this.handle(new String[] { "microservice-create", "-u", "admin", "-p", "Changeme_123", "-m",
+ "http://192.168.99.100:80", "--service-name", "test-service", "--service-version", "v1",
+ "--service-url", "/openapi/sampletest/v1", "127.0.0.1", "8080", "--debug", "--long" });
+ }
+
+ @Test
+ @Ignore
+ public void testServiceShowCommand() {
+ this.handle(new String[] { "microservice-show", "-u", "admin", "-p", "Changeme_123", "-m",
+ "http://192.168.99.100:80", "--service-name", "test-service", "--service-version", "v1", "--debug",
+ "--long" });
+ }
+
+ @Test
+ @Ignore
+ public void testServiceDeleteCommand() {
+ this.handle(new String[] { "microservice-delete", "-u", "admin", "-p", "Changeme_123", "-m",
+ "http://192.168.99.100:80", "--service-name", "test-service", "--service-version", "v1", "--debug",
+ "--long" });
+ }
+
+ @Test
+ @Ignore
+ public void testSdncCreate() {
+
+ this.handle(new String[] { "sdnc-create", "-u", "root1", "-p", "root123", "-m", "http://192.168.4.47:80",
+ "--name", "testcontroller", "--vendor", "testvendor", "--sdnc-version", "v1", "--description",
+ "testingSDNC", "--type", "string", "--url", "onapapi/extsys/v1", "--username", "test", "--password",
+ "test", "--product-name", "testproduct", "--protocol", "http", "-d" });
+ }
+
+ @Test
+ @Ignore
+ public void testSdnclist() {
+
+ this.handle(new String[] { "sdnc-list", "-p", "root123", "--msb-url", "http://192.168.99.100", "-u", "root1",
+ "-d" });
+ }
+
+ @Test
+ @Ignore
+ public void testNFVResourcelist() {
+ this.handle(new String[] { "resource-datacenter-show", "--id", "test", "-u", "root", "-p", "root123",
+ "--msb-url", "http://192.168.99.100", "-a", "-d" });
+ }
+
+ @Test
+ @Ignore
+ public void testNFVResourceShow() {
+
+ this.handle(new String[] { "resource-datacenter-show", "--id", "test", "-u", "root", "-p", "root123",
+ "--msb-url", "http://192.168.99.100", "-a", "-d" });
+ }
+
+ @Test
+ @Ignore
+ public void testSdncdelete() {
+
+ this.handle(new String[] { "sdnc-delete", "-p", "root123", "--msb-url", "http://192.168.4.47", "-u", "root1",
+ "--id", "053104c1-0f8b-481d-9456-f7b02e87c0e7" });
+ }
+
+ @Test
+ @Ignore
+ public void testServiceCreateHelpCommand() {
+ this.handle(new String[] { "microservice-create", "--help" });
+ }
+
+ @Test
+ @Ignore
+ public void testGsoServiceCreateCommand() {
+ this.handle(new String[] { "service-create", "-m", "http://192.168.4.47:80", "-u", "root1", "-p", "root123",
+ "-x", "test", "-z", "test", "-n", "test", "-r", "123", "-j",
+ "D:/workspace/onap/integration/test/csit/plans/gso/sanity-check/jsoninput/lcm_CreateServiceReq.json",
+ "-d" });
+ }
+
+ @Test
+ @Ignore
+ public void testCsrUpload() {
+ this.handle(new String[] { "catalog-csar-create", "-u", "root", "-p", "root123", "--msb-url",
+ "http://192.168.4.47", "-d", "-a", "-z", "D:\\enterprise2DC.csar" });
+ }
+
+ @Test
+ @Ignore
+ public void testCsrDelete() {
+ this.handle(new String[] { "catalog-csar-delete", "-u", "root", "-p", "root123", "--msb-url",
+ "http://192.168.4.47", "-d", "-a", "-i", "7aa791f9-4e5f-433a-afeb-3555bcbabb47" });
+ }
+
+ @Test
+ @Ignore
+ public void testPortCreate() {
+ this.handle(new String[] { "resource-link-create", "-u", "root", "-p", "root123", "--msb-url",
+ "http://192.168.4.213", "-d", "-n", "PradeepLink1", "-b", "19.5.6.13", "-c", "193.4.57.13", "-g",
+ "193.5.6.13", "-q", "189.78.6.13", "-y", "fiberLink" });
+ }
+
+ @Test
+ public void validateCommands() throws IOException, OnapCommandException {
+ Map<String, String> cmdSchemaMap = OnapCommandRegistrar.getRegistrar().getAllCommandToSchemaMap();
+ for (String cmdName : cmdSchemaMap.keySet()) {
+ System.out.println(
+ "************************* '" + cmdSchemaMap.get(cmdName) + "' *******************************");
+ this.handle(new String[] { "schema-validate", "-l", cmdSchemaMap.get(cmdName), "-i", "true", "-m",
+ "http://192.168.4.47:80", "-u", "root1", "-p", "root123" });
+ }
+ }
+
+ @Test
+ public void commandHelpTest() throws OnapCommandException {
+ Set<String> cmds = OnapCommandRegistrar.getRegistrar().listCommands();
+
+ for (String cmdName : cmds) {
+ System.out.println("************************* '" + cmdName + "' *******************************");
+ this.handle(new String[] { cmdName, "-h" });
+ }
+
+ }
+
+ @Test
+ public void interactiveTest() {
+ cli = new OnapCli(new String[] { "-i" });
+ boolean isInter = cli.isInteractive();
+
+ assertTrue(isInter);
+ cli = new OnapCli(new String[] { "--interactive" });
+ isInter = cli.isInteractive();
+ assertTrue(isInter);
+ cli.getExitCode();
+
+ mockConsole("exit");
+ cli.handleInteractive();
+
+ mockConsole("bye");
+ cli.handleInteractive();
+
+ mockConsole("clear");
+ try {
+ cli.handleInteractive();
+ } catch (Exception e) {
+ }
+
+ mockConsole("microservice-create -h");
+
+ try {
+ cli.handleInteractive();
+ } catch (Exception e) {
+ }
+
+ mockConsoleReader();
+ cli.handleInteractive();
+
+ }
+
+ private static void mockConsoleReader() {
+ new MockUp<OnapCli>() {
+ @Mock
+ public ConsoleReader createConsoleReader() throws IOException {
+ throw new IOException("Exception mock");
+ }
+ };
+ }
+
+ private static void mockConsole(String input) {
+ new MockUp<ConsoleReader>() {
+ boolean isMock = true;
+
+ @Mock
+ public String readLine(Invocation inv) throws IOException {
+ if (isMock) {
+ isMock = false;
+ return input;
+ } else {
+ return inv.proceed(input);
+ }
+ }
+ };
+ }
+
+}
diff --git a/main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java b/main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java
new file mode 100644
index 00000000..517d6c4f
--- /dev/null
+++ b/main/src/test/java/org/onap/cli/main/OnapCommandSampleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import org.onap.cli.fw.OnapCommand;
+import org.onap.cli.fw.OnapCommandSchema;
+import org.onap.cli.fw.error.OnapCommandException;
+
+/**
+ * This command helps to test the Command functionalities.
+ *
+ */
+@OnapCommandSchema(name = "sample-test", schema = "sample-test-schema.yaml")
+public class OnapCommandSampleTest extends OnapCommand {
+
+ @Override
+ protected void run() throws OnapCommandException {
+
+ }
+
+}
diff --git a/main/src/test/java/org/onap/cli/main/conf/OnapCliConstantsTest.java b/main/src/test/java/org/onap/cli/main/conf/OnapCliConstantsTest.java
new file mode 100644
index 00000000..af19836a
--- /dev/null
+++ b/main/src/test/java/org/onap/cli/main/conf/OnapCliConstantsTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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.conf;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class OnapCliConstantsTest {
+
+ @Test
+ public void test() {
+ assertTrue(1 == OnapCliConstants.EXIT_FAILURE && 0 == OnapCliConstants.EXIT_SUCCESS
+ && "help".equals(OnapCliConstants.PARAM_HELP_LOGN) && "h".equals(OnapCliConstants.PARAM_HELP_SHORT)
+ && "v".equals(OnapCliConstants.PARAM_VERSION_SHORT)
+ && "version".equals(OnapCliConstants.PARAM_VERSION_LONG));
+ }
+
+}
diff --git a/main/src/test/java/org/onap/cli/main/error/OnapCliArgumentTest.java b/main/src/test/java/org/onap/cli/main/error/OnapCliArgumentTest.java
new file mode 100644
index 00000000..3916c630
--- /dev/null
+++ b/main/src/test/java/org/onap/cli/main/error/OnapCliArgumentTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.error;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class OnapCliArgumentTest {
+
+ @Test
+ public void onapCliArgumentValueMissingTest() {
+ OnapCliArgumentValueMissing failed = new OnapCliArgumentValueMissing("Argument value missing");
+ assertEquals("0x1001::Value for argument Argument value missing is missing", failed.getMessage());
+ }
+
+ @Test
+ public void onapCliInvalidArgumentTest() {
+ OnapCliInvalidArgument failed = new OnapCliInvalidArgument("Invalid Argument");
+ assertEquals("0x1000::Invalid argument Invalid Argument", failed.getMessage());
+ failed = new OnapCliInvalidArgument("Invalid Argument", new Exception(""));
+ assertEquals("0x1000::Invalid argument Invalid Argument , ", failed.getMessage());
+ }
+
+}
diff --git a/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java b/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java
new file mode 100644
index 00000000..9d5cbf17
--- /dev/null
+++ b/main/src/test/java/org/onap/cli/main/interactive/StringCompleterTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.interactive;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class StringCompleterTest {
+
+ @Test
+ public void completeTest() {
+ StringCompleter com = new StringCompleter(Arrays.asList(new String[] { "test", "testing1", "testing2" }));
+ int result = com.complete("test", 1, new ArrayList<CharSequence>());
+ assertTrue(result == 0);
+ result = com.complete(null, 1, new ArrayList<CharSequence>());
+ assertTrue(result == 0);
+
+ com.add("test", "testing1", "testing2");
+ result = com.complete("test", 1, new ArrayList<CharSequence>());
+ assertTrue(result == 0);
+
+ result = com.complete("sfds", 1, new ArrayList<CharSequence>());
+ assertTrue(result == -1);
+
+
+ result = com.complete("test", 1, new ArrayList<CharSequence>());
+ assertTrue(result == 0);
+ }
+
+}
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
new file mode 100644
index 00000000..c7fb7985
--- /dev/null
+++ b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java
@@ -0,0 +1,330 @@
+/*
+ * 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 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.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
+ public void testpopulateParamsLong() throws OnapCommandException {
+ OnapCommandParameter param1 = new OnapCommandParameter();
+ param1.setLongOption("onap-username");
+ param1.setName("onap-username");
+ param1.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param2 = new OnapCommandParameter();
+ param2.setLongOption("onap-password");
+ param2.setName("onap-password");
+ param2.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param3 = new OnapCommandParameter();
+ param3.setLongOption("msb-url");
+ param3.setName("msb-url");
+ param3.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param4 = new OnapCommandParameter();
+ param4.setLongOption("string-param");
+ param4.setName("string-param");
+ param4.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param5 = new OnapCommandParameter();
+ param5.setLongOption("long-opt");
+ param5.setName("long-opt");
+ param5.setParameterType(ParameterType.STRING);
+
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(param1);
+ paramslist.add(param2);
+ paramslist.add(param3);
+ paramslist.add(param4);
+ paramslist.add(param5);
+
+ String[] args = new String[] { "sample-create", "--onap-username", "admin", "--onap-password", "123",
+ "--msb-url", "a@b.com", "--string-param", "blah", "--long-opt", "10" };
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+
+ Assert.assertEquals("onap-username", expectedList.get(2), param1.getValue());
+ Assert.assertEquals("onap-password", expectedList.get(4), param2.getValue());
+ Assert.assertEquals("msb-url", expectedList.get(6), param3.getValue());
+ Assert.assertEquals("string-param", expectedList.get(8), param4.getValue());
+ Assert.assertEquals("long-opt", expectedList.get(10), param5.getValue());
+
+ }
+
+ @Test
+ public void testpositionalargs() throws OnapCommandException {
+ OnapCommandParameter paramargs = new OnapCommandParameter();
+ paramargs.setName("http://localhost:8082/file.txt");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(paramargs);
+ String[] args = new String[] { "positional-args", "http://localhost:8082/file.txt" };
+ paramargs.setParameterType(ParameterType.STRING);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue());
+ }
+
+ @Test
+ public void testboolparamslong() throws OnapCommandException {
+ OnapCommandParameter boolparam = new OnapCommandParameter();
+ boolparam.setLongOption("bool");
+ boolparam.setName("bool-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(boolparam);
+ String[] args = new String[] { "sample-create", "--bool" };
+
+ boolparam.setParameterType(ParameterType.BOOL);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+
+ }
+
+ @Test
+ public void testboolparamsshort() throws OnapCommandException {
+ OnapCommandParameter boolparam = new OnapCommandParameter();
+ boolparam.setShortOption("b");
+ boolparam.setName("bool-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(boolparam);
+ String[] args = new String[] { "sample-create", "-b", };
+
+ boolparam.setParameterType(ParameterType.BOOL);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ }
+
+ @Test
+ public void testjsonparamsshort() throws OnapCommandException {
+ OnapCommandParameter jsonparam = new OnapCommandParameter();
+ jsonparam.setShortOption("j");
+ jsonparam.setName("json-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ 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);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ }
+
+ @Test
+ public void testjsonparamslong() throws OnapCommandException {
+ OnapCommandParameter jsonparam = new OnapCommandParameter();
+ jsonparam.setLongOption("json-param");
+ jsonparam.setName("json-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ 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);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ }
+
+ @Test
+ public void testpopulateParamsShort() throws OnapCommandException {
+
+ OnapCommandParameter param1 = new OnapCommandParameter();
+ param1.setShortOption("u");
+ param1.setName("onap-username");
+ param1.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param2 = new OnapCommandParameter();
+ param2.setShortOption("p");
+ param2.setName("onap-password");
+ param2.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param3 = new OnapCommandParameter();
+ param3.setShortOption("r");
+ param3.setName("msb-url");
+ param3.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param4 = new OnapCommandParameter();
+ param4.setShortOption("c");
+ param4.setName("string-param");
+ param4.setParameterType(ParameterType.STRING);
+ OnapCommandParameter param5 = new OnapCommandParameter();
+ param5.setShortOption("l");
+ param5.setName("long-opt");
+ param5.setParameterType(ParameterType.STRING);
+
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(param1);
+ paramslist.add(param2);
+ paramslist.add(param3);
+ paramslist.add(param4);
+ paramslist.add(param5);
+
+ String[] args11 = new String[] { "sample-create", "-u", "admin", "-p", "123", "-r", "a@b.com", "-c", "blah",
+ "-l", "10", };
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args11));
+
+ List<String> expectedList = Arrays.asList(args11);
+
+ Assert.assertEquals("u", expectedList.get(2), param1.getValue());
+ Assert.assertEquals("-p", expectedList.get(4), param2.getValue());
+ Assert.assertEquals("r", expectedList.get(6), param3.getValue());
+ Assert.assertEquals("c", expectedList.get(8), param4.getValue());
+ Assert.assertEquals("l", expectedList.get(10), param5.getValue());
+ }
+
+ @Test
+ public void testArrayparamslong() throws OnapCommandException {
+ OnapCommandParameter arrayval = new OnapCommandParameter();
+ arrayval.setLongOption("node-ip");
+ arrayval.setName("node-ip");
+
+ String[] args = new String[] { "sample-create", "--node-ip", "{}" };
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(arrayval);
+
+ arrayval.setParameterType(ParameterType.ARRAY);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+ }
+
+ @Test
+ public void testMapparamsShort() throws OnapCommandException {
+ OnapCommandParameter param1 = new OnapCommandParameter();
+ param1.setLongOption("map");
+ param1.setName("MAP");
+ param1.setParameterType(ParameterType.MAP);
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(param1);
+
+ param1.setParameterType(ParameterType.MAP);
+ OnapCliUtils.populateParams(paramslist,
+ Arrays.asList("show", "--map", "param1=value1", "--map", "param2=value2"));
+
+ Assert.assertEquals("{\"param1\":\"value1\",\"param2\":\"value2\"}", paramslist.get(0).getValue().toString());
+ }
+
+ @Test(expected = OnapCliInvalidArgument.class)
+ public void testMapparamsLongfail() throws OnapCommandException {
+ OnapCommandParameter param1 = new OnapCommandParameter();
+ param1.setLongOption("map");
+ param1.setName("MAP");
+ param1.setParameterType(ParameterType.MAP);
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(param1);
+
+ param1.setParameterType(ParameterType.MAP);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList("show", "--map", "param1=value1", "--map", "param2"));
+ Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).getValue().toString());
+ }
+
+ @Test(expected = OnapCliInvalidArgument.class)
+ public void testMapparamsShortfail() throws OnapCommandException {
+ OnapCommandParameter param1 = new OnapCommandParameter();
+ param1.setShortOption("o");
+ param1.setName("node-port");
+ param1.setParameterType(ParameterType.MAP);
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(param1);
+ param1.setParameterType(ParameterType.MAP);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList("show", "-o", "param1=value1", "-o", "param2"));
+ Assert.assertEquals("{\"param1\":\"value1\",\"param2\"}", paramslist.get(0).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<>();
+ paramslist.add(paramargs);
+ 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));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertEquals("positional-args", expectedList.get(1), paramslist.get(0).getValue());
+ }
+
+ @Test(expected = OnapCliInvalidArgument.class)
+ public void testboolparamsshortfails() throws OnapCommandException {
+ OnapCommandParameter boolparam = new OnapCommandParameter();
+ boolparam.setShortOption("b");
+ boolparam.setName("bool-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(boolparam);
+ String[] args = new String[] { "sample-create", "-b", "-b", "-h" };
+
+ boolparam.setParameterType(ParameterType.BOOL);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertEquals("true", paramslist.get(0).getValue());
+ }
+
+ @Test(expected = OnapCliInvalidArgument.class)
+ public void testboolparamsLongfails() throws OnapCommandException {
+ OnapCommandParameter boolparam = new OnapCommandParameter();
+ boolparam.setShortOption("bool");
+ boolparam.setName("bool-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(boolparam);
+ String[] args = new String[] { "sample-create", "--bool", "--bool", "--help" };
+
+ boolparam.setParameterType(ParameterType.BOOL);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertEquals("true", paramslist.get(0).getValue());
+ }
+
+ @Test(expected = OnapCliArgumentValueMissing.class)
+ public void testjsonparamslongfails() throws OnapCommandException {
+ OnapCommandParameter jsonparam = new OnapCommandParameter();
+ jsonparam.setLongOption("json-param");
+ jsonparam.setName("json-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ 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);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertEquals("--json-param", paramslist.get(0).getValue());
+
+ }
+
+ @Test(expected = OnapCliArgumentValueMissing.class)
+ public void testjsonparamsshortfails() throws OnapCommandException {
+ OnapCommandParameter jsonparam = new OnapCommandParameter();
+ jsonparam.setShortOption("j");
+ jsonparam.setName("json-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ 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);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertEquals("--json-param", paramslist.get(0).getValue());
+
+ }
+} \ No newline at end of file