aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java26
-rw-r--r--framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java4
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java2
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java33
-rw-r--r--framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java2
-rw-r--r--framework/src/test/resources/data/test-profile.json0
-rw-r--r--framework/src/test/resources/data/test2-profile.json0
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java4
-rw-r--r--main/src/test/java/org/onap/cli/main/OnapCliMainTest.java7
10 files changed, 75 insertions, 5 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
index 408f4f69..39204237 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
@@ -114,6 +114,8 @@ public class OnapCommandConstants {
public static final String DATA_DIRECTORY = "data";
public static final String DISCOVERY_FILE = "cli-schema.json";
public static final String DATA_PATH_JSON_PATTERN = DATA_DIRECTORY + JSON_PATTERN;
+ public static final String DATA_PATH_PROFILE_JSON = "-profile.json";
+ public static final String DATA_PATH_PROFILE_JSON_PATTERN = DATA_DIRECTORY + "/**/*" + DATA_PATH_PROFILE_JSON;
public static final String DISCOVER_ALWAYS = "discover_always";
public static final String PARAM_CACHE_FILE_NAME = "global-profile";
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 55833167..ee6dbed3 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
@@ -18,6 +18,8 @@ package org.onap.cli.fw.input.cache;
import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_DIRECTORY;
import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_JSON_PATTERN;
+import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_PROFILE_JSON;
+import static org.onap.cli.fw.conf.OnapCommandConstants.DATA_PATH_PROFILE_JSON_PATTERN;
import java.io.File;
import java.io.IOException;
@@ -132,7 +134,7 @@ public class OnapCommandParameterCache {
Resource[] resources = OnapCommandDiscoveryUtils.findResources(DATA_DIRECTORY);
if (resources != null && resources.length == 1) {
String path = resources[0].getURI().getPath();
- File file = new File(path + File.separator + profileName + ".json");
+ File file = new File(path + File.separator + profileName + DATA_PATH_PROFILE_JSON);
ObjectMapper mapper = new ObjectMapper();
mapper.writerWithDefaultPrettyPrinter().writeValue(file, params);
}
@@ -146,7 +148,7 @@ public class OnapCommandParameterCache {
List<OnapCommandParamEntity> params = new ArrayList<>();
try {
- Resource resource = OnapCommandDiscoveryUtils.findResource(profileName + ".json",
+ Resource resource = OnapCommandDiscoveryUtils.findResource(profileName + DATA_PATH_PROFILE_JSON,
DATA_PATH_JSON_PATTERN);
if (resource != null) {
File file = new File(resource.getURI().getPath());
@@ -160,4 +162,24 @@ public class OnapCommandParameterCache {
return params;
}
+
+ public List<String> getProfiles() {
+ List<String> profiles = new ArrayList<>();
+
+ Resource[] resources;
+ try {
+ resources = OnapCommandDiscoveryUtils.findResources(DATA_PATH_PROFILE_JSON_PATTERN);
+ } catch (IOException e) {
+ throw new RuntimeException(e); // NOSONAR
+ }
+
+ if (resources != null && resources.length > 0) {
+ for (Resource res : resources) {
+ String profile = res.getFilename().substring(0, res.getFilename().indexOf(DATA_PATH_PROFILE_JSON));
+ profiles.add(profile);
+ }
+ }
+
+ return profiles;
+ }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
index 854b55be..8ba215e6 100644
--- a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
@@ -94,6 +94,10 @@ public class OnapCommandRegistrar {
this.paramCache.setProfile(profileName);
}
+ public List<String> getUserProfiles() {
+ return paramCache.getProfiles();
+ }
+
private static OnapCommandRegistrar registrar = null;
/**
diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java
index ea06ea1b..302d280b 100644
--- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterCacheTest.java
@@ -27,7 +27,7 @@ public class OnapCommandParameterCacheTest {
cache.add("1.0", "a", "b");
cache.remove("1.0", "a");
- cache.setProfile("test");
+ cache.setProfile("test123");
cache.getParams("1.0");
}
diff --git a/framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java b/framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.java
new file mode 100644
index 00000000..be539946
--- /dev/null
+++ b/framework/src/test/java/org/onap/cli/fw/input/cache/OnapCommandParameterCacheTest.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.fw.input.cache;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+
+public class OnapCommandParameterCacheTest {
+ @Test
+ public void paramTypeGetTest() {
+
+ assertTrue(OnapCommandParameterCache.getInstance().getProfiles().contains("test"));
+
+
+ }
+
+}
diff --git a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
index 539ec245..124b9564 100644
--- a/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
@@ -90,7 +90,7 @@ public class OnapCommandRegistrarTest {
@Test
public void testProfile() throws OnapCommandException {
try {
- OnapCommandRegistrar.getRegistrar().setProfile("test");
+ OnapCommandRegistrar.getRegistrar().setProfile("test12312");
OnapCommandRegistrar.getRegistrar().addParamCache("a", "b");
OnapCommandRegistrar.getRegistrar().getParamCache();
OnapCommandRegistrar.getRegistrar().removeParamCache("a");
diff --git a/framework/src/test/resources/data/test-profile.json b/framework/src/test/resources/data/test-profile.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/framework/src/test/resources/data/test-profile.json
diff --git a/framework/src/test/resources/data/test2-profile.json b/framework/src/test/resources/data/test2-profile.json
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/framework/src/test/resources/data/test2-profile.json
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 3f37faba..ca3c365f 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -243,7 +243,9 @@ public class OnapCli {
handleVersion();
} else if (!args.isEmpty() && this.args.get(0).equals(OnapCliConstants.PARAM_INTERACTIVE_PROFILE)) {
if (args.size() == 1) {
- this.print("Please use it in the form of 'profile <profile-name>'");
+ this.print("Please use it in the form of 'profile <profile-name>'\n");
+ this.print("Profiles:");
+ this.print(OnapCommandRegistrar.getRegistrar().getUserProfiles().toString());
} else {
this.args = Arrays.asList(new String [] {
this.getLongOption(OnapCliConstants.PARAM_PROFILE_LONG),
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 f7401904..8fd34413 100644
--- a/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
+++ b/main/src/test/java/org/onap/cli/main/OnapCliMainTest.java
@@ -152,6 +152,13 @@ public class OnapCliMainTest {
}
cli = new OnapCli(new String[] {});
+ mockConsole("profile");
+ try {
+ cli.handleInteractive();
+ } catch (Exception e) {
+ }
+
+ cli = new OnapCli(new String[] {});
mockConsole("version");
try {
cli.handleInteractive();