X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=test%2Fmocks%2Fpnfsimulator%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpnfsimulator%2Fmessage%2FMessageProvider.java;h=13114eefba3f2342f2410c7165c05e2a1d3f1672;hb=8bd009b7200d34b4c168a945de3d4dae03cade2e;hp=7c3bf9ef877083854653d15e5c55dc7eddcc91e5;hpb=bfaa0be87a23df95f66a224cbc58c12827443381;p=integration.git diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java index 7c3bf9ef8..13114eefb 100644 --- a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java +++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java @@ -21,40 +21,60 @@ package org.onap.pnfsimulator.message; import static org.onap.pnfsimulator.message.MessageConstants.COMMON_EVENT_HEADER; +import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN; import static org.onap.pnfsimulator.message.MessageConstants.EVENT; -import static org.onap.pnfsimulator.message.MessageConstants.PNF_PREFIX; +import static org.onap.pnfsimulator.message.MessageConstants.EVENT_TYPE; +import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS; +import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN_PNF_REGISTRATION; +import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN_NOTIFICATION; import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS; import java.util.Map; +import java.util.Optional; import org.json.JSONObject; public class MessageProvider { - public JSONObject createMessage(JSONObject params) { + public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional pnfRegistrationParams, + Optional notificationParams) { - if (params == null) { - throw new IllegalArgumentException("Params object cannot be null"); + if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) { + throw new IllegalArgumentException( + "Both PNF registration and notification parameters objects are not present"); } + JSONObject event = new JSONObject(); - Map paramsMap = params.toMap(); - JSONObject root = new JSONObject(); JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader(); - JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields(); + Map commonEventHeaderFields = commonEventHeaderParams.toMap(); + commonEventHeaderFields.forEach((key, value) -> { + commonEventHeader.put(key, value); + }); - paramsMap.forEach((key, value) -> { + JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields(); + pnfRegistrationParams.ifPresent(jsonObject -> { + copyParametersToFields(jsonObject.toMap(), pnfRegistrationFields); + commonEventHeader.put(DOMAIN, DOMAIN_PNF_REGISTRATION); + commonEventHeader.put(EVENT_TYPE, DOMAIN_PNF_REGISTRATION); + event.put(PNF_REGISTRATION_FIELDS, pnfRegistrationFields); + }); - if (key.startsWith(PNF_PREFIX)) { - pnfRegistrationFields.put(key.substring(PNF_PREFIX.length()), value); - } else { - commonEventHeader.put(key, value); - } + JSONObject notificationFields = JSONObjectFactory.generateNotificationFields(); + notificationParams.ifPresent(jsonObject -> { + copyParametersToFields(jsonObject.toMap(), notificationFields); + commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION); + event.put(NOTIFICATION_FIELDS, notificationFields); }); - JSONObject event = new JSONObject(); event.put(COMMON_EVENT_HEADER, commonEventHeader); - event.put(PNF_REGISTRATION_FIELDS, pnfRegistrationFields); + JSONObject root = new JSONObject(); root.put(EVENT, event); return root; } + private void copyParametersToFields(Map paramersMap, JSONObject fieldsJsonObject) { + paramersMap.forEach((key, value) -> { + fieldsJsonObject.put(key, value); + }); + } + }