diff options
author | 2023-01-18 10:31:34 +0000 | |
---|---|---|
committer | 2023-01-23 09:11:13 +0000 | |
commit | 3164fd8bd0cb8d3c682fa02093a866c7655cd111 (patch) | |
tree | 2c364929b3421919257481b3e453b1b3d90adfdd /runtime-acm | |
parent | 46964ab900060a560b9b41f7d34ab0e26ac7fd61 (diff) |
Remove reference type of participantId in Unit Tests in ACM
As part of the participantId refactoring, reduce the impact
of the changes by removing the reference type of participantId
in unit tests.
Issue-ID: POLICY-4524
Change-Id: I08837a0739f229a0a8c439c8b12578823277aa32
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
6 files changed, 40 insertions, 67 deletions
diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java index abc3ccb1a..b913cfac9 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionAspectTest.java @@ -26,17 +26,11 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import org.junit.jupiter.api.Test; +import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class SupervisionAspectTest { - private static final ToscaConceptIdentifier PARTICIPANT_ID = - new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0"); - - private static final ToscaConceptIdentifier PARTICIPANT_TYPE = - new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", "1.0.0"); - @Test void testSchedule() throws Exception { var supervisionScanner = mock(SupervisionScanner.class); @@ -59,12 +53,12 @@ class SupervisionAspectTest { @Test void testHandleParticipantStatus() throws Exception { var participantStatusMessage = new ParticipantStatus(); - participantStatusMessage.setParticipantId(PARTICIPANT_ID); + participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); var supervisionScanner = mock(SupervisionScanner.class); try (var supervisionAspect = new SupervisionAspect(supervisionScanner)) { supervisionAspect.handleParticipantStatus(participantStatusMessage); - verify(supervisionScanner, timeout(500)).handleParticipantStatus(PARTICIPANT_ID); + verify(supervisionScanner, timeout(500)).handleParticipantStatus(CommonTestData.getParticipantId()); } } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java index fd6c9a008..4516ccd97 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionHandlerTest.java @@ -39,12 +39,12 @@ import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionStateChangePublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.AutomationCompositionUpdatePublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantUpdatePublisher; +import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionAck; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessageType; @@ -56,9 +56,8 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class SupervisionHandlerTest { private static final String AC_INSTANTIATION_CREATE_JSON = "src/test/resources/rest/acm/AutomationComposition.json"; - private static final UUID identifier = UUID.randomUUID(); - private static final ToscaConceptIdentifier participantId = new ToscaConceptIdentifier("ParticipantId", "1.0.0"); - private static final ToscaConceptIdentifier participantType = + private static final UUID IDENTIFIER = UUID.randomUUID(); + private static final ToscaConceptIdentifier PARTICIPANT_TYPE = new ToscaConceptIdentifier("ParticipantType", "1.0.0"); @Test @@ -221,7 +220,7 @@ class SupervisionHandlerTest { var automationCompositionAckMessage = new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK); automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of()); - automationCompositionAckMessage.setAutomationCompositionId(identifier); + automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER); handler.handleAutomationCompositionStateChangeAckMessage(automationCompositionAckMessage); @@ -232,10 +231,10 @@ class SupervisionHandlerTest { void testHandleAutomationCompositionUpdateAckMessage() { var automationCompositionAckMessage = new AutomationCompositionAck(ParticipantMessageType.AUTOMATION_COMPOSITION_UPDATE_ACK); - automationCompositionAckMessage.setParticipantId(participantId); - automationCompositionAckMessage.setParticipantType(participantType); + automationCompositionAckMessage.setParticipantId(CommonTestData.getParticipantId()); + automationCompositionAckMessage.setParticipantType(PARTICIPANT_TYPE); automationCompositionAckMessage.setAutomationCompositionResultMap(Map.of()); - automationCompositionAckMessage.setAutomationCompositionId(identifier); + automationCompositionAckMessage.setAutomationCompositionId(IDENTIFIER); var automationCompositionProvider = mock(AutomationCompositionProvider.class); var handler = createSupervisionHandler(automationCompositionProvider, mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class), @@ -248,15 +247,10 @@ class SupervisionHandlerTest { } @Test - void testParticipantUpdateAck() throws PfModelException { - var participant = new Participant(); - participant.setName(participantId.getName()); - participant.setVersion(participantId.getVersion()); - participant.setParticipantType(participantType); - + void testParticipantUpdateAck() { var participantUpdateAckMessage = new ParticipantUpdateAck(); - participantUpdateAckMessage.setParticipantId(participantId); - participantUpdateAckMessage.setParticipantType(participantType); + participantUpdateAckMessage.setParticipantId(CommonTestData.getParticipantId()); + participantUpdateAckMessage.setParticipantType(PARTICIPANT_TYPE); participantUpdateAckMessage.setState(ParticipantState.ON_LINE); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class), @@ -267,7 +261,7 @@ class SupervisionHandlerTest { } @Test - void testHandleSendCommissionMessage() throws PfModelException { + void testHandleSendCommissionMessage() { var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class); var handler = createSupervisionHandler(mock(AutomationCompositionProvider.class), mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class), @@ -286,9 +280,9 @@ class SupervisionHandlerTest { mock(AutomationCompositionUpdatePublisher.class), mock(AutomationCompositionStateChangePublisher.class), participantUpdatePublisher, AutomationCompositionOrderedState.PASSIVE, AutomationCompositionState.UNINITIALISED); - handler.handleSendDeCommissionMessage(identifier); + handler.handleSendDeCommissionMessage(IDENTIFIER); - verify(participantUpdatePublisher).sendDecomisioning(identifier); + verify(participantUpdatePublisher).sendDecomisioning(IDENTIFIER); } private SupervisionHandler createSupervisionHandler(AutomationCompositionProvider automationCompositionProvider, @@ -301,7 +295,7 @@ class SupervisionHandlerTest { automationComposition.setOrderedState(orderedState); automationComposition.setState(state); - when(automationCompositionProvider.findAutomationComposition(identifier)) + when(automationCompositionProvider.findAutomationComposition(IDENTIFIER)) .thenReturn(Optional.of(automationComposition)); var acDefinitionProvider = Mockito.mock(AcDefinitionProvider.class); 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 05e356b55..9463d7977 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 @@ -31,7 +31,7 @@ import java.util.UUID; import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantDeregisterAckPublisher; import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantRegisterAckPublisher; -import org.onap.policy.clamp.models.acm.concepts.Participant; +import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister; @@ -40,23 +40,20 @@ import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; class SupervisionParticipantHandlerTest { - private static final ToscaConceptIdentifier PARTICIPANT_ID = new ToscaConceptIdentifier("ParticipantId", "1.0.0"); private static final ToscaConceptIdentifier PARTICIPANT_TYPE = new ToscaConceptIdentifier("ParticipantType", "1.0.0"); @Test void testHandleParticipantDeregister() { - var participant = new Participant(); - participant.setName(PARTICIPANT_ID.getName()); - participant.setVersion(PARTICIPANT_ID.getVersion()); - participant.setParticipantType(PARTICIPANT_TYPE); + var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId()); var participantProvider = mock(ParticipantProvider.class); - when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant)); + when(participantProvider.findParticipant(CommonTestData.getParticipantId())) + .thenReturn(Optional.of(participant)); var participantDeregisterMessage = new ParticipantDeregister(); participantDeregisterMessage.setMessageId(UUID.randomUUID()); - participantDeregisterMessage.setParticipantId(PARTICIPANT_ID); + participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId()); participantDeregisterMessage.setParticipantType(PARTICIPANT_TYPE); var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class); var handler = new SupervisionParticipantHandler(participantProvider, @@ -70,14 +67,9 @@ class SupervisionParticipantHandlerTest { @Test void testHandleParticipantRegister() { - var participant = new Participant(); - participant.setName(PARTICIPANT_ID.getName()); - participant.setVersion(PARTICIPANT_ID.getVersion()); - participant.setParticipantType(PARTICIPANT_TYPE); - var participantRegisterMessage = new ParticipantRegister(); participantRegisterMessage.setMessageId(UUID.randomUUID()); - participantRegisterMessage.setParticipantId(PARTICIPANT_ID); + participantRegisterMessage.setParticipantId(CommonTestData.getParticipantId()); participantRegisterMessage.setParticipantType(PARTICIPANT_TYPE); var participantProvider = mock(ParticipantProvider.class); var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class); @@ -88,14 +80,14 @@ class SupervisionParticipantHandlerTest { handler.handleParticipantMessage(participantRegisterMessage); verify(participantProvider).saveParticipant(any()); - verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), PARTICIPANT_ID, - PARTICIPANT_TYPE); + verify(participantRegisterAckPublisher).send(participantRegisterMessage.getMessageId(), + CommonTestData.getParticipantId(), PARTICIPANT_TYPE); } @Test void testHandleParticipantStatus() { var participantStatusMessage = new ParticipantStatus(); - participantStatusMessage.setParticipantId(PARTICIPANT_ID); + participantStatusMessage.setParticipantId(CommonTestData.getParticipantId()); participantStatusMessage.setParticipantType(PARTICIPANT_TYPE); participantStatusMessage.setState(ParticipantState.ON_LINE); participantStatusMessage.setParticipantSupportedElementType(new ArrayList<>()); @@ -103,8 +95,9 @@ class SupervisionParticipantHandlerTest { var participantProvider = mock(ParticipantProvider.class); var handler = new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class)); - var participant = new Participant(); - when(participantProvider.findParticipant(PARTICIPANT_ID)).thenReturn(Optional.of(participant)); + var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId()); + when(participantProvider.findParticipant(CommonTestData.getParticipantId())) + .thenReturn(Optional.of(participant)); handler.handleParticipantMessage(participantStatusMessage); verify(participantProvider).updateParticipant(any()); diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java index 92597b3c3..93f15f64d 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/supervision/SupervisionScannerTest.java @@ -41,7 +41,6 @@ import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; -import org.onap.policy.clamp.models.acm.concepts.Participant; import org.onap.policy.clamp.models.acm.concepts.ParticipantState; import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; @@ -55,13 +54,10 @@ class SupervisionScannerTest { private static final AcDefinitionProvider acDefinitionProvider = mock(AcDefinitionProvider.class); - private static final String PARTICIPANT_NAME = "Participant0"; - private static final String PARTICIPANT_VERSION = "1.0.0"; - private static UUID compositionId; private static final ToscaConceptIdentifier PARTICIPANT_TYPE = - new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", PARTICIPANT_VERSION); + new ToscaConceptIdentifier("org.onap.policy.clamp.acm.PolicyParticipant", "1.0.0"); @BeforeAll public static void setUpBeforeAll() { @@ -123,9 +119,7 @@ class SupervisionScannerTest { .thenReturn(List.of(automationComposition)); var participantProvider = mock(ParticipantProvider.class); - var participant = new Participant(); - participant.setName(PARTICIPANT_NAME); - participant.setVersion(PARTICIPANT_VERSION); + var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId()); when(participantProvider.getParticipants()).thenReturn(List.of(participant)); var automationCompositionUpdatePublisher = mock(AutomationCompositionUpdatePublisher.class); @@ -186,12 +180,9 @@ class SupervisionScannerTest { acRuntimeParameterGroup.getParticipantParameters().getUpdateParameters().setMaxWaitMs(-1); acRuntimeParameterGroup.getParticipantParameters().setMaxStatusWaitMs(-1); - var participant = new Participant(); - participant.setName(PARTICIPANT_NAME); - participant.setVersion(PARTICIPANT_VERSION); + var participant = CommonTestData.createParticipant(PARTICIPANT_TYPE, CommonTestData.getParticipantId()); participant.setParticipantState(ParticipantState.OFF_LINE); participant.setDefinition(new ToscaConceptIdentifier("unknown", "0.0.0")); - participant.setParticipantType(PARTICIPANT_TYPE); var participantProvider = mock(ParticipantProvider.class); when(participantProvider.getParticipants()).thenReturn(List.of(participant)); 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 b7d2d9303..d9c4ed67f 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 @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; import org.onap.policy.clamp.acm.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionHandler; import org.onap.policy.clamp.acm.runtime.supervision.SupervisionParticipantHandler; +import org.onap.policy.clamp.acm.runtime.util.CommonTestData; import org.onap.policy.clamp.models.acm.concepts.AutomationComposition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition; import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState; @@ -160,7 +161,7 @@ class SupervisionMessagesTest { var publisher = new ParticipantStatusReqPublisher(); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); - publisher.send(getParticipantId()); + publisher.send(CommonTestData.getParticipantId()); verify(topicSink).send(anyString()); } @@ -169,14 +170,10 @@ class SupervisionMessagesTest { var publisher = new ParticipantRegisterAckPublisher(); var topicSink = mock(TopicSink.class); publisher.active(List.of(topicSink)); - publisher.send(UUID.randomUUID(), getParticipantId(), getParticipantType()); + publisher.send(UUID.randomUUID(), CommonTestData.getParticipantId(), getParticipantType()); verify(topicSink).send(anyString()); } - private ToscaConceptIdentifier getParticipantId() { - return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0"); - } - private ToscaConceptIdentifier getParticipantType() { return new ToscaConceptIdentifier("org.onap.policy.acm.PolicyAutomationCompositionParticipant", "2.3.1"); } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java index ad8243bed..195afdc5d 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/util/CommonTestData.java @@ -94,7 +94,7 @@ public class CommonTestData { * @return a new Participant */ public static Participant createParticipant(ToscaConceptIdentifier participantType, - ToscaConceptIdentifier participantId) { + ToscaConceptIdentifier participantId) { var participant = new Participant(); participant.setDefinition(participantId); participant.setParticipantType(participantType); @@ -102,4 +102,8 @@ public class CommonTestData { participant.setVersion(participantId.getVersion()); return participant; } + + public static ToscaConceptIdentifier getParticipantId() { + return new ToscaConceptIdentifier("org.onap.PM_Policy", "1.0.0"); + } } |