diff options
author | Kanagaraj Manickam <kanagaraj.manickam@huawei.com> | 2017-10-26 14:52:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-10-26 14:52:45 +0000 |
commit | 5090b19cde7127ff532d422a7b18e16e2d374da2 (patch) | |
tree | c32d42c8c37e52ce9f3368ba048ed397d5a30470 | |
parent | 9d1818327ce7aeb2839fec218c99e5cd89d77b9d (diff) | |
parent | 3993f730f33d81a6a1ae50eccca9ab926702ec30 (diff) |
Merge changes I3bc55b53,Iff6d1f16,I19bdb8a1,Ia90bd215,I84533921
* changes:
Remove the stale samples for cloud commands
Add samples for cloud-delete
Add samples for cloud-list
Add samples for cloud-create command
Fix the sample file name align with schema
15 files changed, 128 insertions, 52 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java index 1e202a54..90ac961e 100644 --- a/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java +++ b/framework/src/main/java/org/onap/cli/fw/cmd/OnapHttpCommand.java @@ -99,10 +99,10 @@ public class OnapHttpCommand extends OnapCommand { for (OnapCommandResultAttribute attr : this.getResult().getRecords()) { attr.setValues(results.get(attr.getName())); } - generateJsonMock(httpInput, output, this.getName()); + generateJsonMock(httpInput, output, this.getSchemaName()); } - private void generateJsonMock(HttpInput httpInput, HttpResult httpResult, String fileName) + private void generateJsonMock(HttpInput httpInput, HttpResult httpResult, String schemaName) throws OnapCommandFailedMocoGenerate { if (OnapCommandConfg.isSampleGenerateEnabled()) { @@ -118,9 +118,9 @@ public class OnapHttpCommand extends OnapCommand { mockResponse.setJson(httpResult.getBody()); MockJsonGenerator.generateMocking(mockRequest, mockResponse, OnapCommandConfg.getSampleGenerateTargetFolder() - + "/" + fileName); + + "/" + schemaName.replace(".yaml", "") + "-moco.json"); } catch (IOException error) { - throw new OnapCommandFailedMocoGenerate(fileName, error); + throw new OnapCommandFailedMocoGenerate(schemaName, error); } } } 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 0ed27ea1..4cc2132d 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -363,7 +363,7 @@ public class OnapCli { this.print(result.print()); this.exitSuccessfully(); - generateSmapleYaml(result); + generateSmapleYaml(cmd); } catch (Exception e) { this.print(cmd.getResult().getDebugInfo()); if (e instanceof OnapCommandWarning) { @@ -376,13 +376,13 @@ public class OnapCli { } } - private void generateSmapleYaml(OnapCommandResult result) throws OnapCommandException { + private void generateSmapleYaml(OnapCommand cmd) throws OnapCommandException { if (OnapCommandConfg.isSampleGenerateEnabled() && this.getExitCode() == OnapCliConstants.EXIT_SUCCESS) { try { - SampleYamlGenerator.generateSampleYaml(args, result.print(), + SampleYamlGenerator.generateSampleYaml(args, cmd.getResult().print(), OnapCommandRegistrar.getRegistrar().getEnabledProductVersion(), - OnapCommandConfg.getSampleGenerateTargetFolder(), - result.isDebug()); + OnapCommandConfg.getSampleGenerateTargetFolder() + "/" + cmd.getSchemaName().replaceAll(".yaml", "") + "-sample.yaml", + cmd.getResult().isDebug()); } catch (IOException error) { throw new OnapCommandInvalidSample(args.get(0), error); } diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-sample-1.1.yaml b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-sample-1.1.yaml deleted file mode 100644 index 6a5c55c0..00000000 --- a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-sample-1.1.yaml +++ /dev/null @@ -1,8 +0,0 @@ -onap_cli_sample_version: 1.0 - -name: cloud-create -version: onap-1.1 -samples: - sample1: - name: Create a cloud region in onap - input: -h https://locahost:8443 -u AAI -p AAI -x abc-xyz -y ABCXYZ25 diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-schema-1.1-moco.json b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-schema-1.1-moco.json new file mode 100644 index 00000000..223ebd26 --- /dev/null +++ b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-schema-1.1-moco.json @@ -0,0 +1,24 @@ +[ { + "request" : { + "method" : "put", + "uri" : "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/huawei-cloud/bangalore", + "headers" : { + "Authorization" : "Basic QUFJOkFBSQ==", + "X-FromAppId" : "onap-cli", + "Accept" : "application/json", + "X-TransactionId" : "req-63eebfa7-ebdb-4707-9208-a159d2f53c6e", + "Content-Type" : "application/json" + }, + "json" : { + "sriov-automation" : false, + "cloud-region-id" : "bangalore", + "cloud-owner" : "huawei-cloud", + "new-attribute-for-demo" : "blah", + "number-attribute-for-demo" : 1 + } + }, + "response" : { + "status" : 201, + "json" : null + } +} ]
\ No newline at end of file diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-schema-1.1-sample.yaml b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-schema-1.1-sample.yaml new file mode 100644 index 00000000..ad3a521e --- /dev/null +++ b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-create-schema-1.1-sample.yaml @@ -0,0 +1,10 @@ +onap_cli_sample_version: 1.0 +name: cloud-create +version: onap-1.1 +samples: + sample1: + name: cloud-create + input: --cloud-name huawei-cloud --region-name bangalore + moco: cloud-create-schema-1.1-moco.json + ouput: | + diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-sample-1.1.yaml b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-sample-1.1.yaml deleted file mode 100644 index c84b8eca..00000000 --- a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-sample-1.1.yaml +++ /dev/null @@ -1,8 +0,0 @@ -onap_cli_sample_version: 1.0 - -name: cloud-delete -version: onap-1.1 -samples: - sample1: - name: Delete the cloud region in onap - input: -h https://locahost:8443 -u AAI -p AAI -x abc-xyz -y ABCXYZ25 -z 1504257554519
\ No newline at end of file diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-schema-1.1-moco.json b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-schema-1.1-moco.json new file mode 100644 index 00000000..85094a9d --- /dev/null +++ b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-schema-1.1-moco.json @@ -0,0 +1,18 @@ +[ { + "request" : { + "method" : "delete", + "uri" : "/aai/v11/cloud-infrastructure/cloud-regions/cloud-region/huawei-cloud-test/bangalore-test", + "headers" : { + "Authorization" : "Basic QUFJOkFBSQ==", + "X-FromAppId" : "onap-cli", + "Accept" : "application/json", + "X-TransactionId" : "req-2d7993c7-9355-435a-a0d7-2f8aa02bf9a6", + "Content-Type" : "application/json" + }, + "json" : null + }, + "response" : { + "status" : 204, + "json" : null + } +} ]
\ No newline at end of file diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-schema-1.1-sample.yaml b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-schema-1.1-sample.yaml new file mode 100644 index 00000000..57dbc878 --- /dev/null +++ b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-delete-schema-1.1-sample.yaml @@ -0,0 +1,10 @@ +onap_cli_sample_version: 1.0 +name: cloud-delete +version: onap-1.1 +samples: + sample1: + name: cloud-delete + input: --cloud-name huawei-cloud-test --region-name bangalore-test --resource-version 1509027982352 + moco: cloud-delete-schema-1.1-moco.json + ouput: | + diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-sample-1.1.yaml b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-sample-1.1.yaml deleted file mode 100644 index ada90903..00000000 --- a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-sample-1.1.yaml +++ /dev/null @@ -1,18 +0,0 @@ -onap_cli_sample_version: 1.0 - -name: cloud-list -version: onap-1.1 -samples: - sample1: - name: List the configured clouds in onap - input: -h https://locahost:8443 -u AAI -p AAI - output: | - +--------------------------------+------------------------------------+------------------+ - |cloud |region |resource-version | - +--------------------------------+------------------------------------+------------------+ - |example-cloud-owner-val-44086 |example-cloud-region-id-val-67393 |1503503677953 | - +--------------------------------+------------------------------------+------------------+ - |att-aic |AAIAIC25 |1503380675 | - +--------------------------------+------------------------------------+------------------+ - |abc-xyz |ABCXYZ25 |1504257554519 | - +--------------------------------+------------------------------------+------------------+ diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-schema-1.1-moco.json b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-schema-1.1-moco.json new file mode 100644 index 00000000..2e5b1db0 --- /dev/null +++ b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-schema-1.1-moco.json @@ -0,0 +1,34 @@ +[ { + "request" : { + "method" : "get", + "uri" : "/aai/v11/cloud-infrastructure/cloud-regions", + "headers" : { + "Authorization" : "Basic QUFJOkFBSQ==", + "X-FromAppId" : "onap-cli", + "Accept" : "application/json", + "X-TransactionId" : "req-77c08aa0-662e-4d32-9206-bd569c3bf61b", + "Content-Type" : "application/json" + }, + "json" : null + }, + "response" : { + "status" : 200, + "json" : { + "cloud-region" : [ { + "cloud-owner" : "huawei-cloud", + "cloud-region-id" : "bangalore", + "sriov-automation" : false, + "resource-version" : "1509027332165" + }, { + "cloud-owner" : "Rackspace", + "cloud-region-id" : "RegionOne", + "cloud-type" : "SharedNode", + "owner-defined-type" : "OwnerType", + "cloud-region-version" : "v1", + "cloud-zone" : "CloudZone", + "sriov-automation" : false, + "resource-version" : "1508827902543" + } ] + } + } +} ]
\ No newline at end of file diff --git a/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-schema-1.1-sample.yaml b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-schema-1.1-sample.yaml new file mode 100644 index 00000000..e527ea8b --- /dev/null +++ b/plugins/aai/src/test/resources/onap-cli-sample/cloud-region/cloud-list-schema-1.1-sample.yaml @@ -0,0 +1,16 @@ +onap_cli_sample_version: 1.0 +name: cloud-list +version: onap-1.1 +samples: + sample1: + name: cloud-list + input: + moco: cloud-list-schema-1.1-moco.json + ouput: | + +--------------+------------+------------------+ + |cloud |region |resource-version | + +--------------+------------+------------------+ + |huawei-cloud |bangalore |1509027332165 | + +--------------+------------+------------------+ + |Rackspace |RegionOne |1508827902543 | + +--------------+------------+------------------+ diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java index c3006e32..4b2e116c 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockJsonGenerator.java @@ -17,9 +17,7 @@ package org.onap.cli.http.mock; import java.io.File; import java.io.IOException; -import java.text.SimpleDateFormat; import java.util.Arrays; -import java.util.Date; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; @@ -35,8 +33,7 @@ public class MockJsonGenerator { ObjectMapper mapper = new ObjectMapper(); ObjectWriter writer = mapper.writer(new DefaultPrettyPrinter()); - String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); - writer.writeValue(new File(jsonFilePath + "-" + timeStamp + "-moco.json"), + writer.writeValue(new File(jsonFilePath), Arrays.asList(mockObject)); } } diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java index 2b8fa826..7e8cdca8 100644 --- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java +++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java @@ -38,7 +38,7 @@ public class MockResponse { } public void setJson(String json) throws IOException { - if (!json.isEmpty()) { + if (json != null && !json.isEmpty()) { ObjectMapper objectMapper = new ObjectMapper(); this.json = objectMapper.readTree(json); } diff --git a/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java index e18b1d73..9a59cdf6 100644 --- a/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java +++ b/validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java @@ -16,6 +16,7 @@ package org.onap.cli.sample.yaml; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; @@ -27,11 +28,11 @@ public class SampleYamlGenerator { static int nTab; public static void generateSampleYaml(List<String> input, String ouput, String version, - String targetFolder, boolean debug) throws IOException { + String targetPath, boolean debug) throws IOException { String cmdName = input.get(0); - PrintWriter writer = new PrintWriter(targetFolder + "/" + cmdName + "-sample.yaml", "UTF-8"); + PrintWriter writer = new PrintWriter(targetPath, "UTF-8"); writeKeyValuePair(writer, "onap_cli_sample_version", "1.0"); writeKeyValuePair(writer, "name", cmdName); writeKeyValuePair(writer, "version", version); @@ -41,7 +42,7 @@ public class SampleYamlGenerator { writeKeyValuePair(writer, "name", cmdName); writeKeyValuePair(writer, "input", input.stream().skip(1).collect(Collectors.joining(" "))); - writeKeyValuePair(writer, "moco", cmdName + "-sample-yaml.yaml"); + writeKeyValuePair(writer, "moco", new File(targetPath).getName().replaceAll("-sample.yaml", "-moco.json")); writeMultilineKeyValue(writer, "ouput", ouput, debug); writeEndKey(); diff --git a/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java b/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java index c98cb71b..98c0ce9d 100644 --- a/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java +++ b/validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java @@ -26,7 +26,7 @@ public class SampleYamlGeneratorTest { @Test public void testGenerateSampleYaml() throws IOException { SampleYamlGenerator.generateSampleYaml(Arrays.asList("testcmd", "-a", "argument"), - "+--------+\n+val +\n+argument+", "test-version-1.0", "target", false); + "+--------+\n+val +\n+argument+", "test-version-1.0", "target/test.yaml", false); } } |