diff options
author | Hailong Zhang <zhanghailong22@huawei.com> | 2019-09-03 11:40:27 +0800 |
---|---|---|
committer | Hailong Zhang <zhanghailong22@huawei.com> | 2019-09-03 14:10:23 +0800 |
commit | 287615b5aebe447c466c63a00c4dbf683ee439e1 (patch) | |
tree | ae56244eb7fd39ce98e52f5dcf2535da0b1951f2 | |
parent | d810d8d0d5a40cb0801387f27a6b4b2aa890d67a (diff) |
modify Sonar Issue
Issue-ID: VNFSDK-462
Signed-off-by: Hailong Zhang <zhanghailong22@huawei.com>
Change-Id: I46958da7923ef3ab07759aba625800369d5fcf7d
11 files changed, 87 insertions, 83 deletions
diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/AppServletContextListener.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/AppServletContextListener.java index 6ceb9a26..4e7f9b2d 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/AppServletContextListener.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/AppServletContextListener.java @@ -25,13 +25,13 @@ public class AppServletContextListener implements ServletContextListener @Override public void contextInitialized(ServletContextEvent eventData) { - //MsbRegister.handleMsbRegistration(); + } @Override public void contextDestroyed(ServletContextEvent eventData) { - //MsbRegister.handleMsbUnRegistration(); + } } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/MsbDetails.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/MsbDetails.java index 9c769480..0eb6976b 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/MsbDetails.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/msb/MsbDetails.java @@ -18,10 +18,6 @@ package org.onap.vnfsdk.marketplace.msb; public class MsbDetails { private MsbServer defaultServer; - private String connectTimeout; - private String thread; - private String idletimeout; - private String timeout; public MsbServer getDefaultServer() { return defaultServer; diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java index 4d7f0162..25ca4edc 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestExceutor.java @@ -176,12 +176,9 @@ public class FunctionTestExceutor { * @return valid or invalid */ private static boolean checkValidResponse(RestResponse rsp) { - if ((null == rsp.getStatusCode()) || (null == rsp.getResult()) - || (RestConstant.RESPONSE_CODE_200 != rsp.getStatusCode() - && RestConstant.RESPONSE_CODE_201 != rsp.getStatusCode())) { - return false; - } - return true; + return ((null != rsp.getStatusCode()) && (null != rsp.getResult()) + && (RestConstant.RESPONSE_CODE_200 == rsp.getStatusCode() + || RestConstant.RESPONSE_CODE_201 == rsp.getStatusCode())); } private static HttpEntity buildRequest(InputStream inputStream) { diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java index 234892b2..3ffb1bab 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/functiontest/FunctionTestHook.java @@ -141,7 +141,7 @@ public class FunctionTestHook { private void storeFuncTestResultKey(OnBoradingRequest onBoradingReq, String resultKey) { // Currently we will make JSON and Store JSON to Package Path) // ------------------------------------------------------------------------------- - StringBuffer filePath = new StringBuffer(getResultStorePath()); + StringBuilder filePath = new StringBuilder(getResultStorePath()); filePath.append(File.separator); filePath.append(onBoradingReq.getCsarId()); filePath.append(File.separator); @@ -170,7 +170,7 @@ public class FunctionTestHook { logger.debug("Function test Status for Package Id:" + oFuncTestResult.getCsarId() + ", Result:" + ToolUtil.objectToString(oFuncTestResult)); - StringBuffer filePath = new StringBuffer(getResultStorePath()); + StringBuilder filePath = new StringBuilder(getResultStorePath()); filePath.append(File.separator); filePath.append(oFuncTestResult.getCsarId()); filePath.append(File.separator); @@ -212,7 +212,7 @@ public class FunctionTestHook { return null; } - StringBuffer filePath = new StringBuffer(getResultStorePath()); + StringBuilder filePath = new StringBuilder(getResultStorePath()); filePath.append(File.separator); filePath.append(packageData.getCsarId()); filePath.append(File.separator); @@ -224,7 +224,7 @@ public class FunctionTestHook { } private static ResultKey getFuncTestResultKey(PackageData packageData) { - StringBuffer fileName = new StringBuffer(getResultStorePath()); + StringBuilder fileName = new StringBuilder(getResultStorePath()); fileName.append(File.separator); fileName.append(packageData.getCsarId()); fileName.append(File.separator); diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java index 2d57fe21..8d467de2 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/onboarding/hooks/validatelifecycle/LifecycleTestExceutor.java @@ -130,11 +130,8 @@ public class LifecycleTestExceutor { return result; } - String rawDataJson = ""; //TBD - Use Gson - jackson has security issue//JsonUtil.toJson(oLifeCycleTestReq); -// if (null == rawDataJson) { -// logger.error("Failed to convert LifeCycleTestReq object to Json String !!!"); -// return result; -// } + String rawDataJson = ""; + //TBD - Use Gson - jackson has security issue//JsonUtil.toJson(oLifeCycleTestReq); RestResponse oResponse = RestfulClient.sendPostRequest(oMsbDetails.getDefaultServer().getHost(), oMsbDetails.getDefaultServer().getPort(), CommonConstant.LifeCycleTest.LIFECYCLE_TEST_URL, rawDataJson); @@ -156,12 +153,9 @@ public class LifecycleTestExceutor { * @return valid(true) or invalid(false) */ private static boolean checkValidResponse(RestResponse rsp) { - if ((null == rsp.getStatusCode()) || (null == rsp.getResult()) - || (RestConstant.RESPONSE_CODE_200 != rsp.getStatusCode() - && RestConstant.RESPONSE_CODE_201 != rsp.getStatusCode())) { - return false; - } - return true; + return ((null != rsp.getStatusCode()) && (null != rsp.getResult()) + && (RestConstant.RESPONSE_CODE_200 == rsp.getStatusCode() + || RestConstant.RESPONSE_CODE_201 == rsp.getStatusCode())); } /** diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java index b2e31b63..1f6de0a0 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/resource/PackageResource.java @@ -161,7 +161,7 @@ public class PackageResource { @FormDataParam("params") String details, @ApiParam(value = "file detail", required = false) @FormDataParam("file") FormDataContentDisposition fileDetail, @ApiParam(value = "http header") @Context HttpHeaders head) - throws MarketplaceResourceException { + { return PackageWrapper.getInstance().reUploadPackage(csarId, uploadedInputStream, fileDetail, details, head); } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java index 599fb774..60cdf65c 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPModelBase.java @@ -36,7 +36,6 @@ public class VTPModelBase { objectMapper.setSerializationInclusion(Include.NON_EMPTY); return objectMapper.writeValueAsString(obj); } catch (JsonProcessingException e) { - logger.error("Exception while processing json {}", e.getMessage()); return "{}"; } } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java index 1c1c6336..b50e30f1 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/VTPResource.java @@ -105,8 +105,7 @@ public class VTPResource { protected JsonNode makeRpcAndGetJson(List<String> args, int timeout) throws VTPException, IOException { Result result = this.makeRpc(args, timeout); ObjectMapper mapper = new ObjectMapper(); - JsonNode resultJson = mapper.readTree(result.getOutput()); - return resultJson; + return mapper.readTree(result.getOutput()); } protected Output makeRpc(String scenario, String requestId, String profile, String testCase, JsonNode argsJsonNode) throws VTPException { 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 40c43c06..6f41f626 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 @@ -70,7 +70,19 @@ import io.swagger.annotations.ApiResponses; @Path("/vtp") @Api(tags = {"VTP Execution"}) public class VTPExecutionResource extends VTPResource{ - private static final String EXECUTION_ID = "exection-id"; + private static final String EXECUTION_ID = "execution-id"; + private static final String START_TIME = "start-time"; + private static final String END_TIME = "end-time"; + private static final String REQUEST_ID = "request-id"; + private static final String PRODUCT = "product"; + private static final String SERVICE = "service"; + private static final String COMMAND = "command"; + private static final String PROFILE = "profile"; + private static final String STATUS = "status"; + private static final String OUTPUT = "output"; + private static final String INPUT = "input"; + + public VTPTestExecutionList executeHandler(VTPTestExecutionList executions, String requestId) throws VTPException, IOException { if (requestId == null) { requestId = UUID.randomUUID().toString(); @@ -243,27 +255,32 @@ public class VTPExecutionResource extends VTPResource{ JsonNode n = it.next(); if (n.elements().hasNext()) { VTPTestExecution exec = new VTPTestExecution(); - if (n.get("start-time") != null) - exec.setStartTime(n.get("start-time").asText()); + if (n.get(START_TIME) != null) + exec.setStartTime(n.get(START_TIME).asText()); - if (n.get("end-time") != null) - exec.setEndTime(n.get("end-time").asText()); + if (n.get(END_TIME) != null) + exec.setEndTime(n.get(END_TIME).asText()); if (n.get(EXECUTION_ID) != null) exec.setExecutionId(n.get(EXECUTION_ID).asText()); - if (n.get("request-id") != null) - exec.setRequestId(n.get("request-id").asText()); - - if (n.get("product") != null) - exec.setScenario(n.get("product").asText()); - if (n.get("service") != null) - exec.setTestSuiteName(n.get("service").asText()); - if (n.get("command") != null) - exec.setTestCaseName(n.get("command").asText()); - if (n.get("profile") != null) - exec.setExecutionId(n.get("profile").asText()); - if (n.get("status") != null) - exec.setStatus(n.get("status").asText()); + + if (n.get(REQUEST_ID) != null) + exec.setRequestId(n.get(REQUEST_ID).asText()); + + if (n.get(PRODUCT) != null) + exec.setScenario(n.get(PRODUCT).asText()); + + if (n.get(SERVICE) != null) + exec.setTestSuiteName(n.get(SERVICE).asText()); + + if (n.get(COMMAND) != null) + exec.setTestCaseName(n.get(COMMAND).asText()); + + if (n.get(PROFILE) != null) + exec.setExecutionId(n.get(PROFILE).asText()); + + if (n.get(STATUS) != null) + exec.setStatus(n.get(STATUS).asText()); list.getExecutions().add(exec); } @@ -310,43 +327,43 @@ public class VTPExecutionResource extends VTPResource{ VTPTestExecution exec = new VTPTestExecution(); if (result != null && result.elements().hasNext()) { - if (result.get("start-time") != null) - exec.setStartTime(result.get("start-time").asText()); + if (result.get(START_TIME) != null) + exec.setStartTime(result.get(START_TIME).asText()); - if (result.get("end-time") != null) - exec.setEndTime(result.get("end-time").asText()); + if (result.get(END_TIME) != null) + exec.setEndTime(result.get(END_TIME).asText()); if (result.get(EXECUTION_ID) != null) exec.setExecutionId(result.get(EXECUTION_ID).asText()); - if (result.get("request-id") != null) - exec.setExecutionId(result.get("request-id").asText()); - - if (result.get("product") != null) - exec.setScenario(result.get("product").asText()); - if (result.get("service") != null) - exec.setTestSuiteName(result.get("service").asText()); - if (result.get("command") != null) - exec.setTestCaseName(result.get("command").asText()); - if (result.get("profile") != null) - exec.setExecutionId(result.get("profile").asText()); - if (result.get("status") != null) - exec.setStatus(result.get("status").asText()); - if (result.get("input") != null) { - exec.setParameters(result.get("input")); + if (result.get(REQUEST_ID) != null) + exec.setExecutionId(result.get(REQUEST_ID).asText()); + + if (result.get(PRODUCT) != null) + exec.setScenario(result.get(PRODUCT).asText()); + if (result.get(SERVICE) != null) + exec.setTestSuiteName(result.get(SERVICE).asText()); + if (result.get(COMMAND) != null) + exec.setTestCaseName(result.get(COMMAND).asText()); + if (result.get(PROFILE) != null) + exec.setExecutionId(result.get(PROFILE).asText()); + if (result.get(STATUS) != null) + exec.setStatus(result.get(STATUS).asText()); + if (result.get(INPUT) != null) { + exec.setParameters(result.get(INPUT)); } - if (result.get("output") != null) { + if (result.get(OUTPUT) != null) { ObjectMapper mapper = new ObjectMapper(); JsonNode resultJson = null; try { - resultJson = mapper.readTree(result.get("output").asText()); + resultJson = mapper.readTree(result.get(OUTPUT).asText()); //workarround, sometimes its null. if (resultJson == null) { - resultJson = mapper.readTree(result.get("output").toString()); + resultJson = mapper.readTree(result.get(OUTPUT).toString()); } } catch (Exception e) { ObjectNode node = JsonNodeFactory.instance.objectNode(); - node.put("error", result.get("output").asText()); + node.put("error", result.get(OUTPUT).asText()); resultJson = node; } @@ -373,7 +390,7 @@ public class VTPExecutionResource extends VTPResource{ } public String getTestExecutionLogsHandler( - String executionId, String action) throws VTPException, IOException{ + String executionId, String action) throws VTPException { List<String> args = new ArrayList<>(); args.addAll(Arrays.asList(new String[] { "--product", "open-cli", "execution-show-" + action, "--execution-id", executionId, "--format", "text" @@ -397,7 +414,7 @@ public class VTPExecutionResource extends VTPResource{ @ApiParam("Test execution Id") @PathParam("executionId") String executionId, @ApiParam("Test console reports, Options: out, err, debug") @DefaultValue("out") @QueryParam("option") String option ) throws VTPException, IOException { - if (!(option.equalsIgnoreCase("out") || option.equalsIgnoreCase("err") || option.equalsIgnoreCase("debug"))) { + if (!("out".equalsIgnoreCase(option) || "err".equalsIgnoreCase(option) || "debug".equalsIgnoreCase(option))) { option = "out"; } diff --git a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java index 524b8e5a..e56333be 100644 --- a/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java +++ b/vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vtp/execution/model/VTPTestExecution.java @@ -17,13 +17,13 @@ package org.onap.vtp.execution.model; import java.util.ArrayList; -import java.util.HashMap; + import java.util.List; -import java.util.Map; import org.onap.vtp.VTPModelBase; import com.fasterxml.jackson.databind.JsonNode; + import com.fasterxml.jackson.databind.node.JsonNodeFactory; public class VTPTestExecution extends VTPModelBase{ @@ -35,7 +35,7 @@ public class VTPTestExecution extends VTPModelBase{ private String profile; private JsonNode parameters = JsonNodeFactory.instance.objectNode(); private JsonNode results = JsonNodeFactory.instance.objectNode(); - public static enum Status { + public enum Status { IN_PROGRESS, COMPLETED, FAILED; } 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 fda50ca4..575bdc2e 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 @@ -55,6 +55,7 @@ import io.swagger.annotations.ApiResponses; @Path("/vtp") @Api(tags = {"VTP Scenario"}) public class VTPScenarioResource extends VTPResource{ + private static final String DESCRIPTION = "description"; public VTPTestScenarioList listTestScenariosHandler() throws VTPException, IOException{ List<String> args = new ArrayList<>(); @@ -74,10 +75,11 @@ public class VTPScenarioResource extends VTPResource{ if (n.elements().hasNext()) { String name = n.get("product").asText(); - if (name.equalsIgnoreCase("open-cli")) continue; + if ("open-cli".equalsIgnoreCase(name)) + continue; list.getScenarios().add(new VTPTestScenario().setName(name).setDescription( - n.get("description").asText())); + n.get(DESCRIPTION).asText())); } } } @@ -116,7 +118,7 @@ public class VTPScenarioResource extends VTPResource{ JsonNode n = it.next(); if (n.elements().hasNext()) { list.getSuites().add(new VTPTestSuite().setName(n.get("service").asText()).setDescription( - n.get("description").asText())); + n.get(DESCRIPTION).asText())); } } } @@ -198,7 +200,7 @@ public class VTPScenarioResource extends VTPResource{ VTPTestCase tc = new VTPTestCase(); tc.setTestCaseName(schema.get("name").asText()); - tc.setDescription(schema.get("description").asText()); + tc.setDescription(schema.get(DESCRIPTION).asText()); tc.setTestSuiteName(schema.get("service").asText()); tc.setAuthor(schema.get("author").asText()); JsonNode inputsJson = schema.get("inputs"); @@ -207,7 +209,7 @@ public class VTPScenarioResource extends VTPResource{ VTPTestCaseInput input = new VTPTestCaseInput(); input.setName(inputJson.get("name").asText()); - input.setDescription(inputJson.get("description").asText()); + input.setDescription(inputJson.get(DESCRIPTION).asText()); input.setType(inputJson.get("type").asText()); if (inputJson.get("is_optional") != null) @@ -228,7 +230,7 @@ public class VTPScenarioResource extends VTPResource{ for (final JsonNode outputJson: outputsJson) { VTPTestCaseOutput output = new VTPTestCaseOutput(); output.setName(outputJson.get("name").asText()); - output.setDescription(outputJson.get("description").asText()); + output.setDescription(outputJson.get(DESCRIPTION).asText()); output.setType(outputJson.get("type").asText()); tc.getOutputs().add(output); |