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 /runtime-acm/src | |
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>
Diffstat (limited to 'runtime-acm/src')
13 files changed, 47 insertions, 60 deletions
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())) |