diff options
author | Jim Hahn <jrh3@att.com> | 2021-06-29 15:17:11 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-06-29 15:17:11 +0000 |
commit | 77aa9bc1f763e4de8d0b46fefa211e6018303514 (patch) | |
tree | f0bca729dde4ac985285386c6139610aafa04199 /participant/participant-impl/participant-impl-policy | |
parent | fef5b8c6cf7b5999d4ca9b3dbd65121b73076d01 (diff) | |
parent | 7f7f0c5790dc63e43a59c53154e796239ab34cbb (diff) |
Merge "Convert Intermediary Participant to Spring and refactor Participants"
Diffstat (limited to 'participant/participant-impl/participant-impl-policy')
3 files changed, 21 insertions, 35 deletions
diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java index 3b8324151..7b49a9a6b 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/config/ParticipantConfig.java @@ -21,29 +21,23 @@ package org.onap.policy.clamp.controlloop.participant.policy.config; import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; -import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryFactory; import org.onap.policy.clamp.controlloop.participant.policy.main.handler.ControlLoopElementHandler; -import org.onap.policy.clamp.controlloop.participant.policy.main.parameters.ParticipantPolicyParameters; -import org.springframework.context.annotation.Bean; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @Configuration public class ParticipantConfig { /** - * Create ParticipantIntermediaryApi. + * Register ControlLoopElementListener. * - * @param parameters the Participant Policy Parameters - * @param controlLoopElementHandler the ControlLoop Element Handler - * @return ParticipantIntermediaryApi + * @param intermediaryApi the ParticipantIntermediaryApi + * @param clElementHandler the ControlLoop Element Handler */ - @Bean - public ParticipantIntermediaryApi participantIntermediaryApi(ParticipantPolicyParameters parameters, - ControlLoopElementHandler controlLoopElementHandler) { - ParticipantIntermediaryApi intermediaryApi = new ParticipantIntermediaryFactory().createApiImplementation(); - intermediaryApi.init(parameters.getIntermediaryParameters()); - intermediaryApi.registerControlLoopElementListener(controlLoopElementHandler); - controlLoopElementHandler.setIntermediaryApi(intermediaryApi); - return intermediaryApi; + @Autowired + public void registerControlLoopElementListener(ParticipantIntermediaryApi intermediaryApi, + ControlLoopElementHandler clElementHandler) { + intermediaryApi.registerControlLoopElementListener(clElementHandler); + clElementHandler.setIntermediaryApi(intermediaryApi); } } diff --git a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java index 91f7ae47f..ced9d1bd0 100644 --- a/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java +++ b/participant/participant-impl/participant-impl-policy/src/main/java/org/onap/policy/clamp/controlloop/participant/policy/main/parameters/ParticipantPolicyParameters.java @@ -25,12 +25,12 @@ import javax.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantIntermediaryParameters; +import org.onap.policy.clamp.controlloop.participant.intermediary.parameters.ParticipantParameters; import org.onap.policy.common.endpoints.parameters.RestClientParameters; import org.onap.policy.common.parameters.validation.ParameterGroupConstraint; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; - /** * Class to hold all parameters needed for the policy participant. * @@ -39,7 +39,7 @@ import org.springframework.validation.annotation.Validated; @Getter @Setter @ConfigurationProperties(prefix = "participant") -public class ParticipantPolicyParameters { +public class ParticipantPolicyParameters implements ParticipantParameters { @NotNull @Valid diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java index d34a38103..6b8323971 100644 --- a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java +++ b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/controlloop/participant/policy/endtoend/ParticipantPolicyTest.java @@ -28,9 +28,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopStateChange; import org.onap.policy.clamp.controlloop.models.messages.dmaap.participant.ParticipantControlLoopUpdate; -import org.onap.policy.clamp.controlloop.participant.intermediary.api.ParticipantIntermediaryApi; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopStateChangeListener; import org.onap.policy.clamp.controlloop.participant.intermediary.comm.ControlLoopUpdateListener; +import org.onap.policy.clamp.controlloop.participant.intermediary.handler.ParticipantHandler; import org.onap.policy.clamp.controlloop.participant.policy.main.utils.TestListenerUtils; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.springframework.beans.factory.annotation.Autowired; @@ -49,7 +49,7 @@ class ParticipantPolicyTest { private static final String TOPIC = "my-topic"; @Autowired - private ParticipantIntermediaryApi participantIntermediaryApi; + private ParticipantHandler participantHandler; @Test void testUpdatePolicyTypes() { @@ -60,14 +60,12 @@ class ParticipantPolicyTest { assertNotNull(participantControlLoopUpdateMsg.getControlLoopDefinition().getPolicyTypes()); synchronized (lockit) { - ControlLoopUpdateListener clUpdateListener = - new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler()); + ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler); clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg); } // Verify the result of GET participants with what is stored - assertEquals("org.onap.PM_Policy", - participantIntermediaryApi.getParticipantHandler().getParticipantId().getName()); + assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName()); } @Test @@ -83,14 +81,12 @@ class ParticipantPolicyTest { participantControlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies()); synchronized (lockit) { - ControlLoopUpdateListener clUpdateListener = - new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler()); + ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler); clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg); } // Verify the result of GET participants with what is stored - assertEquals("org.onap.PM_Policy", - participantIntermediaryApi.getParticipantHandler().getParticipantId().getName()); + assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName()); } @Test @@ -106,24 +102,20 @@ class ParticipantPolicyTest { participantControlLoopUpdateMsg.getControlLoopDefinition().getToscaTopologyTemplate().getPolicies()); synchronized (lockit) { - ControlLoopUpdateListener clUpdateListener = - new ControlLoopUpdateListener(participantIntermediaryApi.getParticipantHandler()); + ControlLoopUpdateListener clUpdateListener = new ControlLoopUpdateListener(participantHandler); clUpdateListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopUpdateMsg); } // Verify the result of GET participants with what is stored - assertEquals("org.onap.PM_Policy", - participantIntermediaryApi.getParticipantHandler().getParticipantId().getName()); + assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName()); - ControlLoopStateChangeListener clStateChangeListener = - new ControlLoopStateChangeListener(participantIntermediaryApi.getParticipantHandler()); + ControlLoopStateChangeListener clStateChangeListener = new ControlLoopStateChangeListener(participantHandler); ParticipantControlLoopStateChange participantControlLoopStateChangeMsg = TestListenerUtils.createControlLoopStateChangeMsg(ControlLoopOrderedState.UNINITIALISED); participantControlLoopStateChangeMsg.setOrderedState(ControlLoopOrderedState.UNINITIALISED); clStateChangeListener.onTopicEvent(INFRA, TOPIC, null, participantControlLoopStateChangeMsg); // Verify the result of GET participants with what is stored - assertEquals("org.onap.PM_Policy", - participantIntermediaryApi.getParticipantHandler().getParticipantId().getName()); + assertEquals("org.onap.PM_Policy", participantHandler.getParticipantId().getName()); } } |