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";
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;
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);
}
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());
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;
+ }
}
this.paramCache.setProfile(profileName);
}
+ public List<String> getUserProfiles() {
+ return paramCache.getProfiles();
+ }
+
private static OnapCommandRegistrar registrar = null;
/**
cache.add("1.0", "a", "b");
cache.remove("1.0", "a");
- cache.setProfile("test");
+ cache.setProfile("test123");
cache.getParams("1.0");
}
--- /dev/null
+/*
+ * 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"));
+
+
+ }
+
+}
@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");
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),
} catch (Exception e) {
}
+ cli = new OnapCli(new String[] {});
+ mockConsole("profile");
+ try {
+ cli.handleInteractive();
+ } catch (Exception e) {
+ }
+
cli = new OnapCli(new String[] {});
mockConsole("version");
try {