summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-10-04 23:04:34 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2017-11-20 12:24:22 +0530
commitc521118e69aaa589d631f95f34dcf88e7a8bd1b6 (patch)
tree0fd1b0c92b95747bb30c6873c43ed63c707e42f6
parent863a720fec2abf3fec87cff154df390e29ee5187 (diff)
Add overriding concept to Parameters
Issue-Id: CLI-66 Change-Id: I90b69da1b4235bfa12d4eaffd3f73538fd12a443 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/ad/OnapCredentials.java68
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java69
-rw-r--r--framework/src/main/resources/open-cli-schema/basic-logout.yaml8
-rw-r--r--framework/src/main/resources/open-cli-schema/catalog.yaml7
-rw-r--r--framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientTest.java214
-rw-r--r--framework/src/test/java/org/onap/cli/fw/ad/OnapCredentialsTest.java32
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java1
9 files changed, 59 insertions, 346 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
index 69e45bd2..ec7e1338 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -177,7 +177,9 @@ public abstract class OnapCommand {
*/
protected void validate() throws OnapCommandException {
for (OnapCommandParameter param : this.getParameters()) {
- param.validate();
+ if (param.isInclude()) {
+ param.validate();
+ }
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
index 0f5c9058..49919f43 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommandRegistrar.java
@@ -199,7 +199,7 @@ public class OnapCommandRegistrar {
//don't expose the auth type and catalog type commands
if (cls == null) {
- throw new OnapCommandNotFound(cmdName, version);
+ throw new OnapCommandNotFound(cmdName, version);
}
OnapCommand cmd;
diff --git a/framework/src/main/java/org/onap/cli/fw/ad/OnapCredentials.java b/framework/src/main/java/org/onap/cli/fw/ad/OnapCredentials.java
deleted file mode 100644
index 02cbef7b..00000000
--- a/framework/src/main/java/org/onap/cli/fw/ad/OnapCredentials.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.ad;
-
-/**
- * Onap Service credentials.
- */
-//mrkanag deprecate it
-public class OnapCredentials {
-
- /*
- * Onap Service username.
- */
- private String username;
-
- /*
- * Onap Service password
- */
- private String password;
-
- /*
- * Onap Service host-url
- */
- private String hostUrl;
-
- /**
- * Onap credentials with username and password.
- *
- * @param username
- * user name
- * @param password
- * password
- * @param hostUrl
- * host url
- */
- public OnapCredentials(String username, String password, String hostUrl) {
- super();
- this.username = username;
- this.password = password;
- this.hostUrl = hostUrl;
- }
-
- public String getUsername() {
- return username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getHostUrl() {
- return hostUrl;
- }
-}
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 08ee8fed..e056456a 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
@@ -255,21 +255,19 @@ public class OnapCommandUtils {
public static List<String> loadSchema(OnapCommand cmd, String schemaName, boolean includeDefault,
boolean validateSchema) throws OnapCommandException {
try {
- Map<String, ?> defaultParameterMap = includeDefault ?
- validateSchemaVersion(DEFAULT_PARAMETER_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
+ List<String> errors = new ArrayList<>();
+ if (includeDefault) {
+ Map<String, ?> defaultParameterMap = includeDefault ?
+ validateSchemaVersion(DEFAULT_PARAMETER_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
+ errors.addAll(parseSchema(cmd, defaultParameterMap, validateSchema));
+ }
Map<String, List<Map<String, String>>> commandYamlMap =
(Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
- if (includeDefault) {
- if (commandYamlMap.get(PARAMETERS) == null) {
- commandYamlMap.put(PARAMETERS, (List<Map<String, String>>) defaultParameterMap.get(PARAMETERS));
- } else {
- commandYamlMap.get(PARAMETERS).addAll((List<Map<String, String>>) defaultParameterMap.get(PARAMETERS));
- }
- }
+ errors.addAll(parseSchema(cmd, commandYamlMap, validateSchema));
- return parseSchema(cmd, commandYamlMap, validateSchema);
+ return errors;
} catch (OnapCommandException e) {
throw e;
} catch (Exception e) {
@@ -281,19 +279,18 @@ public class OnapCommandUtils {
public static List<String> loadHttpSchema(OnapHttpCommand cmd, String schemaName, boolean includeDefault,
boolean validateSchema) throws OnapCommandException {
try {
- Map<String, ?> defaultParameterMap = includeDefault ?
- validateSchemaVersion(DEFAULT_PARAMETER_HTTP_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
- Map<String, List<Map<String, String>>> commandYamlMap = (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
-
+ List<String> errors = new ArrayList<>();
if (includeDefault) {
- if (commandYamlMap.get(PARAMETERS) == null) {
- commandYamlMap.put(PARAMETERS, (List<Map<String, String>>) defaultParameterMap.get(PARAMETERS));
- } else {
- commandYamlMap.get(PARAMETERS).addAll((List<Map<String, String>>) defaultParameterMap.get(PARAMETERS));
- }
- }
- List<String> errors = parseSchema(cmd, commandYamlMap, validateSchema);
+ Map<String, ?> defaultParameterMap = includeDefault ?
+ validateSchemaVersion(DEFAULT_PARAMETER_HTTP_FILE_NAME, cmd.getSchemaVersion()) : new HashMap<>();
+ errors.addAll(parseSchema(cmd, defaultParameterMap, validateSchema));
+ }
+
+ Map<String, List<Map<String, String>>> commandYamlMap =
+ (Map<String, List<Map<String, String>>>)validateSchemaVersion(schemaName, cmd.getSchemaVersion());
+
errors.addAll(parseHttpSchema(cmd, commandYamlMap, validateSchema));
+
return errors;
} catch (OnapCommandException e) {
@@ -315,6 +312,7 @@ public class OnapCommandUtils {
private static void validateTags(List<String> schemaErrors, Map<String, ?> yamlMap,
List<String> totalParams, List<String> mandatoryParams,
String section) {
+ //mrkanag capture invalid entries as well
for (String param : totalParams) {
boolean isMandatory = mandatoryParams.contains(param);
boolean isYamlContains = yamlMap.containsKey(param);
@@ -441,12 +439,19 @@ public class OnapCommandUtils {
if (parameters != null) {
Set<String> names = new HashSet<>();
+ //To support overriding of the parameters, if command is already
+ //having the same named parameters, means same parameter is
+ //Overridden from included template into current template
+ Set<String> existingParamNames = cmd.getParametersMap().keySet();
+
for (Map<String, String> parameter : parameters) {
+ boolean isOverriding = false;
OnapCommandParameter param = new OnapCommandParameter();
//Override the parameters from its base such as default parameters list
- if (cmd.getParametersMap().containsKey(param.getName())) {
- param = cmd.getParametersMap().get(param.getName());
+ if (existingParamNames.contains(parameter.getOrDefault(NAME, ""))) {
+ param = cmd.getParametersMap().get(parameter.getOrDefault(NAME, ""));
+ isOverriding = true;
}
if (validate) {
@@ -461,8 +466,10 @@ public class OnapCommandUtils {
case NAME:
if (names.contains(parameter.get(key2))) {
throwOrCollect(new OnapCommandParameterNameConflict(parameter.get(key2)), exceptionList, validate);
+ } else {
+ names.add(parameter.get(key2));
}
- names.add(parameter.get(key2));
+
param.setName(parameter.get(key2));
break;
@@ -545,8 +552,10 @@ public class OnapCommandUtils {
}
}
- if ( !cmd.getParametersMap().containsKey(param.getName()) ) {
+ if ( !isOverriding) {
cmd.getParameters().add(param);
+ } else {
+ cmd.getParametersMap().replace(param.getName(), param);
}
}
}
@@ -938,9 +947,9 @@ public class OnapCommandUtils {
//On None type, username, password and no_auth are invalid
if (srv.isNoAuth()) {
- cmd.getParametersMap().remove(DEAFULT_PARAMETER_USERNAME);
- cmd.getParametersMap().remove(DEAFULT_PARAMETER_PASSWORD);
- cmd.getParametersMap().remove(DEFAULT_PARAMETER_NO_AUTH);
+ cmd.getParametersMap().get(DEAFULT_PARAMETER_USERNAME).setInclude(false);
+ cmd.getParametersMap().get(DEAFULT_PARAMETER_PASSWORD).setInclude(false);
+ cmd.getParametersMap().get(DEFAULT_PARAMETER_NO_AUTH).setInclude(false);
}
break;
@@ -1104,6 +1113,10 @@ public class OnapCommandUtils {
int newLineOptions = 0;
for (OnapCommandParameter param : cmd.getParameters()) {
+ if (!param.isInclude()) {
+ continue;
+ }
+
// First column Option or positional args
String optFirstCol;
if (newLineOptions == 3) {
diff --git a/framework/src/main/resources/open-cli-schema/basic-logout.yaml b/framework/src/main/resources/open-cli-schema/basic-logout.yaml
index 088fe7df..ef60006c 100644
--- a/framework/src/main/resources/open-cli-schema/basic-logout.yaml
+++ b/framework/src/main/resources/open-cli-schema/basic-logout.yaml
@@ -9,3 +9,11 @@ info:
service: basic-auth
type: auth
author: Kanagaraj Manickam mkr1481@gmail.com
+
+parameters:
+ - name: host-username
+ is_include: false
+ - name: host-password
+ is_include: false
+ - name: no-auth
+ is_include: false \ No newline at end of file
diff --git a/framework/src/main/resources/open-cli-schema/catalog.yaml b/framework/src/main/resources/open-cli-schema/catalog.yaml
index 4fafec4c..d3ee9992 100644
--- a/framework/src/main/resources/open-cli-schema/catalog.yaml
+++ b/framework/src/main/resources/open-cli-schema/catalog.yaml
@@ -23,7 +23,12 @@ parameters:
short_option: i
long_option: catalog-service-version
is_optional: false
-
+ - name: host-username
+ is_include: false
+ - name: host-password
+ is_include: false
+ - name: no-auth
+ is_include: false
results:
direction: portrait
attributes:
diff --git a/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientTest.java b/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientTest.java
deleted file mode 100644
index 4c14c889..00000000
--- a/framework/src/test/java/org/onap/cli/fw/ad/OnapAuthClientTest.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * 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.ad;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.onap.cli.fw.conf.OnapCommandConfg;
-import org.onap.cli.fw.error.OnapCommandException;
-import org.onap.cli.fw.error.OnapCommandExecutionFailed;
-import org.onap.cli.fw.error.OnapCommandHttpFailure;
-import org.onap.cli.fw.error.OnapCommandServiceNotFound;
-import org.onap.cli.fw.http.HttpInput;
-import org.onap.cli.fw.http.HttpResult;
-import org.onap.cli.fw.http.OnapHttpConnection;
-import org.onap.cli.fw.input.OnapCommandParameter;
-
-import mockit.Invocation;
-import mockit.Mock;
-import mockit.MockUp;
-
-@Ignore
-public class OnapAuthClientTest {
-
- OnapAuthClient client;
-
- @Before
- public void setUp() throws OnapCommandHttpFailure, OnapCommandException {
- OnapCredentials creds = new OnapCredentials("test", "test123", "http://192.168.99.10:80");
- OnapService service = new OnapService();
- List<OnapCommandParameter> params = new ArrayList<>();
- client = new OnapAuthClient(null, false);
- }
-
- @Test
- public void loginFailedAuthIgnoredTest() throws OnapCommandException {
- OnapCredentials creds = new OnapCredentials("test", "test123", "http://192.168.99.10:80");
- OnapService service = new OnapService();
- List<OnapCommandParameter> params = new ArrayList<>();
- if (OnapCommandConfg.isAuthIgnored()) {
- client.getDebugInfo();
- client.login();
- }
- }
-
- @Test
- public void logoutFailedAuthIgnoredTest() throws OnapCommandException {
- OnapCredentials creds = new OnapCredentials("test", "test123", "http://192.168.99.10:80");
- OnapService service = new OnapService();
- List<OnapCommandParameter> params = new ArrayList<>();
- if (OnapCommandConfg.isAuthIgnored()) {
- client.logout();
- }
- }
-
- @Test
- public void getMsbUrlTest() throws OnapCommandException {
- OnapCredentials creds = new OnapCredentials("test", "test123", "http://192.168.99.10:80");
- OnapService service = new OnapService();
- List<OnapCommandParameter> params = new ArrayList<>();
- OnapService srv = new OnapService();
- srv.setName("msb");
- String msb = client.getServiceUrl();
- assertEquals("http://192.168.99.10:80/api/microservices/v1", msb);
- }
-
- @Ignore
- @Test(expected = OnapCommandServiceNotFound.class)
- public void loginFailedServiceNotFoundTest() throws OnapCommandException {
- mockIsAuthIgnored(false);
- HttpResult result = new HttpResult();
- result.setStatus(404);
- mockHttpRequest(result);
- client.login();
-
- }
-
- @Ignore
- @Test(expected = OnapCommandExecutionFailed.class)
- public void loginFailedCommandExecutionFailedTest() throws OnapCommandException {
-
- mockIsAuthIgnored(false);
- HttpResult result = new HttpResult();
- result.setStatus(401);
- mockHttpRequest(result);
- client.login();
- }
-
- @Ignore
- @Test(expected = OnapCommandExecutionFailed.class)
- public void loginFailedWrongJasonBodyTest() throws OnapCommandException {
- mockIsAuthIgnored(false);
- HttpResult result = new HttpResult();
- result.setStatus(200);
- mockHttpRequest(result);
- client.login();
- }
-
- @Ignore
- @Test
- public void loginSuccessTest() {
-
- mockIsAuthIgnored(false);
- HttpResult result = new HttpResult();
- result.setBody("{\"url\":\"http://192.168.4.47\"}");
- result.setStatus(200);
- mockHttpConsecutiveRequest(result);
- try {
- client.login();
- } catch (OnapCommandException e) {
- }
- mockHttpRequest(null);
- }
-
- @Test
- public void logoutFailedTest() {
-
- mockIsAuthIgnored(false);
- HttpResult result = new HttpResult();
- result.setBody("{\"url\":\"http://192.168.4.47\"}");
- result.setStatus(200);
- mockHttpConsecutiveRequest(result);
- try {
- client.logout();
- } catch (OnapCommandException e) {
- }
- mockHttpRequest(null);
- }
-
- @Test
- public void logoutSuccessTest() {
-
- mockIsAuthIgnored(false);
- HttpResult result = new HttpResult();
- result.setBody("{\"url\":\"http://192.168.4.47\"}");
- result.setStatus(204);
- mockHttpConsecutiveRequest(result);
- try {
- client.logout();
- } catch (OnapCommandException e) {
- }
- mockHttpRequest(null);
- }
-
- private void mockIsAuthIgnored(boolean isAuthIgnored) {
-
- new MockUp<OnapCommandConfg>() {
- boolean isMock = true;
-
- @Mock
- public boolean isAuthIgnored(Invocation inv) {
- if (isMock) {
- isMock = false;
- return isAuthIgnored;
- } else {
- return inv.proceed();
- }
- }
- };
- }
-
- private static void mockHttpRequest(HttpResult result) {
- new MockUp<OnapHttpConnection>() {
- boolean isMock = true;
-
- @Mock
- public HttpResult request(Invocation inv, HttpInput input) throws OnapCommandHttpFailure {
- if (isMock) {
- isMock = false;
- return result;
- } else {
- return inv.proceed(input);
- }
- }
- };
- }
-
- private void mockHttpConsecutiveRequest(HttpResult result) {
- new MockUp<OnapHttpConnection>() {
- @Mock
- public HttpResult request(Invocation inv, HttpInput input) throws OnapCommandHttpFailure {
- return result;
- }
- };
- }
-
- @AfterClass
- public static void clear() {
- HttpResult result = new HttpResult();
- result.setBody("{\"url\":\"http://192.168.4.47\"}");
- result.setStatus(200);
- mockHttpRequest(result);
- }
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/ad/OnapCredentialsTest.java b/framework/src/test/java/org/onap/cli/fw/ad/OnapCredentialsTest.java
deleted file mode 100644
index cc431454..00000000
--- a/framework/src/test/java/org/onap/cli/fw/ad/OnapCredentialsTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.ad;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class OnapCredentialsTest {
-
- @Test
- public void credentialsTest() {
- OnapCredentials cre = new OnapCredentials("test", "test123", "url");
- assertTrue(cre.getUsername().equals("test") && cre.getPassword().equals("test123")
- && cre.getHostUrl().equals("url"));
- }
-
-}
diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
index faf8394a..82869fa3 100644
--- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
@@ -37,7 +37,6 @@ import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.OnapCommandSchema;
-import org.onap.cli.fw.ad.OnapCredentials;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.error.OnapCommandException;