diff options
author | Liam Fallon <liam.fallon@est.tech> | 2021-10-29 08:55:32 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-10-29 08:55:32 +0000 |
commit | 0086ef431dfea90dc0a4143ba8121bac14c8ee3f (patch) | |
tree | 227eb8a55fde32554e68c7849d5d23c15a353db1 /participant/participant-impl/participant-impl-simulator | |
parent | 5b1714f58b0e9543a2dda894b5daa0148d28d741 (diff) | |
parent | e90fadeec27e0249bb64da08d817fa1c475630fa (diff) |
Merge "Move code to common, avoid duplication"
Diffstat (limited to 'participant/participant-impl/participant-impl-simulator')
-rw-r--r-- | participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java | 71 |
1 files changed, 4 insertions, 67 deletions
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java index bd3316abb..c9848248e 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java @@ -33,9 +33,9 @@ import java.util.Set; import java.util.UUID; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.onap.policy.clamp.controlloop.common.utils.CommonUtils; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; @@ -166,39 +166,12 @@ public final class TestListenerUtils { List<ParticipantUpdates> participantUpdates = new ArrayList<>(); for (ControlLoopElement element : elements.values()) { - prepareParticipantUpdateForControlLoop(element, participantUpdates); + CommonUtils.prepareParticipantUpdate(element, participantUpdates); } clUpdateMsg.setParticipantUpdatesList(participantUpdates); return clUpdateMsg; } - private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement, - List<ParticipantUpdates> participantUpdates) { - if (participantUpdates.isEmpty()) { - participantUpdates.add(getControlLoopElementList(clElement)); - } else { - boolean participantExists = false; - for (ParticipantUpdates participantUpdate : participantUpdates) { - if (participantUpdate.getParticipantId().equals(clElement.getParticipantId())) { - participantUpdate.getControlLoopElementList().add(clElement); - participantExists = true; - } - } - if (!participantExists) { - participantUpdates.add(getControlLoopElementList(clElement)); - } - } - } - - private static ParticipantUpdates getControlLoopElementList(ControlLoopElement clElement) { - ParticipantUpdates participantUpdate = new ParticipantUpdates(); - List<ControlLoopElement> controlLoopElementList = new ArrayList<>(); - participantUpdate.setParticipantId(clElement.getParticipantId()); - controlLoopElementList.add(clElement); - participantUpdate.setControlLoopElementList(controlLoopElementList); - return participantUpdate; - } - /** * Method to create participantUpdateMsg. * @@ -226,8 +199,8 @@ public final class TestListenerUtils { toscaServiceTemplate)) { var clParticipantType = ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); - prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(), - toscaInputEntry.getValue(), participantDefinitionUpdates); + CommonUtils.prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(), + toscaInputEntry.getValue(), participantDefinitionUpdates, null); } } @@ -235,42 +208,6 @@ public final class TestListenerUtils { return participantUpdateMsg; } - private static 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 static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition, - ToscaConceptIdentifier clParticipantType, - List<ControlLoopElementDefinition> controlLoopElementDefinitionList) { - ParticipantDefinition participantDefinition = new ParticipantDefinition(); - participantDefinition.setParticipantType(clParticipantType); - controlLoopElementDefinitionList.add(clDefinition); - participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList); - return participantDefinition; - } - /** * Method to create ControlLoopUpdate using the arguments passed. * |