aboutsummaryrefslogtreecommitdiffstats
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-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
8 files changed, 65 insertions, 4 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