Fixed SonarQube issues 89/142389/2
authorFrancescoFioraEst <francesco.fiora@est.tech>
Fri, 31 Oct 2025 16:28:58 +0000 (16:28 +0000)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 5 Nov 2025 11:01:55 +0000 (11:01 +0000)
Fixed SonarQube issues and removed not used delete Participant.

Issue-ID: POLICY-5403
Change-Id: Ie21a2aa1536611ae90b69bd9154fbe3653a1a822
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
14 files changed:
models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java
models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollbackTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java
models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java

index b854f11..4a05568 100644 (file)
@@ -117,25 +117,6 @@ public class ParticipantProvider {
         return result.toAuthorative();
     }
 
-    /**
-     * Delete a participant.
-     *
-     * @param participantId the Id of the participant to delete
-     * @return the participant deleted
-     */
-    public Participant deleteParticipant(@NonNull final UUID participantId) {
-        var jpaDeleteParticipantOpt = participantRepository.findById(participantId.toString());
-
-        if (jpaDeleteParticipantOpt.isEmpty()) {
-            String errorMessage =
-                "delete of participant \"" + participantId + "\" failed, participant does not exist";
-            throw new PfModelRuntimeException(Status.BAD_REQUEST, errorMessage);
-        }
-        participantRepository.delete(jpaDeleteParticipantOpt.get());
-
-        return jpaDeleteParticipantOpt.get().toAuthorative();
-    }
-
     /**
      * Get a map with SupportedElement as key and the participantId as value.
      *
index f7b9788..7c5d4df 100644 (file)
@@ -22,7 +22,6 @@ package org.onap.policy.clamp.models.acm.concepts;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -45,7 +44,6 @@ class AutomationCompositionTest {
 
     @Test
     void testAutomationCompositionLombok() {
-        assertDoesNotThrow(() -> new AutomationComposition());
         var ac0 = new AutomationComposition();
         ac0.setElements(new LinkedHashMap<>());
 
index 8df6db6..8460a4a 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-2025 OpenInfra Foundation Europe. 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.
@@ -22,7 +22,6 @@ package org.onap.policy.clamp.models.acm.concepts;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 
@@ -34,7 +33,6 @@ class ParticipantReplicaTest {
 
     @Test
     void testParticipantLombok() {
-        assertDoesNotThrow(() -> new ParticipantReplica());
         var p0 = new ParticipantReplica();
 
         assertThat(p0.toString()).contains("ParticipantReplica(");
index 2c6c60e..7ba5015 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. 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.
@@ -21,7 +21,6 @@
 package org.onap.policy.clamp.models.acm.concepts;
 
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 
@@ -34,7 +33,6 @@ class ParticipantTest {
 
     @Test
     void testParticipantLombok() {
-        assertDoesNotThrow(() -> new Participant());
         var p0 = new Participant();
 
         assertThat(p0.toString()).contains("Participant(");
index 2d63343..62d3ada 100644 (file)
@@ -74,7 +74,6 @@ class JpaAutomationCompositionElementTest {
             new JpaAutomationCompositionElement(null, null);
         }).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
 
-        assertDoesNotThrow(() -> new JpaAutomationCompositionElement());
         assertDoesNotThrow(() -> new JpaAutomationCompositionElement(KEY, KEY));
     }
 
index bf91168..6079b7e 100644 (file)
@@ -24,7 +24,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;\r
 import static org.junit.jupiter.api.Assertions.assertEquals;\r
 \r
-import java.util.LinkedHashMap;\r
 import java.util.Map;\r
 import java.util.UUID;\r
 import org.junit.jupiter.api.Test;\r
@@ -60,9 +59,7 @@ class JpaAutomationCompositionRollbackTest {
             new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, null);\r
         }).hasMessageMatching("elements" + NULL_ERROR);\r
 \r
-        assertDoesNotThrow(() -> new JpaAutomationCompositionRollback());\r
-        Map<String, Object> map = new LinkedHashMap<>();\r
-        map.put("test", "test");\r
+        Map<String, Object> map = Map.of("test", "test");\r
         assertDoesNotThrow(() -> new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, map));\r
     }\r
 \r
index 5a94dbb..7a8dda0 100644 (file)
@@ -22,7 +22,6 @@ package org.onap.policy.clamp.models.acm.persistence.concepts;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -57,8 +56,6 @@ class JpaAutomationCompositionTest {
         assertThatThrownBy(() -> {
             new JpaAutomationComposition((AutomationComposition) null);
         }).hasMessageMatching("authorativeConcept" + NULL_ERROR);
-
-        assertDoesNotThrow(() -> new JpaAutomationComposition());
     }
 
     @Test
index 8cc9580..4f48c66 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2024 Nordix Foundation.
+ * Copyright (C) 2024-2025 OpenInfra Foundation Europe. 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.
@@ -40,7 +40,6 @@ class JpaParticipantReplicaTest {
         assertThatThrownBy(() -> new JpaParticipantReplica(null, UUID.randomUUID().toString()))
                 .hasMessageMatching("replicaId is marked .*ull but is null");
 
-        assertDoesNotThrow(() -> new JpaParticipantReplica());
         assertDoesNotThrow(() -> new JpaParticipantReplica(UUID.randomUUID().toString(), UUID.randomUUID().toString()));
     }
 
index d74ce03..6bd25bb 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2023 Nordix Foundation.
+ * Copyright (C) 2023,2025 OpenInfra Foundation Europe. 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.
@@ -74,7 +74,6 @@ class JpaParticipantSupportedElementTypeTest {
             new JpaParticipantSupportedElementType("key", "key", "name", null);
         }).hasMessageMatching("typeVersion" + NULL_ERROR);
 
-        assertDoesNotThrow(() -> new JpaParticipantSupportedElementType());
         assertDoesNotThrow(() -> new JpaParticipantSupportedElementType("key", "key"));
         assertDoesNotThrow(() -> new JpaParticipantSupportedElementType("key", "key", "name",
             "1.0.0"));
index d2d253e..ceca60f 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 OpenInfra Foundation Europe. 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.
@@ -57,7 +57,6 @@ class JpaParticipantTest {
         assertThatThrownBy(() -> new JpaParticipant(UUID.randomUUID().toString(), new ArrayList<>(), null))
             .hasMessageMatching("replicas is marked .*ull but is null");
 
-        assertDoesNotThrow(() -> new JpaParticipant());
         assertDoesNotThrow(() -> new JpaParticipant(UUID.randomUUID().toString(),
                 new ArrayList<>(), new ArrayList<>()));
     }
index 54aa8be..7df50ad 100644 (file)
@@ -155,26 +155,6 @@ class ParticipantProviderTest {
             PfModelRuntimeException.class).hasMessageMatching("Participant Not Found with ID:.*.");
     }
 
-    @Test
-    void testDeleteParticipant() {
-        var participantRepository = mock(ParticipantRepository.class);
-        var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
-        var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
-        var participantProvider = new ParticipantProvider(participantRepository,
-            automationCompositionElementRepository, nodeTemplateStateRepository,
-            mock(ParticipantReplicaRepository.class));
-
-        var participantId = inputParticipants.get(0).getParticipantId();
-        assertThatThrownBy(() -> participantProvider.deleteParticipant(participantId))
-            .hasMessageMatching(".*.failed, participant does not exist");
-
-        when(participantRepository.findById(participantId.toString()))
-            .thenReturn(Optional.of(jpaParticipantList.get(0)));
-
-        var deletedParticipant = participantProvider.deleteParticipant(participantId);
-        assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(deletedParticipant);
-    }
-
     @Test
     void testGetAutomationCompositionElements() {
         var participantRepository = mock(ParticipantRepository.class);
@@ -230,7 +210,6 @@ class ParticipantProviderTest {
         assertThrows(NullPointerException.class, () -> participantProvider.getParticipantById(null));
         assertThrows(NullPointerException.class, () -> participantProvider.findParticipant(null));
         assertThrows(NullPointerException.class, () -> participantProvider.saveParticipant(null));
-        assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null));
 
         var pageable = Pageable.unpaged();
         assertThrows(NullPointerException.class, () ->
index c364771..07c20ee 100644 (file)
@@ -49,7 +49,6 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantSt
 import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq;
 import org.onap.policy.common.message.bus.event.Topic;
 import org.onap.policy.common.message.bus.event.TopicSink;
-import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.coder.StandardCoderObject;
index 8608e0c..f26116f 100644 (file)
@@ -28,19 +28,18 @@ import static org.mockito.Mockito.when;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
-public class InterceptorConfigTest {
+class InterceptorConfigTest {
 
     @Test
-    public void testGetWebMvcConfigurerAddsInterceptor() {
-        InterceptorConfig config = new InterceptorConfig();
-        EndPointInterceptor interceptor = mock(EndPointInterceptor.class);
-        InterceptorRegistry registry = mock(InterceptorRegistry.class);
+    void testGetWebMvcConfigurerAddsInterceptor() {
+        var config = new InterceptorConfig();
+        var interceptor = mock(EndPointInterceptor.class);
+        var registry = mock(InterceptorRegistry.class);
 
         when(registry.addInterceptor(interceptor)).thenReturn(null);
 
-        WebMvcConfigurer webMvcConfigurer = config.getWebMvcConfigurer(interceptor);
+        var webMvcConfigurer = config.getWebMvcConfigurer(interceptor);
         webMvcConfigurer.addInterceptors(registry);
 
         verify(registry, times(1)).addInterceptor(interceptor);
index a36625b..bc14fbd 100644 (file)
@@ -30,22 +30,22 @@ import jakarta.servlet.http.HttpServletResponse;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor;
 
-public class EndPointInterceptorTest {
+class EndPointInterceptorTest {
 
     @Test
-    public void testPreHandleReturnsTrueAndLogs() throws Exception {
-        EndPointInterceptor interceptor = new EndPointInterceptor();
-        HttpServletRequest request = mock(HttpServletRequest.class);
-        HttpServletResponse response = mock(HttpServletResponse.class);
+    void testPreHandleReturnsTrueAndLogs() throws Exception {
+        var interceptor = new EndPointInterceptor();
+        var request = mock(HttpServletRequest.class);
+        var response = mock(HttpServletResponse.class);
 
         when(request.getMethod()).thenReturn("GET");
         when(request.getRequestURI()).thenReturn("/test/uri");
 
-        boolean result = interceptor.preHandle(request, response, new Object());
+        var result = interceptor.preHandle(request, response, new Object());
 
         assertTrue(result);
 
         verify(request).getMethod();
         verify(request).getRequestURI();
     }
-}
\ No newline at end of file
+}