summaryrefslogtreecommitdiffstats
path: root/test/mocks
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocks')
-rw-r--r--test/mocks/pnfsimulator/README.md8
-rw-r--r--test/mocks/pnfsimulator/config/config.json41
-rw-r--r--test/mocks/pnfsimulator/docker-compose.yml18
-rwxr-xr-xtest/mocks/pnfsimulator/ftpes/tls/pure-ftpd.pem49
-rwxr-xr-xtest/mocks/pnfsimulator/ftpes/userpass/pureftpd.passwd1
-rw-r--r--test/mocks/pnfsimulator/json_schema/input_validator.json326
-rw-r--r--test/mocks/pnfsimulator/pom.xml5
-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.java50
-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.java46
-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.java42
-rw-r--r--test/mocks/pnfsimulator/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java67
-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
-rw-r--r--test/mocks/sniroemulator/pom.xml8
22 files changed, 571 insertions, 308 deletions
diff --git a/test/mocks/pnfsimulator/README.md b/test/mocks/pnfsimulator/README.md
index d53a07521..b1ff56035 100644
--- a/test/mocks/pnfsimulator/README.md
+++ b/test/mocks/pnfsimulator/README.md
@@ -14,6 +14,7 @@ The configuration for simulator is stored in */config/config.json* file.
It contains all parameters for simulation such as duration time,interval between messages and values of the configurable fields of VES message.
If you want to change duration or value of message sending to VES collector you just need to edit this file.
The message that is being sent to VES is built inside the simulator and it's content can be found in log of the simulator.
+Proper config must contain *simulatorParams*, *commonEventHeaderParams* and *pnfRegistrationParams* or notificationParams.
###Running simulator
The recommended way is to checkout PNF Simulator project from ONAP Git repository and use *simulator*.sh script
@@ -32,6 +33,13 @@ Connection to SFTP server is being done with usage of SSH keys. Private key is s
In order to download *sftp-file.txt* file simply run *sftp -P 2222 -i ssh/ssh_host_rsa_key sftp-user@localhost:sftp/sftp-file.txt*
In order to add a new file (e.g. test.zip), put the file into *sftp* directory and run simulator.
After that again execute sftp command: *sftp -P 2222 -i ssh/ssh_host_rsa_key sftp-user@localhost:sftp/test.zip*
+In order to disable usage of SSH keys and start using password, change in *docker-compose.yml* service *sftp-service* entry *command* from *sftp-user::1001* to *sftp-user:password:1001*
+
+###FTPES support
+PNF Simulator allows to serve files via FTPES server. FTPES server has predefined user: onap with password: pano.
+In order to connect we execute command *ftp-ssl host* and then enter user name and password.
+In order to download execute command while logged in*get file_name*.
+In order to add a new file execute command while logged in*put file_name*.
###Developer mode
For development of PNF Simulator, run *simulator.sh* start-dev in order to run Netopeer.
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/docker-compose.yml b/test/mocks/pnfsimulator/docker-compose.yml
index 5f73cde74..f3500d248 100644
--- a/test/mocks/pnfsimulator/docker-compose.yml
+++ b/test/mocks/pnfsimulator/docker-compose.yml
@@ -27,6 +27,7 @@ services:
restart: on-failure
depends_on:
- sftp-server
+ - ftpes-server
sftp-server:
container_name: sftp-server
@@ -37,4 +38,19 @@ services:
- ./sftp:/home/sftp-user/sftp
- ./ssh/ssh_host_rsa_key.pub:/home/sftp-user/.ssh/keys/ssh_host_rsa_key.pub:ro
restart: on-failure
- command: sftp-user::1001 \ No newline at end of file
+ command: sftp-user::1001
+
+ ftpes-server:
+ container_name: ftpes-server
+ image: stilliard/pure-ftpd:latest
+ ports:
+ - "2221:21"
+# - "30000-30009:30000-30009"
+ volumes:
+ - ./ftpes/userpass/:/etc/pure-ftpd/passwd/
+ - ./ftpes/tls/:/etc/ssl/private/
+ environment:
+ PUBLICHOST: localhost
+ ADDED_FLAGS: --tls=2
+# entrypoint: /run.sh -c 5 -C 5 -l puredb:/etc/pure-ftpd/pureftpd.pdb -E -j -R -p 30000:30009
+ restart: on-failure \ No newline at end of file
diff --git a/test/mocks/pnfsimulator/ftpes/tls/pure-ftpd.pem b/test/mocks/pnfsimulator/ftpes/tls/pure-ftpd.pem
new file mode 100755
index 000000000..0ce676efa
--- /dev/null
+++ b/test/mocks/pnfsimulator/ftpes/tls/pure-ftpd.pem
@@ -0,0 +1,49 @@
+-----BEGIN PRIVATE KEY-----
+MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHbSk5/cABTpCt
+q54QyTkhuhb84nEz5ztKL0hY56fsVtAA2gSAde+qV9YwUIuReOUhAF4RVVt2Lkn/
+1R0yX+0IjrXnO7jYzDj6QhgyqYKb3iQlvShZMMQ7qihn8qBxobk7+O10x6VLS2L8
+WYpQxGXu7T1qXbw10RhrqG8nbXYX+aHMsv9zMt9OYqKSI073OZR2vk3K49Uqcurj
+sXuRJOa10MRsxgA726pr8OLWAWejsoFaqP2fQS3HeT2RnAqPyAgPc0P6n7gxo0JU
+U5dPnrPbsvfdegIFxfc57oZXrLz7nYXkJEcjYTBFSQ+JAaRfx9kNXZ7Gft7EAMyF
+BLemY/0VAgMBAAECggEARD9bSHlKaCgW4xhEM8JpRt2EWG62BukvJSghPiupD/x1
+mpUBzWSO7GC68DXgTZxt7WlOx+fKMRuOP3sTTtX9LFyKa+PIUokxRpOv7EaOaAER
+pciiMkO6JCELSueBeOG7noaF3N0l+CqIaYvLBfDwYV/XELubWV+BV/aAc6HGNFWi
+4bjM+BOBLQstrEeJh2jVylzv4CTtlTs2pwiHFSyrHhudTk5nnATAHn1gi+X42v1A
+zk3UfqADZJmMI0/Roup4YPZ3+6zUzDN2i+qasHexL0OKIjRcSqpgqQoIeKEbKKfw
+sOgiWIR2Xvj7EJmhzJlWgKjk8OLs/7U4QpnD+s0agQKBgQDu3ojqKNWnPHy0Nupm
+tmAs28WLK76R0iZeAd2nwsU2K6lnm9z5o2ab3ffTJVB9kAetKJa3UerKskF/qF9C
+MtjlEn6F++uYFitpLjQevnyrKSqFqbzytDXrQlk+gZLglmi6YylT5k9qLSREAu55
+XS/wbm9XU2Q7sl8oTnZHXptT7QKBgQDVunvqdDn1FaNU9EwQCGPS3QGu+go22xkM
+4Rs2CoHWfqmhGOo8lJKBElDqsXvxggrZLWJe/1lgnELT/9aXS8QLWBnZxpTj9wfd
+igH+CJc3mWnLThmUGdSV/tuHon2IdQ8/1CiGSwIr9kYCnStidUtOXjIbgc6kUTTi
+5wtIGHh4yQKBgQDXJ/0dJbDklRgiX4CdCdLxNPfnlnxt7mN+s6GK1WY7l/JcD8ln
+1qW66aGrP2YT42L2tqOi9hdNgmh66xb6ksBI/XKXjsWz1Ow/Lk3mD2BN76OMh8pY
+trgGc1ndcmrw/qnQkTcNilqn4YdT92wER0rB/0cs2kFjgBQ0QxBI0s+INQKBgA6Y
+2fW9UmgGvk0DEl7V89tm9MJ6mU/9zswuY6lhNlTr+bHi/bx9eTQPiC8/R/PKqesD
+SoCqd/Q9N+M6yfEzX4RW1A0nnuui54qd7lznQUyu0abtApo22WoVKfEti91SAWSe
+nNXvMYrHGyj6iwgCcs47aLiwOOjIExCcLw0RfsjhAoGAc1zaRbrtjjh66FJYjLiJ
+Q6EXfm31ptaQQUn5rQyHMD2VRlajCYV+fv75tezf2dQvJcqHYWrEuY8U+OTbB1TB
+IEqN8ETUeLegl5RgvWoyWinqdbv/0d9LtwVBdtiEQLoYumD934mshEDgzCOOjrBe
+Salcd1vc6y6NiFooPlvloXQ=
+-----END PRIVATE KEY-----
+-----BEGIN CERTIFICATE-----
+MIIDYDCCAkigAwIBAgIJAMH2upKd2yAJMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
+BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
+aWRnaXRzIFB0eSBMdGQwHhcNMTgwOTEwMTI1ODE2WhcNMzgwOTA1MTI1ODE2WjBF
+MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
+ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
+CgKCAQEAx20pOf3AAU6QraueEMk5IboW/OJxM+c7Si9IWOen7FbQANoEgHXvqlfW
+MFCLkXjlIQBeEVVbdi5J/9UdMl/tCI615zu42Mw4+kIYMqmCm94kJb0oWTDEO6oo
+Z/KgcaG5O/jtdMelS0ti/FmKUMRl7u09al28NdEYa6hvJ212F/mhzLL/czLfTmKi
+kiNO9zmUdr5NyuPVKnLq47F7kSTmtdDEbMYAO9uqa/Di1gFno7KBWqj9n0Etx3k9
+kZwKj8gID3ND+p+4MaNCVFOXT56z27L33XoCBcX3Oe6GV6y8+52F5CRHI2EwRUkP
+iQGkX8fZDV2exn7exADMhQS3pmP9FQIDAQABo1MwUTAdBgNVHQ4EFgQUt51lQ+ab
+MTq+w2U/knCsIPb3wrkwHwYDVR0jBBgwFoAUt51lQ+abMTq+w2U/knCsIPb3wrkw
+DwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAQ69AktYLQ+VRbojz
+zC0XQ2M1FAkfJI2P0LvPoYxZgId2CnZW3sMIdnJdF+KjvOqeGyFmw+hn8WkoKiWj
+0sxuGmrWt5t+5bF2wcq0CtTeF1/o6DsRhRiJBzmcLe81ItrN6emZSg96xCKzkHBZ
+3nF4fG88vtiYgD932lMStDqQzSTx0FsCGpGaKh9xDmKvlP24NWdM9gyOEsRbDvqd
+vS1Q45Jx0jzkp7X5d0casqBWIZak3z0EVdK7c8Y/GxxTcWfIMINCl9+F9kpTA/ZX
+uARYzrPWaBfDBi2r5acWi/AHJM3U+LgzO5nCKa+38vtjNw3NtbslA4InQ5cU2B8X
+QN8NlQ==
+-----END CERTIFICATE-----
diff --git a/test/mocks/pnfsimulator/ftpes/userpass/pureftpd.passwd b/test/mocks/pnfsimulator/ftpes/userpass/pureftpd.passwd
new file mode 100755
index 000000000..7961e710d
--- /dev/null
+++ b/test/mocks/pnfsimulator/ftpes/userpass/pureftpd.passwd
@@ -0,0 +1 @@
+onap:$6$Guq6OMhBdNZ6nTk0$7dLt6hOrAv.in36jzWGd5UgWeDqN3CuKjrzJ.izRTdgZRTszeNYbT2dk7UDh9CLD7pohnB0.k1NSZmRIUB/ID/:1001:1001::/home/ftpusers/onap/./::::::::::::
diff --git a/test/mocks/pnfsimulator/json_schema/input_validator.json b/test/mocks/pnfsimulator/json_schema/input_validator.json
index 195f4bf35..f5573af49 100644
--- a/test/mocks/pnfsimulator/json_schema/input_validator.json
+++ b/test/mocks/pnfsimulator/json_schema/input_validator.json
@@ -1,193 +1,207 @@
{
- "$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",
+ "commonEventHeaderParams",
+ "pnfRegistrationParams"
+ ]
+ },
+ {
+ "required": [
+ "simulatorParams",
+ "commonEventHeaderParams",
+ "notificationParams"
+ ]
+ }
]
+
+
} \ No newline at end of file
diff --git a/test/mocks/pnfsimulator/pom.xml b/test/mocks/pnfsimulator/pom.xml
index 563ee271f..b4adcd806 100644
--- a/test/mocks/pnfsimulator/pom.xml
+++ b/test/mocks/pnfsimulator/pom.xml
@@ -4,10 +4,11 @@
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>
- <version>1.1.0</version>
+ <version>1.2.1</version>
</parent>
<groupId>org.onap.pnfsimulator</groupId>
@@ -320,4 +321,4 @@
</plugin>
</plugins>
</build>
-</project> \ No newline at end of file
+</project>
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..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<JSONObject> pnfRegistrationParams,
+ 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..aadb54cdc 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,16 +25,21 @@ 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;
public class MessageProviderTest {
- private static final String testParamsJson =
- "{\"key1\": \"val1\",\"key2\": \"val2\",\"pnf_key3\": \"pnfVal3\",\"key4\": \"val4\"}";
+ private static final String testParamsPnfRegistration =
+ "{\"pnfKey1\": \"pnfVal1\",\"pnfKey2\": \"pnfVal2\",\"pnfKey3\": \"pnfVal3\",\"pnfKey4\": \"pnfVal4\"}";
+
+ private static final String testParamsNotification =
+ "{\"notKey1\": \"notVal1\",\"notKey2\": \"notVal2\",\"notKey3\": \"notVal3\",\"notKey4\": \"notVal4\"}";
private static MessageProvider messageProvider;
@@ -44,22 +49,25 @@ 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 +78,38 @@ 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(new JSONObject(testParamsPnfRegistration)),
+ Optional.of(new JSONObject(testParamsNotification)));
JSONObject event = message.getJSONObject(EVENT);
JSONObject commonEventHeader = event.getJSONObject(COMMON_EVENT_HEADER);
+ assertEquals(10, commonEventHeader.keySet().size());
+
JSONObject pnfRegistrationFields = event.getJSONObject(PNF_REGISTRATION_FIELDS);
+ assertEquals("pnfVal1", pnfRegistrationFields.getString("pnfKey1"));
+ assertEquals("pnfVal2", pnfRegistrationFields.getString("pnfKey2"));
+
+ JSONObject notificationFields = event.getJSONObject(NOTIFICATION_FIELDS);
+ assertEquals("notVal1", notificationFields.getString("notKey1"));
+ assertEquals("notVal2", notificationFields.getString("notKey2"));
- assertEquals("pnfVal3", pnfRegistrationFields.getString("key3"));
- assertEquals("val1", commonEventHeader.getString("key1"));
- assertEquals("val2", commonEventHeader.getString("key2"));
- assertEquals("val4", commonEventHeader.getString("key4"));
}
}
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..ea7a09785 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
@@ -22,18 +22,21 @@ package org.onap.pnfsimulator.simulator;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_MESSAGE_PARAMS_1;
-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_NOTIFICATION_PARAMS;
+import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_PNF_REGISTRATION_PARAMS_1;
+import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_PNF_REGISTRATION_PARAMS_2;
+import static org.onap.pnfsimulator.simulator.TestMessages.INVALID_PNF_REGISTRATION_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_COMMON_EVENT_HEADER_PARAMS;
+import static org.onap.pnfsimulator.simulator.TestMessages.VALID_NOTIFICATION_PARAMS;
+import static org.onap.pnfsimulator.simulator.TestMessages.VALID_PNF_REGISTRATION_PARAMS;
import static org.onap.pnfsimulator.simulator.TestMessages.VALID_SIMULATOR_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;
@@ -50,16 +53,25 @@ class SimulatorFactoryTest {
}
@Test
- void should_successfully_create_simulator_given_valid_params_and_valid_output_message()
+ void should_successfully_create_simulator_given_valid_pnf_registration_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_successfully_create_simulator_given_valid_notification_params_and_valid_output_message()
+ throws ValidationException, IOException, ProcessingException {
+ assertNotNull(simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
+ Optional.empty(), VALID_NOTIFICATION_PARAMS));
}
@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 +79,22 @@ 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_PNF_REGISTRATION_PARAMS_1, Optional.empty()));
+
+ assertThrows(
+ ValidationException.class,
+ () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
+ INVALID_PNF_REGISTRATION_PARAMS_2, 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_PNF_REGISTRATION_PARAMS_3, Optional.empty()));
assertThrows(
ValidationException.class,
- () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, INVALID_MESSAGE_PARAMS_3));
+ () -> simulatorFactory.create(VALID_SIMULATOR_PARAMS, VALID_COMMON_EVENT_HEADER_PARAMS,
+ VALID_PNF_REGISTRATION_PARAMS, INVALID_NOTIFICATION_PARAMS));
}
} \ 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..7511084c4 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,20 @@
package org.onap.pnfsimulator.simulator;
+import java.io.IOException;
+import java.nio.file.Files;
+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_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 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
+ .of(new JSONObject(getContent("validPnfRegistrationParams.json")));
+ static final Optional<JSONObject> VALID_NOTIFICATION_PARAMS = Optional
+ .of(new JSONObject(getContent("validNotificationParams.json")));
static final JSONObject INVALID_SIMULATOR_PARAMS = new JSONObject(
"{\n" +
@@ -57,7 +42,7 @@ final class TestMessages {
"}");
- static final JSONObject INVALID_MESSAGE_PARAMS_1 = new JSONObject(
+ static final Optional<JSONObject> INVALID_PNF_REGISTRATION_PARAMS_1 = Optional.of(new JSONObject(
"{\n" +
" \"pnfSerialNumber\": \"val1\",\n" +
" \"pnfVendorName\": \"val2\",\n" +
@@ -71,9 +56,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_PNF_REGISTRATION_PARAMS_2 = Optional.of(new JSONObject(
"{\n" +
" \"pnfVendorName\": \"val2\",\n" +
" \"pnfOamIpv4Address\": \"val3\",\n" +
@@ -88,9 +73,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_PNF_REGISTRATION_PARAMS_3 = Optional.of(new JSONObject(
"{\n" +
" \"pnfSerialNumber\": \"val1\",\n" +
" \"pnfOamIpv4Address\": \"val3\",\n" +
@@ -104,8 +89,28 @@ final class TestMessages {
" \"sourceName\": \"val12\",\n" +
" \"sourceId\": \"val13\",\n" +
" \"reportingEntityName\": \"val14\"\n" +
- "}");
+ "}"));
+
+ static final Optional<JSONObject> INVALID_NOTIFICATION_PARAMS = Optional.of(new JSONObject(
+ "{\n" +
+ " \"mother\": \"val1\",\n" +
+ " \"father\": \"val3\",\n" +
+ "}"));
+
private TestMessages() {
}
+
+ private static String getContent(String fileName) {
+ try {
+ String pathAsString = TestMessages.class.getResource(fileName).getPath();
+ StringBuilder stringBuilder = new StringBuilder();
+ Files.readAllLines(Paths.get(pathAsString)).forEach(line -> {
+ stringBuilder.append(line);
+ });
+ return stringBuilder.toString();
+ } catch (IOException e) {
+ throw new RuntimeException(String.format("Cannot read JSON file %s", fileName));
+ }
+ }
}
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
diff --git a/test/mocks/sniroemulator/pom.xml b/test/mocks/sniroemulator/pom.xml
index 11b556d34..288ecb63b 100644
--- a/test/mocks/sniroemulator/pom.xml
+++ b/test/mocks/sniroemulator/pom.xml
@@ -12,15 +12,9 @@
<parent>
<groupId>org.onap.oparent</groupId>
<artifactId>oparent</artifactId>
- <version>0.1.1</version>
+ <version>1.2.1</version>
</parent>
-<!-- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.7.RELEASE</version>
-</parent>
--->
<properties>
<dockerLocation>${basedir}/target</dockerLocation>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>