Merge "Add new testcase to PRH CSITs"
diff --git a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json
index ede956f..c10f0d6 100644
--- a/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json
+++ b/tests/dcaegen2/prh-testcases/assets/json_events/event_with_optional_registration_fields_missing_partial.json
@@ -4,7 +4,7 @@
"sourceName":"NOK6061ZW4"
},
"pnfRegistrationFields": {
- "oamV4IpAddress":"",
+ "oamV4IpAddress":"10.16.123.234",
"oamV6IpAddress":"",
"serialNumber":"123",
"modelNumber":"sn123243",
diff --git a/tests/dcaegen2/prh-testcases/prh_tests.robot b/tests/dcaegen2/prh-testcases/prh_tests.robot
index 429f365..e485f58 100644
--- a/tests/dcaegen2/prh-testcases/prh_tests.robot
+++ b/tests/dcaegen2/prh-testcases/prh_tests.robot
@@ -38,6 +38,7 @@
${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_ALL_FILLED}
${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_EMPTY}
${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_MISSING_ALL}
+ ${EVENT_WITH_OPTIONAL_REGISTRATION_FIELDS_MISSING_PARTIAL}
Invalid DMaaP event cannot be converted to PNF_READY notification
[Documentation] PRH get invalid event from DMaaP with missing required fields - PRH does not produce PNF_READY notification
diff --git a/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py b/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
index ee89be6..6667bd7 100644
--- a/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
+++ b/tests/dcaegen2/prh-testcases/resources/PrhLibrary.py
@@ -31,7 +31,8 @@
vendor_name = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "vendorName", "vendorName")
model_number = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "modelNumber", "modelNumber")
unit_type = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "unitType", "unitType")
- additional_fields = PrhLibrary.extract_additional_fields(json_to_python, "additionalFields")
+
+ additional_fields = PrhLibrary.extract_additional_fields(json_to_python)
str_json = '{' + correlation_id + ipv4 + ipv6 + serial_number + vendor_name + model_number + unit_type + '"nfNamingCode":""' + "," + '"softwareVersion":"",' + additional_fields
return json.dumps(str_json).replace("\\", "")[1:-1].replace("\":", "\": ").rstrip(',') + '\\n}'
@@ -44,7 +45,8 @@
vendor_name = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "equip-vendor", "vendorName")
model_number = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "equip-model", "modelNumber")
unit_type = PrhLibrary.extract_value_from_pnfRegistrationFields(json_to_python, "equip-type", "unitType")
- additional_fields = PrhLibrary.extract_additional_fields_value(json_to_python, "additionalFields")
+
+ additional_fields = PrhLibrary.extract_additional_fields_value(json_to_python)
nf_role = json_to_python.get("event").get("commonEventHeader").get("nfNamingCode") if "nfNamingCode" in json_to_python["event"]["commonEventHeader"] else ""
@@ -53,23 +55,29 @@
return json.dumps(str_json.rstrip(',') + '}').replace("\\", "")[1:-1]
@staticmethod
- def extract_additional_fields(content, name):
- fields = content.get("event").get("pnfRegistrationFields").get(name) if name in content["event"]["pnfRegistrationFields"] else []
- if fields == []:
- return '"additionalFields":' + 'null'
- res = '"' + name + '":{'
- for f in fields:
- res += '"' + f + '"' + ':' + '"' + fields.get(f) + '",'
- return res.rstrip(',') + '},'
+ def extract_additional_fields_value(content):
+ fields = PrhLibrary.get_additional_fields_as_key_value_pairs(content)
+ if len(fields) == 0:
+ return ""
+ return PrhLibrary.build_additional_fields_json(fields)
@staticmethod
- def extract_additional_fields_value(content, name):
- fields = content.get("event").get("pnfRegistrationFields").get(name) if name in content["event"]["pnfRegistrationFields"] else []
- if fields == [] or len(fields) == 0:
- return ""
- res = '"' + name + '":{'
+ def extract_additional_fields(content):
+ fields = PrhLibrary.get_additional_fields_as_key_value_pairs(content)
+ if fields == []:
+ return '"additionalFields":null'
+ return PrhLibrary.build_additional_fields_json(fields)
+
+ @staticmethod
+ def get_additional_fields_as_key_value_pairs(content):
+ return content.get("event").get("pnfRegistrationFields").get(
+ "additionalFields") if "additionalFields" in content["event"]["pnfRegistrationFields"] else []
+
+ @staticmethod
+ def build_additional_fields_json(fields):
+ res = '"additionalFields":{'
for f in fields:
- res += '"' + f + '"' + ':' + '"' + fields.get(f) + '",'
+ res += '"' + f + '":"' + fields.get(f) + '",'
return res.rstrip(',') + '},'
@staticmethod