Fix sonar issue for ACM 59/138559/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 24 Jul 2024 08:56:46 +0000 (09:56 +0100)
committerFrancesco Fiora <francesco.fiora@est.tech>
Wed, 24 Jul 2024 09:06:26 +0000 (09:06 +0000)
Issue-ID: POLICY-5065
Change-Id: Id95e8dbd4be14db36eb2fa4ddfc852d37572f25a
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java [deleted file]
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java
models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantAckMessageTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantMessageTest.java
participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/k8s/InferenceServiceValidatorTest.java
participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/api/impl/ParticipantIntermediaryApiImplTest.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/AutomationCompositionInstantiationProviderTest.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java

diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/GenericNameVersion.java
deleted file mode 100644 (file)
index 3e39e97..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2021 Nordix Foundation.
- *  ================================================================================
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *        http://www.apache.org/licenses/LICENSE-2.0
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *
- *  SPDX-License-Identifier: Apache-2.0
- *  ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.models.acm.messages.rest;
-
-import lombok.Data;
-
-@Data
-public class GenericNameVersion {
-
-    private String name;
-
-    private String version;
-}
index fd8b635..7bffdd9 100644 (file)
@@ -42,8 +42,6 @@ public class AcInstanceStateResolver {
     private static final String DELETING = DeployState.DELETING.name();
     private static final String MIGRATING = DeployState.MIGRATING.name();
     private static final String MIGRATION_PRECHECKING = SubState.MIGRATION_PRECHECKING.name();
-    private static final String PREPARING = SubState.PREPARING.name();
-    private static final String REVIEWING = SubState.REVIEWING.name();
     private static final String SUB_STATE_NONE = SubState.NONE.name();
 
     private static final String LOCKED = LockState.LOCKED.name();
index 72e4efb..2535c37 100644 (file)
@@ -32,7 +32,6 @@ import org.onap.policy.clamp.models.acm.utils.CommonTestData;
 import org.onap.policy.common.utils.coder.CoderException;
 
 class ParticipantAckMessageTest {
-    private ParticipantAckMessage message;
 
     @Test
     void testCopyConstructor() throws CoderException {
@@ -40,8 +39,8 @@ class ParticipantAckMessageTest {
                 .isInstanceOf(NullPointerException.class);
 
         // verify with null values
-        message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
-        ParticipantAckMessage newmsg = new ParticipantAckMessage(message);
+        var message = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+        var newmsg = new ParticipantAckMessage(message);
         newmsg.setResponseTo(message.getResponseTo());
         assertEquals(message.toString(), newmsg.toString());
 
@@ -56,14 +55,15 @@ class ParticipantAckMessageTest {
 
     @Test
     void testAppliesTo_NullParticipantId() {
-        message = makeMessage();
-        assertThatThrownBy(() -> message.appliesTo(UUID.randomUUID(), null)).isInstanceOf(NullPointerException.class);
-        assertThatThrownBy(() -> message.appliesTo(null, UUID.randomUUID())).isInstanceOf(NullPointerException.class);
+        var message = makeMessage();
+        var participantId = CommonTestData.getRndParticipantId();
+        assertThatThrownBy(() -> message.appliesTo(participantId, null)).isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> message.appliesTo(null, participantId)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
     void testAppliesTo_ParticipantIdMatches() {
-        message = makeMessage();
+        var message = makeMessage();
 
         // ParticipantId matches
         assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
@@ -72,7 +72,7 @@ class ParticipantAckMessageTest {
 
     @Test
     void testAppliesTo_ParticipantIdNoMatch() {
-        message = makeMessage();
+        var message = makeMessage();
 
         // ParticipantId does not match
         assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
@@ -80,7 +80,7 @@ class ParticipantAckMessageTest {
     }
 
     private ParticipantAckMessage makeMessage() {
-        ParticipantAckMessage msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK);
+        var msg = new ParticipantAckMessage(ParticipantMessageType.PARTICIPANT_DEREGISTER_ACK);
 
         msg.setParticipantId(CommonTestData.getParticipantId());
         msg.setMessage("Successfull Ack");
index db31d0f..c6386a5 100644 (file)
@@ -33,7 +33,6 @@ import org.onap.policy.clamp.models.acm.utils.CommonTestData;
 import org.onap.policy.common.utils.coder.CoderException;
 
 class ParticipantMessageTest {
-    private ParticipantMessage message;
 
     @Test
     void testCopyConstructor() throws CoderException {
@@ -41,7 +40,7 @@ class ParticipantMessageTest {
                 .isInstanceOf(NullPointerException.class);
 
         // verify with null values
-        message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
+        var message = new ParticipantMessage(ParticipantMessageType.PARTICIPANT_STATE_CHANGE);
         var newmsg = new ParticipantMessage(message);
         newmsg.setMessageId(message.getMessageId());
         newmsg.setTimestamp(message.getTimestamp());
@@ -59,15 +58,15 @@ class ParticipantMessageTest {
 
     @Test
     void testAppliesTo_NullParticipantId() {
-        message = makeMessage();
-
-        assertThatThrownBy(() -> message.appliesTo(UUID.randomUUID(), null)).isInstanceOf(NullPointerException.class);
-        assertThatThrownBy(() -> message.appliesTo(null, UUID.randomUUID())).isInstanceOf(NullPointerException.class);
+        var message = makeMessage();
+        var participantId = CommonTestData.getParticipantId();
+        assertThatThrownBy(() -> message.appliesTo(participantId, null)).isInstanceOf(NullPointerException.class);
+        assertThatThrownBy(() -> message.appliesTo(null, participantId)).isInstanceOf(NullPointerException.class);
     }
 
     @Test
     void testAppliesTo_ParticipantIdMatches() {
-        message = makeMessage();
+        var message = makeMessage();
 
         // ParticipantId matches
         assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
@@ -76,7 +75,7 @@ class ParticipantMessageTest {
 
     @Test
     void testAppliesTo_ParticipantIdNoMatch() {
-        message = makeMessage();
+        var message = makeMessage();
         assertFalse(message.appliesTo(CommonTestData.getRndParticipantId(), CommonTestData.getReplicaId()));
         assertTrue(message.appliesTo(CommonTestData.getParticipantId(), CommonTestData.getReplicaId()));
     }
index 5bf7bf1..70285f7 100644 (file)
@@ -36,15 +36,15 @@ class InferenceServiceValidatorTest {
     private static final int TIMEOUT = 2;
     private static final int STATUS_CHECK_INTERVAL = 1;
 
-    private static final String inferenceSvcName = "inference-test";
-    private static final String namespace = "test";
+    private static final String INFERENCE_SVC_NAME = "inference-test";
+    private static final String NAMESPACE = "test";
 
     @Test
     void test_runningPodState() throws IOException, ApiException {
         var kserveClient = mock(KserveClient.class);
         doReturn("True").when(kserveClient).getInferenceServiceStatus(any(), any());
         var inferenceServiceValidator =
-                new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
+                new InferenceServiceValidator(INFERENCE_SVC_NAME, NAMESPACE, TIMEOUT, STATUS_CHECK_INTERVAL,
                         kserveClient);
         assertDoesNotThrow(inferenceServiceValidator::run);
     }
@@ -54,7 +54,7 @@ class InferenceServiceValidatorTest {
         var kserveClient = mock(KserveClient.class);
         doReturn("").when(kserveClient).getInferenceServiceStatus(any(), any());
         var inferenceServiceValidator =
-                new InferenceServiceValidator("", namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
+                new InferenceServiceValidator("", NAMESPACE, TIMEOUT, STATUS_CHECK_INTERVAL,
                         kserveClient);
         assertThatThrownBy(inferenceServiceValidator::run).isInstanceOf(KserveException.class)
                 .cause().hasMessage("Kserve setup is unavailable for inference service to be deployed");
@@ -65,7 +65,7 @@ class InferenceServiceValidatorTest {
         var kserveClient = mock(KserveClient.class);
         doReturn("False").when(kserveClient).getInferenceServiceStatus(any(), any());
         var inferenceServiceValidator =
-                new InferenceServiceValidator(inferenceSvcName, namespace, TIMEOUT, STATUS_CHECK_INTERVAL,
+                new InferenceServiceValidator(INFERENCE_SVC_NAME, NAMESPACE, TIMEOUT, STATUS_CHECK_INTERVAL,
                         kserveClient);
         assertThatThrownBy(inferenceServiceValidator::run).isInstanceOf(KserveException.class)
                 .hasMessage("Error verifying the status of the inference service. Exiting");
index 5640ac4..c925385 100644 (file)
@@ -47,8 +47,8 @@ class PodStatusValidatorTest {
 
     private static final Coder CODER = new StandardCoder();
     private static final String CHART_INFO_YAML = "src/test/resources/ChartList.json";
-    private static int TIMEOUT = 2;
-    private static int STATUS_CHECK_INTERVAL = 1;
+    private static final int TIMEOUT = 2;
+    private static final int STATUS_CHECK_INTERVAL = 1;
     private static List<ChartInfo> charts;
 
     @InjectMocks
index 22929a2..529ae7a 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
+ *  Copyright (C) 2021-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.
@@ -84,7 +84,7 @@ class ParticipantIntermediaryApiImplTest {
         var automationComposiitonHandler = mock(AutomationCompositionOutHandler.class);
         var apiImpl = new ParticipantIntermediaryApiImpl(automationComposiitonHandler, mock(CacheProvider.class));
         apiImpl.sendAcDefinitionInfo(COMPOSITION_ID, DEFINITION_ELEMENT_ID, MAP);
-        verify(automationComposiitonHandler).sendAcDefinitionInfo(COMPOSITION_ID, DEFINITION_ELEMENT_ID, MAP);;
+        verify(automationComposiitonHandler).sendAcDefinitionInfo(COMPOSITION_ID, DEFINITION_ELEMENT_ID, MAP);
     }
 
     @Test
index 0591ab0..a7ae99f 100644 (file)
@@ -72,15 +72,17 @@ class AutomationCompositionInstantiationProviderTest {
             "src/test/resources/rest/acm/AutomationCompositionNotFound.json";
     private static final String DELETE_BAD_REQUEST = "Automation composition state is still %s";
 
-    private static final String AC_ELEMENT_NAME_NOT_FOUND =
-            "\"AutomationComposition\" INVALID, item has status INVALID\n"
-                    + "  \"entry PMSHInstance0AcElementNotFound\" INVALID, item has status INVALID\n"
-                    + "    \"entry org.onap.domain.pmsh.DCAEMicroservice\" INVALID, Not found\n"
-                    + "    \"entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement\""
-                    + " INVALID, Not found\n";
-    private static final String AC_DEFINITION_NOT_FOUND = "\"AutomationComposition\" INVALID, item has status INVALID\n"
-            + "  item \"ServiceTemplate\" value \"%s\" INVALID,"
-            + " Commissioned automation composition definition not found\n";
+    private static final String AC_ELEMENT_NAME_NOT_FOUND = """
+            "AutomationComposition" INVALID, item has status INVALID
+              "entry PMSHInstance0AcElementNotFound" INVALID, item has status INVALID
+                "entry org.onap.domain.pmsh.DCAEMicroservice" INVALID, Not found
+                "entry org.onap.domain.pmsh.PMSH_MonitoringPolicyAutomationCompositionElement" INVALID, Not found
+            """;
+    private static final String AC_DEFINITION_NOT_FOUND = """
+            "AutomationComposition" INVALID, item has status INVALID
+              item "ServiceTemplate" value "%s" INVALID, Commissioned automation composition definition not found
+            """;
+
     private static final String DO_NOT_MATCH = " do not match with ";
 
     private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
index 4842a77..ca3b9bf 100644 (file)
@@ -70,8 +70,8 @@ class ParticipantControllerTest extends CommonRestController {
     private static final String PARTICIPANT_JSON2 = "src/test/resources/providers/TestParticipant2.json";
 
     private static final List<Participant> inputParticipants = new ArrayList<>();
-    private static final String originalJson = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
-    private static final String originalJson2 = ResourceUtils.getResourceAsString(PARTICIPANT_JSON2);
+    private static final String ORIGINAL_JSON = ResourceUtils.getResourceAsString(PARTICIPANT_JSON);
+    private static final String ORIGINAL_JSON2 = ResourceUtils.getResourceAsString(PARTICIPANT_JSON2);
 
     @Autowired
     private ParticipantProvider participantProvider;
@@ -81,8 +81,8 @@ class ParticipantControllerTest extends CommonRestController {
      */
     @BeforeAll
     public static void setUpBeforeClass() throws CoderException {
-        inputParticipants.add(CODER.decode(originalJson, Participant.class));
-        inputParticipants.add(CODER.decode(originalJson2, Participant.class));
+        inputParticipants.add(CODER.decode(ORIGINAL_JSON, Participant.class));
+        inputParticipants.add(CODER.decode(ORIGINAL_JSON2, Participant.class));
     }
 
     @BeforeEach