diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2021-09-24 14:14:24 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2021-09-27 13:57:23 +0100 |
commit | d426686c7bda61c7cb6872e1d7bbd527289174a4 (patch) | |
tree | 3d740224e88b4bad4e0dd3d0f90ad211039f0f2b /runtime-controlloop/src/test/java | |
parent | 6bcadaa32d556a623fb1908f08c8611786d615d6 (diff) |
Add validation participants registered in issue ControlLoop Command
Issue-ID: POLICY-3681
Change-Id: I80ad2c3b9a3b46aed01a0255b9791fa4f148ea4b
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-controlloop/src/test/java')
4 files changed, 75 insertions, 133 deletions
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java index 7f04056cf..24272e308 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java @@ -26,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.io.IOException; import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -107,7 +108,7 @@ class ControlLoopInstantiationProviderTest { @BeforeAll public static void setUpBeforeClass() throws Exception { serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_TEMPLATE_YAML), - ToscaServiceTemplate.class); + ToscaServiceTemplate.class); } /** @@ -119,8 +120,7 @@ class ControlLoopInstantiationProviderTest { public static void setupDbProviderParameters() throws PfModelException { ClRuntimeParameterGroup controlLoopParameters = CommonTestData.geParameterGroup("instantproviderdb"); - modelsProvider = - CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters()); + modelsProvider = CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters()); clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters()); participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters()); @@ -138,8 +138,8 @@ class ControlLoopInstantiationProviderTest { var participantDeregisterAckPublisher = Mockito.mock(ParticipantDeregisterAckPublisher.class); var participantUpdatePublisher = Mockito.mock(ParticipantUpdatePublisher.class); supervisionHandler = new SupervisionHandler(clProvider, participantProvider, monitoringProvider, - controlLoopUpdatePublisher, controlLoopStateChangePublisher, - participantRegisterAckPublisher, participantDeregisterAckPublisher, participantUpdatePublisher); + controlLoopUpdatePublisher, controlLoopStateChangePublisher, participantRegisterAckPublisher, + participantDeregisterAckPublisher, participantUpdatePublisher); } @BeforeEach @@ -160,13 +160,14 @@ class ControlLoopInstantiationProviderTest { @Test void testInstantiationCrud() throws Exception { + participantProvider.createParticipants(CommonTestData.createParticipants()); ControlLoops controlLoopsCreate = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Crud"); ControlLoops controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate); assertThat(controlLoopsDb.getControlLoopList()).isEmpty(); - var instantiationProvider = - new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, + supervisionHandler, participantProvider); InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate); InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate); @@ -222,8 +223,8 @@ class ControlLoopInstantiationProviderTest { ControlLoops controlLoopsDb = new ControlLoops(); controlLoopsDb.setControlLoopList(new ArrayList<>()); - var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, - commissioningProvider, supervisionHandler); + var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, + supervisionHandler, participantProvider); for (ControlLoop controlLoop : controlLoopsSource.getControlLoopList()) { ControlLoops controlLoopsFromDb = @@ -242,12 +243,12 @@ class ControlLoopInstantiationProviderTest { ControlLoop controlLoop0 = controlLoops.getControlLoopList().get(0); - var instantiationProvider = - new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, + supervisionHandler, participantProvider); assertThatThrownBy( - () -> instantiationProvider.deleteControlLoop(controlLoop0.getName(), controlLoop0.getVersion())) - .hasMessageMatching(CONTROL_LOOP_NOT_FOUND); + () -> instantiationProvider.deleteControlLoop(controlLoop0.getName(), controlLoop0.getVersion())) + .hasMessageMatching(CONTROL_LOOP_NOT_FOUND); InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoops), controlLoops); @@ -277,13 +278,13 @@ class ControlLoopInstantiationProviderTest { controlLoop.setState(state); - var instantiationProvider = - new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, + supervisionHandler, participantProvider); instantiationProvider.updateControlLoops(controlLoops); assertThatThrownBy( - () -> instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion())) - .hasMessageMatching(String.format(DELETE_BAD_REQUEST, state)); + () -> instantiationProvider.deleteControlLoop(controlLoop.getName(), controlLoop.getVersion())) + .hasMessageMatching(String.format(DELETE_BAD_REQUEST, state)); } @Test @@ -295,8 +296,8 @@ class ControlLoopInstantiationProviderTest { ControlLoops controlLoopsDb = getControlLoopsFromDb(controlLoopsCreate); assertThat(controlLoopsDb.getControlLoopList()).isEmpty(); - var instantiationProvider = - new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, + supervisionHandler, participantProvider); InstantiationResponse instantiationResponse = instantiationProvider.createControlLoops(controlLoopsCreate); InstantiationUtils.assertInstantiationResponse(instantiationResponse, controlLoopsCreate); @@ -315,10 +316,11 @@ class ControlLoopInstantiationProviderTest { ControlLoops controlLoops = InstantiationUtils .getControlLoopsFromResource(CL_INSTANTIATION_DEFINITION_NAME_NOT_FOUND_JSON, "ClElementNotFound"); - var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler, + participantProvider); // to validate control Loop, it needs to define ToscaServiceTemplate - // InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider); + // InstantiationUtils.storeToscaServiceTemplate(TOSCA_TEMPLATE_YAML, commissioningProvider); assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty(); @@ -333,15 +335,16 @@ class ControlLoopInstantiationProviderTest { assertThat(getControlLoopsFromDb(controlLoops).getControlLoopList()).isEmpty(); - var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var provider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler, + participantProvider); assertThatThrownBy(() -> provider.createControlLoops(controlLoops)) .hasMessageMatching(CONTROLLOOP_DEFINITION_NOT_FOUND); } @Test void testIssueControlLoopCommand_OrderedStateInvalid() throws ControlLoopRuntimeException, IOException { - var instantiationProvider = - new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, + supervisionHandler, participantProvider); assertThatThrownBy(() -> instantiationProvider.issueControlLoopCommand(new InstantiationCommand())) .hasMessageMatching(ORDERED_STATE_INVALID); } @@ -353,8 +356,8 @@ class ControlLoopInstantiationProviderTest { InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "V1"); assertThat(getControlLoopsFromDb(controlLoopsV1).getControlLoopList()).isEmpty(); - var instantiationProvider = - new ControlLoopInstantiationProvider(clProvider, commissioningProvider, supervisionHandler); + var instantiationProvider = new ControlLoopInstantiationProvider(clProvider, commissioningProvider, + supervisionHandler, participantProvider); InstantiationUtils.assertInstantiationResponse(instantiationProvider.createControlLoops(controlLoopsV1), controlLoopsV1); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java index 42e4ddee2..5a15687c5 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java @@ -36,6 +36,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops; +import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopPrimedResponse; import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand; import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse; @@ -43,6 +44,7 @@ import org.onap.policy.clamp.controlloop.runtime.instantiation.ControlLoopInstan import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils; import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup; import org.onap.policy.clamp.controlloop.runtime.main.rest.InstantiationController; +import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData; import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController; import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -94,6 +96,9 @@ class InstantiationControllerTest extends CommonRestController { @Autowired private ControlLoopInstantiationProvider instantiationProvider; + @Autowired + private ParticipantProvider participantProvider; + @LocalServerPort private int randomServerPort; @@ -326,10 +331,11 @@ class InstantiationControllerTest extends CommonRestController { @Test void testCommand() throws Exception { - var controlLoops = InstantiationUtils.getControlLoopsFromResource(CL_INSTANTIATION_CREATE_JSON, "Command"); instantiationProvider.createControlLoops(controlLoops); + participantProvider.createParticipants(CommonTestData.createParticipants()); + InstantiationCommand command = InstantiationUtils.getInstantiationCommandFromResource(CL_INSTANTIATION_CHANGE_STATE_JSON, "Command"); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java index bcc3a701c..70d115e47 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/comm/SupervisionMessagesTest.java @@ -24,29 +24,20 @@ package org.onap.policy.clamp.controlloop.runtime.supervision.comm; import static org.assertj.core.api.Assertions.assertThatCode; import java.time.Instant; -import java.util.ArrayList; import java.util.Collections; -import java.util.List; -import java.util.Map; import java.util.UUID; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantUtils; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ClElementStatisticsProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantStatisticsProvider; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantDeregisterAck; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegister; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantRegisterAck; -import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdate; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantUpdateAck; -import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider; import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup; import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider; import org.onap.policy.clamp.controlloop.runtime.supervision.SupervisionHandler; @@ -54,27 +45,18 @@ import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData; import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.event.comm.TopicSink; -import org.onap.policy.common.utils.coder.YamlJsonTranslator; -import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; class SupervisionMessagesTest extends CommonRestController { - private static final String TOSCA_SERVICE_TEMPLATE_YAML = - "src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml"; private static final Object lockit = new Object(); private static final CommInfrastructure INFRA = CommInfrastructure.NOOP; private static final String TOPIC = "my-topic"; private static SupervisionHandler supervisionHandler; - private static CommissioningProvider commissioningProvider; private static ControlLoopProvider clProvider; private static PolicyModelsProvider modelsProvider; - private static ParticipantProvider participantProvider; - private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator(); /** * setup Db Provider Parameters. @@ -87,13 +69,11 @@ class SupervisionMessagesTest extends CommonRestController { modelsProvider = CommonTestData.getPolicyModelsProvider(controlLoopParameters.getDatabaseProviderParameters()); clProvider = new ControlLoopProvider(controlLoopParameters.getDatabaseProviderParameters()); - participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters()); var participantStatisticsProvider = new ParticipantStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters()); var clElementStatisticsProvider = new ClElementStatisticsProvider(controlLoopParameters.getDatabaseProviderParameters()); - commissioningProvider = new CommissioningProvider(modelsProvider, clProvider, null, participantProvider); var monitoringProvider = new MonitoringProvider(participantStatisticsProvider, clElementStatisticsProvider, clProvider); var participantProvider = new ParticipantProvider(controlLoopParameters.getDatabaseProviderParameters()); @@ -114,26 +94,6 @@ class SupervisionMessagesTest extends CommonRestController { } @Test - void testReceiveParticipantRegister() throws Exception { - final ParticipantRegister participantRegisterMsg = new ParticipantRegister(); - participantRegisterMsg.setParticipantId(getParticipantId()); - participantRegisterMsg.setTimestamp(Instant.now()); - participantRegisterMsg.setParticipantType(getParticipantType()); - - synchronized (lockit) { - ParticipantRegisterListener participantRegisterListener = - new ParticipantRegisterListener(supervisionHandler); - ToscaServiceTemplate serviceTemplate = yamlTranslator.fromYaml( - ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class); - - // List<ToscaNodeTemplate> listOfTemplates = commissioningProvider.getControlLoopDefinitions(null, null); - commissioningProvider.createControlLoopDefinitions(serviceTemplate); - assertThatCode(() -> participantRegisterListener.onTopicEvent(INFRA, TOPIC, null, participantRegisterMsg)) - .doesNotThrowAnyException(); - } - } - - @Test void testSendParticipantRegisterAck() throws Exception { final ParticipantRegisterAck participantRegisterAckMsg = new ParticipantRegisterAck(); participantRegisterAckMsg.setMessage("ParticipantRegisterAck message"); @@ -178,72 +138,6 @@ class SupervisionMessagesTest extends CommonRestController { } @Test - void testSendParticipantUpdate() throws Exception { - final ParticipantUpdate participantUpdateMsg = new ParticipantUpdate(); - participantUpdateMsg.setParticipantId(getParticipantId()); - participantUpdateMsg.setTimestamp(Instant.now()); - participantUpdateMsg.setParticipantType(getParticipantType()); - participantUpdateMsg.setTimestamp(Instant.ofEpochMilli(3000)); - participantUpdateMsg.setMessageId(UUID.randomUUID()); - - ToscaServiceTemplate toscaServiceTemplate = commissioningProvider.getToscaServiceTemplate(null, null); - List<ParticipantDefinition> participantDefinitionUpdates = new ArrayList<>(); - for (Map.Entry<String, ToscaNodeTemplate> toscaInputEntry : toscaServiceTemplate.getToscaTopologyTemplate() - .getNodeTemplates().entrySet()) { - if (ParticipantUtils.checkIfNodeTemplateIsControlLoopElement(toscaInputEntry.getValue(), - toscaServiceTemplate)) { - var clParticipantType = - ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); - prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(), - toscaInputEntry.getValue(), participantDefinitionUpdates); - } - } - - participantUpdateMsg.setParticipantDefinitionUpdates(participantDefinitionUpdates); - synchronized (lockit) { - ParticipantUpdatePublisher participantUpdatePublisher = new ParticipantUpdatePublisher(modelsProvider); - participantUpdatePublisher.active(Collections.singletonList(Mockito.mock(TopicSink.class))); - assertThatCode(() -> participantUpdatePublisher.send(participantUpdateMsg)).doesNotThrowAnyException(); - } - } - - private void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey, - ToscaNodeTemplate entryValue, List<ParticipantDefinition> participantDefinitionUpdates) { - - var clDefinition = new ControlLoopElementDefinition(); - clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion())); - clDefinition.setControlLoopElementToscaNodeTemplate(entryValue); - List<ControlLoopElementDefinition> controlLoopElementDefinitionList = new ArrayList<>(); - - if (participantDefinitionUpdates.isEmpty()) { - participantDefinitionUpdates - .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); - } else { - boolean participantExists = false; - for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) { - if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) { - participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition); - participantExists = true; - } - } - if (!participantExists) { - participantDefinitionUpdates.add( - getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); - } - } - } - - private ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition, - ToscaConceptIdentifier clParticipantType, - List<ControlLoopElementDefinition> controlLoopElementDefinitionList) { - ParticipantDefinition participantDefinition = new ParticipantDefinition(); - participantDefinition.setParticipantType(clParticipantType); - controlLoopElementDefinitionList.add(clDefinition); - participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList); - return participantDefinition; - } - - @Test void testReceiveParticipantUpdateAckMessage() throws Exception { final ParticipantUpdateAck participantUpdateAckMsg = new ParticipantUpdateAck(); participantUpdateAckMsg.setMessage("ParticipantUpdateAck message"); diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java index 300c662ce..13d30e401 100644 --- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java +++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/util/CommonTestData.java @@ -20,8 +20,10 @@ package org.onap.policy.clamp.controlloop.runtime.util; +import java.util.List; import javax.ws.rs.core.Response.Status; import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException; +import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant; import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.CoderException; @@ -32,6 +34,7 @@ import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; +import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; /** * Class to hold/create all parameters for test cases. @@ -81,4 +84,40 @@ public class CommonTestData { throw new PfModelRuntimeException(e); } } + + /** + * Create a List of Participants. + * + * @return a List of Participants + */ + public static List<Participant> createParticipants() { + var participant1 = createParticipant( + new ToscaConceptIdentifier("org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", "2.3.4"), + new ToscaConceptIdentifier("org.onap.dcae.controlloop.DCAEMicroserviceControlLoopParticipant", + "2.3.4")); + var participant2 = createParticipant( + new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1"), + new ToscaConceptIdentifier("org.onap.policy.controlloop.PolicyControlLoopParticipant", "2.3.1")); + var participant3 = createParticipant( + new ToscaConceptIdentifier("org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", "2.2.1"), + new ToscaConceptIdentifier("org.onap.ccsdk.cds.controlloop.CdsControlLoopParticipant", "2.2.1")); + return List.of(participant1, participant2, participant3); + } + + /** + * Create a new Participant. + * + * @param participantType the participant Type + * @param participantId the participant id + * @return a new Participant + */ + public static Participant createParticipant(ToscaConceptIdentifier participantType, + ToscaConceptIdentifier participantId) { + var participant = new Participant(); + participant.setDefinition(participantId); + participant.setParticipantType(participantType); + participant.setName(participantId.getName()); + participant.setVersion(participantId.getVersion()); + return participant; + } } |