From ddc79e252a0ec710e6ae701aef7e07f233534b63 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Thu, 28 Feb 2019 15:31:00 +0530 Subject: CVC: Update VTP with scenario, execution Issue-ID: VNFSDK-352 Change-Id: I3cb2f5d3bcfda16a6bb01121878533f527e226fe Signed-off-by: Kanagaraj Manickam k00365106 --- .../org/onap/vtp/scenario/VTPScenarioResource.java | 258 +++++++++++++++++++++ .../org/onap/vtp/scenario/model/VTPTestCase.java | 171 ++++++++++++++ .../onap/vtp/scenario/model/VTPTestScenario.java | 57 +++++ .../org/onap/vtp/scenario/model/VTPTestSuite.java | 58 +++++ 4 files changed, 544 insertions(+) create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java create mode 100644 vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario') diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java new file mode 100644 index 00000000..66849f34 --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java @@ -0,0 +1,258 @@ +/** + * Copyright 2018 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.vtp.scenario; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.eclipse.jetty.http.HttpStatus; +import org.onap.vtp.VTPResource; +import org.onap.vtp.error.VTPError; +import org.onap.vtp.error.VTPError.VTPException; +import org.onap.vtp.scenario.model.VTPTestCase; +import org.onap.vtp.scenario.model.VTPTestScenario; +import org.onap.vtp.scenario.model.VTPTestSuite; +import org.onap.vtp.scenario.model.VTPTestCase.VTPTestCaseInput; +import org.onap.vtp.scenario.model.VTPTestCase.VTPTestCaseList; +import org.onap.vtp.scenario.model.VTPTestCase.VTPTestCaseOutput; +import org.onap.vtp.scenario.model.VTPTestScenario.VTPTestScenarioList; +import org.onap.vtp.scenario.model.VTPTestSuite.VTPTestSuiteList; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + +@Path("/vtp") +@Api(tags = {"VTP Scenario"}) +public class VTPScenarioResource extends VTPResource{ + public VTPTestScenarioList listTestScenariosHandler() throws VTPException, IOException{ + List args = new ArrayList<>(); + + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "product-list", "--format", "json" + })); + + JsonNode results = this.makeRpcAndGetJson(args); + + VTPTestScenarioList list = new VTPTestScenarioList(); + + if (results != null && results.isArray()) { + ArrayNode resultsArray = (ArrayNode)results; + if (resultsArray.size() >= 0) { + for (Iterator it = resultsArray.iterator(); it.hasNext();) { + JsonNode n = it.next(); + if (n.elements().hasNext()) { + String name = n.get("product").asText(); + + if (name.equalsIgnoreCase("open-cli")) continue; + + list.getScenarios().add(new VTPTestScenario().setName(name).setDescription( + n.get("description").asText())); + } + } + } + } + + return list; + } + + @Path("/scenarios") + @GET + @ApiOperation(tags = "VTP Scenario", value = " List available test scenarios", response = VTPTestScenario.class, responseContainer = "List") + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response listTestScenarios() throws VTPException, IOException { + return Response.ok(this.listTestScenariosHandler().getScenarios().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestSuiteList listTestSutiesHandler(String scenario) throws VTPException, IOException{ + List args = new ArrayList<>(); + + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "service-list", "--product", scenario, "--format", "json" + })); + + JsonNode results = this.makeRpcAndGetJson(args); + + VTPTestSuiteList list = new VTPTestSuiteList(); + + if (results != null && results.isArray()) { + ArrayNode resultsArray = (ArrayNode)results; + if (resultsArray.size() >= 0) { + for (Iterator it = resultsArray.iterator(); it.hasNext();) { + JsonNode n = it.next(); + if (n.elements().hasNext()) { + list.getSuites().add(new VTPTestSuite().setName(n.get("service").asText()).setDescription( + n.get("description").asText())); + } + } + } + } + + return list; + } + + @Path("/scenarios/{scenario}/testsuites") + @GET + @ApiOperation(tags = "VTP Scenario", value = " List available test suties in given scenario", response = VTPTestSuite.class, responseContainer = "List") + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response listTestSuties( + @ApiParam("Test scenario name") @PathParam("scenario") String scenario) throws VTPException, IOException { + + return Response.ok(this.listTestSutiesHandler(scenario).getSuites().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestCaseList listTestcasesHandler(String testSuiteName, String scenario) throws VTPException, IOException{ + List args = new ArrayList<>(); + + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "schema-list", "--product", scenario, "--format", "json" + })); + if (testSuiteName != null) { + args.add("--service"); + args.add(testSuiteName); + } + + JsonNode results = this.makeRpcAndGetJson(args); + + VTPTestCaseList list = new VTPTestCaseList(); + + if (results != null && results.isArray()) { + ArrayNode resultsArray = (ArrayNode)results; + if (resultsArray.size() >= 0) { + for (Iterator it = resultsArray.iterator(); it.hasNext();) { + JsonNode n = it.next(); + if (n.elements().hasNext()) + list.getTestCases().add( + new VTPTestCase().setTestCaseName( + n.get("command").asText()).setTestSuiteName( + n.get("service").asText())); + } + } + } + + return list; + } + + @Path("/scenarios/{scenario}/testcases") + @GET + @ApiOperation(tags = "VTP Scenario", value = " List available test cases", response = VTPTestCase.class, responseContainer = "List") + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", + response = VTPError.class) }) + public Response listTestcases( + @ApiParam("Test scenario name") @PathParam("scenario") String scenario, + @ApiParam("Test suite name") @QueryParam("testSuiteName") String testSuiteName + ) throws VTPException, IOException { + + return Response.ok(this.listTestcasesHandler(testSuiteName, scenario).getTestCases().toString(), MediaType.APPLICATION_JSON).build(); + } + + public VTPTestCase getTestcaseHandler(String scenario, String testSuiteName, String testCaseName) throws VTPException, IOException { + List args = new ArrayList<>(); + args.addAll(Arrays.asList(new String[] { + "--product", "open-cli", "schema-show", "--product", scenario, "--service", testSuiteName, "--command", testCaseName , "--format", "json" + })); + JsonNode results = this.makeRpcAndGetJson(args); + + JsonNode schema = results.get("schema"); + + VTPTestCase tc = new VTPTestCase(); + tc.setTestCaseName(schema.get("name").asText()); + tc.setDescripton(schema.get("description").asText()); + tc.setTestSuiteName(schema.get("service").asText()); + tc.setAuthor(schema.get("author").asText()); + JsonNode inputsJson = schema.get("inputs"); + if (inputsJson != null && inputsJson.isArray()) { + for (final JsonNode inputJson: inputsJson) { + VTPTestCaseInput input = new VTPTestCaseInput(); + + input.setName(inputJson.get("name").asText()); + input.setDescription(inputJson.get("description").asText()); + input.setType(inputJson.get("type").asText()); + + if (inputJson.get("is_optional") != null) + input.setIsOptional(inputJson.get("is_optional").asBoolean()); + + if (inputJson.get("default_value") != null) + input.setDefaultValue(inputJson.get("default_value").asText()); + + if (inputJson.get("metadata") != null) + input.setMetadata(inputJson.get("metadata")); + + tc.getInputs().add(input); + } + } + + JsonNode outputsJson = schema.get("outputs"); + if (outputsJson != null && outputsJson.isArray()) { + for (final JsonNode outputJson: outputsJson) { + VTPTestCaseOutput output = new VTPTestCaseOutput(); + output.setName(outputJson.get("name").asText()); + output.setDescription(outputJson.get("description").asText()); + output.setType(outputJson.get("type").asText()); + + tc.getOutputs().add(output); + } + } + + return tc; + } + + @Path("/scenarios/{scenario}/testsuites/{testSuiteName}/testcases/{testCaseName}") + @GET + @ApiOperation(tags = "VTP Scenario", value = "Retrieve test cases details like inputs outputs and test suite name", response = VTPTestCase.class) + @Produces(MediaType.APPLICATION_JSON) + @ApiResponses(value = { + @ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500, + message = "Failed to perform the operation", response = VTPError.class), + @ApiResponse(code = HttpStatus.NOT_FOUND_404, + message = "Test case does not exist", response = VTPError.class)}) + public Response getTestcase( + @ApiParam("Test scenario name") @PathParam("scenario") String scenario, + @ApiParam(value = "Test case name") @PathParam("testSuiteName") String testSuiteName, + @ApiParam(value = "Test case name") @PathParam("testCaseName") String testCaseName) + throws IOException, VTPException { + + return Response.ok(this.getTestcaseHandler(scenario, testSuiteName, testCaseName).toString(), MediaType.APPLICATION_JSON).build(); + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java new file mode 100644 index 00000000..f0ab2e38 --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestCase.java @@ -0,0 +1,171 @@ +/** + * Copyright 2019 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.vtp.scenario.model; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vtp.VTPModelBase; + +import com.fasterxml.jackson.databind.JsonNode; + +public class VTPTestCase extends VTPModelBase{ + private String scenario; + private String testCaseName; + private String testSuiteName; + private String descripton; + private String author; + private List inputs = new ArrayList<>(); + private List outputs = new ArrayList<>(); + + public String getTestSuiteName() { + return testSuiteName; + } + public VTPTestCase setTestSuiteName(String testSuiteName) { + this.testSuiteName = testSuiteName; + return this; + } + public String getTestCaseName() { + return testCaseName; + } + public VTPTestCase setTestCaseName(String testCaseName) { + this.testCaseName = testCaseName; + return this; + } + + public String getDescripton() { + return descripton; + } + public void setDescripton(String descripton) { + this.descripton = descripton; + } + + public List getInputs() { + return inputs; + } + public VTPTestCase setInputs(List inputs) { + this.inputs = inputs; + return this; + } + + public List getOutputs() { + return outputs; + } + public VTPTestCase setOutputs(List outputs) { + this.outputs = outputs; + return this; + } + + public String getScenario() { + return scenario; + } + public VTPTestCase setScenario(String scenario) { + this.scenario = scenario; + return this; + } + + public String getAuthor() { + return author; + } + public void setAuthor(String author) { + this.author = author; + } + + public static class VTPTestCaseList extends VTPModelBase { + List testCases = new ArrayList<>(); + + public List getTestCases() { + return testCases; + } + + public VTPTestCaseList setTestCases(List testCases) { + this.testCases = testCases; + return this; + } + } + + public static class VTPTestCaseInput extends VTPModelBase { + private String name; + private String description; + private String type; + private String defaultValue; + private Boolean isOptional; + private JsonNode metadata; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getDefaultValue() { + return defaultValue; + } + public void setDefaultValue(String defaultValue) { + this.defaultValue = defaultValue; + } + public Boolean getIsOptional() { + return isOptional; + } + public void setIsOptional(Boolean isOptional) { + this.isOptional = isOptional; + } + public JsonNode getMetadata() { + return metadata; + } + public void setMetadata(JsonNode metadata) { + this.metadata = metadata; + } + } + + public static class VTPTestCaseOutput extends VTPModelBase { + private String name; + private String description; + private String type; + + public String getName() { + return this.name; + } + public void setName(String name) { + this.name = name; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java new file mode 100644 index 00000000..9ddac81b --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestScenario.java @@ -0,0 +1,57 @@ +/** + * Copyright 2019 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.vtp.scenario.model; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vtp.VTPModelBase; + +public class VTPTestScenario extends VTPModelBase{ + private String name; + private String description; + public String getName() { + return name; + } + + public VTPTestScenario setName(String name) { + this.name = name; + return this; + } + + public String getDescription() { + return description; + } + + public VTPTestScenario setDescription(String description) { + this.description = description; + return this; + } + + public static class VTPTestScenarioList extends VTPModelBase { + List scenarios = new ArrayList<>(); + + public List getScenarios() { + return scenarios; + } + + public VTPTestScenarioList setScenarios(List scenarios) { + this.scenarios = scenarios; + return this; + } + } +} diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java new file mode 100644 index 00000000..0759975a --- /dev/null +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/model/VTPTestSuite.java @@ -0,0 +1,58 @@ +/** + * Copyright 2019 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.vtp.scenario.model; + +import java.util.ArrayList; +import java.util.List; + +import org.onap.vtp.VTPModelBase; + +public class VTPTestSuite extends VTPModelBase{ + private String name; + + private String description; + + public String getDescription() { + return description; + } + + public VTPTestSuite setDescription(String description) { + this.description = description; + return this; + } + public String getName() { + return name; + } + + public VTPTestSuite setName(String name) { + this.name = name; + return this; + } + + public static class VTPTestSuiteList extends VTPModelBase { + List suites = new ArrayList<>(); + + public List getSuites() { + return suites; + } + + public VTPTestSuiteList setSuites(List suites) { + this.suites = suites; + return this; + } + } +} -- cgit 1.2.3-korg