aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMarcin Migdal <marcin.migdal@nokia.com>2018-09-07 12:59:00 +0200
committerMarcin Migdal <marcin.migdal@nokia.com>2018-09-13 16:12:18 +0200
commit577247a99292445a59e86e7bfe565a58be9a538f (patch)
tree6b0403306c9a33d5e74dbfe3d9bb2f1997db58d2 /test
parent1c760c54176f529dad26b5ab1b7875231ec2e3b3 (diff)
Extracting configs and schema for notifications
Change-Id: Id004fdaabced8efbe6aff354db608d3d1b28a63e Issue-ID: INT-607 Signed-off-by: Marcin Migdal <marcin.migdal@nokia.com>
Diffstat (limited to 'test')
-rw-r--r--test/mocks/pnfsimulator/config/config.json41
-rw-r--r--test/mocks/pnfsimulator/json_schema/input_validator.json324
-rw-r--r--test/mocks/pnfsimulator/pom.xml1
-rw-r--r--test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java30
-rw-r--r--test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java60
-rw-r--r--test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java51
-rw-r--r--test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java24
-rw-r--r--test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java7
-rw-r--r--test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java14
-rw-r--r--test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java28
-rw-r--r--test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java40
-rw-r--r--test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java17
-rw-r--r--test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java58
-rw-r--r--test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validCommonEventHeaderParams.json8
-rw-r--r--test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validNotificationParams.json20
-rw-r--r--test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validPnfRegistrationParams.json10
-rw-r--r--test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validSimulatorParams.json5
17 files changed, 449 insertions, 289 deletions
diff --git a/test/mocks/pnfsimulator/config/config.json b/test/mocks/pnfsimulator/config/config.json
index 2a67be511..6311d5ef5 100644
--- a/test/mocks/pnfsimulator/config/config.json
+++ b/test/mocks/pnfsimulator/config/config.json
@@ -1,24 +1,45 @@
-
{
"simulatorParams": {
"vesServerUrl": "http://VES-HOST:VES-PORT/eventListener/v7",
"testDuration": "10",
"messageInterval": "1"
},
- "messageParams": {
- "pnf_serialNumber": "6061ZW3",
- "pnf_vendorName": "Nokia",
- "pnf_oamV4IpAddress": "val3",
- "pnf_oamV6IpAddress": "val4",
- "pnf_unitFamily": "BBU",
- "pnf_modelNumber": "val6",
- "pnf_softwareVersion": "val7",
- "pnf_unitType": "val8",
+ "commonEventHeaderParams": {
"eventName": "pnfRegistration_Nokia_5gDu",
"nfNamingCode": "gNB",
"nfcNamingCode": "oam",
"sourceName": "NOK6061ZW3",
"sourceId": "val13",
"reportingEntityName": "NOK6061ZW3"
+ },
+ "pnfRegistrationParams": {
+ "serialNumber": "6061ZW3",
+ "vendorName": "Nokia",
+ "oamV4IpAddress": "val3",
+ "oamV6IpAddress": "val4",
+ "unitFamily": "BBU",
+ "modelNumber": "val6",
+ "softwareVersion": "val7",
+ "unitType": "val8"
+ },
+ "notificationParams": {
+ "changeIdentifier": "PM_MEAS_FILES",
+ "changeType": "FileReady",
+ "arrayOfNamedHashMap": [
+ {"name": "A20161221.1031-1041.bin.gz", "hashMap": {
+ "location": "ftpes://192.169.0.1:22/ftp/rop/A20161224.1030-1045.bin.gz",
+ "compression": "gzip",
+ "fileformatType": "org.3GPP.32.435#measCollec",
+ "fileFormatVersion": "V10"
+ }
+ },
+ {"name": "A20161222.1042-1102.bin.gz", "hashMap": {
+ "location": "ftpes://192.168.0.102:22/ftp/rop/A20161224.1045-1100.bin.gz",
+ "compression": "gzip",
+ "fileFormatType": "org.3GPP.32.435#measCollec",
+ "fileFormatVersion": "V10"
+ }
+ }
+ ]
}
}
diff --git a/test/mocks/pnfsimulator/json_schema/input_validator.json b/test/mocks/pnfsimulator/json_schema/input_validator.json
index 195f4bf35..d278bfc87 100644
--- a/test/mocks/pnfsimulator/json_schema/input_validator.json
+++ b/test/mocks/pnfsimulator/json_schema/input_validator.json
@@ -1,193 +1,205 @@
{
- "$id": "http://example.com/example.json",
+ "$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
- "definitions": {},
- "$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"simulatorParams": {
- "$id": "/properties/simulatorParams",
"type": "object",
"properties": {
"vesServerUrl": {
- "$id": "/properties/simulatorParams/properties/vesServerUrl",
- "type": "string",
- "title": "The Vesserverurl Schema ",
- "default": "",
- "examples": [
- "http://10.42.111.53:VES-PORT/eventListener/v7"
- ]
+ "type": "string"
},
"testDuration": {
- "$id": "/properties/simulatorParams/properties/testDuration",
- "type": "string",
- "title": "The Testduration Schema ",
- "default": "",
- "examples": [
- "10"
- ]
+ "type": "string"
},
"messageInterval": {
- "$id": "/properties/simulatorParams/properties/messageInterval",
- "type": "string",
- "title": "The Messageinterval Schema ",
- "default": "",
- "examples": [
- "1"
- ]
+ "type": "string"
}
- }
+ },
+ "required": [
+ "vesServerUrl",
+ "testDuration",
+ "messageInterval"
+ ]
},
- "messageParams": {
- "$id": "/properties/messageParams",
+ "commonEventHeaderParams": {
"type": "object",
"properties": {
- "pnf_serialNumber": {
- "$id": "/properties/messageParams/properties/pnf_serialNumber",
- "type": "string",
- "title": "The Pnf_serialnumber Schema ",
- "default": "",
- "examples": [
- "6061ZW3"
- ]
- },
- "pnf_vendorName": {
- "$id": "/properties/messageParams/properties/pnf_vendorName",
- "type": "string",
- "title": "The Pnf_vendorname Schema ",
- "default": "",
- "examples": [
- "Nokia"
- ]
- },
- "pnf_oamV4IpAddress": {
- "$id": "/properties/messageParams/properties/pnf_oamV4IpAddress",
- "type": "string",
- "title": "The Pnf_oamv4ipaddress Schema ",
- "default": "",
- "examples": [
- "val3"
- ]
- },
- "pnf_oamV6IpAddress": {
- "$id": "/properties/messageParams/properties/pnf_oamV6IpAddress",
- "type": "string",
- "title": "The Pnf_oamv6ipaddress Schema ",
- "default": "",
- "examples": [
- "val4"
- ]
- },
- "pnf_unitFamily": {
- "$id": "/properties/messageParams/properties/pnf_unitFamily",
- "type": "string",
- "title": "The Pnf_unitfamily Schema ",
- "default": "",
- "examples": [
- "BBU"
- ]
- },
- "pnf_modelNumber": {
- "$id": "/properties/messageParams/properties/pnf_modelNumber",
- "type": "string",
- "title": "The Pnf_modelnumber Schema ",
- "default": "",
- "examples": [
- "val6"
- ]
- },
- "pnf_softwareVersion": {
- "$id": "/properties/messageParams/properties/pnf_softwareVersion",
- "type": "string",
- "title": "The Pnf_softwareversion Schema ",
- "default": "",
- "examples": [
- "val7"
- ]
- },
- "pnf_unitType": {
- "$id": "/properties/messageParams/properties/pnf_unitType",
- "type": "string",
- "title": "The Pnf_unittype Schema ",
- "default": "",
- "examples": [
- "val8"
- ]
- },
"eventName": {
- "$id": "/properties/messageParams/properties/eventName",
- "type": "string",
- "title": "The Eventname Schema ",
- "default": "",
- "examples": [
- "pnfRegistration_Nokia_5gDu"
- ]
+ "type": "string"
},
"nfNamingCode": {
- "$id": "/properties/messageParams/properties/nfNamingCode",
- "type": "string",
- "title": "The Nfnamingcode Schema ",
- "default": "",
- "examples": [
- "gNB"
- ]
+ "type": "string"
},
"nfcNamingCode": {
- "$id": "/properties/messageParams/properties/nfcNamingCode",
- "type": "string",
- "title": "The Nfcnamingcode Schema ",
- "default": "",
- "examples": [
- "oam"
- ]
+ "type": "string"
},
"sourceName": {
- "$id": "/properties/messageParams/properties/sourceName",
- "type": "string",
- "title": "The Sourcename Schema ",
- "default": "",
- "examples": [
- "NOK6061ZW3"
- ]
+ "type": "string"
},
"sourceId": {
- "$id": "/properties/messageParams/properties/sourceId",
- "type": "string",
- "title": "The Sourceid Schema ",
- "default": "",
- "examples": [
- "val13"
- ]
+ "type": "string"
},
"reportingEntityName": {
- "$id": "/properties/messageParams/properties/reportingEntityName",
- "type": "string",
- "title": "The Reportingentityname Schema ",
- "default": "",
- "examples": [
- "NOK6061ZW3"
- ]
+ "type": "string"
}
},
"required": [
- "pnf_serialNumber",
- "pnf_vendorName"
- ],
- "anyOf": [
- {
- "required": [
- "pnf_oamV4IpAddress"
- ]
+ "eventName",
+ "nfNamingCode",
+ "nfcNamingCode",
+ "sourceName",
+ "sourceId",
+ "reportingEntityName"
+ ]
+ },
+
+
+ "pnfRegistrationParams": {
+ "type": "object",
+ "properties": {
+ "serialNumber": {
+ "type": "string"
+ },
+ "vendorName": {
+ "type": "string"
},
- {
- "required": [
- "pnf_oamV6IpAddress"
+ "oamV4IpAddress": {
+ "type": "string"
+ },
+ "oamV6IpAddress": {
+ "type": "string"
+ },
+ "unitFamily": {
+ "type": "string"
+ },
+ "modelNumber": {
+ "type": "string"
+ },
+ "softwareVersion": {
+ "type": "string"
+ },
+ "unitType": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "serialNumber",
+ "vendorName",
+ "oamV4IpAddress",
+ "oamV6IpAddress",
+ "unitFamily",
+ "modelNumber",
+ "softwareVersion",
+ "unitType"
+ ]
+ },
+ "notificationParams": {
+ "type": "object",
+ "properties": {
+ "changeIdentifier": {
+ "type": "string"
+ },
+ "changeType": {
+ "type": "string"
+ },
+ "arrayOfNamedHashMap": {
+ "type": "array",
+ "items": [
+ {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "hashMap": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string"
+ },
+ "compression": {
+ "type": "string"
+ },
+ "fileformatType": {
+ "type": "string"
+ },
+ "fileFormatVersion": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "location",
+ "compression",
+ "fileformatType",
+ "fileFormatVersion"
+ ]
+ }
+ },
+ "required": [
+ "name",
+ "hashMap"
+ ]
+ },
+ {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "hashMap": {
+ "type": "object",
+ "properties": {
+ "location": {
+ "type": "string"
+ },
+ "compression": {
+ "type": "string"
+ },
+ "fileFormatType": {
+ "type": "string"
+ },
+ "fileFormatVersion": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "location",
+ "compression",
+ "fileFormatType",
+ "fileFormatVersion"
+ ]
+ }
+ },
+ "required": [
+ "name",
+ "hashMap"
+ ]
+ }
]
}
+ },
+ "required": [
+ "changeIdentifier",
+ "changeType",
+ "arrayOfNamedHashMap"
]
}
},
- "required": [
- "simulatorParams",
- "messageParams"
+
+ "oneOf": [
+ {
+ "required": [
+ "simulatorParams",
+ "pnfRegistrationParams"
+ ]
+ },
+ {
+ "required": [
+ "simulatorParams",
+ "notificationParams"
+ ]
+ }
]
+
+
} \ No newline at end of file
diff --git a/test/mocks/pnfsimulator/pom.xml b/test/mocks/pnfsimulator/pom.xml
index 563ee271f..03b3883d8 100644
--- a/test/mocks/pnfsimulator/pom.xml
+++ b/test/mocks/pnfsimulator/pom.xml
@@ -4,6 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java
index fd2b95af1..3ebf5674a 100644
--- a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java
+++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java
@@ -20,7 +20,24 @@
package org.onap.pnfsimulator.message;
-import static org.onap.pnfsimulator.message.MessageConstants.*;
+import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID;
+import static org.onap.pnfsimulator.message.MessageConstants.INTERNAL_HEADER_FIELDS;
+import static org.onap.pnfsimulator.message.MessageConstants.LAST_EPOCH_MICROSEC;
+import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION;
+import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION_VALUE;
+import static org.onap.pnfsimulator.message.MessageConstants.PNF_LAST_SERVICE_DATE;
+import static org.onap.pnfsimulator.message.MessageConstants.PNF_MANUFACTURE_DATE;
+import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION;
+import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION_VALUE;
+import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY;
+import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY_NORMAL;
+import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE;
+import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE_NUMBER;
+import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC;
+import static org.onap.pnfsimulator.message.MessageConstants.VERSION;
+import static org.onap.pnfsimulator.message.MessageConstants.VERSION_NUMBER;
+import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION;
+import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION_NUMBER;
import org.json.JSONObject;
@@ -29,9 +46,7 @@ final class JSONObjectFactory {
static JSONObject generateConstantCommonEventHeader() {
JSONObject commonEventHeader = new JSONObject();
long timestamp = System.currentTimeMillis();
- commonEventHeader.put(DOMAIN, PNF_REGISTRATION);
commonEventHeader.put(EVENT_ID, generateEventId());
- commonEventHeader.put(EVENT_TYPE, PNF_REGISTRATION);
commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp);
commonEventHeader.put(PRIORITY, PRIORITY_NORMAL);
commonEventHeader.put(SEQUENCE, SEQUENCE_NUMBER);
@@ -50,13 +65,20 @@ final class JSONObjectFactory {
return pnfRegistrationFields;
}
+ static JSONObject generateNotificationFields() {
+ JSONObject notificationFields = new JSONObject();
+ notificationFields.put(NOTIFICATION_FIELDS_VERSION, NOTIFICATION_FIELDS_VERSION_VALUE);
+ return notificationFields;
+ }
+
+
static String generateEventId() {
String timeAsString = String.valueOf(System.currentTimeMillis());
return String.format("registration_%s",
timeAsString.substring(timeAsString.length() - 11, timeAsString.length() - 3));
}
- private JSONObjectFactory(){
+ private JSONObjectFactory() {
}
diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java
index 7861d5f9c..95e8f69f3 100644
--- a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java
+++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java
@@ -22,9 +22,25 @@ package org.onap.pnfsimulator.message;
public final class MessageConstants {
- public static final String SIMULATOR_PARAMS_CONTAINER = "simulatorParams";
- public static final String MESSAGE_PARAMS_CONTAINER = "messageParams";
+ public static final String SIMULATOR_PARAMS = "simulatorParams";
+ public static final String COMMON_EVENT_HEADER_PARAMS = "commonEventHeaderParams";
+ public static final String PNF_REGISTRATION_PARAMS = "pnfRegistrationParams";
+ public static final String NOTIFICATION_PARAMS = "notificationParams";
+
+ static final String COMMON_EVENT_HEADER = "commonEventHeader";
+ static final String PNF_REGISTRATION_FIELDS = "pnfRegistrationFields";
+ static final String NOTIFICATION_FIELDS = "notificationFields";
static final String EVENT = "event";
+
+ //=============================================================================================
+ //Simulation parameters
+ public static final String VES_SERVER_URL = "vesServerUrl";
+ public static final String TEST_DURATION = "testDuration";
+ public static final String MESSAGE_INTERVAL = "messageInterval";
+
+ //=============================================================================================
+ //commonEventHeader
+ //parameters
static final String DOMAIN = "domain";
static final String EVENT_ID = "eventId";
static final String EVENT_TYPE = "eventType";
@@ -34,32 +50,30 @@ public final class MessageConstants {
static final String START_EPOCH_MICROSEC = "startEpochMicrosec";
static final String INTERNAL_HEADER_FIELDS = "internalHeaderFields";
static final String VERSION = "version";
- static final String PNF_REGISTRATION_FIELDS_VERSION = "pnfRegistrationFieldsVersion";
- static final String PNF_LAST_SERVICE_DATE = "lastServiceDate";
- static final String PNF_MANUFACTURE_DATE = "manufactureDate";
static final String VES_EVENT_LISTENER_VERSION = "vesEventListenerVersion";
-
- // mandatory used in json file, but not in java logic
- //public static final String PNF_OAM_IPV4_ADDRESS = "pnfOamIpv4Address";
- //public static final String PNF_OAM_IPV6_ADDRESS = "pnfOamIpv6Address";
- //public static final String PNF_SERIAL_NUMBER = "pnfSerialNumber";
- //public static final String PNF_VENDOR_NAME = "pnfVendorName";
- public static final String VES_SERVER_URL = "vesServerUrl";
- public static final String TEST_DURATION = "testDuration";
- public static final String MESSAGE_INTERVAL = "messageInterval";
- static final String PNF_PREFIX = "pnf_";
- static final String COMMON_EVENT_HEADER = "commonEventHeader";
- static final String PNF_REGISTRATION_FIELDS = "pnfRegistrationFields";
-
-
- //===============================================================
//constant values
- static final String PNF_REGISTRATION ="pnfRegistration";
- static final String PRIORITY_NORMAL = "Normal";
+ static final int SEQUENCE_NUMBER = 0;
static final String VERSION_NUMBER = "4.0.1";
static final String VES_EVENT_LISTENER_VERSION_NUMBER = "7.0.1";
+ static final String PRIORITY_NORMAL = "Normal";
+
+ //=============================================================================================
+ //PNF registration
+ //parameters
+ static final String PNF_REGISTRATION_FIELDS_VERSION = "pnfRegistrationFieldsVersion";
+ static final String PNF_LAST_SERVICE_DATE = "lastServiceDate";
+ static final String PNF_MANUFACTURE_DATE = "manufactureDate";
+ //constant values
static final String PNF_REGISTRATION_FIELDS_VERSION_VALUE = "2.0";
- static final int SEQUENCE_NUMBER = 0;
+ static final String DOMAIN_PNF_REGISTRATION ="pnfRegistration";
+
+ //=============================================================================================
+ // Notifications
+ //parameters
+ static final String NOTIFICATION_FIELDS_VERSION = "notificationFieldsVersion";
+ //constant values
+ static final String NOTIFICATION_FIELDS_VERSION_VALUE = "2.0";
+ static final String DOMAIN_NOTIFICATION ="notification";
private MessageConstants() {
}
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..4931c3b91 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,61 @@
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 javax.annotation.Nonnull;
import org.json.JSONObject;
public class MessageProvider {
- public JSONObject createMessage(JSONObject params) {
+ public JSONObject createMessage(@Nonnull JSONObject commonEventHeaderParams,@Nonnull Optional<JSONObject> pnfRegistrationParams,
+ @Nonnull Optional<JSONObject> 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<String, Object> paramsMap = params.toMap();
- JSONObject root = new JSONObject();
JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
- JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields();
+ Map<String, Object> 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<String, Object> paramersMap, JSONObject fieldsJsonObject) {
+ paramersMap.forEach((key, value) -> {
+ fieldsJsonObject.put(key, value);
+ });
+ }
+
}
diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
index 3b275a66f..506d21b6c 100644
--- a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
+++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
@@ -27,7 +27,8 @@ import static org.onap.pnfsimulator.logging.MDCVariables.RESPONSE_CODE;
import static org.onap.pnfsimulator.logging.MDCVariables.SERVICE_NAME;
import static org.onap.pnfsimulator.logging.MDCVariables.X_INVOCATION_ID;
import static org.onap.pnfsimulator.logging.MDCVariables.X_ONAP_REQUEST_ID;
-import static org.onap.pnfsimulator.message.MessageConstants.SIMULATOR_PARAMS_CONTAINER;
+import static org.onap.pnfsimulator.message.MessageConstants.SIMULATOR_PARAMS;
+import static org.onap.pnfsimulator.message.MessageConstants.COMMON_EVENT_HEADER_PARAMS;
import static org.onap.pnfsimulator.rest.util.ResponseBuilder.MESSAGE;
import static org.onap.pnfsimulator.rest.util.ResponseBuilder.REMAINING_TIME;
import static org.onap.pnfsimulator.rest.util.ResponseBuilder.SIMULATOR_STATUS;
@@ -40,6 +41,7 @@ import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
+import java.util.Optional;
import java.util.UUID;
import org.json.JSONException;
import org.json.JSONObject;
@@ -65,7 +67,6 @@ import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-
@RestController
@RequestMapping("/simulator")
public class SimulatorController {
@@ -74,7 +75,6 @@ public class SimulatorController {
private static final DateFormat RESPONSE_DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss,SSS");
private final Marker ENTRY = MarkerFactory.getMarker("ENTRY");
private Simulator simulator;
-
private JSONValidator validator;
private SimulatorFactory factory;
@@ -90,7 +90,7 @@ public class SimulatorController {
MDC.put(INVOCATION_ID, headers.getFirst(X_INVOCATION_ID));
MDC.put(INSTANCE_UUID, UUID.randomUUID().toString());
MDC.put(SERVICE_NAME, "/simulator/start");
- LOGGER.info(ENTRY,"Simulator starting");
+ LOGGER.info(ENTRY, "Simulator starting");
if (isSimulatorRunning()) {
MDC.put(RESPONSE_CODE, BAD_REQUEST.toString());
@@ -103,12 +103,15 @@ public class SimulatorController {
try {
validator.validate(message, "json_schema/input_validator.json");
-
JSONObject root = new JSONObject(message);
- JSONObject simulatorParams = root.getJSONObject(SIMULATOR_PARAMS_CONTAINER);
- JSONObject messageParams = root.getJSONObject(MessageConstants.MESSAGE_PARAMS_CONTAINER);
-
- simulator = factory.create(simulatorParams, messageParams);
+ JSONObject simulatorParams = root.getJSONObject(SIMULATOR_PARAMS);
+ JSONObject commonEventHeaderParams = root.getJSONObject(COMMON_EVENT_HEADER_PARAMS);
+ Optional<JSONObject> pnfRegistrationFields = root.has(MessageConstants.PNF_REGISTRATION_PARAMS) ? Optional
+ .of(root.getJSONObject(MessageConstants.PNF_REGISTRATION_PARAMS)) : Optional.empty();
+ Optional<JSONObject> notificationFields = root.has(MessageConstants.NOTIFICATION_PARAMS) ? Optional
+ .of(root.getJSONObject(MessageConstants.NOTIFICATION_PARAMS)) : Optional.empty();
+ simulator = factory
+ .create(simulatorParams, commonEventHeaderParams, pnfRegistrationFields, notificationFields);
simulator.start();
MDC.put(RESPONSE_CODE, OK.toString());
@@ -145,8 +148,7 @@ public class SimulatorController {
.put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
.put(MESSAGE, "Unexpected exception: " + e.getMessage())
.build();
- }
- finally {
+ } finally {
MDC.clear();
}
}
diff --git a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
index 394864431..046c97cad 100644
--- a/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
+++ b/test/mocks/pnfsimulator/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
@@ -28,6 +28,7 @@ import static org.onap.pnfsimulator.message.MessageConstants.VES_SERVER_URL;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import java.io.IOException;
import java.time.Duration;
+import java.util.Optional;
import org.json.JSONObject;
import org.onap.pnfsimulator.message.MessageProvider;
import org.onap.pnfsimulator.simulator.validation.JSONValidator;
@@ -49,13 +50,15 @@ public class SimulatorFactory {
this.validator = validator;
}
- public Simulator create(JSONObject simulatorParams, JSONObject messageParams)
+ public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams,
+ Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams)
throws ProcessingException, IOException, ValidationException {
Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION)));
Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL)));
String vesUrl = simulatorParams.getString(VES_SERVER_URL);
- JSONObject messageBody = messageProvider.createMessage(messageParams);
+ JSONObject messageBody = messageProvider
+ .createMessage(commonEventHeaderParams, pnfRegistrationParams, notificationParams);
validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH);
return Simulator.builder()
diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java
index bc3d17f79..4331195c9 100644
--- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java
+++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java
@@ -32,18 +32,14 @@ public class JSONObjectFactoryTest {
@Test
public void generateConstantCommonEventHeader_shouldCreateProperly(){
JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
- assertEquals(10,commonEventHeader.toMap().size());
- assertTrue(commonEventHeader.has(DOMAIN));
+ assertEquals(8,commonEventHeader.toMap().size());
assertTrue(commonEventHeader.has(EVENT_ID));
- assertTrue(commonEventHeader.has(EVENT_TYPE));
assertTrue(commonEventHeader.has(LAST_EPOCH_MICROSEC));
assertTrue(commonEventHeader.has(PRIORITY));
assertTrue(commonEventHeader.has(SEQUENCE));
assertTrue(commonEventHeader.has(START_EPOCH_MICROSEC));
assertTrue(commonEventHeader.has(INTERNAL_HEADER_FIELDS));
assertTrue(commonEventHeader.has(VERSION));
- assertEquals(commonEventHeader.get(DOMAIN),PNF_REGISTRATION);
- assertEquals(commonEventHeader.get(EVENT_TYPE),PNF_REGISTRATION);
assertEquals(commonEventHeader.get(PRIORITY),PRIORITY_NORMAL);
assertEquals(commonEventHeader.get(SEQUENCE),SEQUENCE_NUMBER);
assertEquals(commonEventHeader.get(VERSION),VERSION_NUMBER);
@@ -66,4 +62,12 @@ public class JSONObjectFactoryTest {
assertTrue(eventId.startsWith("registration_"));
}
+ @Test
+ public void generateNotificationFields_shouldCreateProperly(){
+ JSONObject notificationFields = JSONObjectFactory.generateNotificationFields();
+ assertEquals(1,notificationFields.keySet().size());
+ assertEquals(NOTIFICATION_FIELDS_VERSION_VALUE,notificationFields.get(NOTIFICATION_FIELDS_VERSION));
+
+ }
+
}
diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java
index 3d1f25397..d40e29cee 100644
--- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java
+++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java
@@ -25,8 +25,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.onap.pnfsimulator.message.MessageConstants.COMMON_EVENT_HEADER;
import static org.onap.pnfsimulator.message.MessageConstants.EVENT;
+import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS;
import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS;
+import java.util.Optional;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -44,22 +46,24 @@ public class MessageProviderTest {
}
@Test
- public void createMessage_should_throw_when_given_null_argument() {
+ public void createMessage_should_throw_when_given_empty_arguments() {
assertThrows(IllegalArgumentException.class,
- () -> messageProvider.createMessage(null),
+ () -> messageProvider.createMessage(new JSONObject(),Optional.empty(),Optional.empty()),
"Params object cannot be null");
}
@Test
public void createMessage_should_create_constant_message_when_no_params_specified() {
- JSONObject message = messageProvider.createMessage(new JSONObject());
+ JSONObject message = messageProvider.createMessage(new JSONObject(),Optional.ofNullable(new JSONObject()),Optional.ofNullable(new JSONObject()));
JSONObject event = message.getJSONObject(EVENT);
JSONObject commonEventHeader = event.getJSONObject(COMMON_EVENT_HEADER);
JSONObject pnfRegistrationFields = event.getJSONObject(PNF_REGISTRATION_FIELDS);
+ JSONObject notificationFields = event.getJSONObject(NOTIFICATION_FIELDS);
JSONObject expectedCommonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
JSONObject expectedPnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields();
+ JSONObject expectedNotificationFields = JSONObjectFactory.generateNotificationFields();
expectedCommonEventHeader
.toMap()
@@ -70,22 +74,30 @@ public class MessageProviderTest {
.toMap()
.forEach((key, val) -> assertTrue(pnfRegistrationFields.has(key),
() -> String.format("Key %s is not present", key)));
+
+ expectedNotificationFields
+ .toMap()
+ .forEach((key, val) -> assertTrue(notificationFields.has(key),
+ () -> String.format("Key %s is not present", key)));
}
+ @Test
+ public void createMessage_should_throw_exception_when_params_specified_as_empty() {
+ assertThrows(IllegalArgumentException.class, () ->messageProvider.createMessage(new JSONObject(), Optional.empty(),
+ Optional.empty()));
+ }
@Test
public void createMessage_should_add_specified_params_to_valid_subobjects() {
JSONObject params = new JSONObject(testParamsJson);
- JSONObject message = messageProvider.createMessage(params);
+ JSONObject message = messageProvider.createMessage(new JSONObject(),Optional.of(params),Optional.empty());
JSONObject event = message.getJSONObject(EVENT);
JSONObject commonEventHeader = event.getJSONObject(COMMON_EVENT_HEADER);
JSONObject pnfRegistrationFields = event.getJSONObject(PNF_REGISTRATION_FIELDS);
- assertEquals("pnfVal3", pnfRegistrationFields.getString("key3"));
- assertEquals("val1", commonEventHeader.getString("key1"));
- assertEquals("val2", commonEventHeader.getString("key2"));
- assertEquals("val4", commonEventHeader.getString("key4"));
+ assertEquals("val1", pnfRegistrationFields.getString("key1"));
+ assertEquals("val2", pnfRegistrationFields.getString("key2"));
}
}
diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
index 8cb190609..3603480bf 100644
--- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
+++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
@@ -55,25 +55,27 @@ class SimulatorControllerTest {
private static final String JSON_STATUS_EXPRESSION = "$.simulatorStatus";
private static final String PROPER_JSON = "{\n" +
" \"simulatorParams\": {\n" +
- " \"vesServerUrl\": \"http://10.154.187.70:8080/eventListener/v5\",\n" +
+ " \"vesServerUrl\": \"http://10.154.187.70:8080/eventListener/v7\",\n" +
" \"testDuration\": \"10\",\n" +
" \"messageInterval\": \"1\"\n" +
" },\n" +
- " \"messageParams\": {\n" +
- " \"pnfSerialNumber\": \"val1\",\n" +
- " \"pnfVendorName\": \"val2\",\n" +
- " \"pnfOamIpv4Address\": \"val3\",\n" +
- " \"pnfOamIpv6Address\": \"val4\",\n" +
- " \"pnfFamily\": \"val5\",\n" +
- " \"pnfModelNumber\": \"val6\",\n" +
- " \"pnfSoftwareVersion\": \"val7\",\n" +
- " \"pnfType\": \"val8\",\n" +
- " \"eventName\": \"val9\",\n" +
- " \"nfNamingCode\": \"val10\",\n" +
- " \"nfcNamingCode\": \"val11\",\n" +
- " \"sourceName\": \"val12\",\n" +
- " \"sourceId\": \"val13\",\n" +
- " \"reportingEntityName\": \"val14\"\n" +
+ " \"commonEventHeaderParams\": {\n" +
+ " \"eventName\": \"val11\",\n" +
+ " \"nfNamingCode\": \"val12\",\n" +
+ " \"nfcNamingCode\": \"val13\",\n" +
+ " \"sourceName\": \"val14\",\n" +
+ " \"sourceId\": \"val15\",\n" +
+ " \"reportingEntityName\": \"val16\",\n" +
+ " },\n" +
+
+ " \"pnfRegistrationParams\": {\n" +
+ " \"SerialNumber\": \"val1\",\n" +
+ " \"VendorName\": \"val2\",\n" +
+ " \"OamIpv4Address\": \"val3\",\n" +
+ " \"OamIpv6Address\": \"val4\",\n" +
+ " \"Family\": \"val5\",\n" +
+ " \"ModelNumber\": \"val6\",\n" +
+ " \"SoftwareVersion\": \"val7\",\n" +
" }\n" +
"}";
private static final String WRONG_JSON = "{\n" +
@@ -119,7 +121,7 @@ class SimulatorControllerTest {
@Test
void wrongJSONFormatOnStart() throws Exception {
- when(factory.create(any(), any())).thenReturn(simulator);
+ when(factory.create(any(),any(), any(),any())).thenReturn(simulator);
doThrow(new ValidationException("")).when(validator).validate(anyString(), anyString());
mockMvc.perform(post("/simulator/start").content(WRONG_JSON))
@@ -134,7 +136,7 @@ class SimulatorControllerTest {
startSimulator();
verify(validator).validate(anyString(), anyString());
- verify(factory).create(any(), any());
+ verify(factory).create(any(),any(), any(),any());
verify(simulator).start();
}
@@ -185,7 +187,7 @@ class SimulatorControllerTest {
}
private void startSimulator() throws Exception {
- when(factory.create(any(), any())).thenReturn(simulator);
+ when(factory.create(any(), any(), any(),any())).thenReturn(simulator);
mockMvc
.perform(post(START_URL).content(PROPER_JSON))
diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
index 970f8cfaa..26f66b7e0 100644
--- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
+++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
@@ -26,14 +26,15 @@ import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_MESSAGE_PARAM
import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_MESSAGE_PARAMS_2;
import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_MESSAGE_PARAMS_3;
import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_SIMULATOR_PARAMS;
-import static org.onap.pnfsimulator.simulator.TestMessages.VALID_MESSAGE_PARAMS;
+import static org.onap.pnfsimulator.simulator.TestMessages.VALID_PNF_REGISTRATION_PARAMS;
import static org.onap.pnfsimulator.simulator.TestMessages.VALID_SIMULATOR_PARAMS;
+import static org.onap.pnfsimulator.simulator.TestMessages.VALID_COMMON_EVENT_HEADER_PARAMS;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import java.io.IOException;
+import java.util.Optional;
import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.onap.pnfsimulator.message.MessageProvider;
import org.onap.pnfsimulator.simulator.validation.JSONValidator;
@@ -52,14 +53,16 @@ class SimulatorFactoryTest {
@Test
void should_successfully_create_simulator_given_valid_params_and_valid_output_message()
throws ValidationException, IOException, ProcessingException {
- assertNotNull(simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_MESSAGE_PARAMS));
+ assertNotNull(simulatorFactory.create(VALID_SIMULATOR_PARAMS,VALID_COMMON_EVENT_HEADER_PARAMS,
+ VALID_PNF_REGISTRATION_PARAMS,Optional.empty()));
}
@Test
void should_throw_given_invalid_params() {
assertThrows(
JSONException.class,
- () -> simulatorFactory.create(INVALID_SIMULATOR_PARAMS, VALID_MESSAGE_PARAMS));
+ () -> simulatorFactory.create(INVALID_SIMULATOR_PARAMS,VALID_COMMON_EVENT_HEADER_PARAMS,
+ VALID_PNF_REGISTRATION_PARAMS,Optional.empty()));
}
@Test
@@ -67,14 +70,14 @@ class SimulatorFactoryTest {
assertThrows(
ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, INVALID_MESSAGE_PARAMS_1));
+ () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS ,INVALID_MESSAGE_PARAMS_1,Optional.empty()));
assertThrows(
ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, INVALID_MESSAGE_PARAMS_2));
+ () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS, INVALID_MESSAGE_PARAMS_2,Optional.empty()));
assertThrows(
ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, INVALID_MESSAGE_PARAMS_3));
+ () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS, INVALID_MESSAGE_PARAMS_3,Optional.empty()));
}
} \ No newline at end of file
diff --git a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
index 2f166b26f..7f33e179d 100644
--- a/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
+++ b/test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
@@ -20,35 +20,34 @@
package org.onap.pnfsimulator.simulator;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Optional;
import org.json.JSONObject;
final class TestMessages {
- static final JSONObject VALID_SIMULATOR_PARAMS = new JSONObject(
- "{\n" +
- " \"vesServerUrl\": \"http://10.42.111.42:8080/eventListener/v5\",\n" +
- " \"testDuration\": \"10\",\n" +
- " \"messageInterval\": \"1\"\n" +
- "}");
+ static final JSONObject VALID_SIMULATOR_PARAMS = new JSONObject(getContent("validSimulatorParams.json"));
+ static final JSONObject VALID_COMMON_EVENT_HEADER_PARAMS = new JSONObject(getContent("validCommonEventHeaderParams.json"));
+ static final Optional<JSONObject> VALID_PNF_REGISTRATION_PARAMS = Optional.ofNullable(new JSONObject(getContent("validPnfRegistrationParams.json")));
+
+ private static String getContent(String fileName){
+ try {
+ String pathAsString = TestMessages.class.getResource(fileName).getPath();
+ Path path = Paths.get(pathAsString);
+ StringBuilder stringBuilder = new StringBuilder();
+ Files.readAllLines(path).forEach(line -> {
+ stringBuilder.append(line);
+ });
+ return stringBuilder.toString();
+ } catch (IOException e) {
+ throw new RuntimeException(String.format("Cannot read JSON file %s",fileName));
+ }
- static final JSONObject VALID_MESSAGE_PARAMS = new JSONObject(
- "{\n"
- + " \"pnf_serialNumber\": \"6061ZW3\",\n"
- + " \"pnf_vendorName\": \"Nokia\",\n"
- + " \"pnf_oamV4IpAddress\": \"val3\",\n"
- + " \"pnf_oamV6IpAddress\": \"val4\",\n"
- + " \"pnf_unitFamily\": \"BBU\",\n"
- + " \"pnf_modelNumber\": \"val6\",\n"
- + " \"pnf_softwareVersion\": \"val7\",\n"
- + " \"pnf_unitType\": \"val8\",\n"
- + " \"eventName\": \"pnfRegistration_Nokia_5gDu\",\n"
- + " \"nfNamingCode\": \"gNB\",\n"
- + " \"nfcNamingCode\": \"oam\",\n"
- + " \"sourceName\": \"NOK6061ZW3\",\n"
- + " \"sourceId\": \"val13\",\n"
- + " \"reportingEntityName\": \"NOK6061ZW3\"\n"
- + " }");
+ }
static final JSONObject INVALID_SIMULATOR_PARAMS = new JSONObject(
"{\n" +
@@ -57,7 +56,7 @@ final class TestMessages {
"}");
- static final JSONObject INVALID_MESSAGE_PARAMS_1 = new JSONObject(
+ static final Optional<JSONObject> INVALID_MESSAGE_PARAMS_1 = Optional.ofNullable(new JSONObject(
"{\n" +
" \"pnfSerialNumber\": \"val1\",\n" +
" \"pnfVendorName\": \"val2\",\n" +
@@ -71,9 +70,9 @@ final class TestMessages {
" \"sourceName\": \"val12\",\n" +
" \"sourceId\": \"val13\",\n" +
" \"reportingEntityName\": \"val14\"\n" +
- "}");
+ "}"));
- static final JSONObject INVALID_MESSAGE_PARAMS_2 = new JSONObject(
+ static final Optional<JSONObject> INVALID_MESSAGE_PARAMS_2 = Optional.ofNullable(new JSONObject(
"{\n" +
" \"pnfVendorName\": \"val2\",\n" +
" \"pnfOamIpv4Address\": \"val3\",\n" +
@@ -88,9 +87,9 @@ final class TestMessages {
" \"sourceName\": \"val12\",\n" +
" \"sourceId\": \"val13\",\n" +
" \"reportingEntityName\": \"val14\"\n" +
- "}");
+ "}"));
- static final JSONObject INVALID_MESSAGE_PARAMS_3 = new JSONObject(
+ static final Optional<JSONObject> INVALID_MESSAGE_PARAMS_3 = Optional.ofNullable(new JSONObject(
"{\n" +
" \"pnfSerialNumber\": \"val1\",\n" +
" \"pnfOamIpv4Address\": \"val3\",\n" +
@@ -104,7 +103,8 @@ final class TestMessages {
" \"sourceName\": \"val12\",\n" +
" \"sourceId\": \"val13\",\n" +
" \"reportingEntityName\": \"val14\"\n" +
- "}");
+ "}"));
+
private TestMessages() {
}
diff --git a/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validCommonEventHeaderParams.json b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validCommonEventHeaderParams.json
new file mode 100644
index 000000000..e0f455045
--- /dev/null
+++ b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validCommonEventHeaderParams.json
@@ -0,0 +1,8 @@
+{
+ "eventName": "pnfRegistration_Nokia_5gDu",
+ "nfNamingCode": "gNB",
+ "nfcNamingCode": "oam",
+ "sourceName": "NOK6061ZW3",
+ "sourceId": "val13",
+ "reportingEntityName": "NOK6061ZW3"
+} \ No newline at end of file
diff --git a/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validNotificationParams.json b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validNotificationParams.json
new file mode 100644
index 000000000..f7f463d3d
--- /dev/null
+++ b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validNotificationParams.json
@@ -0,0 +1,20 @@
+{
+ "changeIdentifier": "PM_MEAS_FILES",
+ "changeType": "FileReady",
+ "arrayOfNamedHashMap": [
+ {"name": "A20161221.1031-1041.bin.gz", "hashMap": {
+ "location": "ftpes://192.169.0.1:22/ftp/rop/A20161224.1030-1045.bin.gz",
+ "compression": "gzip",
+ "fileformatType": "org.3GPP.32.435#measCollec",
+ "fileFormatVersion": "V10"
+ }
+ },
+ {"name": "A20161222.1042-1102.bin.gz", "hashMap": {
+ "location": "ftpes://192.168.0.102:22/ftp/rop/A20161224.1045-1100.bin.gz",
+ "compression": "gzip",
+ "fileFormatType": "org.3GPP.32.435#measCollec",
+ "fileFormatVersion": "V10"
+ }
+ }
+ ]
+}
diff --git a/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validPnfRegistrationParams.json b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validPnfRegistrationParams.json
new file mode 100644
index 000000000..b95f8e60a
--- /dev/null
+++ b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validPnfRegistrationParams.json
@@ -0,0 +1,10 @@
+{
+ "serialNumber": "6061ZW3",
+ "vendorName": "Nokia",
+ "oamV4IpAddress": "val3",
+ "oamV6IpAddress": "val4",
+ "unitFamily": "BBU",
+ "modelNumber": "val6",
+ "softwareVersion": "val7",
+ "unitType": "val8"
+} \ No newline at end of file
diff --git a/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validSimulatorParams.json b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validSimulatorParams.json
new file mode 100644
index 000000000..6485ee4a4
--- /dev/null
+++ b/test/mocks/pnfsimulator/src/test/resources/org/onap/pnfsimulator/simulator/validSimulatorParams.json
@@ -0,0 +1,5 @@
+{
+ "vesServerUrl": "http://VES-HOST:VES-PORT/eventListener/v7",
+ "testDuration": "10",
+ "messageInterval": "1"
+} \ No newline at end of file