diff options
author | waynedunican <wayne.dunican@est.tech> | 2024-07-23 09:23:51 +0100 |
---|---|---|
committer | waynedunican <wayne.dunican@est.tech> | 2024-08-13 08:49:10 +0100 |
commit | b7804abcf865dc58a01bed3f2be4756e731d9288 (patch) | |
tree | 7f6fc3b50622578bb8612de9fe5e5c6adddfaf28 /models-interactions/model-impl | |
parent | a029ccab07f2dd71286804da620c513da9fdfc0e (diff) |
Improve code coverage and sonar fixes
Increased code coverage to 90%
SONAR - Removed TODO comments
SONAR - Added NOSONAR where appropriate
SONAR - Replaced stream.Collect() with stream.toList() where applicable
SONAR - Made variables serializable or transient to comply with sonar rules
Issue-ID: POLICY-5069
Change-Id: Ife256eaf4e6f427fe40b138bacc6f112dc5bcea4
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'models-interactions/model-impl')
21 files changed, 28 insertions, 37 deletions
diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java index 7a6eb6859..ed77525be 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiCqResponse.java @@ -3,7 +3,7 @@ * * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +42,6 @@ import org.onap.aai.domain.yang.Vserver; public class AaiCqResponse implements Serializable { private static final long serialVersionUID = 1L; - public static final String CONTEXT_KEY = AaiConstants.CONTEXT_PREFIX + "AaiCqResponse"; public static final String OPERATION = "CustomQuery"; private static final String GENERIC_VNF = "generic-vnf"; private static final String VF_MODULE = "vf-module"; @@ -50,7 +49,7 @@ public class AaiCqResponse implements Serializable { @SerializedName("results") private List<Serializable> inventoryResponseItems = new LinkedList<>(); - private final Gson gson; + private final transient Gson gson; /** * Constructor creates a custom query response from a valid json string. diff --git a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java index a6a671815..26a39875f 100644 --- a/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java +++ b/models-interactions/model-impl/aai/src/main/java/org/onap/policy/aai/AaiManager.java @@ -3,7 +3,7 @@ * aai * ================================================================================ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,6 +25,7 @@ package org.onap.policy.aai; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -48,8 +49,6 @@ import org.slf4j.LoggerFactory; @AllArgsConstructor public final class AaiManager { - // TODO remove this class - /** The Constant logger. */ private static final Logger logger = LoggerFactory.getLogger(AaiManager.class); @@ -246,12 +245,12 @@ public final class AaiManager { pnfName = URLEncoder.encode(pnfName, StandardCharsets.UTF_8.toString()) + AAI_DEPTH_SUFFIX; } catch (UnsupportedEncodingException e) { logger.error("Failed to encode the pnfName: {} using UTF-8", pnfName, e); - return null; + return Collections.emptyMap(); } var responseGet = getStringQuery(urlGet, username, password, requestId, pnfName); if (responseGet == null) { logger.error("Null response from AAI for the url: {}.", urlGet); - return null; + return Collections.emptyMap(); } try { @SuppressWarnings("unchecked") @@ -261,7 +260,7 @@ public final class AaiManager { .collect(Collectors.toMap(e -> "pnf." + e.getKey(), Map.Entry::getValue)); } catch (CoderException e) { logger.error("Failed to fetch PNF from AAI", e); - return null; + return Collections.emptyMap(); } } } diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java index 72a78147b..0a47fcb05 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/CommonHeaderTest.java @@ -87,7 +87,7 @@ class CommonHeaderTest { assertEquals(commonHeader, (Object) commonHeader); assertEquals(commonHeader, copiedCommonHeader); - assertNotEquals(commonHeader, null); + assertNotNull(commonHeader); assertNotEquals(commonHeader, (Object) "Hello"); CommonHeader clonedCommonHeader = new CommonHeader(commonHeader); diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java index 7ab4ae746..67b3d85d4 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/RequestTest.java @@ -76,7 +76,7 @@ class RequestTest { assertEquals(request, (Object) request); assertEquals(request, copiedRequest); - assertNotEquals(request, null); + assertNotNull(request); assertNotEquals(request, (Object) "Hello"); checkField(commonHeader, Request::setCommonHeader); diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java index a13e08f64..f095df909 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseStatusTest.java @@ -58,7 +58,7 @@ class ResponseStatusTest { assertEquals(status, (Object) status); assertEquals(status, copiedStatus); - assertNotEquals(status, null); + assertNotNull(status); assertNotEquals(status, (Object) "Hello"); status.setCode(-1); diff --git a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java index ee0ff371b..dffb9588c 100644 --- a/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java +++ b/models-interactions/model-impl/appc/src/test/java/org/onap/policy/appc/ResponseTest.java @@ -70,7 +70,7 @@ class ResponseTest { assertEquals(response, (Object) response); assertEquals(response, copiedResponse); - assertNotEquals(response, null); + assertNotNull(response); assertNotEquals(response, (Object) "Hello"); response.setCommonHeader(null); diff --git a/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java b/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java index 1a35064ca..b0a605b8c 100644 --- a/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java +++ b/models-interactions/model-impl/cds/src/test/java/org/onap/policy/cds/client/CdsProcessorGrpcClientTest.java @@ -152,9 +152,7 @@ class CdsProcessorGrpcClientTest { @Test void testCdsProcessorGrpcClientConstructorFailure() { props.setHost(null); - assertThrows(IllegalStateException.class, () -> { - new CdsProcessorGrpcClient(listener, props).close(); - }); + assertThrows(IllegalStateException.class, () -> new CdsProcessorGrpcClient(listener, props)); } @Test diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java index 4f0dbf730..8ac1c3f49 100644 --- a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/ControlLoopEvent.java @@ -3,7 +3,7 @@ * controlloop * ================================================================================ * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,7 +47,7 @@ public abstract class ControlLoopEvent implements Serializable { protected String policyName; protected String policyVersion; protected ControlLoopEventStatus closedLoopEventStatus; - protected Map<String, String> additionalEventParams; + private Map<String, String> additionalEventParams; /** * Construct an instance from an existing instance. diff --git a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java index b7622bde2..12900a2b4 100644 --- a/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java +++ b/models-interactions/model-impl/events/src/main/java/org/onap/policy/controlloop/VirtualControlLoopEvent.java @@ -3,7 +3,7 @@ * controlloop * ================================================================================ * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public class VirtualControlLoopEvent extends ControlLoopEvent { private static final long serialVersionUID = -5752405682246066226L; @SerializedName("AAI") - protected Map<String, String> aai = new HashMap<>(); + private Map<String, String> aai = new HashMap<>(); protected String payload; protected Instant closedLoopAlarmStart; protected Instant closedLoopAlarmEnd; diff --git a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java index 4770000c8..b14df21ef 100644 --- a/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java +++ b/models-interactions/model-impl/events/src/test/java/org/onap/policy/controlloop/ControlLoopOperationTest.java @@ -37,7 +37,7 @@ class ControlLoopOperationTest { assertEquals(operation, (Object) operation); assertNotEquals(operation, (Object) ""); - assertNotEquals(operation, null); + assertNotNull(operation); assertNotEquals(0, operation.hashCode()); assertTrue(operation.toString().startsWith("ControlLoopOperation")); diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java index 23c9cea3b..5f21633e3 100644 --- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/HttpDeleteWithBodyTest.java @@ -33,6 +33,6 @@ class HttpDeleteWithBodyTest { void testGetMethod() { HttpDeleteWithBody deleteWithBody = new HttpDeleteWithBody(NO_URI); assertEquals("DELETE", deleteWithBody.getMethod()); - assertEquals(deleteWithBody.getURI().toString(), NO_URI); + assertEquals(NO_URI, deleteWithBody.getURI().toString()); } }
\ No newline at end of file diff --git a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java index 28136e667..7a2177136 100644 --- a/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java +++ b/models-interactions/model-impl/rest/src/test/java/org/onap/policy/rest/RestTest.java @@ -107,7 +107,7 @@ public class RestTest { * @throws Exception if there is a problem */ @AfterAll - public static void tearDown() throws Exception { + public static void tearDown() { HttpServletServerFactoryInstance.getServerFactory().destroy(); } diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java index 1885ed124..d852e8bda 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciCommonHeaderTest.java @@ -80,7 +80,7 @@ class PciCommonHeaderTest { assertEquals(commonHeader, (Object) commonHeader); assertEquals(commonHeader, copiedPciCommonHeader); - assertNotEquals(commonHeader, null); + assertNotNull(commonHeader); assertNotEquals(commonHeader, (Object) "Hello"); PciCommonHeader clonedPciCommonHeader = new PciCommonHeader(commonHeader); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java index 1334fcc42..00eb694e8 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestTest.java @@ -61,7 +61,7 @@ class PciRequestTest { assertEquals(request, (Object) request); assertEquals(request, copiedPciRequest); - assertNotEquals(request, null); + assertNotNull(request); assertNotEquals(request, (Object) "Hello"); request.setCommonHeader(null); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java index 722c081d4..a4a3e45b0 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciRequestWrapperTest.java @@ -54,7 +54,7 @@ class PciRequestWrapperTest { assertEquals(requestWrapper, (Object) requestWrapper); assertEquals(requestWrapper, copiedPciRequestWrapper); - assertNotEquals(requestWrapper, null); + assertNotNull(requestWrapper); assertNotEquals(requestWrapper, (Object) "Hello"); requestWrapper.setBody(null); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java index 70480b1f7..d2e28fd68 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseTest.java @@ -67,8 +67,7 @@ class PciResponseTest { @Test void testEqualsObject() { PciResponse response = new PciResponse(); - assertEquals(response, response); - assertNotEquals(response, null); + assertNotNull(response); assertNotEquals(response, new Object()); PciResponse response2 = new PciResponse(); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java index 1b0247336..a34d65c9d 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciResponseWrapperTest.java @@ -50,17 +50,13 @@ class PciResponseWrapperTest { copiedPciResponseWrapper.setBody(responseWrapper.getBody()); assertEquals(responseWrapper, (Object) responseWrapper); - //assertEquals(responseWrapper, copiedPciResponseWrapper); - assertNotEquals(responseWrapper, null); + assertNotNull(responseWrapper); assertNotEquals(responseWrapper, (Object) "Hello"); responseWrapper.setBody(null); assertNotEquals(responseWrapper, copiedPciResponseWrapper); copiedPciResponseWrapper.setBody(null); - //assertEquals(responseWrapper, copiedPciResponseWrapper); responseWrapper.setBody(response); - //assertNotEquals(responseWrapper, copiedPciResponseWrapper); copiedPciResponseWrapper.setBody(response); - //assertEquals(responseWrapper, copiedPciResponseWrapper); } } diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java index e8f779edb..495fc133f 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciStatusTest.java @@ -52,7 +52,7 @@ class PciStatusTest { assertEquals(status, (Object) status); assertEquals(status, copiedStatus); - assertNotEquals(status, null); + assertNotNull(status); assertNotEquals(status, (Object) "Hello"); status.setCode(-1); diff --git a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java index 8e915c3e9..3c11c0966 100644 --- a/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java +++ b/models-interactions/model-impl/sdnr/src/test/java/org/onap/policy/sdnr/PciWrapperTest.java @@ -71,7 +71,7 @@ class PciWrapperTest { assertEquals(wrapper, (Object) wrapper); assertEquals(wrapper, copiedPciWrapper); - assertNotEquals(wrapper, null); + assertNotNull(wrapper); assertNotEquals(wrapper, (Object) "Hello"); checkField(VERSION_19, PciWrapper::setVersion); diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java index 98a828979..64fc4ac60 100644 --- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestDetailsTest.java @@ -115,7 +115,7 @@ class SoRequestDetailsTest { assertEquals(details, (Object) details); assertEquals(details, copiedDetails); - assertNotEquals(details, null); + assertNotNull(details); assertNotEquals(details, (Object) "Hello"); checkField(cloudConfiguration, SoRequestDetails::setCloudConfiguration); diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java index f33bfd72f..32298816e 100644 --- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java +++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java @@ -74,7 +74,7 @@ class SoResponseWrapperTest { assertEquals(responseWrapper, (Object) responseWrapper); assertEquals(responseWrapper, identicalResponseWrapper); - assertNotEquals(responseWrapper, null); + assertNotNull(responseWrapper); assertNotEquals(responseWrapper, (Object) "AString"); assertEquals(new SoResponseWrapper(null, null), new SoResponseWrapper(null, null)); |