From a4cd2403a5a171d6ab6aa6b1b0b1aae83345121b Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Tue, 29 Aug 2017 18:15:10 +0530 Subject: Add versioning for command By allowing to add version to the YAML, helps to create same command for multiple versions of product say onap 1.0, 1.1 CLI-37 Change-Id: Ic3982ea912045ff4f422fcf093cbd98ecd99716d Signed-off-by: Kanagaraj Manickam k00365106 --- .../org/onap/cli/cmd/sample/OnapCommandSample.java | 2 +- .../org/onap/cli/fw/OnapCommandRegistrarTest.java | 20 ++++---- .../onap/cli/fw/error/OnapCommandErrorTest.java | 6 ++- .../onap/cli/fw/utils/OnapCommandUtilsTest.java | 6 +-- .../cli/fw/utils/OpenCommandRegistrarTest.java | 4 +- .../onap-cli-schema/sample-test1-schema-http.yaml | 1 + framework/src/test/resources/onap-test-schema.yaml | 1 + framework/src/test/resources/onap.properties | 56 ++++++++++++++++++++++ ...e-test-invalid-schema-duplicate-longoption.yaml | 1 + .../sample-test-invalid-schema-duplicate-name.yaml | 1 + ...-test-invalid-schema-duplicate-shortoption.yaml | 1 + .../test/resources/sample-test-invalid-schema.yaml | 3 +- .../sample-test-schema-auth-required.yaml | 1 + .../test/resources/sample-test-schema-http.yaml | 1 + .../test/resources/sample-test-schema-swagger.yaml | 1 + .../src/test/resources/sample-test-schema.yaml | 1 + 16 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 framework/src/test/resources/onap.properties (limited to 'framework/src/test') diff --git a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java index 69714ad7..16c92185 100644 --- a/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java +++ b/framework/src/test/java/org/onap/cli/cmd/sample/OnapCommandSample.java @@ -25,7 +25,7 @@ import org.onap.cli.fw.error.OnapCommandExecutionFailed; * This command helps to test the Command functionalities. * */ -@OnapCommandSchema(name = "sample-test", schema = "sample-test-schema.yaml") +@OnapCommandSchema(name = "sample-test", version="cli-1.0", schema = "sample-test-schema.yaml") public class OnapCommandSample extends OnapCommand { public OnapCommandSample() { 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 a076eee6..840a75d7 100644 --- a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java +++ b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java @@ -50,7 +50,7 @@ public class OnapCommandRegistrarTest { if (!file.exists()) { file.mkdir(); } else { - File f1 = new File(path + "/external-schema.json"); + File f1 = new File(path + "/cli-schema.json"); f1.delete(); } } @@ -60,7 +60,7 @@ public class OnapCommandRegistrarTest { public void registerTest() throws OnapCommandException { OnapCommand test = new OnapCommandTest(); Class cmd = (Class) test.getClass(); - registerar.register("Test", cmd); + registerar.register("Test", "cli-1.0", cmd); OnapCommand cc = registerar.get("Test"); assertTrue(cmd == cc.getClass()); @@ -71,7 +71,7 @@ public class OnapCommandRegistrarTest { public void cmdTestSchema() throws OnapCommandException { OnapCommand test = new OnapCommandTest(); Class cmd = (Class) test.getClass(); - registerar.register("Test", cmd); + registerar.register("Test", "cli-1.0", cmd); OnapCommand cc = registerar.get("Test"); } @@ -82,14 +82,16 @@ public class OnapCommandRegistrarTest { registerar.get("Test1"); fail("This should have thrown an exception"); } catch (OnapCommandNotFound e) { - assertEquals(e.getMessage(), "0x0011::Command Test1 is not registered"); + //pass // NOSONAR + } catch (Exception e) { + fail("This should have thrown an OnapCommandNotFound exception"); } } @Test public void onapCommandRegistrationFailedTest() throws OnapCommandException { - @OnapCommandSchema(name = "Test2", schema = "sample-test-schema.yaml") + @OnapCommandSchema(name = "Test2", version= "cli-1.0", schema = "sample-test-schema.yaml") class Test extends OnapCommand { @Override @@ -102,7 +104,7 @@ public class OnapCommandRegistrarTest { OnapCommand com = new Test(); Class cmd = (Class) com.getClass(); try { - registerar.register("Test2", cmd); + registerar.register("Test2", "cli-1.0", cmd); registerar.get("Test2"); fail("This should have thrown an exception"); } catch (OnapCommandRegistrationFailed e) { @@ -116,7 +118,7 @@ public class OnapCommandRegistrarTest { OnapCommand test = new OnapCommandTest1(); Class cmd = (Class) test.getClass(); registerar = new OnapCommandRegistrar(); - registerar.register("test1", cmd); + registerar.register("test1", "cli-1.0", cmd); String help = registerar.getHelp(); assertNotNull(help); } @@ -139,7 +141,7 @@ public class OnapCommandRegistrarTest { } } -@OnapCommandSchema(name = OnapCommandTest.CMD_NAME, schema = "sample-test-schema.yaml") +@OnapCommandSchema(name = OnapCommandTest.CMD_NAME, version = "cli-1.0", schema = "sample-test-schema.yaml") class OnapCommandTest extends OnapCommand { public OnapCommandTest() { @@ -154,7 +156,7 @@ class OnapCommandTest extends OnapCommand { } -@OnapCommandSchema(name = OnapCommandTest1.CMD_NAME, schema = "test-schema.yaml") +@OnapCommandSchema(name = OnapCommandTest1.CMD_NAME, version = "cli-1.0", schema = "test-schema.yaml") class OnapCommandTest1 extends OnapCommand { public OnapCommandTest1() { 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 1d0c1a6b..0a388e5f 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 @@ -190,9 +190,11 @@ public class OnapCommandErrorTest { @Test public void onapCommandNotFoundTest() { - OnapCommandNotFound failed = new OnapCommandNotFound("Test"); + OnapCommandNotFound failed = new OnapCommandNotFound("Test", "1.0"); - assertEquals("0x0011::Command Test is not registered", failed.getMessage()); + assertEquals("0x0011::Command Test is not available for product version 1.0." + + " so please check command name or product version set in env variable CLI_PRODUCT_VERSION or" + + " cli.product.version in onap.properties", failed.getMessage()); } @Test 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 064576d8..5a992c6f 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 @@ -434,14 +434,14 @@ public class OnapCommandUtilsTest { } - @OnapCommandSchema(name = "sample-test", schema = "sample-test-schema.yaml") + @OnapCommandSchema(name = "sample-test", version = "cli-1.0", schema = "sample-test-schema.yaml") class OnapCommandSample extends OnapCommand { @Override protected void run() throws OnapCommandException { } } - @OnapCommandSchema(name = "sample-swagger-test", schema = "sample-test-schema-swagger.yaml") + @OnapCommandSchema(name = "sample-swagger-test", version = "cli-1.0", schema = "sample-test-schema-swagger.yaml") class OnapSwaggerBasedCommandSample extends OnapSwaggerCommand { @Override @@ -449,7 +449,7 @@ public class OnapCommandUtilsTest { } } - @OnapCommandSchema(name = "sample-http-test", schema = "sample-test-schema-http.yaml") + @OnapCommandSchema(name = "sample-http-test", version = "cli-1.0", schema = "sample-test-schema-http.yaml") class OnapHttpCommandSample extends OnapHttpCommand { @Override diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java index fa73ea6e..f7ba2355 100644 --- a/framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java +++ b/framework/src/test/java/org/onap/cli/fw/utils/OpenCommandRegistrarTest.java @@ -34,9 +34,9 @@ public class OpenCommandRegistrarTest { public void test() throws OnapCommandException { OnapCommandRegistrar registrar = OnapCommandRegistrar.getRegistrar(); OnapCommand cmd = registrar.get("sample-test"); - registrar.listCommands(); - registrar.getAllCommandToSchemaMap(); cmd.printVersion(); + registrar.listCommands(); + } } diff --git a/framework/src/test/resources/onap-cli-schema/sample-test1-schema-http.yaml b/framework/src/test/resources/onap-cli-schema/sample-test1-schema-http.yaml index 18a7bb16..0da1d22e 100644 --- a/framework/src/test/resources/onap-cli-schema/sample-test1-schema-http.yaml +++ b/framework/src/test/resources/onap-cli-schema/sample-test1-schema-http.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test1 description: Onap sample command to test the command features +version: cli-1.0 service: name: sample version: v1 diff --git a/framework/src/test/resources/onap-test-schema.yaml b/framework/src/test/resources/onap-test-schema.yaml index aa656064..0a2f5c47 100644 --- a/framework/src/test/resources/onap-test-schema.yaml +++ b/framework/src/test/resources/onap-test-schema.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features +verion: cli-1.0 service: name: sample version: v1 diff --git a/framework/src/test/resources/onap.properties b/framework/src/test/resources/onap.properties new file mode 100644 index 00000000..9e6b34bd --- /dev/null +++ b/framework/src/test/resources/onap.properties @@ -0,0 +1,56 @@ +cli.ignore_auth=false +cli.version=1.0 +cli.http.api_key_use_cookies=true + +cli.service_name=onap-cli +cli.api_gateway=msb +cli.auth_service=auth + +# service section +cli.exclude_params_internal_cmd=onap-username,onap-password,host-url,no-auth +cli.no_auth_disable_include_params_external_cmd=onap-username,onap-password,host-url,no-auth +cli.no_auth_enable_exclude_params_external_cmd=onap-username,onap-password,no-auth +cli.no_auth_enable_include_params_external_cmd=host-url + +cli.http.basic.common_headers=x-auth-token,x-transaction-id,x-app-id +cli.http.basic.common_headers.x-auth-token=Authorization +cli.http.basic.common_headers.x-transaction-id=X-TransactionId +cli.http.basic.common_headers.x-transaction-id.value=req-uuid +cli.http.basic.common_headers.x-app-id=X-FromAppId +cli.http.basic.common_headers.x-app-id.value=onap-cli + +# Service specific headers +cli.http.basic.common_headers.sdc=user-id +cli.http.basic.common_headers.sdc.user-id=USER_ID +cli.http.basic.common_headers.sdc.user-id.value=${onap-username} + +#TODO mrkanag add support for aaf like defined above for basic +#cli.service.auth=aaf + +#schema validation +cli.schema.top_level_params_list=onap_cmd_schema_version,name,version,description,service,parameters,results,http +cli.schema.top_level_mandatory_list=onap_cmd_schema_version + +cli.schema.service_params_list=name,version,auth,mode +cli.schema.service_params_mandatory_list=name,version + +cli.schema.input_params_list=name,description,type,short_option,long_option, is_optional,default_value,is_secured +cli.schema.input_params_mandatory_list=name,description,type + +cli.schema.result_params_list=name,description,scope,type,is_secured +cli.schema.result_params_mandatory_list=name, description, type + +cli.schema.http_sections=request,success_codes,result_map,sample_response +cli.schema.http_mandatory_sections=equest, success_codes + +cli.schema.http_request_params=uri,method,body,headers,queries,multipart_entity_name +cli.schema.http_request_mandatory_params=uri,method + +cli.schema.http_methods=post,get,delete,put,head + +cli.schema.boolean_values=true,false +cli.schema.auth_values=none,basic +cli.schema.mode_values=direct,catalog + +#product version +cli.product.version=cli-1.0 diff --git a/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml b/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml index 8761bb30..a18aacc0 100644 --- a/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema-duplicate-longoption.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features +version: cli-1.0 service: name: sample version: v1 diff --git a/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml b/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml index df4ed316..375f4548 100644 --- a/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema-duplicate-name.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features +version: cli-1.0 service: name: sample version: v1 diff --git a/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml b/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml index 519f6e3b..9c501452 100644 --- a/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema-duplicate-shortoption.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features +version: cli-1.0 service: name: sample version: v1 diff --git a/framework/src/test/resources/sample-test-invalid-schema.yaml b/framework/src/test/resources/sample-test-invalid-schema.yaml index ed21772c..fc301bbd 100644 --- a/framework/src/test/resources/sample-test-invalid-schema.yaml +++ b/framework/src/test/resources/sample-test-invalid-schema.yaml @@ -1,11 +1,12 @@ onap_cmd_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features +version: cli-1.0 service: name: sample version: v1 parameters: - -- name: bool-param + - name: bool-param type: bool description: Onap boolean param, by default its always false. short_option: b diff --git a/framework/src/test/resources/sample-test-schema-auth-required.yaml b/framework/src/test/resources/sample-test-schema-auth-required.yaml index 4df6445a..408c74c7 100644 --- a/framework/src/test/resources/sample-test-schema-auth-required.yaml +++ b/framework/src/test/resources/sample-test-schema-auth-required.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features +version: cli-1.0 service: name: sample version: v1 diff --git a/framework/src/test/resources/sample-test-schema-http.yaml b/framework/src/test/resources/sample-test-schema-http.yaml index 7bbf6775..56a0a536 100644 --- a/framework/src/test/resources/sample-test-schema-http.yaml +++ b/framework/src/test/resources/sample-test-schema-http.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-create-http description: Register microservice into Onap +version: onap-1.0 service: name: msb version: v1 diff --git a/framework/src/test/resources/sample-test-schema-swagger.yaml b/framework/src/test/resources/sample-test-schema-swagger.yaml index c88ddb7a..b9944363 100644 --- a/framework/src/test/resources/sample-test-schema-swagger.yaml +++ b/framework/src/test/resources/sample-test-schema-swagger.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test-swagger description: Sample swagger command test. +version: cli-1.0 service: name: sample version: v1 diff --git a/framework/src/test/resources/sample-test-schema.yaml b/framework/src/test/resources/sample-test-schema.yaml index dbb5cbed..2f021779 100644 --- a/framework/src/test/resources/sample-test-schema.yaml +++ b/framework/src/test/resources/sample-test-schema.yaml @@ -1,6 +1,7 @@ onap_cmd_schema_version: 1.0 name: sample-test description: Onap sample command to test the command features +version: onap-1.0 service: name: sample version: v1 -- cgit 1.2.3-korg