summaryrefslogtreecommitdiffstats
path: root/vnfmarket-be/vnf-sdk-marketplace/src/main
diff options
context:
space:
mode:
authorHailong Zhang <zhanghailong22@huawei.com>2019-09-06 09:39:46 +0800
committerWeitao Gao <victor.gao@huawei.com>2019-10-14 06:52:48 +0000
commita671d6f99e5533e729015f3bba74b36d03a890f4 (patch)
tree9b43ab2ec3bdf440f4e4d7022ccc31be636b8584 /vnfmarket-be/vnf-sdk-marketplace/src/main
parent51041bd80a870aad7bc3ad135e28221d5445b25d (diff)
modify Sonar Issue
Issue-ID: VNFSDK-462 Signed-off-by: Hailong Zhang <zhanghailong22@huawei.com> Change-Id: I1bd7cbff0d3d444613991ae0dd2c8146107ea891
Diffstat (limited to 'vnfmarket-be/vnf-sdk-marketplace/src/main')
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java40
-rw-r--r--vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/scenario/VTPScenarioResource.java44
2 files changed, 62 insertions, 22 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
index 83db8e8b..9eb2a7b7 100644
--- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
+++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/VTPExecutionResource.java
@@ -86,8 +86,7 @@ public class VTPExecutionResource extends VTPResource{
private static final String ERROR = "error";
private static final String FILE = "file://";
-
- public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws Exception {
+ public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException {
if (requestId == null) {
requestId = UUID.randomUUID().toString();
}
@@ -121,10 +120,18 @@ public class VTPExecutionResource extends VTPResource{
ObjectMapper mapper = new ObjectMapper();
Map<String,String> m = output.getAttrsMap();
if ((m.containsKey(ERROR)) && (!StringUtils.equals(m.get(ERROR), "{}"))) {
- execution.setResults(mapper.readTree(m.get(ERROR)));
+ try {
+ execution.setResults(mapper.readTree(m.get(ERROR)));
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
}
else if (m.containsKey("results")) {
- execution.setResults(mapper.readTree(m.get("results")));
+ try {
+ execution.setResults(mapper.readTree(m.get("results")));
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
}
}
@@ -174,10 +181,15 @@ public class VTPExecutionResource extends VTPResource{
public Response executeTestcases(
@ApiParam(value = "Request Id") @QueryParam("requestId") String requestId,
@ApiParam(value = "Testcase File arguments", required = false) @FormDataParam("file") List<FormDataBodyPart> bodyParts,
- @FormDataParam("executions") String executionsJson) throws Exception {
+ @FormDataParam("executions") String executionsJson) throws VTPException {
VTPTestExecutionList executions = new VTPTestExecution.VTPTestExecutionList();
- Map<String, String> map = this.storeTestCaseInputFiles(bodyParts);
+ Map<String, String> map = null;
+ try {
+ map = this.storeTestCaseInputFiles(bodyParts);
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
for (Map.Entry<String, String> entry: map.entrySet()) {
if (executionsJson.contains(FILE + entry.getKey())) {
@@ -193,13 +205,21 @@ public class VTPExecutionResource extends VTPResource{
}
- executions.setExecutions(
- new ObjectMapper().readValue(executionsJson, new TypeReference<List<VTPTestExecution>>(){}));
+ try {
+ executions.setExecutions(
+ new ObjectMapper().readValue(executionsJson, new TypeReference<List<VTPTestExecution>>(){}));
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
executions = this.executeHandler(executions, requestId);
for (Map.Entry<String, String> entry: map.entrySet()) {
- FileUtils.forceDelete(new File(entry.getValue()));
+ try {
+ FileUtils.forceDelete(new File(entry.getValue()));
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
}
return Response.ok(executions.getExecutions().toString(), MediaType.APPLICATION_JSON).build();
@@ -366,7 +386,7 @@ public class VTPExecutionResource extends VTPResource{
resultJson = mapper.readTree(result.get(OUTPUT).toString());
}
} catch (Exception e) {
- LOG.error("Exception occirs", e);
+ LOG.error("Exception occurs", e);
ObjectNode node = JsonNodeFactory.instance.objectNode();
node.put(ERROR, result.get(OUTPUT).asText());
resultJson = node;
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
index 575bdc2e..2329d1bc 100644
--- 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
@@ -56,14 +56,19 @@ import io.swagger.annotations.ApiResponses;
@Api(tags = {"VTP Scenario"})
public class VTPScenarioResource extends VTPResource{
private static final String DESCRIPTION = "description";
- public VTPTestScenarioList listTestScenariosHandler() throws VTPException, IOException{
+ public VTPTestScenarioList listTestScenariosHandler() throws VTPException {
List<String> args = new ArrayList<>();
args.addAll(Arrays.asList(new String[] {
"--product", "open-cli", "product-list", "--format", "json"
}));
- JsonNode results = this.makeRpcAndGetJson(args);
+ JsonNode results = null;
+ try {
+ results = this.makeRpcAndGetJson(args);
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
VTPTestScenarioList list = new VTPTestScenarioList();
@@ -96,18 +101,23 @@ public class VTPScenarioResource extends VTPResource{
@ApiResponse(code = HttpStatus.INTERNAL_SERVER_ERROR_500,
message = "Failed to perform the operation",
response = VTPError.class) })
- public Response listTestScenarios() throws VTPException, IOException {
+ public Response listTestScenarios() throws VTPException {
return Response.ok(this.listTestScenariosHandler().getScenarios().toString(), MediaType.APPLICATION_JSON).build();
}
- public VTPTestSuiteList listTestSutiesHandler(String scenario) throws VTPException, IOException{
+ public VTPTestSuiteList listTestSutiesHandler(String scenario) throws VTPException {
List<String> args = new ArrayList<>();
args.addAll(Arrays.asList(new String[] {
"--product", "open-cli", "service-list", "--product", scenario, "--format", "json"
}));
- JsonNode results = this.makeRpcAndGetJson(args);
+ JsonNode results = null;
+ try {
+ results = this.makeRpcAndGetJson(args);
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
VTPTestSuiteList list = new VTPTestSuiteList();
@@ -136,12 +146,12 @@ public class VTPScenarioResource extends VTPResource{
message = "Failed to perform the operation",
response = VTPError.class) })
public Response listTestSuties(
- @ApiParam("Test scenario name") @PathParam("scenario") String scenario) throws VTPException, IOException {
+ @ApiParam("Test scenario name") @PathParam("scenario") String scenario) throws VTPException {
return Response.ok(this.listTestSutiesHandler(scenario).getSuites().toString(), MediaType.APPLICATION_JSON).build();
}
- public VTPTestCaseList listTestcasesHandler(String testSuiteName, String scenario) throws VTPException, IOException{
+ public VTPTestCaseList listTestcasesHandler(String testSuiteName, String scenario) throws VTPException {
List<String> args = new ArrayList<>();
args.addAll(Arrays.asList(new String[] {
@@ -152,7 +162,12 @@ public class VTPScenarioResource extends VTPResource{
args.add(testSuiteName);
}
- JsonNode results = this.makeRpcAndGetJson(args);
+ JsonNode results = null;
+ try {
+ results = this.makeRpcAndGetJson(args);
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
VTPTestCaseList list = new VTPTestCaseList();
@@ -184,17 +199,22 @@ public class VTPScenarioResource extends VTPResource{
public Response listTestcases(
@ApiParam("Test scenario name") @PathParam("scenario") String scenario,
@ApiParam("Test suite name") @QueryParam("testSuiteName") String testSuiteName
- ) throws VTPException, IOException {
+ ) throws VTPException {
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 {
+ public VTPTestCase getTestcaseHandler(String scenario, String testSuiteName, String testCaseName) throws VTPException {
List<String> 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 results = null;
+ try {
+ results = this.makeRpcAndGetJson(args);
+ } catch (IOException e) {
+ LOG.error("IOException occurs",e);
+ }
JsonNode schema = results.get("schema");
@@ -253,7 +273,7 @@ public class VTPScenarioResource extends VTPResource{
@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 {
+ throws VTPException {
return Response.ok(this.getTestcaseHandler(scenario, testSuiteName, testCaseName).toString(), MediaType.APPLICATION_JSON).build();
}