From: FrancescoFioraEst Date: Fri, 31 Oct 2025 16:28:58 +0000 (+0000) Subject: Fixed SonarQube issues X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=515fcbdc568e51fdda10ece675046d87e4999ae5;p=policy%2Fclamp.git Fixed SonarQube issues Fixed SonarQube issues and removed not used delete Participant. Issue-ID: POLICY-5403 Change-Id: Ie21a2aa1536611ae90b69bd9154fbe3653a1a822 Signed-off-by: FrancescoFioraEst --- diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java index b854f1113..4a0556826 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProvider.java @@ -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. * diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java index f7b978838..7c5d4df8e 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionTest.java @@ -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<>()); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java index 8df6db65e..8460a4aba 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplicaTest.java @@ -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("); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java index 2c6c60edc..7ba501579 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/concepts/ParticipantTest.java @@ -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("); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java index 2d63343ba..62d3ada22 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElementTest.java @@ -74,7 +74,6 @@ class JpaAutomationCompositionElementTest { new JpaAutomationCompositionElement(null, null); }).hasMessageMatching(NULL_ELEMENT_ID_ERROR); - assertDoesNotThrow(() -> new JpaAutomationCompositionElement()); assertDoesNotThrow(() -> new JpaAutomationCompositionElement(KEY, KEY)); } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollbackTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollbackTest.java index bf91168ff..6079b7ed5 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollbackTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionRollbackTest.java @@ -24,7 +24,6 @@ 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 java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.Test; @@ -60,9 +59,7 @@ class JpaAutomationCompositionRollbackTest { new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, null); }).hasMessageMatching("elements" + NULL_ERROR); - assertDoesNotThrow(() -> new JpaAutomationCompositionRollback()); - Map map = new LinkedHashMap<>(); - map.put("test", "test"); + Map map = Map.of("test", "test"); assertDoesNotThrow(() -> new JpaAutomationCompositionRollback(INSTANCE_ID, COMPOSITION_ID, map)); } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java index 5a94dbbc4..7a8dda0f2 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionTest.java @@ -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 diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java index 8cc9580cb..4f48c664a 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantReplicaTest.java @@ -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())); } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java index d74ce03e5..6bd25bb9a 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantSupportedElementTypeTest.java @@ -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")); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java index d2d253e06..ceca60f2d 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaParticipantTest.java @@ -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<>())); } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java index 54aa8be8d..7df50ad30 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/persistence/provider/ParticipantProviderTest.java @@ -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, () -> diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java index c36477183..07c20ee9e 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/comm/ParticipantCommTest.java @@ -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; diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java index 8608e0c6b..f26116f01 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/InterceptorConfigTest.java @@ -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); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java index a36625b69..bc14fbd3b 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/EndPointInterceptorTest.java @@ -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 +}