diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2023-02-28 19:39:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-02-28 19:39:45 +0000 |
commit | 0c8a0f949e55bedc2f94311e283ead61703b83cc (patch) | |
tree | 58c53e0814a89bc34468a541be6f4afb9e021cb9 /main/src | |
parent | f563d9c79baeef2009db57914a82c0731051a2d1 (diff) | |
parent | a7e30d0527dbf8ddf7e431bcb9c16f39c30aab8b (diff) |
Merge "Fixed sonar issues in policy-pap"
Diffstat (limited to 'main/src')
4 files changed, 18 insertions, 16 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java index 4d142114..dc4a030b 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2021,2023 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021-2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -159,10 +159,8 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { return true; } - if (exceptionClazz.isInstance(thrown)) { - if (isDuplicateKeyException(thrown.getCause(), exceptionClazz)) { - return true; - } + if (exceptionClazz.isInstance(thrown) && isDuplicateKeyException(thrown.getCause(), exceptionClazz)) { + return true; } thrown = thrown.getCause(); diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java index 11917e4e..f63fc1d5 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019-2023 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. - * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. + * Modifications Copyright (C) 2021, 2023 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ import org.springframework.web.bind.annotation.RestController; @Profile("default") public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 implements PdpGroupStateChangeControllerV1Api { - private static final Logger logger = LoggerFactory.getLogger(PdpGroupHealthCheckControllerV1.class); + private static final Logger logger = LoggerFactory.getLogger(PdpGroupStateChangeControllerV1.class); private final PdpGroupStateChangeProvider provider; /** diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java index d2ab15fb..1f4f10f3 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/stub/StubUtils.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023 Bell Canada. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,6 +45,9 @@ import org.springframework.stereotype.Service; @Profile("stub") class StubUtils { private static final Logger log = LoggerFactory.getLogger(StubUtils.class); + private static final String APPLICATION_JSON = "application/json"; + private static final String SERIALIZE_RESPONSE_FAILURE_MSG = + "Couldn't serialize response for content type application/json"; private final HttpServletRequest request; private static final String ACCEPT = "Accept"; private static final String PAP_DB = @@ -52,14 +56,14 @@ class StubUtils { <T> ResponseEntity<T> getStubbedResponse(Class<T> clazz) { var accept = request.getHeader(ACCEPT); - if (accept != null && accept.contains("application/json")) { + if (accept != null && accept.contains(APPLICATION_JSON)) { final var resource = new ClassPathResource(PAP_DB); try (var inputStream = resource.getInputStream()) { final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); var targetObject = JSON_TRANSLATOR.fromJson(string, clazz); return new ResponseEntity<>(targetObject, HttpStatus.OK); } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); + log.error(SERIALIZE_RESPONSE_FAILURE_MSG, e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -68,14 +72,14 @@ class StubUtils { <T> ResponseEntity<List<T>> getStubbedResponseList(Class<T> clazz) { var accept = request.getHeader(ACCEPT); - if (accept != null && accept.contains("application/json")) { + if (accept != null && accept.contains(APPLICATION_JSON)) { final var resource = new ClassPathResource(PAP_DB); try (var inputStream = resource.getInputStream()) { final var string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); var targetObject = Arrays.asList(JSON_TRANSLATOR.fromJson(string, clazz)); return new ResponseEntity<>(targetObject, HttpStatus.OK); } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); + log.error(SERIALIZE_RESPONSE_FAILURE_MSG, e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -84,7 +88,7 @@ class StubUtils { ResponseEntity<Map<String, Object>> getStubbedResponseMap() { var accept = request.getHeader(ACCEPT); - if (accept != null && accept.contains("application/json")) { + if (accept != null && accept.contains(APPLICATION_JSON)) { final var resource = new ClassPathResource(PAP_DB); try (var inputStream = resource.getInputStream()) { Map<String, Object> map = new HashMap<>(); @@ -93,7 +97,7 @@ class StubUtils { JSON_TRANSLATOR.fromJson(string, Object.class)); return new ResponseEntity<>(map, HttpStatus.OK); } catch (IOException e) { - log.error("Couldn't serialize response for content type application/json", e); + log.error(SERIALIZE_RESPONSE_FAILURE_MSG, e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -102,7 +106,7 @@ class StubUtils { ResponseEntity<Map<String, Map<String, List<PdpStatistics>>>> getStubbedResponseStatistics() { var accept = request.getHeader(ACCEPT); - if (accept != null && accept.contains("application/json")) { + if (accept != null && accept.contains(APPLICATION_JSON)) { Map<String, Map<String, List<PdpStatistics>>> map = new HashMap<>(); return new ResponseEntity<>(map, HttpStatus.OK); } diff --git a/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java b/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java index aeb2fdbb..6166580e 100644 --- a/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2022 Bell Canada. All rights reserved. + * Copyright (C) 2022-2023 Bell Canada. All rights reserved. * Modifications Copyright (C) 2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -141,7 +141,7 @@ public class PolicyStatusServiceTest extends CommonPapRestServer { // Test delete policyStatusService.cudPolicyStatus(null, null, List.of(status)); - assertThat(policyStatusService.getAllPolicyStatus()).hasSize(0); + assertThat(policyStatusService.getAllPolicyStatus()).isEmpty(); } private List<PdpPolicyStatus> createStatusList() { |