diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2023-09-29 15:29:55 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2023-10-02 16:47:37 +0000 |
commit | a70a907e2ad4f49c4807b1914e69b97f7573561e (patch) | |
tree | 4024b2a5785129aed25eeacdec22b15e5b5a2027 /participant/participant-impl/participant-impl-acelement | |
parent | c706398593f184301d38bd6cba86566da60bece6 (diff) |
Fix Sonar Issues for clamp/acm
Issue-ID: POLICY-4834
Change-Id: I4489dc66e9b20c8264ec88593f0b5d89d62f1ef8
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-acelement')
3 files changed, 11 insertions, 15 deletions
diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java index 3442eedf6..081eb035d 100755 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021-2022 Nordix Foundation. + * Copyright (C) 2021-2023 Nordix Foundation. * ================================================================================ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -27,7 +27,6 @@ import jakarta.servlet.http.HttpServletRequest; import java.util.Map; import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.servlet.error.ErrorAttributes; import org.springframework.boot.web.servlet.error.ErrorController; @@ -43,9 +42,6 @@ public class AcElementErrorController implements ErrorController { private final ErrorAttributes errorAttributes; - @Value("${server.error.path}") - private String path; - /** * Constructor. * @@ -56,7 +52,7 @@ public class AcElementErrorController implements ErrorController { } protected HttpStatus getStatus(HttpServletRequest request) { - Integer statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + var statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); if (statusCode == null) { return HttpStatus.INTERNAL_SERVER_ERROR; } @@ -73,19 +69,20 @@ public class AcElementErrorController implements ErrorController { * @param request HttpServletRequest * @return ResponseEntity */ + @SuppressWarnings("squid:S3752") @RequestMapping(value = "${server.error.path}", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<TypedSimpleResponse<SimpleResponse>> handleError(HttpServletRequest request) { Map<String, Object> map = this.errorAttributes.getErrorAttributes(new ServletWebRequest(request), ErrorAttributeOptions.defaults()); var sb = new StringBuilder(); - final Object error = map.get("error"); + final var error = map.get("error"); if (error != null) { - sb.append(error.toString() + " "); + sb.append(error).append(" "); } - final Object message = map.get("message"); + final var message = map.get("message"); if (message != null) { - sb.append(message.toString()); + sb.append(message); } TypedSimpleResponse<SimpleResponse> resp = new TypedSimpleResponse<>(); diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java index 1ffe7d11d..a2ed1ca34 100755 --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ package org.onap.policy.clamp.acm.element.rest; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doThrow; @@ -165,5 +165,4 @@ class AcElementControllerTest { private String getElementConfigJson() throws IOException { return FileUtils.readFileToString(new File(ELEMENT_CONFIG_YAML), StandardCharsets.UTF_8); } - } diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java index 1b43e607f..a1d22038e 100755 --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Nordix Foundation. + * Copyright (C) 2022-2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ package org.onap.policy.clamp.acm.element.utils; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import jakarta.ws.rs.client.Client; import jakarta.ws.rs.client.ClientBuilder; |