aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java38
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java39
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java16
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java15
-rw-r--r--framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java15
-rw-r--r--framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java23
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java2
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCliMainTest.java49
-rw-r--r--main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java31
-rw-r--r--main/src/test/resources/sample-test-schema.yaml22
10 files changed, 229 insertions, 21 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java
new file mode 100644
index 00000000..0e3846a0
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandLoadProfileFailed.java
@@ -0,0 +1,38 @@
+/*
+ * 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.fw.error;
+
+/**
+ * Command profile persistence failed.
+ *
+ */
+public class OnapCommandLoadProfileFailed extends OnapCommandException {
+
+ private static final long serialVersionUID = 8580121615330415123L;
+
+ /**
+ * Command result empty.
+ */
+ public OnapCommandLoadProfileFailed(String error) {
+ super("0x1301", "Failed to load profile details, " + error);
+ }
+
+ public OnapCommandLoadProfileFailed(Throwable error) {
+ this(error.getMessage());
+ }
+
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.java
new file mode 100644
index 00000000..4e563d51
--- /dev/null
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandPersistProfileFailed.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.fw.error;
+
+import java.io.IOException;
+
+/**
+ * Command profile persistence failed.
+ *
+ */
+public class OnapCommandPersistProfileFailed extends OnapCommandException {
+
+ private static final long serialVersionUID = 8580121615330415123L;
+
+ /**
+ * Command result empty.
+ */
+ public OnapCommandPersistProfileFailed(String error) {
+ super("0x1302", "Failed to persist profile details, " + error);
+ }
+
+ public OnapCommandPersistProfileFailed(Throwable e1) {
+ this(e1.getMessage());
+ }
+}
diff --git a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
index 6ce09179..1d9cb549 100644
--- a/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
+++ b/framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
@@ -22,6 +22,8 @@ import java.util.List;
import java.util.Map;
import org.onap.cli.fw.conf.Constants;
+import org.onap.cli.fw.error.OnapCommandLoadProfileFailed;
+import org.onap.cli.fw.error.OnapCommandPersistProfileFailed;
import org.onap.cli.fw.utils.OnapCommandUtils;
public class OnapCommandParameterCache {
@@ -77,6 +79,7 @@ public class OnapCommandParameterCache {
private void persist() {
List<Param> params = new ArrayList<>();
+
for (String p: this.paramCache.keySet()) {
for (String name: this.paramCache.get(p).keySet()) {
@@ -89,11 +92,20 @@ public class OnapCommandParameterCache {
}
}
- OnapCommandUtils.persistParams(params, this.profileName);
+ try {
+ OnapCommandUtils.persistParams(params, this.profileName);
+ } catch (OnapCommandPersistProfileFailed e) {
+ throw new RuntimeException(e); // NOSONAR
+ }
}
private void load() {
- List<Param> params = OnapCommandUtils.loadParamFromCache(this.profileName);
+ List<Param> params= new ArrayList<>();
+ try {
+ params = OnapCommandUtils.loadParamFromCache(this.profileName);
+ } catch (OnapCommandLoadProfileFailed e) {
+ throw new RuntimeException(e); // NOSONAR
+ }
for (Param p : params) {
this.add(p.getProduct(), p.getName(), p.getValue());
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index 4cde5088..2404a899 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -23,6 +23,8 @@ import static org.onap.cli.fw.conf.Constants.AUTH_VALUES;
import static org.onap.cli.fw.conf.Constants.BODY;
import static org.onap.cli.fw.conf.Constants.BOOLEAN_VALUE;
import static org.onap.cli.fw.conf.Constants.CLIENT;
+import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
+import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY_JSON_PATTERN;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_HOST_URL;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_PASS_WORD;
import static org.onap.cli.fw.conf.Constants.DEAFULT_PARAMETER_USERNAME;
@@ -36,8 +38,6 @@ import static org.onap.cli.fw.conf.Constants.DIRECTION;
import static org.onap.cli.fw.conf.Constants.ENTITY;
import static org.onap.cli.fw.conf.Constants.EXCEPTION;
import static org.onap.cli.fw.conf.Constants.EXECUTOR;
-import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY;
-import static org.onap.cli.fw.conf.Constants.DATA_DIRECTORY_JSON_PATTERN;
import static org.onap.cli.fw.conf.Constants.EXTERNAL_DISCOVERY_FILE;
import static org.onap.cli.fw.conf.Constants.EXTERNAL_SCHEMA_DIRECTORY;
import static org.onap.cli.fw.conf.Constants.EXTERNAL_SCHEMA_PATH_PATERN;
@@ -125,9 +125,11 @@ import org.onap.cli.fw.error.OnapCommandInvalidPrintDirection;
import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion;
+import org.onap.cli.fw.error.OnapCommandLoadProfileFailed;
import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
import org.onap.cli.fw.error.OnapCommandParameterNotFound;
import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
+import org.onap.cli.fw.error.OnapCommandPersistProfileFailed;
import org.onap.cli.fw.error.OnapCommandResultEmpty;
import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
import org.onap.cli.fw.error.OnapCommandSchemaNotFound;
@@ -136,6 +138,7 @@ import org.onap.cli.fw.http.HttpResult;
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.input.cache.Param;
+import org.onap.cli.fw.log.OnapCommandLogger;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
@@ -1626,7 +1629,7 @@ public class OnapCommandUtils {
}
}
- public static void persistParams(List<Param> params, String profileName) {
+ public static void persistParams(List<Param> params, String profileName) throws OnapCommandPersistProfileFailed {
if (params != null) {
try {
Resource[] resources = getExternalResources(DATA_DIRECTORY);
@@ -1637,7 +1640,7 @@ public class OnapCommandUtils {
mapper.writerWithDefaultPrettyPrinter().writeValue(file, params);
}
} catch (IOException e1) {
- // pass // NOSONAR
+ throw new OnapCommandPersistProfileFailed(e1);
}
}
}
@@ -1700,7 +1703,7 @@ public class OnapCommandUtils {
return schemas;
}
- public static List<Param> loadParamFromCache(String profileName) {
+ public static List<Param> loadParamFromCache(String profileName) throws OnapCommandLoadProfileFailed {
List<Param> params = new ArrayList<>();
try {
@@ -1713,7 +1716,7 @@ public class OnapCommandUtils {
params.addAll(Arrays.asList(list));
}
} catch (IOException e) {
- // pass // NOSONAR
+ throw new OnapCommandLoadProfileFailed(e);
}
return params;
diff --git a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
index ecbbf972..d123a875 100644
--- a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
@@ -141,15 +141,24 @@ public class OnapCommandRegistrarTest {
}
@Test
- public void testParamCache() throws OnapCommandException {
+ public void testCoverageScope() throws OnapCommandException {
+ OnapCommandRegistrar.getRegistrar().setProfile("test");
OnapCommandRegistrar.getRegistrar().addParamCache("a", "b");
OnapCommandRegistrar.getRegistrar().getParamCache();
- OnapCommandRegistrar.getRegistrar().getAvailableProductVersions();
+ OnapCommandRegistrar.getRegistrar().removeParamCache("a");
+
OnapCommandRegistrar.getRegistrar().setDevMode(true);
OnapCommandRegistrar.getRegistrar().isDevMode();
+
OnapCommandRegistrar.getRegistrar().isInteractiveMode();
- OnapCommandRegistrar.getRegistrar().getEnabledProductVersion();
+ OnapCommandRegistrar.getRegistrar().setInteractiveMode(false);
+
OnapCommandRegistrar.getRegistrar().setEnabledProductVersion("cli-1.0");
+ OnapCommandRegistrar.getRegistrar().getEnabledProductVersion();
+ OnapCommandRegistrar.getRegistrar().getAvailableProductVersions();
+ OnapCommandRegistrar.getRegistrar().listCommandsForEnabledProductVersion();
+
+ OnapCommandRegistrar.getRegistrar().listCommandInfo();
}
}
diff --git a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
index 20402b0d..704d4704 100644
--- a/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/error/OnapCommandErrorTest.java
@@ -269,4 +269,27 @@ public class OnapCommandErrorTest {
assertEquals("0x0013::Command does not support the output format Format", failed.getMessage());
}
+
+ @Test
+ public void onapProfilePersistTest() {
+ OnapCommandPersistProfileFailed failed = new OnapCommandPersistProfileFailed("error");
+
+ assertEquals("0x1302::Failed to persist profile details, error", failed.getMessage());
+
+ failed = new OnapCommandPersistProfileFailed(new Exception("error"));
+
+ assertEquals("0x1302::Failed to persist profile details, error", failed.getMessage());
+ }
+
+
+ @Test
+ public void onapProfileLoadTest() {
+ OnapCommandLoadProfileFailed failed = new OnapCommandLoadProfileFailed("error");
+
+ assertEquals("0x1301::Failed to load profile details, error", failed.getMessage());
+
+ failed = new OnapCommandLoadProfileFailed(new Exception("error"));
+
+ assertEquals("0x1301::Failed to load profile details, error", failed.getMessage());
+ }
}
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 57e39f20..9255da20 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -74,7 +74,7 @@ public class OnapCli {
throwable.printStackTrace(); // NOSONAR
}
} catch (OnapCommandException e) {
- // pass // NOSONAR
+ System.out.println(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 0a84d268..092ef8d8 100644
--- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
+++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
@@ -129,6 +129,25 @@ public class OnapCliMainTest {
}
@Test
+ public void testVersionSampleCommandShort() {
+ this.handle(new String[] { "sample-test", "-v" });
+ }
+
+ @Test
+ public void testHandleSampleCommandSet() throws OnapCommandException {
+ OnapCommandRegistrar.getRegistrar().addParamCache("sample:string-param", "paramValue");
+ OnapCommandRegistrar.getRegistrar().addParamCache("onap-username", "paramValue");
+ OnapCommandRegistrar.getRegistrar().addParamCache("onap-password", "paramValue");
+ OnapCommandRegistrar.getRegistrar().addParamCache("host-url", "paramValue");
+ this.handle(new String[] { "sample-test", "--string-param", "test"});
+ }
+
+ @Test
+ public void testHandleSampleCommandFailure() throws OnapCommandException {
+ this.handle(new String[] { "sample-test", "--string-param"});
+ }
+
+ @Test
public void interactiveTest() {
cli = new OnapCli(new String[] {});
@@ -141,43 +160,71 @@ public class OnapCliMainTest {
} catch (Exception e) {
}
- mockConsole("microservice-create -h");
+ cli = new OnapCli(new String[] {});
+ mockConsole("sample-test -h");
+
+ try {
+ cli.handleInteractive();
+ } catch (Exception e) {
+ }
+ cli = new OnapCli(new String[] {});
+ mockConsole("use cli-1.0");
try {
cli.handleInteractive();
} catch (Exception e) {
}
+ cli = new OnapCli(new String[] {});
mockConsole("set a=b");
try {
cli.handleInteractive();
} catch (Exception e) {
}
+ cli = new OnapCli(new String[] {});
+ mockConsole("set");
+ try {
+ cli.handleInteractive();
+ } catch (Exception e) {
+ }
+
+ cli = new OnapCli(new String[] {});
+ mockConsole("set a=");
+ try {
+ cli.handleInteractive();
+ } catch (Exception e) {
+ }
+
+ cli = new OnapCli(new String[] {});
mockConsole("unset a");
try {
cli.handleInteractive();
} catch (Exception e) {
}
+ cli = new OnapCli(new String[] {});
mockConsole("profile test");
try {
cli.handleInteractive();
} catch (Exception e) {
}
+ cli = new OnapCli(new String[] {});
mockConsole("version");
try {
cli.handleInteractive();
} catch (Exception e) {
}
+ cli = new OnapCli(new String[] {});
mockConsole("help");
try {
cli.handleInteractive();
} catch (Exception e) {
}
+ cli = new OnapCli(new String[] {});
mockConsoleReader();
cli.handleInteractive();
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 8870029b..622cea5f 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
@@ -119,6 +119,37 @@ public class OnapCliUtilsTest {
}
@Test
+ public void testTextparamslong() throws OnapCommandException {
+ OnapCommandParameter boolparam = new OnapCommandParameter();
+ boolparam.setLongOption("text-param");
+ boolparam.setName("text-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(boolparam);
+ String[] args = new String[] { "sample-create", "--text-param" , "text"};
+
+ boolparam.setParameterType(ParameterType.TEXT);
+ OnapCliUtils.populateParams(paramslist, Arrays.asList(args));
+ List<String> expectedList = Arrays.asList(args);
+ Assert.assertNotNull(expectedList.get(1), paramslist.get(0).getValue());
+
+ }
+
+ @Test
+ public void testTextparamsshort() throws OnapCommandException {
+ OnapCommandParameter boolparam = new OnapCommandParameter();
+ boolparam.setShortOption("e");
+ boolparam.setName("text-param");
+ List<OnapCommandParameter> paramslist = new ArrayList<>();
+ paramslist.add(boolparam);
+ String[] args = new String[] { "sample-create", "-e" , "text"};
+
+ boolparam.setParameterType(ParameterType.TEXT);
+ 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");
diff --git a/main/src/test/resources/sample-test-schema.yaml b/main/src/test/resources/sample-test-schema.yaml
index a4fd8563..36edc7de 100644
--- a/main/src/test/resources/sample-test-schema.yaml
+++ b/main/src/test/resources/sample-test-schema.yaml
@@ -19,54 +19,60 @@ parameters:
short_option: x
long_option: secure
is_secured: true
- is_optional: false
+ is_optional: true
default_Value: pass123#
- name: string-param
type: string
description: Onap string param
long_option: string-param
short_option: c
- is_optional: false
+ is_optional: true
default_Value: test
- name: yaml-param
type: json
description: Onap yaml file location param
long_option: yaml-param
short_option: y
- is_optional: false
+ is_optional: true
- name: json-param
type: json
description: Onap json file location param
long_option: json-param
short_option: j
- is_optional: false
+ is_optional: true
- name: long-param
type: digit
description: Onap long param
short_option: l
long_option: long-opt
- is_optional: false
+ is_optional: true
default_value: 10
- name: url-param
type: url
description: Onap url param
short_option: r
long_option: url
- is_optional: false
+ is_optional: true
default_value: http://localhost:8082/file.txt
- name: env-param
type: string
description: Onap env param.
short_option: z
long_option: env
- is_optional: false
+ is_optional: true
default_value: ${ENV_VAR}
default_value: http://localhost:8082/file.txt
- name: positional-args
type: string
description: Onap positional args, if no short option and no long option given for it
- is_optional: false
+ is_optional: true
default_value: http://localhost:8082/file.txt
+ - name: text-param
+ type: text
+ description: Onap text file location param
+ long_option: text-param
+ short_option: e
+ is_optional: true
results:
direction: portrait
attributes: