diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2024-06-17 13:23:07 +0100 |
---|---|---|
committer | Francesco Fiora <francesco.fiora@est.tech> | 2024-06-17 13:36:52 +0000 |
commit | 45b94ba92d2ea581f1415ee57a005383bc6629e1 (patch) | |
tree | 0a4795f7cc58f7db9516031511df4809114e95aa | |
parent | 8c76c17a2d589d4e94571f4b6dce40261c0bb62d (diff) |
Improve code in ACM
Code clean-up on ACM: remove unused imports,
remove updateParticipant method (duplicated method)
and remove public in Unit test classes.
Issue-ID: POLICY-5047
Change-Id: I308815cacaa2c5ce81ed54c676d3d5e26778f0f6
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
25 files changed, 55 insertions, 110 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java index 23f72191a..73dfad564 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/ParticipantReplica.java @@ -37,6 +37,7 @@ public class ParticipantReplica { @NonNull private ParticipantState participantState = ParticipantState.ON_LINE; + // last time ACM-R has received a status message from participant replica @NonNull private String lastMsg; 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 b3437c06f..85c9e67cb 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 @@ -116,20 +116,6 @@ public class ParticipantProvider { } /** - * Updates an existing participant. - * - * @param participant participant to update - * @return the participant updated - */ - public Participant updateParticipant(@NonNull final Participant participant) { - var result = participantRepository - .save(ProviderUtils.getJpaAndValidate(participant, JpaParticipant::new, "participant")); - - // Return the saved participant - return result.toAuthorative(); - } - - /** * Delete a participant. * * @param participantId the Id of the participant to delete diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java index 970b94824..2fee9c55a 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/messages/kafka/participant/ParticipantSyncTest.java @@ -40,7 +40,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -public class ParticipantSyncTest { +class ParticipantSyncTest { @Test void testCopyConstructor() throws CoderException { 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 d77760860..8cc9580cb 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 @@ -28,9 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import java.util.UUID; import org.junit.jupiter.api.Test; -import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; -import org.onap.policy.clamp.models.acm.utils.TimestampHelper; class JpaParticipantReplicaTest { 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 9ceeef640..ac3aa87c5 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 @@ -114,25 +114,6 @@ class ParticipantProviderTest { } @Test - void testParticipantUpdate() { - 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)); - - assertThatThrownBy(() -> participantProvider.updateParticipant(null)).hasMessageMatching(LIST_IS_NULL); - - when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0)); - - var updatedParticipant = participantProvider.updateParticipant(inputParticipants.get(0)); - updatedParticipant.setParticipantId(inputParticipants.get(0).getParticipantId()); - assertThat(updatedParticipant).usingRecursiveComparison().isEqualTo(inputParticipants.get(0)); - } - - @Test void testGetAutomationCompositions() { var participantRepository = mock(ParticipantRepository.class); var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class); @@ -240,7 +221,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.updateParticipant(null)); assertThrows(NullPointerException.class, () -> participantProvider.deleteParticipant(null)); assertThrows(NullPointerException.class, () -> participantProvider.getAutomationCompositionElements(null)); assertThrows(NullPointerException.class, () -> participantProvider.getAcNodeTemplateStates(null)); diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java index e6135fe5b..91f26f7c1 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/rest/RestUtilsTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2021 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. @@ -47,7 +47,7 @@ class RestUtilsTest { var response = RestUtils.toSimpleResponse(ex); - assertThat(response.getStatusCodeValue()).isEqualTo(STATUS_ERROR.getStatusCode()); + assertThat(response.getStatusCode().value()).isEqualTo(STATUS_ERROR.getStatusCode()); assertThat(response.getBody()).isNotNull(); assertThat(response.getBody().getErrorDetails()).isEqualTo(MESSAGE_ERROR); } diff --git a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java index aaba0bcc8..d87b8bcd2 100644 --- a/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java +++ b/models/src/test/java/org/onap/policy/clamp/models/acm/utils/TimestampHelperTest.java @@ -30,7 +30,7 @@ class TimestampHelperTest { void testNow() { assertThat(TimestampHelper.nowTimestamp()).isNotNull(); assertThat(TimestampHelper.now()).isNotNull(); - assertThat(TimestampHelper.nowEpochMilli()).isNotNull(); + assertThat(TimestampHelper.nowEpochMilli()).isNotZero(); } @Test diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java index 88f080bc7..4902a9efb 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/CompositionDto.java @@ -20,10 +20,8 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; -import java.util.List; import java.util.Map; import java.util.UUID; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; public record CompositionDto(UUID compositionId, diff --git a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java index 197d7e46d..297af6c43 100644 --- a/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java +++ b/participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/api/InstanceElementDto.java @@ -22,8 +22,6 @@ package org.onap.policy.clamp.acm.participant.intermediary.api; import java.util.Map; import java.util.UUID; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; -import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; public record InstanceElementDto(UUID instanceId, UUID elementId, ToscaServiceTemplate toscaServiceTemplateFragment, 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 d7c97bd00..33325122e 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 @@ -42,12 +42,11 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRe import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatus; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq; import org.onap.policy.common.endpoints.event.comm.TopicSink; -import org.onap.policy.common.utils.coder.CoderException; class ParticipantCommTest { @Test - void participantListenerTest() throws CoderException { + void participantListenerTest() { var participantHandler = mock(ParticipantHandler.class); var participantRegisterAckListener = new ParticipantRegisterAckListener(participantHandler); @@ -137,7 +136,7 @@ class ParticipantCommTest { } @Test - void messageSenderTest() throws CoderException { + void messageSenderTest() { var participantHandler = mock(ParticipantHandler.class); var participantParameters = CommonTestData.getParticipantParameters(); var messageSender = new MessageSender(participantHandler, participantParameters); diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java index 3bbdc3dbf..0c73e87ed 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/AcDefinitionHandlerTest.java @@ -40,7 +40,7 @@ import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantPr import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantRestart; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -public class AcDefinitionHandlerTest { +class AcDefinitionHandlerTest { @Test void handleComposiotPrimeTest() { diff --git a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/IntermediaryActivatorTest.java b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/IntermediaryActivatorTest.java index 8868c733a..89bafa196 100644 --- a/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/IntermediaryActivatorTest.java +++ b/participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/IntermediaryActivatorTest.java @@ -34,10 +34,8 @@ import static org.mockito.Mockito.when; import java.util.List; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantStatusReqListener; -import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantSyncListener; import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantStatusReq; -import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantSync; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardCoderObject; diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/Publisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/Publisher.java index a76a09d99..63957c685 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/Publisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/config/messaging/Publisher.java @@ -20,8 +20,6 @@ package org.onap.policy.clamp.acm.runtime.config.messaging; -import java.util.List; -import org.onap.policy.clamp.acm.runtime.main.parameters.Topics; import org.onap.policy.common.endpoints.event.comm.TopicSink; /** diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/ParticipantController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/ParticipantController.java index 855681e69..1136dcb16 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/ParticipantController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/ParticipantController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * 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. @@ -41,8 +41,7 @@ public class ParticipantController extends AbstractRestController implements Par @Override public ResponseEntity<ParticipantInformation> getParticipant(UUID participantId, UUID requestId) { - ParticipantInformation participantInformation = acmParticipantProvider - .getParticipantById(participantId); + var participantInformation = acmParticipantProvider.getParticipantById(participantId); return ResponseEntity.ok().body(participantInformation); } @@ -61,7 +60,7 @@ public class ParticipantController extends AbstractRestController implements Par @Override public ResponseEntity<List<ParticipantInformation>> queryParticipants(String name, String version, UUID requestId) { - List<ParticipantInformation> participantInformationList = acmParticipantProvider.getAllParticipants(); + var participantInformationList = acmParticipantProvider.getAllParticipants(); return ResponseEntity.ok().body(participantInformationList); } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java index 13382e0fb..282389a74 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/participants/AcmParticipantProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * 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. @@ -99,7 +99,7 @@ public class AcmParticipantProvider { LOGGER.debug("Requesting Participant Status Now ParticipantStatusReq"); participantStatusReqPublisher.send(participantId); participant.setParticipantState(ParticipantState.OFF_LINE); - participantProvider.updateParticipant(participant); + participantProvider.saveParticipant(participant); } /** diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java index 4d2a22f26..b7f0be8eb 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionPartecipantScanner.java @@ -76,7 +76,7 @@ public class SupervisionPartecipantScanner { if ((now - lastMsg) > maxWaitMs) { LOGGER.debug("report Participant OFF_LINE {}", id); participant.setParticipantState(ParticipantState.OFF_LINE); - participantProvider.updateParticipant(participant); + participantProvider.saveParticipant(participant); } } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java index d1efb6ac0..609e036be 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandler.java @@ -105,7 +105,7 @@ public class SupervisionParticipantHandler { if (participantOpt.isPresent()) { var participant = participantOpt.get(); participant.setParticipantState(ParticipantState.OFF_LINE); - participantProvider.updateParticipant(participant); + participantProvider.saveParticipant(participant); } participantDeregisterAckPublisher.send(participantDeregisterMsg.getMessageId()); diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantAckPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantAckPublisher.java index 5014f7dc3..1e8ff7072 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantAckPublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantAckPublisher.java @@ -21,10 +21,7 @@ package org.onap.policy.clamp.acm.runtime.supervision.comm; import jakarta.ws.rs.core.Response.Status; -import java.util.List; -import java.util.Optional; import org.onap.policy.clamp.acm.runtime.config.messaging.Publisher; -import org.onap.policy.clamp.acm.runtime.main.parameters.Topics; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantAckMessage; import org.onap.policy.common.endpoints.event.comm.TopicSink; diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java index 5afb7eba4..0619f05d0 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/supervision/comm/AbstractParticipantPublisher.java @@ -21,10 +21,7 @@ package org.onap.policy.clamp.acm.runtime.supervision.comm; import jakarta.ws.rs.core.Response.Status; -import java.util.List; -import java.util.Optional; import org.onap.policy.clamp.acm.runtime.config.messaging.Publisher; -import org.onap.policy.clamp.acm.runtime.main.parameters.Topics; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.clamp.models.acm.messages.kafka.participant.ParticipantMessage; import org.onap.policy.common.endpoints.event.comm.TopicSink; diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java index 66595c89a..7e79c6e03 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/config/messaging/MessageDispatcherActivatorTest.java @@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java index 8639dffcd..564723b7c 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/instantiation/InstantiationUtils.java @@ -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. @@ -34,7 +34,6 @@ import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.coder.StandardYamlCoder; import org.onap.policy.common.utils.resources.ResourceUtils; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; /** diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java index f8443de33..4842a77a8 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/participant/ParticipantControllerTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2023 Nordix Foundation. + * 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. @@ -45,7 +45,6 @@ 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.resources.ResourceUtils; -import org.onap.policy.models.base.PfModelException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.server.LocalServerPort; @@ -104,61 +103,61 @@ class ParticipantControllerTest extends CommonRestController { @Test void testQueryParticipant() { participantProvider.saveParticipant(inputParticipants.get(0)); - UUID participantId = participantProvider.getParticipants().get(0).getParticipantId(); + var participantId = participantProvider.getParticipants().get(0).getParticipantId(); var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + participantId); - var response = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); - var entityList = response.readEntity(ParticipantInformation.class); - assertNotNull(entityList); + try (var response = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + var entityList = response.readEntity(ParticipantInformation.class); + assertNotNull(entityList); + } } @Test void testBadQueryParticipant() { participantProvider.saveParticipant(inputParticipants.get(0)); var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + UUID.randomUUID()); - var response = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + try (var response = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + } } @Test void getAllParticipants() { - inputParticipants.forEach(p -> { - participantProvider.saveParticipant(p); - }); + inputParticipants.forEach(p -> participantProvider.saveParticipant(p)); var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT); - var response = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); - List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {}); - assertThat(entityList).isNotEmpty(); - var participantIds = entityList.stream().map(ParticipantInformation::getParticipant) - .map(Participant::getParticipantId).collect(Collectors.toSet()); - inputParticipants.forEach(p -> { - assertThat(participantIds).contains(p.getParticipantId()); - }); + try (var response = invocationBuilder.buildGet().invoke()) { + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + List<ParticipantInformation> entityList = response.readEntity(new GenericType<>() {}); + assertThat(entityList).isNotEmpty(); + var participantIds = + entityList.stream().map(ParticipantInformation::getParticipant).map(Participant::getParticipantId) + .collect(Collectors.toSet()); + inputParticipants.forEach(p -> assertThat(participantIds).contains(p.getParticipantId())); + } } @Test - void testOrderParticipantReport() throws PfModelException { + void testOrderParticipantReport() { participantProvider.saveParticipant(inputParticipants.get(0)); - UUID participantId = participantProvider.getParticipants().get(0).getParticipantId(); + var participantId = participantProvider.getParticipants().get(0).getParticipantId(); var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + participantId); - var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity("" - + - "", MediaType.APPLICATION_JSON)); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus()); + try (var response = invocationBuilder.header("Content-Length", 0) + .put(Entity.entity("", MediaType.APPLICATION_JSON))) { + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus()); + } } @Test - void testBadOrderParticipantReport() throws PfModelException { + void testBadOrderParticipantReport() { var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT + "/" + UUID.randomUUID()); - var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity("" - + - "", MediaType.APPLICATION_JSON)); - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + try (var response = invocationBuilder.header("Content-Length", 0) + .put(Entity.entity("", MediaType.APPLICATION_JSON))) { + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + } } @Test @@ -167,9 +166,9 @@ class ParticipantControllerTest extends CommonRestController { participantProvider.saveParticipant(p); }); var invocationBuilder = super.sendRequest(PARTICIPANTS_ENDPOINT); - var response = invocationBuilder.header("Content-Length", 0).put(Entity.entity("" - + - "", MediaType.APPLICATION_JSON)); - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus()); + try (var response = invocationBuilder.header("Content-Length", 0) + .put(Entity.entity("", MediaType.APPLICATION_JSON))) { + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus()); + } } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java index 41f1c9c31..e352d2f2a 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantHandlerTest.java @@ -78,7 +78,7 @@ class SupervisionParticipantHandlerTest { handler.handleParticipantMessage(participantDeregisterMessage); - verify(participantProvider).updateParticipant(any()); + verify(participantProvider).saveParticipant(any()); verify(participantDeregisterAckPublisher).send(participantDeregisterMessage.getMessageId()); } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java index 3c9f91785..690ad9672 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionParticipantScannerTest.java @@ -47,10 +47,10 @@ class SupervisionParticipantScannerTest { participant.setParticipantState(ParticipantState.OFF_LINE); supervisionScanner.run(); - verify(participantProvider, times(0)).updateParticipant(any()); + verify(participantProvider, times(0)).saveParticipant(any()); participant.setParticipantState(ParticipantState.ON_LINE); supervisionScanner.run(); - verify(participantProvider, times(1)).updateParticipant(any()); + verify(participantProvider, times(1)).saveParticipant(any()); } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java index 31cd659b3..766380ac4 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/comm/SupervisionMessagesTest.java @@ -28,7 +28,6 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,7 +35,6 @@ import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup; -import org.onap.policy.clamp.acm.runtime.main.parameters.Topics; import org.onap.policy.clamp.acm.runtime.participants.AcmParticipantProvider; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; @@ -107,6 +105,7 @@ class SupervisionMessagesTest { acDeregisterAckPublisher.stop(); } + @Test void testSendParticipantDeregisterAckNoActive() { var acDeregisterAckPublisher = new ParticipantDeregisterAckPublisher(); assertThatThrownBy(() -> acDeregisterAckPublisher.send(new ParticipantDeregisterAck())) |