aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/mass-pnf-sim/pnf-sim-lightweight
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocks/mass-pnf-sim/pnf-sim-lightweight')
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/README.md39
-rwxr-xr-xtest/mocks/mass-pnf-sim/pnf-sim-lightweight/ROP_file_creator.sh59
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.json30
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.yml9
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/netconf.env8
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-ftps-template.json29
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-sftp-template.json28
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml14
-rwxr-xr-xtest/mocks/mass-pnf-sim/pnf-sim-lightweight/files/prepare-ROP-files.sh10
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/json_schema/input_validator.json96
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.data.xml4
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.yang9
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/pom.xml345
-rwxr-xr-xtest/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh77
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/assembly/resources.xml75
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/ConfigurationProvider.java28
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java44
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/Main.java53
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/PnfSimConfig.java59
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logback.xml50
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logging/MDCVariables.java35
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java133
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java95
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java88
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTask.java62
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorService.java71
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfiguration.java114
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCache.java34
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReader.java42
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriter.java51
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConnectionParams.java45
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java232
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/DateUtil.java35
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java62
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java198
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java52
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapter.java26
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java89
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/JSONValidator.java66
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/ValidationException.java28
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/resources/application.properties6
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java73
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java115
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTaskTest.java95
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfigurationTest.java72
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceTest.java73
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCacheTest.java38
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReaderTest.java70
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriterTest.java67
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java197
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/DateUtilTest.java38
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/ResponseBuilderTest.java65
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java0
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java0
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java116
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java71
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/validation/JSONValidatorTest.java123
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/invalid-test-schema.json19
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/logback-test.xml49
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validCommonEventHeaderParams.json8
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validNotificationParams.json20
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validPnfRegistrationParams.json10
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validSimulatorParams.json5
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/valid-test-schema.json19
-rw-r--r--test/mocks/mass-pnf-sim/pnf-sim-lightweight/templates/file_template_new.xml.gzbin0 -> 188545 bytes
65 files changed, 3760 insertions, 213 deletions
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/README.md b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/README.md
new file mode 100644
index 000000000..0e2b668a4
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/README.md
@@ -0,0 +1,39 @@
+##Local development shortcuts:
+####To start listening on port 10000 for test purposes
+`nc -l -k -p 10000`
+####Test the command above:
+`echo "Hello World" | nc localhost 10000`
+
+####Trigger the pnf simulator locally:
+
+```
+~/dev/git/integration/test/mocks/mass-pnf-sim/pnf-sim-lightweight$ curl -s -X POST -H "Content-Type: application/json" -H "X-ONAP-RequestID: 123" -H "X-InvocationID: 456" -d @config/config.json
+http://localhost:5000/simulator/start
+```
+#### VES event sending
+the default action is to send a VES Message every 15 minutes and the total duration of the VES FileReady Message sending is 1 day (these values can be changed in config/config.json)
+
+Message from the stdout of nc:
+
+```
+POST / HTTP/1.1
+Content-Type: application/json
+X-ONAP-RequestID: 123
+X-InvocationID: 3a256e95-2594-4b11-b25c-68c4baeb5c20
+Content-Length: 734
+Host: localhost:10000
+Connection: Keep-Alive
+User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_162)
+Accept-Encoding: gzip,deflate
+```
+
+```javascript
+{"event":{"commonEventHeader":{"startEpochMicrosec":"1551865758690","sourceId":"val13","eventId":"registration_51865758",
+"nfcNamingCode":"oam","internalHeaderFields":{},"priority":"Normal","version":"4.0.1","reportingEntityName":"NOK6061ZW3",
+"sequence":"0","domain":"notification","lastEpochMicrosec":"1551865758690","eventName":"pnfRegistration_Nokia_5gDu",
+"vesEventListenerVersion":"7.0.1","sourceName":"NOK6061ZW3","nfNamingCode":"gNB"},
+"notificationFields":{"notificationFieldsVersion":"2.0","changeType":"FileReady","changeIdentifier":"PM_MEAS_FILES",
+"arrayOfNamedHashMap":[{"name":"10MB.tar.gz","hashMap":{
+"location":"ftpes://10.11.0.68/10MB.tar.gz","fileFormatType":"org.3GPP.32.435#measCollec",
+"fileFormatVersion":"V10","compression":"gzip"}}]}}}
+``` \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/ROP_file_creator.sh b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/ROP_file_creator.sh
new file mode 100755
index 000000000..6ea6ffde0
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/ROP_file_creator.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+MAIN_DIRECTORY=${PWD##*/}
+FULL_DIRECTORY=${PWD}
+FILE_DIRECTORY=$FULL_DIRECTORY/files/onap
+FILE_TEMPLATE=$FULL_DIRECTORY/templates/file_template_new.xml.gz
+UPDATE_MINS=15
+NUM_FILES=96
+
+rm -rf $FILE_DIRECTORY
+mkdir -p "$FILE_DIRECTORY"
+
+for ((n=0;n<$NUM_FILES;n++))
+do
+ if [[ "$OSTYPE" == "linux-gnu" ]]; then # Linux OS
+ DATE=$(date -d $(($UPDATE_MINS*($n+1)-1))" minutes ago" +"%Y%m%d")
+ TIME_START=$(date -d $(($UPDATE_MINS*($n+1)-1))" minutes ago" +"%H%M%z")
+ TIME_END=$(date -d $(($UPDATE_MINS*$n))" minutes ago" +"%H%M%z")
+ elif [[ "$OSTYPE" == "darwin"* ]]; then # Mac OS
+ DATE=$(date -v "-"$(($UPDATE_MINS*($n+1)-1))"M" +"%Y%m%d")
+ TIME_START=$(date -v "-"$(($UPDATE_MINS*($n+1)-1))"M" +"%H%M%z")
+ TIME_END=$(date -v "-"$(($UPDATE_MINS*$n))"M" +"%H%M%z")
+ else
+ echo "ERROR: OS not supported"
+ exit 1
+ fi
+
+ FILE_NAME_TIMESTAMP="A"$DATE"."$TIME_START"-"$TIME_END
+ FILE_NAME=$FILE_NAME_TIMESTAMP"_"$HOSTNAME"-"$MAIN_DIRECTORY".xml.gz"
+ cp $FILE_TEMPLATE $FILE_DIRECTORY/$FILE_NAME
+
+ TIMESTAMP_ARRAY[$n]=$FILE_NAME_TIMESTAMP
+done
+
+while true
+do
+ sleep $(($UPDATE_MINS*60))
+ OLD_TIMESTAMP=${TIMESTAMP_ARRAY[$NUM_FILES-1]}
+ unset TIMESTAMP_ARRAY[$NUM_FILES-1]
+
+ TIME_END=$(date +"%H%M%z")
+ if [[ "$OSTYPE" == "linux-gnu" ]]; then # Linux OS
+ DATE=$(date -d $(($UPDATE_MINS-1))" minutes ago" +"%Y%m%d")
+ TIME_START=$(date -d $(($UPDATE_MINS-1))" minutes ago" +"%H%M%z")
+ elif [[ "$OSTYPE" == "darwin"* ]]; then # Mac OS
+ DATE=$(date -v "-"$(($UPDATE_MINS-1))"M" +"%Y%m%d")
+ TIME_START=$(date -v "-"$(($UPDATE_MINS-1))"M" +"%H%M%z")
+ else
+ echo "ERROR: OS not supported"
+ exit 1
+ fi
+
+ NEW_TIMESTAMP="A"$DATE"."$TIME_START"-"$TIME_END
+ OLD_FILE_NAME=$OLD_TIMESTAMP"_"$HOSTNAME"-"$MAIN_DIRECTORY".xml.gz"
+ NEW_FILE_NAME=$NEW_TIMESTAMP"_"$HOSTNAME"-"$MAIN_DIRECTORY".xml.gz"
+ mv $FILE_DIRECTORY/$OLD_FILE_NAME $FILE_DIRECTORY/$NEW_FILE_NAME
+ #echo "Renamed OLD file: "$OLD_FILE_NAME" to NEW file: "$NEW_FILE_NAME # uncomment for debugging
+
+ TIMESTAMP_ARRAY=("$NEW_TIMESTAMP" "${TIMESTAMP_ARRAY[@]}")
+done
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.json
index f0ded4c04..9d2ba7e08 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.json
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.json
@@ -1,35 +1,15 @@
{
"simulatorParams": {
- "vesServerUrl": "http://localhost:10000/eventListener/v7",
- "testDuration": "10",
- "messageInterval": "1"
+ "testDuration": "86400",
+ "messageInterval": "900"
},
"commonEventHeaderParams": {
- "eventName": "pnfRegistration_Nokia_5gDu",
+ "eventName": "Noti_RnNode-Ericsson_FileReady",
"nfNamingCode": "gNB",
- "nfcNamingCode": "oam",
- "sourceName": "NOK6061ZW3",
- "sourceId": "val13",
- "reportingEntityName": "NOK6061ZW3"
+ "nfcNamingCode": "oam"
},
"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"
- }
- }
- ]
+ "changeType": "FileReady"
}
}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.yml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.yml
new file mode 100644
index 000000000..06c832099
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/config.yml
@@ -0,0 +1,9 @@
+---
+urlves: http://localhost:10000/eventListener/v7
+urlftps: ftps://onap:pano@10.11.0.67
+urlsftp: sftp://onap:pano@10.11.0.68
+#when run in simulator, it does not have own IP
+ippnfsim: localhost
+defaultfileserver: sftp
+#defaultfileserver: ftps
+...
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/netconf.env b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/netconf.env
index 6cf310a27..c4f7b4a80 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/netconf.env
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/netconf.env
@@ -1,4 +1,10 @@
-NETCONF_ADDRESS=netopeer
+
+//to run in simulator
+//NETCONF_ADDRESS=netopeer
+
+//to run in docker
+NETCONF_ADDRESS=localhost
+
NETCONF_PORT=830
NETCONF_MODEL=pnf-simulator
NETCONF_MAIN_CONTAINER=config
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-ftps-template.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-ftps-template.json
deleted file mode 100644
index de1e95707..000000000
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-ftps-template.json
+++ /dev/null
@@ -1,29 +0,0 @@
-{
- "simulatorParams": {
- "vesServerUrl": "http://______$IP_OF_VES_____:_____$PORT_OF_VES/eventListener/v7",
- "testDuration": "10",
- "messageInterval": "1"
- },
- "commonEventHeaderParams": {
- "eventName": "pnfRegistration_Nokia_5gDu",
- "nfNamingCode": "gNB",
- "nfcNamingCode": "oam",
- "sourceName": "NOK6061ZW3",
- "sourceId": "val13",
- "reportingEntityName": "NOK6061ZW3"
- },
- "notificationParams": {
- "changeIdentifier": "PM_MEAS_FILES",
- "changeType": "FileReady",
- "arrayOfNamedHashMap": [
- {"name": "1MB.tar.gz", "hashMap": {
- "location": "sftp://$IPSFTP}/1MB.tar.gz",
- "compression": "gzip",
- "fileFormatType": "org.3GPP.32.435#measCollec",
- "fileFormatVersion": "V10"
- }
- }
- }
- ]
- }
-}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-sftp-template.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-sftp-template.json
deleted file mode 100644
index c8c38b000..000000000
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/config/singlefile-config-sftp-template.json
+++ /dev/null
@@ -1,28 +0,0 @@
-{
- "simulatorParams": {
- "vesServerUrl": "http://______$IP_OF_VES_____:_____$PORT_OF_VES/eventListener/v7",
- "testDuration": "10",
- "messageInterval": "1"
- },
- "commonEventHeaderParams": {
- "eventName": "pnfRegistration_Nokia_5gDu",
- "nfNamingCode": "gNB",
- "nfcNamingCode": "oam",
- "sourceName": "NOK6061ZW3",
- "sourceId": "val13",
- "reportingEntityName": "NOK6061ZW3"
- },
- "notificationParams": {
- "changeIdentifier": "PM_MEAS_FILES",
- "changeType": "FileReady",
- "arrayOfNamedHashMap": [
- {"name": "1MB.tar.gz", "hashMap": {
- "location": "ftps://$IP/1MB.tar.gz",
- "compression": "gzip",
- "fileFormatType": "org.3GPP.32.435#measCollec",
- "fileFormatVersion": "V10"
- }
- }
- ]
- }
-}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml
index f4ff7d81c..aa0261c0a 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/docker-compose-template.yml
@@ -10,14 +10,15 @@ networks:
services:
pnf-simulator-${I}:
container_name: pnf-simulator-${I}
-
- image: nexus3.onap.org:10003/onap/pnf-simulator:4.0.0-SNAPSHOT
+ image: nexus3.onap.org:10003/onap/masspnf-simulator:1.0.0-SNAPSHOT
networks:
front-${I}:
ipv4_address: "${IPPNFSIM}"
volumes:
- ./logs:/var/log
- ./json_schema:/json_schema
+ - ./config/config.yml:/config/config.yml:rw
+ - ./files/:/files/:rw
env_file:
- ./config/netconf.env
restart: on-failure
@@ -28,6 +29,8 @@ services:
networks:
front-${I}:
ipv4_address: "${IPSFTP}"
+ ports:
+ - "${PORTSFTP}:22"
volumes:
- ./files/onap/:/home/onap/
restart: on-failure
@@ -39,6 +42,8 @@ services:
networks:
front-${I}:
ipv4_address: "${IPFTPS}"
+ ports:
+ - "${PORTFTPS}:21"
environment:
FTP_USER: onap
FTP_PASSWORD: pano
@@ -50,10 +55,7 @@ services:
- ./tls/ftp.key:/etc/ssl/private/ftp.key:ro
- ./tls/dfc.crt:/etc/ssl/private/dfc.crt:ro
- ./config/vsftpd_ssl.conf:/etc/vsftpd_ssl.conf:ro
- - ./files/onap/0.5MB.tar.gz:/srv/0.5MB.tar.gz:ro
- - ./files/onap/1MB.tar.gz:/srv/1MB.tar.gz:ro
- - ./files/onap/5MB.tar.gz:/srv/5MB.tar.gz:ro
- - ./files/onap/10MB.tar.gz:/srv/10MB.tar.gz:ro
+ - ./files/onap/:/srv/
restart: on-failure
command: vsftpd /etc/vsftpd_ssl.conf
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/files/prepare-ROP-files.sh b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/files/prepare-ROP-files.sh
deleted file mode 100755
index 4c7c5060e..000000000
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/files/prepare-ROP-files.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-
-echo "Creating ROP files"
-set -x
-mkdir -p onap
-
-dd if=/dev/urandom of=./onap/0.5MB.tar.gz bs=1k count=512
-dd if=/dev/urandom of=./onap/1MB.tar.gz bs=1M count=1
-dd if=/dev/urandom of=./onap/5MB.tar.gz bs=1M count=5
-dd if=/dev/urandom of=./onap/10MB.tar.gz bs=1M count=10 \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/json_schema/input_validator.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/json_schema/input_validator.json
index 4e75e0adc..7b38e05d6 100644
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/json_schema/input_validator.json
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/json_schema/input_validator.json
@@ -5,9 +5,6 @@
"simulatorParams": {
"type": "object",
"properties": {
- "vesServerUrl": {
- "type": "string"
- },
"testDuration": {
"type": "string"
},
@@ -16,7 +13,6 @@
}
},
"required": [
- "vesServerUrl",
"testDuration",
"messageInterval"
]
@@ -32,22 +28,10 @@
},
"nfcNamingCode": {
"type": "string"
- },
- "sourceName": {
- "type": "string"
- },
- "sourceId": {
- "type": "string"
- },
- "reportingEntityName": {
- "type": "string"
}
},
"required": [
- "eventName",
- "sourceName",
- "sourceId",
- "reportingEntityName"
+ "eventName"
]
},
@@ -99,87 +83,11 @@
},
"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"
+ "changeType"
]
}
},
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.data.xml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.data.xml
new file mode 100644
index 000000000..9d648bba7
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.data.xml
@@ -0,0 +1,4 @@
+<config xmlns="http://nokia.com/pnf-simulator">
+ <itemValue1>42</itemValue1>
+ <itemValue2>35</itemValue2>
+</config>
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.yang b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.yang
new file mode 100644
index 000000000..d7fc2f26e
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/netconf/pnf-simulator.yang
@@ -0,0 +1,9 @@
+module pnf-simulator {
+ namespace "http://nokia.com/pnf-simulator";
+ prefix config;
+ container config {
+ config true;
+ leaf itemValue1 {type uint32;}
+ leaf itemValue2 {type uint32;}
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/pom.xml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/pom.xml
new file mode 100644
index 000000000..abfa615cc
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/pom.xml
@@ -0,0 +1,345 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+ 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.2.1</version>
+ </parent>
+
+ <groupId>org.onap.masspnfsimulator</groupId>
+ <artifactId>masspnf-simulator</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <name>pnf-simulator-sandbox</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
+
+ <simulator.main.class>org.onap.pnfsimulator.Main</simulator.main.class>
+ <docker.image.tag>latest</docker.image.tag>
+ <junit.jupiter.version>5.1.0</junit.jupiter.version>
+ <junit.vintage.version>5.1.0</junit.vintage.version>
+ <docker.image.name>onap/${project.artifactId}</docker.image.name>
+
+ <dependency.directory.name>libs</dependency.directory.name>
+ <dependency.directory.location>${project.build.directory}/${dependency.directory.name}
+ </dependency.directory.location>
+
+ <onap.nexus.dockerregistry.daily>nexus3.onap.org:10003</onap.nexus.dockerregistry.daily>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>2.0.2.RELEASE</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ <version>2.0.2.RELEASE</version>
+ </dependency>
+<dependency>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-yaml</artifactId>
+ <version>2.9.8</version>
+</dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>1.2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.25</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ <version>20180130</version>
+ </dependency>
+ <dependency>
+ <groupId>org.everit.json</groupId>
+ <artifactId>org.everit.json.schema</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.github.fge</groupId>
+ <artifactId>json-schema-validator</artifactId>
+ <version>2.2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.8.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ <version>4.5.5</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>21.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>jnc</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>5.1.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-migrationsupport</artifactId>
+ <version>${junit.jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.9.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sshd</groupId>
+ <artifactId>sshd-core</artifactId>
+ <version>0.9.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.18.3</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>5.0.4.RELEASE</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <version>2.0.1.RELEASE</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptor>src/assembly/resources.xml</descriptor>
+ <finalName>${project.artifactId}-${project.version}</finalName>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.7.0</version>
+ <configuration>
+ <source>${maven.compiler.source}</source>
+ <target>${maven.compiler.target}</target>
+ <showWarnings>true</showWarnings>
+ <showDeprecation>true</showDeprecation>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Main-Class>${simulator.main.class}</Main-Class>
+ <Build-Time>${maven.build.timestamp}</Build-Time>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>pl.project13.maven</groupId>
+ <artifactId>git-commit-id-plugin</artifactId>
+ <version>2.2.4</version>
+ <executions>
+ <execution>
+ <id>get-commit-info</id>
+ <goals>
+ <goal>revision</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
+ <generateGitPropertiesFile>true</generateGitPropertiesFile>
+ <includeOnlyProperties>git.commit.id.abbrev</includeOnlyProperties>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.19</version>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-surefire-provider</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ </dependencies>
+ <configuration>
+ <detail>true</detail>
+ <printSummary>true</printSummary>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <configuration>
+ <outputDirectory>${dependency.directory.location}</outputDirectory>
+ <includeScope>runtime</includeScope>
+ <silent>true</silent>
+ </configuration>
+ <executions>
+ <execution>
+ <id>copy-external-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.spotify</groupId>
+ <artifactId>docker-maven-plugin</artifactId>
+ <version>1.0.0</version>
+ <configuration>
+ <registryUrl>${onap.nexus.dockerregistry.daily}</registryUrl>
+ <imageName>${onap.nexus.dockerregistry.daily}/${docker.image.name}</imageName>
+ <forceTags>true</forceTags>
+ <imageTags>
+ <tag>${project.version}</tag>
+ <tag>${project.version}-${maven.build.timestamp}</tag>
+ </imageTags>
+ <baseImage>openjdk:8-jre-alpine</baseImage>
+ <cmd>java -cp ${dependency.directory.name}/*:${project.build.finalName}.jar ${simulator.main.class}</cmd>
+ <resources>
+ <resource>
+ <targetPath>${dependency.directory.name}</targetPath>
+ <directory>${dependency.directory.location}</directory>
+ </resource>
+ <resource>
+ <targetPath>/</targetPath>
+ <directory>${project.build.directory}</directory>
+ <include>${project.build.finalName}.jar</include>
+ </resource>
+ </resources>
+ <forceTags>true</forceTags>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.8.1</version>
+ <configuration>
+ <excludes>
+ <exclude>org/onap/pnfsimulator/Main.class</exclude>
+ </excludes>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>report</id>
+ <phase>prepare-package</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>check</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <rule>
+ <element>CLASS</element>
+ <limits>
+ <limit>
+ <value>COVEREDRATIO</value>
+ <minimum>0.70</minimum>
+ </limit>
+ <limit>
+ <counter>BRANCH</counter>
+ <value>COVEREDRATIO</value>
+ <minimum>0.75</minimum>
+ </limit>
+ </limits>
+ </rule>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh
index 12b20477a..4c5d9f062 100755
--- a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/simulator.sh
@@ -6,9 +6,12 @@ COMPOSE_FILE_NAME=docker-compose.yml
NETOPEER_CONTAINER_NAME=netopeer
SIMULATOR_CONTAINER_NAME=pnf-simulator
SIMULATOR_PORT=5000
-SIMULATOR_START_URL=http://localhost:$SIMULATOR_PORT/simulator/start
-SIMULATOR_STOP_URL=http://localhost:$SIMULATOR_PORT/simulator/stop
-SIMULATOR_STATUS_URL=http://localhost:$SIMULATOR_PORT/simulator/status
+
+SIMULATOR_BASE=http://localhost:$SIMULATOR_PORT/simulator/
+SIMULATOR_START_URL=$SIMULATOR_BASE/start
+SIMULATOR_STOP_URL=$SIMULATOR_BASE/stop
+SIMULATOR_STATUS_URL=$SIMULATOR_BASE/status
+
RUNNING_COMPOSE_CONFIG=$COMPOSE_FILE_NAME
function main(){
@@ -17,16 +20,23 @@ function main(){
case $COMMAND in
"compose")
- compose $2 $3 $4 $5 $6 $7 $8;;
- #IPGW, #IPSUBNET, #I, #IPVES, #IPPNFSIM, #IPFTP, #IPSFTP,
+ compose $2 $3 $4 $5 $6 $7 $8 $9 "${10}" "${11}" ;;
+ #IPGW, #IPSUBNET, #I, #IPVES, #IPPNFSIM, #IPFILESERVER, #PORTSFTP, #PORTFTPS, #IPFTPS, #IPSFTP
"build")
build_image;;
"start")
start $COMPOSE_FILE_NAME;;
"stop")
- stop;;
+ if [[ -z ${2+x} ]]
+ then
+ echo "Error: action 'stop' requires the instance identifier"
+ exit
+ fi
+ stop $2;;
"run-simulator")
run_simulator;;
+ "trigger-simulator")
+ trigger_simulator;;
"stop-simulator")
stop_simulator;;
"status")
@@ -38,6 +48,18 @@ function main(){
esac
}
+
+function get_pnfsim_ip() {
+
+ export IPPNFSIM=$(cat ./config/config.yml | grep ippnfsim | awk -F'[ ]' '{print $2}')
+ echo "PNF-Sim IP: " $IPPNFSIM
+
+ export SIMULATOR_BASE=http://$IPPNFSIM:$SIMULATOR_PORT/simulator/
+ export SIMULATOR_START_URL=$SIMULATOR_BASE/start
+ export SIMULATOR_STOP_URL=$SIMULATOR_BASE/stop
+ export SIMULATOR_STATUS_URL=$SIMULATOR_BASE/status
+}
+
function compose(){
#creating custom docker-compose based on IP arguments
#creting config.json by injecting the same IP
@@ -47,8 +69,11 @@ function compose(){
export I=$3
export IPVES=$4
export IPPNFSIM=$5
- export IPFTPS=$6
- export IPSFTP=$7
+ export IPFILESERVER=$6
+ export PORTSFTP=$7
+ export PORTFTPS=$8
+ export IPFTPS=$9
+ export IPSFTP=${10}
#will insert $I to distinguish containers, networks properly
#docker compose cannot substitute these, as they are keys, not values.
@@ -57,19 +82,17 @@ function compose(){
docker-compose -f docker-compose-temporary.yml config > docker-compose.yml
rm docker-compose-temporary.yml
- cd files
- ./prepare-ROP-files.sh
- cd -
+ ./ROP_file_creator.sh $I &
set_vsftpd_file_owner
- write_config $IPVES $IPFTPS $IPSFTP
+ write_config $IPVES $IPFILESERVER $PORTSFTP $PORTFTPS $IPPNFSIM
}
function build_image(){
if [ -f pom.xml ]; then
- mvn clean package docker:build
+ mvn clean package docker:build -Dcheckstyle.skip -DskipTests
else
echo "pom.xml file not found"
exit 1
@@ -83,15 +106,16 @@ function set_vsftpd_file_owner() {
function write_config(){
#building a YML file for usage in Java
- echo "---" > config/config.yml
- echo "configuration:" >> config/config.yml
- echo " vesip: $1" >> config/config.yml
- echo " ipftps: $2" >> config/config.yml
- echo " ipsftp: $3" >> config/config.yml
+ echo "urlves: $1" > config/config.yml
+ echo "urlsftp: sftp://onap:pano@$2:$3" >> config/config.yml
+ echo "urlftps: ftps://onap:pano@$2:$4" >> config/config.yml
+ echo "ippnfsim: $5" >> config/config.yml
+ echo "defaultfileserver: sftp" >> config/config.yml
}
function start(){
+ get_pnfsim_ip
if [[ $(running_containers) ]]; then
echo "Simulator containers are already up"
else
@@ -108,6 +132,8 @@ function running_containers(){
}
function stop(){
+ get_pnfsim_ip
+ kill $(ps -ef | grep "[.]/ROP_file_creator.sh $1" | head -n 1 | awk '{print $2}')
if [[ $(running_containers) ]]; then
docker-compose -f $RUNNING_COMPOSE_CONFIG down
@@ -117,8 +143,16 @@ function stop(){
fi
}
-function run_simulator(){
+function trigger_simulator(){
+get_pnfsim_ip
+cat << EndOfMessage
+Simulator response:
+$(curl -s -X POST -H "Content-Type: application/json" -H "X-ONAP-RequestID: 123" -H "X-InvocationID: 456" -d @config/config.json $SIMULATOR_START_URL)
+EndOfMessage
+}
+function run_simulator(){
+get_pnfsim_ip
cat << EndOfMessage
Simulator response:
$(curl -s -X POST -H "Content-Type: application/json" -H "X-ONAP-RequestID: 123" -H "X-InvocationID: 456" -d @config/$CONFIG_JSON $SIMULATOR_START_URL)
@@ -126,6 +160,7 @@ EndOfMessage
}
function stop_simulator(){
+get_pnfsim_ip
cat << EndOfMessage
Simulator response:
$(curl -s -X POST $SIMULATOR_STOP_URL)
@@ -133,7 +168,7 @@ EndOfMessage
}
function get_status(){
-
+ get_pnfsim_ip
if [[ $(running_containers) ]]; then
print_status
else
@@ -142,6 +177,7 @@ function get_status(){
}
function print_status(){
+get_pnfsim_ip
cat << EndOfMessage
$(docker-compose -f $RUNNING_COMPOSE_CONFIG ps)
@@ -156,6 +192,7 @@ Available options:
build - locally builds simulator image from existing code
start - starts simulator and netopeer2 containers using remote simulator image and specified model name
compose - customize the docker-compose and configuration based on arguments
+trigger-simulator - start monitoring the ROP files and report periodically
run-simulator - starts sending PNF registration messages with parameters specified in config.json
stop-simulator - stop sending PNF registration messages
stop - stops both containers
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/assembly/resources.xml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/assembly/resources.xml
new file mode 100644
index 000000000..063c7100a
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/assembly/resources.xml
@@ -0,0 +1,75 @@
+<assembly>
+ <id>resources</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <fileSets>
+ <fileSet>
+ <includes>
+ <include>simulator.sh</include>
+ </includes>
+ <lineEnding>unix</lineEnding>
+ <fileMode>0755</fileMode>
+ </fileSet>
+ <fileSet>
+ <includes>
+ <include>docker-compose.yml</include>
+ </includes>
+ <lineEnding>unix</lineEnding>
+ <fileMode>0644</fileMode>
+ </fileSet>
+ <fileSet>
+ <directory>config</directory>
+ <outputDirectory>config</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>deployment</directory>
+ <outputDirectory>deployment</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>ftpes</directory>
+ <outputDirectory>ftpes</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <fileMode>0644</fileMode>
+
+ </fileSet>
+ <fileSet>
+ <directory>json_schema</directory>
+ <outputDirectory>json_schema</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>netconf</directory>
+ <outputDirectory>netconf</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>sftp</directory>
+ <outputDirectory>sftp</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>ssh</directory>
+ <outputDirectory>ssh</outputDirectory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+
+ </fileSet>
+ </fileSets>
+</assembly> \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/ConfigurationProvider.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/ConfigurationProvider.java
new file mode 100644
index 000000000..15c687e2c
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/ConfigurationProvider.java
@@ -0,0 +1,28 @@
+package org.onap.pnfsimulator;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+import java.io.File;
+
+public class ConfigurationProvider {
+ static PnfSimConfig conf = null;
+
+ public static PnfSimConfig getConfigInstance() {
+
+ ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
+ try {
+ File file = new File("./config/config.yml");
+
+ conf = mapper.readValue(file, PnfSimConfig.class);
+ System.out.println("Ves URL: " + conf.getUrlves());
+ System.out.println("SFTP URL: " + conf.getUrlsftp());
+ System.out.println("FTPS URL: " + conf.getUrlftps());
+ System.out.println("PNF sim IP: " + conf.getIppnfsim());
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return conf;
+ }
+
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java
new file mode 100644
index 000000000..9eb733227
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/FileProvider.java
@@ -0,0 +1,44 @@
+package org.onap.pnfsimulator;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class FileProvider {
+
+ private FileProvider() {}
+
+ public static List<String> getFiles() {
+
+ List<String> files = queryFiles();
+
+ files.sort(Collections.reverseOrder());
+
+ List<String> fileListSorted = new ArrayList<>();
+ for (String f : files) {
+ fileListSorted.add(f);
+ }
+ return fileListSorted;
+ }
+
+ private static List<String> queryFiles() {
+
+ File folder = new File("./files/onap/");
+ File[] listOfFiles = folder.listFiles();
+ List<String> results = new ArrayList<>();
+
+ if (listOfFiles.length == 0) {
+ return results;
+ // TODO: this should be a thrown exception catched in the Simulator class
+ }
+
+ for (int i = 0; i < listOfFiles.length; i++) {
+ if (listOfFiles[i].isFile()) {
+ results.add(listOfFiles[i].getName());
+ }
+ }
+
+ return results;
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/Main.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/Main.java
new file mode 100644
index 000000000..a66bedbcb
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/Main.java
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================ Copyright (C)
+ * 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================ Licensed under
+ * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License. ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator;
+
+import java.util.concurrent.TimeUnit;
+import org.onap.pnfsimulator.message.MessageProvider;
+import org.onap.pnfsimulator.simulator.validation.JSONValidator;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.scheduling.annotation.EnableAsync;
+
+@SpringBootApplication
+@EnableAsync
+public class Main {
+
+ public static void main(String[] args) throws InterruptedException {
+ SpringApplication.run(Main.class, args);
+
+ TimeUnit.SECONDS.sleep(5);
+ System.out.println("Start sending VES events");
+
+
+ }
+
+ @Bean
+ public MessageProvider messageProvider() {
+ return new MessageProvider();
+ }
+
+ @Bean
+ public JSONValidator jsonValidator() {
+ return new JSONValidator();
+ }
+
+}
+
+
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/PnfSimConfig.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/PnfSimConfig.java
new file mode 100644
index 000000000..89f59a391
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/PnfSimConfig.java
@@ -0,0 +1,59 @@
+package org.onap.pnfsimulator;
+
+public class PnfSimConfig {
+ private String urlves;
+ private String urlftps;
+ private String urlsftp;
+ private String ippnfsim;
+ private String defaultfileserver;
+
+ public String getDefaultfileserver() {
+ return defaultfileserver;
+ }
+
+ public void setDefaultfileserver(String defaultfileserver) {
+ this.defaultfileserver = defaultfileserver;
+ }
+
+
+ public String getUrlves() {
+ return urlves;
+ }
+
+ public void setUrlves(String urlves) {
+ this.urlves = urlves;
+ }
+
+ public String getUrlftps() {
+ return urlftps;
+ }
+
+ public void setUrlftps(String urlftps) {
+ this.urlftps = urlftps;
+ }
+
+ public String getUrlsftp() {
+ return urlsftp;
+ }
+
+ public void setUrlsftp(String urlsftp) {
+ this.urlsftp = urlsftp;
+ }
+
+ public void setIppnfsim(String ippnfsim) {
+ this.ippnfsim = ippnfsim;
+ }
+
+ public String getIppnfsim() {
+ return ippnfsim;
+ }
+
+ @Override
+ public String toString() {
+ return "PnfSimConfig [vesip=" + urlves + ", urlftps=" + urlftps + ", ippnfsim=" + ippnfsim + ", urlsftp="
+ + urlsftp + "]";
+ }
+
+
+
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logback.xml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logback.xml
new file mode 100644
index 000000000..0f6d9de6c
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logback.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration complete="true" compact="true">
+
+ <Property name="outputFilename" value="pnfsimulator_output"/>
+ <Property name="log-path" value="/var/log/ONAP/pnfsimulator"/>
+ <Property name="archive" value="/var/log/ONAP/pnfsimulator/archive"/>
+ <property name="maxFileSize" value="50MB"/>
+ <property name="maxHistory" value="30"/>
+ <property name="totalSizeCap" value="10GB"/>
+
+ <appender name="Console" target="SYSTEM_OUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%nopexception%logger
+ |%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC}
+ |%level
+ |%replace(%replace(%message){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%mdc){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%rootException){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%marker){'\t','\\\\t'}){'\n','\\\\n'}
+ |%thread
+ |%n</Pattern>
+ </encoder>
+ </appender>
+
+ <appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <encoder>
+ <pattern>%nopexception%logger
+ |%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC}
+ |%level
+ |%replace(%replace(%message){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%mdc){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%rootException){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%marker){'\t','\\\\t'}){'\n','\\\\n'}
+ |%thread
+ |%n</pattern>
+ </encoder>
+ <File>${log-path}/${outputFilename}.log</File>
+ <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+ <FileNamePattern>${archive}/${outputFilename}.%d{yyyy-MM-dd}.%i.log.zip</FileNamePattern>
+ <MaxFileSize>${maxFileSize}</MaxFileSize>
+ <MaxHistory>${maxHistory}</MaxHistory>
+ <TotalSizeCap>${totalSizeCap}</TotalSizeCap>
+ </rollingPolicy>
+ </appender>
+
+ <root level="debug">
+ <appender-ref ref="Console" />
+ <appender-ref ref="ROLLING-FILE" />
+ </root>
+</Configuration>
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logging/MDCVariables.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logging/MDCVariables.java
new file mode 100644
index 000000000..8f6fe3b66
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/logging/MDCVariables.java
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.logging;
+
+public final class MDCVariables {
+
+ public static final String X_ONAP_REQUEST_ID = "X-ONAP-RequestID";
+ public static final String X_INVOCATION_ID = "X-InvocationID";
+ public static final String REQUEST_ID = "RequestID";
+ public static final String INVOCATION_ID = "InvocationID";
+ public static final String INSTANCE_UUID = "InstanceUUID";
+ public static final String RESPONSE_CODE = "ResponseCode";
+ public static final String SERVICE_NAME = "ServiceName";
+
+ private MDCVariables() {
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java
new file mode 100644
index 000000000..545a56882
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/JSONObjectFactory.java
@@ -0,0 +1,133 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.message;
+
+import static org.onap.pnfsimulator.message.MessageConstants.COMPRESSION;
+import static org.onap.pnfsimulator.message.MessageConstants.COMPRESSION_VALUE;
+import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID;
+import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_TYPE;
+import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_TYPE_VALUE;
+import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_VERSION;
+import static org.onap.pnfsimulator.message.MessageConstants.FILE_FORMAT_VERSION_VALUE;
+import static org.onap.pnfsimulator.message.MessageConstants.HASH_MAP;
+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.LOCATION;
+import static org.onap.pnfsimulator.message.MessageConstants.NAME;
+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.REPORTING_ENTITY_NAME;
+import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE;
+import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE_NUMBER;
+import static org.onap.pnfsimulator.message.MessageConstants.SOURCE_NAME;
+import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC;
+import static org.onap.pnfsimulator.message.MessageConstants.TIME_ZONE_OFFSET;
+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 java.io.File;
+import java.util.List;
+import java.util.TimeZone;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+final class JSONObjectFactory {
+
+ static JSONObject generateConstantCommonEventHeader() {
+ JSONObject commonEventHeader = new JSONObject();
+ long timestamp = System.currentTimeMillis();
+ commonEventHeader.put(EVENT_ID, generateEventId());
+ commonEventHeader.put(TIME_ZONE_OFFSET, generateTimeZone(timestamp));
+ commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp);
+ commonEventHeader.put(PRIORITY, PRIORITY_NORMAL);
+ commonEventHeader.put(SEQUENCE, SEQUENCE_NUMBER);
+ commonEventHeader.put(START_EPOCH_MICROSEC, timestamp);
+ commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject());
+ commonEventHeader.put(VERSION, VERSION_NUMBER);
+ commonEventHeader.put(VES_EVENT_LISTENER_VERSION, VES_EVENT_LISTENER_VERSION_NUMBER);
+ String absPath = System.getProperty("user.dir");
+ String nodeName = absPath.substring(absPath.lastIndexOf(File.separator)+1);
+ commonEventHeader.put(SOURCE_NAME, nodeName);
+ commonEventHeader.put(REPORTING_ENTITY_NAME, nodeName);
+ return commonEventHeader;
+ }
+
+ static JSONObject generatePnfRegistrationFields() {
+ JSONObject pnfRegistrationFields = new JSONObject();
+ pnfRegistrationFields.put(PNF_REGISTRATION_FIELDS_VERSION, PNF_REGISTRATION_FIELDS_VERSION_VALUE);
+ pnfRegistrationFields.put(PNF_LAST_SERVICE_DATE, String.valueOf(System.currentTimeMillis()));
+ pnfRegistrationFields.put(PNF_MANUFACTURE_DATE, String.valueOf(System.currentTimeMillis()));
+ return pnfRegistrationFields;
+ }
+
+ static JSONObject generateNotificationFields() {
+ JSONObject notificationFields = new JSONObject();
+ notificationFields.put(NOTIFICATION_FIELDS_VERSION, NOTIFICATION_FIELDS_VERSION_VALUE);
+ return notificationFields;
+ }
+
+ static JSONArray generateArrayOfNamedHashMap(List<String> fileList, String xnfUrl) {
+ JSONArray arrayOfNamedHashMap = new JSONArray();
+
+ for (String fileName : fileList) {
+ JSONObject namedHashMap = new JSONObject();
+ namedHashMap.put(NAME, fileName);
+
+ JSONObject hashMap = new JSONObject();
+ hashMap.put(FILE_FORMAT_TYPE, FILE_FORMAT_TYPE_VALUE);
+ hashMap.put(LOCATION, xnfUrl.concat(fileName));
+ hashMap.put(FILE_FORMAT_VERSION, FILE_FORMAT_VERSION_VALUE);
+ hashMap.put(COMPRESSION, COMPRESSION_VALUE);
+ namedHashMap.put(HASH_MAP, hashMap);
+
+ arrayOfNamedHashMap.put(namedHashMap);
+ }
+
+
+ return arrayOfNamedHashMap;
+ }
+
+
+ static String generateEventId() {
+ String timeAsString = String.valueOf(System.currentTimeMillis());
+ return String.format("FileReady_%s", timeAsString);
+ }
+
+ static String generateTimeZone(long timestamp) {
+ TimeZone timeZone = TimeZone.getDefault();
+ int offsetInMillis = timeZone.getOffset(timestamp);
+ String offsetHHMM = String.format("%02d:%02d", Math.abs(offsetInMillis / 3600000),
+ Math.abs((offsetInMillis / 60000) % 60));
+ return ("UTC" + (offsetInMillis >= 0 ? "+" : "-") + offsetHHMM);
+ }
+
+ private JSONObjectFactory() {
+
+ }
+
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java
new file mode 100644
index 000000000..6ff6e5dc8
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageConstants.java
@@ -0,0 +1,95 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.message;
+
+public final class MessageConstants {
+
+ 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 TIME_ZONE_OFFSET = "timeZoneOffset";
+ static final String EVENT_TYPE = "eventType";
+ static final String LAST_EPOCH_MICROSEC = "lastEpochMicrosec";
+ static final String PRIORITY = "priority";
+ static final String SEQUENCE = "sequence";
+ static final String START_EPOCH_MICROSEC = "startEpochMicrosec";
+ static final String INTERNAL_HEADER_FIELDS = "internalHeaderFields";
+ static final String VERSION = "version";
+ static final String VES_EVENT_LISTENER_VERSION = "vesEventListenerVersion";
+ static final String SOURCE_NAME = "sourceName";
+ static final String REPORTING_ENTITY_NAME = "reportingEntityName";
+ //constant values
+ 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 String DOMAIN_PNF_REGISTRATION ="pnfRegistration";
+
+ //=============================================================================================
+ // Notifications
+ //parameters
+ static final String NOTIFICATION_FIELDS_VERSION = "notificationFieldsVersion";
+ static final String ARRAY_OF_NAMED_HASH_MAP = "arrayOfNamedHashMap";
+ static final String NAME = "name";
+ static final String HASH_MAP = "hashMap";
+ static final String FILE_FORMAT_TYPE = "fileFormatType";
+ static final String LOCATION = "location";
+ static final String FILE_FORMAT_VERSION = "fileFormatVersion";
+ static final String COMPRESSION = "compression";
+
+ //constant values
+ static final String NOTIFICATION_FIELDS_VERSION_VALUE = "2.0";
+ static final String DOMAIN_NOTIFICATION ="notification";
+ static final String FILE_FORMAT_TYPE_VALUE = "org.3GPP.32.435#measCollec";
+ static final String FILE_FORMAT_VERSION_VALUE = "V10";
+ static final String COMPRESSION_VALUE = "gzip";
+
+ private MessageConstants() {
+ }
+
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java
new file mode 100644
index 000000000..c86362509
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/message/MessageProvider.java
@@ -0,0 +1,88 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================ Copyright (C)
+ * 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================ Licensed under
+ * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License. ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.message;
+
+import static org.onap.pnfsimulator.message.MessageConstants.ARRAY_OF_NAMED_HASH_MAP;
+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.DOMAIN_NOTIFICATION;
+import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN_PNF_REGISTRATION;
+import static org.onap.pnfsimulator.message.MessageConstants.EVENT;
+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.PNF_REGISTRATION_FIELDS;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+public class MessageProvider {
+
+ public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams,
+ Optional<JSONObject> notificationParams) {
+ List<String> emptyList = new ArrayList<>();
+ String emptyString = "";
+ return createMessage(commonEventHeaderParams, pnfRegistrationParams, notificationParams, emptyList, emptyString);
+ }
+
+ public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams,
+ Optional<JSONObject> notificationParams, List<String> fileList, String xnfUrl) {
+
+ if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) {
+ throw new IllegalArgumentException(
+ "Both PNF registration and notification parameters objects are not present");
+ }
+ JSONObject event = new JSONObject();
+
+ JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
+ Map<String, Object> commonEventHeaderFields = commonEventHeaderParams.toMap();
+ commonEventHeaderFields.forEach((key, value) -> {
+ commonEventHeader.put(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);
+ });
+
+ JSONObject notificationFields = JSONObjectFactory.generateNotificationFields();
+ notificationParams.ifPresent(jsonObject -> {
+ copyParametersToFields(jsonObject.toMap(), notificationFields);
+ JSONArray arrayOfNamedHashMap = JSONObjectFactory.generateArrayOfNamedHashMap(fileList, xnfUrl);
+ notificationFields.put(ARRAY_OF_NAMED_HASH_MAP, arrayOfNamedHashMap);
+ commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION);
+ event.put(NOTIFICATION_FIELDS, notificationFields);
+ });
+
+ event.put(COMMON_EVENT_HEADER, commonEventHeader);
+ 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/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTask.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTask.java
new file mode 100644
index 000000000..bb173aef2
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTask.java
@@ -0,0 +1,62 @@
+/// *
+// * ============LICENSE_START=======================================================
+// * PNF-REGISTRATION-HANDLER
+// * ================================================================================
+// * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+// * ================================================================================
+// * Licensed under the Apache License, Version 2.0 (the "License");
+// * you may not use this file except in compliance with the License.
+// * You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// * ============LICENSE_END=========================================================
+// */
+//
+// package org.onap.pnfsimulator.netconfmonitor;
+//
+// import com.tailf.jnc.JNCException;
+// import java.io.IOException;
+// import java.util.TimerTask;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
+// import org.slf4j.Logger;
+// import org.slf4j.LoggerFactory;
+//
+// public class NetconfConfigurationCheckingTask extends TimerTask {
+//
+// private static final Logger LOGGER =
+/// LoggerFactory.getLogger(NetconfConfigurationCheckingTask.class);
+//
+// private final NetconfConfigurationReader reader;
+// private final NetconfConfigurationWriter writer;
+// private final NetconfConfigurationCache cache;
+//
+// public NetconfConfigurationCheckingTask(NetconfConfigurationReader reader,
+// NetconfConfigurationWriter writer,
+// NetconfConfigurationCache cache) {
+// this.reader = reader;
+// this.writer = writer;
+// this.cache = cache;
+// }
+//
+// @Override
+// public void run() {
+// try {
+// String currentConfiguration = reader.read();
+// if (!currentConfiguration.equals(cache.getConfiguration())) {
+// LOGGER.info("Configuration has changed, new configuration:\n\n{}", currentConfiguration);
+// writer.writeToFile(currentConfiguration);
+// cache.update(currentConfiguration);
+// }
+// } catch (IOException | JNCException e) {
+// LOGGER.warn("Error during configuration reading: {}", e.getMessage());
+// }
+// }
+// }
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorService.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorService.java
new file mode 100644
index 000000000..4e484b9d9
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorService.java
@@ -0,0 +1,71 @@
+/// *
+// * ============LICENSE_START=======================================================
+// * PNF-REGISTRATION-HANDLER
+// * ================================================================================ Copyright (C)
+// * 2018 NOKIA Intellectual Property. All rights reserved.
+// * ================================================================================ Licensed under
+// * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+// * with the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software distributed under the
+/// License
+// * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
+/// express
+// * or implied. See the License for the specific language governing permissions and limitations
+/// under
+// * the License. ============LICENSE_END=========================================================
+// */
+//
+// package org.onap.pnfsimulator.netconfmonitor;
+//
+// import com.tailf.jnc.JNCException;
+// import java.io.IOException;
+// import java.util.Timer;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
+// import org.slf4j.Logger;
+// import org.slf4j.LoggerFactory;
+// import org.springframework.beans.factory.annotation.Autowired;
+//
+//// @Service
+// public class NetconfMonitorService {
+// private static final Logger LOGGER = LoggerFactory.getLogger(NetconfMonitorService.class);
+// private static final long timePeriod = 1000L;
+// private static final long startDelay = 0;
+//
+// private Timer timer;
+// private NetconfConfigurationReader reader;
+// private NetconfConfigurationWriter writer;
+// private NetconfConfigurationCache cache;
+//
+// @Autowired
+// public NetconfMonitorService(Timer timer, NetconfConfigurationReader reader,
+/// NetconfConfigurationWriter writer,
+// NetconfConfigurationCache cache) {
+// this.timer = timer;
+// this.reader = reader;
+// this.writer = writer;
+// this.cache = cache;
+// }
+//
+// // @PostConstruct
+// public void start() {
+// setStartConfiguration();
+// NetconfConfigurationCheckingTask task = new NetconfConfigurationCheckingTask(reader, writer,
+/// cache);
+// timer.scheduleAtFixedRate(task, startDelay, timePeriod);
+// }
+//
+// private void setStartConfiguration() {
+// try {
+// String configuration = reader.read();
+// writer.writeToFile(configuration);
+// cache.update(configuration);
+// } catch (IOException | JNCException e) {
+// LOGGER.warn("Error during configuration reading: {}", e.getMessage());
+// }
+// }
+// }
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfiguration.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfiguration.java
new file mode 100644
index 000000000..d97315ba4
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfiguration.java
@@ -0,0 +1,114 @@
+/// *
+// * ============LICENSE_START=======================================================
+// * PNF-REGISTRATION-HANDLER
+// * ================================================================================
+// * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+// * ================================================================================
+// * Licensed under the Apache License, Version 2.0 (the "License");
+// * you may not use this file except in compliance with the License.
+// * You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// * ============LICENSE_END=========================================================
+// */
+//
+// package org.onap.pnfsimulator.netconfmonitor;
+//
+// import com.tailf.jnc.JNCException;
+// import com.tailf.jnc.NetconfSession;
+// import com.tailf.jnc.SSHConnection;
+// import com.tailf.jnc.SSHSession;
+// import java.io.IOException;
+// import java.util.Map;
+// import java.util.Timer;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConnectionParams;
+// import org.slf4j.Logger;
+// import org.slf4j.LoggerFactory;
+// import org.springframework.context.annotation.Bean;
+// import org.springframework.context.annotation.Configuration;
+//
+// @Configuration
+// public class NetconfMonitorServiceConfiguration {
+//
+// private static final Logger LOGGER =
+/// LoggerFactory.getLogger(NetconfMonitorServiceConfiguration.class);
+// private static final Map<String, String> enviroment = System.getenv();
+//
+// private static final String LOG_PATH = "/var/log";
+//
+// private static final String NETCONF_ADDRESS = "NETCONF_ADDRESS";
+// private static final String NETCONF_PORT = "NETCONF_PORT";
+// private static final String NETCONF_MODEL = "NETCONF_MODEL";
+// private static final String NETCONF_MAIN_CONTAINER = "NETCONF_MAIN_CONTAINER";
+//
+// private static final String DEFAULT_NETCONF_ADDRESS = "localhost";
+// private static final int DEFAULT_NETCONF_PORT = 830;
+// private static final String DEFAULT_NETCONF_MODEL = "pnf-simulator";
+// private static final String DEFAULT_NETCONF_MAIN_CONTAINER = "config";
+//
+// private static final String DEFAULT_NETCONF_USER = "netconf";
+// private static final String DEFAULT_NETCONF_PASSWORD = "netconf";
+//
+// @Bean
+// public Timer timer() {
+// return new Timer("NetconfMonitorServiceTimer");
+// }
+//
+// @Bean
+// public NetconfConfigurationCache configurationCache() {
+// return new NetconfConfigurationCache();
+// }
+//
+// @Bean
+// public NetconfConfigurationReader configurationReader() throws IOException, JNCException {
+// NetconfConnectionParams params = resolveConnectionParams();
+// LOGGER.info("Configuration params are : {}", params);
+// NetconfSession session = createNetconfSession(params);
+// return new NetconfConfigurationReader(session, buildModelPath());
+// }
+//
+// NetconfSession createNetconfSession(NetconfConnectionParams params) throws IOException,
+/// JNCException {
+// SSHConnection sshConnection = new SSHConnection(params.address, params.port);
+// sshConnection.authenticateWithPassword(params.user, params.password);
+// return new NetconfSession( new SSHSession(sshConnection));
+// }
+//
+// @Bean
+// public NetconfConfigurationWriter netconfConfigurationWriter() {
+// return new NetconfConfigurationWriter(LOG_PATH);
+// }
+//
+// private String buildModelPath() {
+// return String.format("/%s:%s",
+// enviroment.getOrDefault(NETCONF_MODEL, DEFAULT_NETCONF_MODEL),
+// enviroment.getOrDefault(NETCONF_MAIN_CONTAINER, DEFAULT_NETCONF_MAIN_CONTAINER));
+// }
+//
+// NetconfConnectionParams resolveConnectionParams() {
+// return new NetconfConnectionParams(
+// enviroment.getOrDefault(NETCONF_ADDRESS, DEFAULT_NETCONF_ADDRESS),
+// resolveNetconfPort(),
+// DEFAULT_NETCONF_USER,
+// DEFAULT_NETCONF_PASSWORD);
+// }
+//
+// private int resolveNetconfPort() {
+// try {
+// return Integer.parseInt(enviroment.get(NETCONF_PORT));
+// } catch (NumberFormatException e) {
+// LOGGER.warn("Invalid netconf port: {}. Default netconf port {} is set.", e.getMessage(),
+// DEFAULT_NETCONF_PORT);
+// return DEFAULT_NETCONF_PORT;
+// }
+// }
+// }
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCache.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCache.java
new file mode 100644
index 000000000..39721841b
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCache.java
@@ -0,0 +1,34 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.netconfmonitor.netconf;
+
+public class NetconfConfigurationCache {
+
+ private String configuration = "";
+
+ public String getConfiguration() {
+ return configuration;
+ }
+
+ public void update(String configuration) {
+ this.configuration = configuration;
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReader.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReader.java
new file mode 100644
index 000000000..e41e58f78
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReader.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================ Copyright (C)
+ * 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================ Licensed under
+ * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License. ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.netconfmonitor.netconf;
+
+import com.tailf.jnc.JNCException;
+import com.tailf.jnc.NetconfSession;
+import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class NetconfConfigurationReader {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(NetconfConfigurationReader.class);
+ private final NetconfSession session;
+ private final String netconfModelPath;
+
+ public NetconfConfigurationReader(NetconfSession session, String netconfModelPath) {
+ LOGGER.warn("netconfModelPath: {}", netconfModelPath);
+ this.session = session;
+ this.netconfModelPath = netconfModelPath;
+ }
+
+ public String read() throws IOException, JNCException {
+ return session.getConfig(netconfModelPath).first().toXMLString();
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriter.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriter.java
new file mode 100644
index 000000000..40030796f
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriter.java
@@ -0,0 +1,51 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.netconfmonitor.netconf;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import org.onap.pnfsimulator.rest.util.DateUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NetconfConfigurationWriter {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(NetconfConfigurationWriter.class);
+ private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
+ private String pathToLog;
+
+ public NetconfConfigurationWriter(String pathToLog) {
+ this.pathToLog = pathToLog;
+ }
+
+ public void writeToFile(String configuration) {
+ String fileName = String.format("%s/config[%s].xml", pathToLog, DateUtil.getTimestamp(dateFormat));
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName))) {
+ writer.write(configuration);
+ LOGGER.info("Configuration wrote to file {}/{} ", pathToLog, fileName);
+ } catch (IOException e) {
+ LOGGER.warn("Failed to write configuration to file: {}", e.getMessage());
+ }
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConnectionParams.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConnectionParams.java
new file mode 100644
index 000000000..1d6eb89bf
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConnectionParams.java
@@ -0,0 +1,45 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.netconfmonitor.netconf;
+
+public class NetconfConnectionParams {
+
+ public final String address;
+ public final int port;
+ public final String user;
+ public final String password;
+
+ public NetconfConnectionParams(String address, int port, String user, String password) {
+ this.address = address;
+ this.port = port;
+ this.user = user;
+ this.password = password;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("NetconfConnectionParams{address=%s, port=%d, user=%s, password=%s}",
+ address,
+ port,
+ user,
+ password);
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
new file mode 100644
index 000000000..2a685eac8
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/SimulatorController.java
@@ -0,0 +1,232 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================ Copyright (C)
+ * 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================ Licensed under
+ * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License. ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.rest;
+
+import static org.onap.pnfsimulator.logging.MDCVariables.INSTANCE_UUID;
+import static org.onap.pnfsimulator.logging.MDCVariables.INVOCATION_ID;
+import static org.onap.pnfsimulator.logging.MDCVariables.REQUEST_ID;
+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.COMMON_EVENT_HEADER_PARAMS;
+import static org.onap.pnfsimulator.message.MessageConstants.SIMULATOR_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;
+import static org.onap.pnfsimulator.rest.util.ResponseBuilder.TIMESTAMP;
+import static org.springframework.http.HttpStatus.BAD_REQUEST;
+import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
+import static org.springframework.http.HttpStatus.OK;
+import com.github.fge.jsonschema.core.exceptions.ProcessingException;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Optional;
+import java.util.UUID;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.onap.pnfsimulator.message.MessageConstants;
+import org.onap.pnfsimulator.rest.util.DateUtil;
+import org.onap.pnfsimulator.rest.util.ResponseBuilder;
+import org.onap.pnfsimulator.simulator.Simulator;
+import org.onap.pnfsimulator.simulator.SimulatorFactory;
+import org.onap.pnfsimulator.simulator.validation.JSONValidator;
+import org.onap.pnfsimulator.simulator.validation.ValidationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+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 {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Simulator.class);
+ 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;
+
+ @Autowired
+ public SimulatorController(JSONValidator validator, SimulatorFactory factory) {
+ this.validator = validator;
+ this.factory = factory;
+ }
+
+ @PostMapping("start")
+ public ResponseEntity start(@RequestHeader HttpHeaders headers, @RequestBody String message) {
+ MDC.put(REQUEST_ID, headers.getFirst(X_ONAP_REQUEST_ID));
+ 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");
+
+ if (isSimulatorRunning()) {
+ MDC.put(RESPONSE_CODE, BAD_REQUEST.toString());
+ return ResponseBuilder.status(BAD_REQUEST).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Cannot start simulator since it's already running").build();
+ }
+
+ try {
+ validator.validate(message, "json_schema/input_validator.json");
+ JSONObject root = new JSONObject(message);
+ 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());
+ return ResponseBuilder.status(OK).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Simulator started").build();
+
+ } catch (JSONException e) {
+ MDC.put(RESPONSE_CODE, BAD_REQUEST.toString());
+ LOGGER.warn("Cannot start simulator, invalid json format: {}", e.getMessage());
+ LOGGER.debug("Received json has invalid format", e);
+ return ResponseBuilder.status(BAD_REQUEST).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Cannot start simulator, invalid json format").build();
+
+ } catch (ProcessingException | ValidationException | IOException e) {
+ MDC.put(RESPONSE_CODE, BAD_REQUEST.toString());
+ LOGGER.warn("Json validation failed: {}", e.getMessage());
+ return ResponseBuilder.status(BAD_REQUEST).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Cannot start simulator - Json format is not compatible with schema definitions")
+ .build();
+
+ } catch (Exception e) {
+ MDC.put(RESPONSE_CODE, INTERNAL_SERVER_ERROR.toString());
+ LOGGER.error("Cannot start simulator - unexpected exception", e);
+ return ResponseBuilder.status(INTERNAL_SERVER_ERROR)
+ .put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Unexpected exception: " + e.getMessage()).build();
+ } finally {
+ MDC.clear();
+ }
+ }
+
+ @PostMapping("startmassmode")
+ public ResponseEntity startmassmode(@RequestHeader HttpHeaders headers, @RequestBody String message) {
+ MDC.put(REQUEST_ID, headers.getFirst(X_ONAP_REQUEST_ID));
+ 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");
+
+ if (isSimulatorRunning()) {
+ MDC.put(RESPONSE_CODE, BAD_REQUEST.toString());
+ return ResponseBuilder.status(BAD_REQUEST).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Cannot start simulator since it's already running").build();
+ }
+
+ try {
+ validator.validate(message, "json_schema/input_validator.json");
+ JSONObject root = new JSONObject(message);
+ 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());
+ return ResponseBuilder.status(OK).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Simulator started").build();
+
+ } catch (JSONException e) {
+ MDC.put(RESPONSE_CODE, BAD_REQUEST.toString());
+ LOGGER.warn("Cannot start simulator, invalid json format: {}", e.getMessage());
+ LOGGER.debug("Received json has invalid format", e);
+ return ResponseBuilder.status(BAD_REQUEST).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Cannot start simulator, invalid json format").build();
+
+ } catch (ProcessingException | ValidationException | IOException e) {
+ MDC.put(RESPONSE_CODE, BAD_REQUEST.toString());
+ LOGGER.warn("Json validation failed: {}", e.getMessage());
+ return ResponseBuilder.status(BAD_REQUEST).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Cannot start simulator - Json format is not compatible with schema definitions")
+ .build();
+
+ } catch (Exception e) {
+ MDC.put(RESPONSE_CODE, INTERNAL_SERVER_ERROR.toString());
+ LOGGER.error("Cannot start simulator - unexpected exception", e);
+ return ResponseBuilder.status(INTERNAL_SERVER_ERROR)
+ .put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Unexpected exception: " + e.getMessage()).build();
+ } finally {
+ MDC.clear();
+ }
+ }
+
+
+
+ @GetMapping("status")
+ public ResponseEntity status() {
+ if (isSimulatorRunning()) {
+ ResponseBuilder responseBuilder = ResponseBuilder.status(OK)
+ .put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT)).put(SIMULATOR_STATUS, "RUNNING");
+
+ return !simulator.isEndless() ? responseBuilder.put(REMAINING_TIME, simulator.getRemainingTime()).build()
+ : responseBuilder.build();
+ } else {
+ return ResponseBuilder.status(OK).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(SIMULATOR_STATUS, "NOT RUNNING").build();
+ }
+ }
+
+ @PostMapping("stop")
+ public ResponseEntity stop() {
+ if (isSimulatorRunning()) {
+ simulator.interrupt();
+
+ return ResponseBuilder.status(OK).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Simulator successfully stopped").build();
+ } else {
+ return ResponseBuilder.status(BAD_REQUEST).put(TIMESTAMP, DateUtil.getTimestamp(RESPONSE_DATE_FORMAT))
+ .put(MESSAGE, "Cannot stop simulator, because it's not running").build();
+ }
+ }
+
+ private boolean isSimulatorRunning() {
+ return simulator != null && simulator.isAlive();
+ }
+}
+
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/DateUtil.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/DateUtil.java
new file mode 100644
index 000000000..284d58904
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/DateUtil.java
@@ -0,0 +1,35 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.rest.util;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+public final class DateUtil {
+
+ private DateUtil() {
+ }
+
+ public static String getTimestamp(DateFormat dateFormat) {
+
+ return dateFormat.format(new Date());
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java
new file mode 100644
index 000000000..98f4588c1
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/rest/util/ResponseBuilder.java
@@ -0,0 +1,62 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.rest.util;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+public class ResponseBuilder {
+
+ public static final String TIMESTAMP = "timestamp";
+ public static final String MESSAGE = "message";
+ public static final String SIMULATOR_STATUS = "simulatorStatus";
+ public static final String REMAINING_TIME = "remainingTime";
+
+ private HttpStatus httpStatus;
+ private Map<String, Object> body = new LinkedHashMap<>();
+
+ private ResponseBuilder(HttpStatus httpStatus) {
+ this.httpStatus = httpStatus;
+ }
+
+ public static ResponseBuilder status(HttpStatus httpStatus) {
+
+ return new ResponseBuilder(httpStatus);
+ }
+
+ public ResponseBuilder put(String key, Object value) {
+
+ body.put(key, value);
+ return this;
+ }
+
+ public ResponseEntity build() {
+
+ if (body.isEmpty()) {
+ return ResponseEntity.status(httpStatus).build();
+ }
+
+ return ResponseEntity.status(httpStatus).body(body);
+ }
+
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java
new file mode 100644
index 000000000..5c6405742
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/Simulator.java
@@ -0,0 +1,198 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================ Copyright (C)
+ * 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================ Licensed under
+ * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License. ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator;
+
+import com.github.fge.jsonschema.core.exceptions.ProcessingException;
+import java.io.IOException;
+import java.time.Duration;
+import java.time.Instant;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import org.json.JSONObject;
+import org.onap.pnfsimulator.FileProvider;
+import org.onap.pnfsimulator.message.MessageProvider;
+import org.onap.pnfsimulator.simulator.client.HttpClientAdapter;
+import org.onap.pnfsimulator.simulator.client.HttpClientAdapterImpl;
+import org.onap.pnfsimulator.simulator.validation.JSONValidator;
+import org.onap.pnfsimulator.simulator.validation.ValidationException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+public class Simulator extends Thread {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(Simulator.class);
+ private final Marker EXIT = MarkerFactory.getMarker("EXIT");
+ private Map<String, String> contextMap = MDC.getCopyOfContextMap();
+ private boolean isEndless;
+ private String vesUrl;
+ private HttpClientAdapter httpClient;
+ private JSONObject messageBody;
+ private Duration duration;
+ private Duration interval;
+ private Instant endTime;
+ private JSONObject commonEventHeaderParams;
+ private Optional<JSONObject> pnfRegistrationParams;
+ private Optional<JSONObject> notificationParams;
+ private String xnfUrl;
+ private static final String DEFAULT_OUTPUT_SCHEMA_PATH = "json_schema/output_validator_ves_schema_30.0.1.json";
+
+ private Simulator() {}
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ @Override
+ public void run() {
+ setMdcContextMap(contextMap);
+ LOGGER.info("Simulation started - duration: {}, interval: {}s", getDuration(), interval.getSeconds());
+ endTime = Instant.now().plus(duration);
+ while (isEndless || runningTimeNotExceeded()) {
+ try {
+ List<String> fileList = FileProvider.getFiles();
+ MessageProvider messageProvider = new MessageProvider();
+ JSONValidator validator = new JSONValidator();
+
+ messageBody = messageProvider.createMessage(this.commonEventHeaderParams, this.pnfRegistrationParams,
+ this.notificationParams, fileList, this.xnfUrl);
+ validator.validate(messageBody.toString(), DEFAULT_OUTPUT_SCHEMA_PATH);
+
+ LOGGER.info("Message to be sent:\n" + getMessage());
+ httpClient.send(messageBody.toString(), vesUrl);
+ Thread.sleep(interval.toMillis());
+ } catch (InterruptedException | ValidationException | ProcessingException | IOException e) {
+ LOGGER.info("Simulation stopped due to an exception");
+ return;
+ }
+ }
+ LOGGER.info(EXIT, "Simulation finished");
+ MDC.clear();
+ }
+
+ private void setMdcContextMap(Map<String, String> mdcContextMap) {
+ if (mdcContextMap != null)
+ MDC.setContextMap(mdcContextMap);
+ }
+
+ private String getMessage() {
+ return messageBody.toString(4);
+ }
+
+ private String getDuration() {
+ return isEndless() ? "infinity" : duration.getSeconds() + "s";
+ }
+
+ private boolean runningTimeNotExceeded() {
+ return Instant.now().isBefore(endTime);
+ }
+
+ public boolean isEndless() {
+ return isEndless;
+ }
+
+ public long getRemainingTime() {
+ return Duration.between(Instant.now(), endTime).getSeconds();
+ }
+
+ public static class Builder {
+
+ private String vesUrl;
+ private HttpClientAdapter httpClient;
+ //private JSONObject messageBody;
+ private Duration duration;
+ private Duration interval;
+ private Optional<JSONObject> notificationParams;
+ private Optional<JSONObject> pnfRegistrationParams;
+ private JSONObject commonEventHeaderParams;
+ private String xnfUrl;
+
+ private Builder() {
+ this.vesUrl = "";
+ this.httpClient = new HttpClientAdapterImpl();
+ //this.messageBody = new JSONObject();
+ this.duration = Duration.ZERO;
+ this.interval = Duration.ZERO;
+ this.commonEventHeaderParams = new JSONObject();
+ }
+
+ public Builder withVesUrl(String vesUrl) {
+ this.vesUrl = vesUrl;
+ return this;
+ }
+
+ public Builder withCustomHttpClientAdapter(HttpClientAdapter httpClient) {
+ this.httpClient = httpClient;
+ return this;
+ }
+
+ /*public Builder withMessageBody(JSONObject messageBody) {
+ this.messageBody = messageBody;
+ return this;
+ }*/
+
+ public Builder withDuration(Duration duration) {
+ this.duration = duration;
+ return this;
+ }
+
+
+ public Builder withInterval(Duration interval) {
+ this.interval = interval;
+ return this;
+ }
+
+ public Builder withCommonEventHeaderParams(JSONObject commonEventHeaderParams) {
+ this.commonEventHeaderParams = commonEventHeaderParams;
+ return this;
+ }
+
+ public Builder withNotificationParams(Optional<JSONObject> notificationParams) {
+ this.notificationParams = notificationParams;
+ return this;
+ }
+
+ public Builder withPnfRegistrationParams(Optional<JSONObject> pnfRegistrationParams) {
+ this.pnfRegistrationParams = pnfRegistrationParams;
+ return this;
+ }
+
+ public Builder withXnfUrl(String xnfUrl) {
+ this.xnfUrl = xnfUrl;
+ return this;
+ }
+
+ public Simulator build() {
+ Simulator simulator = new Simulator();
+ simulator.vesUrl = this.vesUrl;
+ simulator.httpClient = this.httpClient;
+ //simulator.messageBody = this.messageBody;
+ simulator.duration = this.duration;
+ simulator.interval = this.interval;
+ simulator.xnfUrl = this.xnfUrl;
+ simulator.commonEventHeaderParams = this.commonEventHeaderParams;
+ simulator.pnfRegistrationParams = this.pnfRegistrationParams;
+ simulator.notificationParams = this.notificationParams;
+ simulator.isEndless = duration.equals(Duration.ZERO);
+ return simulator;
+ }
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
new file mode 100644
index 000000000..a01c2e0c6
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/SimulatorFactory.java
@@ -0,0 +1,52 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================ Copyright (C)
+ * 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================ Licensed under
+ * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License. ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator;
+
+import static java.lang.Integer.parseInt;
+import static org.onap.pnfsimulator.message.MessageConstants.MESSAGE_INTERVAL;
+import static org.onap.pnfsimulator.message.MessageConstants.TEST_DURATION;
+import java.time.Duration;
+import java.util.Optional;
+import org.json.JSONObject;
+import org.onap.pnfsimulator.ConfigurationProvider;
+import org.onap.pnfsimulator.PnfSimConfig;
+import org.springframework.stereotype.Service;
+
+@Service
+public class SimulatorFactory {
+
+ public Simulator create(JSONObject simulatorParams, JSONObject commonEventHeaderParams,
+ Optional<JSONObject> pnfRegistrationParams, Optional<JSONObject> notificationParams) {
+ PnfSimConfig configuration = ConfigurationProvider.getConfigInstance();
+
+ String xnfUrl = null;
+ if (configuration.getDefaultfileserver().equals("sftp")) {
+ xnfUrl = configuration.getUrlsftp() + "/";
+ } else if (configuration.getDefaultfileserver().equals("ftps")) {
+ xnfUrl = configuration.getUrlftps() + "/";
+ }
+
+ String urlVes = configuration.getUrlves();
+ Duration duration = Duration.ofSeconds(parseInt(simulatorParams.getString(TEST_DURATION)));
+ Duration interval = Duration.ofSeconds(parseInt(simulatorParams.getString(MESSAGE_INTERVAL)));
+
+ return Simulator.builder().withVesUrl(urlVes).withXnfUrl(xnfUrl).withDuration(duration)
+ .withCommonEventHeaderParams(commonEventHeaderParams).withNotificationParams(notificationParams)
+ .withPnfRegistrationParams(pnfRegistrationParams).withInterval(interval).build();
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapter.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapter.java
new file mode 100644
index 000000000..47f2e3112
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapter.java
@@ -0,0 +1,26 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator.client;
+
+public interface HttpClientAdapter {
+
+ void send(String content, String url);
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java
new file mode 100644
index 000000000..f0c9917f5
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImpl.java
@@ -0,0 +1,89 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator.client;
+
+import static org.onap.pnfsimulator.logging.MDCVariables.REQUEST_ID;
+import static org.onap.pnfsimulator.logging.MDCVariables.X_INVOCATION_ID;
+import static org.onap.pnfsimulator.logging.MDCVariables.X_ONAP_REQUEST_ID;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.UUID;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+public class HttpClientAdapterImpl implements HttpClientAdapter {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientAdapterImpl.class);
+ private static final String CONTENT_TYPE = "Content-Type";
+ private static final String APPLICATION_JSON = "application/json";
+ private final Marker INVOKE = MarkerFactory.getMarker("INVOKE");
+ private static final RequestConfig CONFIG = RequestConfig.custom()
+ .setConnectTimeout(1000)
+ .setConnectionRequestTimeout(1000)
+ .setSocketTimeout(1000)
+ .build();
+
+ private HttpClient client;
+
+ public HttpClientAdapterImpl() {
+ this.client = HttpClientBuilder
+ .create()
+ .setDefaultRequestConfig(CONFIG)
+ .build();
+ }
+
+ @Override
+ public void send(String content, String url) {
+ try {
+ HttpPost request = createRequest(content, url);
+ HttpResponse response = client.execute(request);
+ EntityUtils.consumeQuietly(response.getEntity());
+ LOGGER.info(INVOKE, "Message sent, ves response code: {}", response.getStatusLine());
+ } catch (IOException e) {
+ LOGGER.warn("Error sending message to ves: {}", e.getMessage());
+ }
+ }
+
+ HttpClientAdapterImpl(HttpClient client) {
+ this.client = client;
+ }
+
+ private HttpPost createRequest(String content, String url) throws UnsupportedEncodingException {
+ HttpPost request = new HttpPost(url);
+ StringEntity stringEntity = new StringEntity(content);
+ request.addHeader(CONTENT_TYPE, APPLICATION_JSON);
+ request.addHeader(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID));
+ request.addHeader(X_INVOCATION_ID, UUID.randomUUID().toString());
+ request.setEntity(stringEntity);
+ return request;
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/JSONValidator.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/JSONValidator.java
new file mode 100644
index 000000000..89135f9b4
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/JSONValidator.java
@@ -0,0 +1,66 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator.validation;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.github.fge.jackson.JsonLoader;
+import com.github.fge.jsonschema.core.exceptions.ProcessingException;
+import com.github.fge.jsonschema.core.report.LogLevel;
+import com.github.fge.jsonschema.core.report.ProcessingMessage;
+import com.github.fge.jsonschema.core.report.ProcessingReport;
+import com.github.fge.jsonschema.main.JsonSchema;
+import com.github.fge.jsonschema.main.JsonSchemaFactory;
+import com.google.gson.JsonParser;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+public class JSONValidator {
+
+ public void validate(String data, String jsonSchemaPath)
+ throws ValidationException, ProcessingException, IOException {
+ String jsonSchema = readJsonSchemaAsString(jsonSchemaPath);
+ JsonNode jsonData = JsonLoader.fromString(data);
+ ProcessingReport report = createJsonSchema(jsonSchema).validate(jsonData);
+
+ if (!report.isSuccess()) {
+ throw new ValidationException(constructValidationErrors(report));
+ }
+ }
+
+ private String readJsonSchemaAsString(String schemaPath) throws IOException {
+ try (FileReader reader = new FileReader(schemaPath)) {
+ return new JsonParser().parse(reader).toString();
+ }
+ }
+
+ private JsonSchema createJsonSchema(String schema) throws ProcessingException, IOException {
+ return JsonSchemaFactory.byDefault().getJsonSchema(JsonLoader.fromString(schema));
+ }
+
+ private String constructValidationErrors(ProcessingReport report) {
+ return StreamSupport.stream(report.spliterator(), false)
+ .filter(entry -> entry.getLogLevel() == LogLevel.ERROR)
+ .map(ProcessingMessage::getMessage)
+ .collect(Collectors.joining("\n"));
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/ValidationException.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/ValidationException.java
new file mode 100644
index 000000000..a9349174a
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/java/org/onap/pnfsimulator/simulator/validation/ValidationException.java
@@ -0,0 +1,28 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator.validation;
+
+public class ValidationException extends Exception {
+
+ public ValidationException(String message) {
+ super(message);
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/resources/application.properties b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/resources/application.properties
new file mode 100644
index 000000000..9740eff3c
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/main/resources/application.properties
@@ -0,0 +1,6 @@
+server.port=5000
+logging.level.root=ERROR
+logging.level.org.springframework=ERROR
+logging.level.org.springframework.data=ERROR
+logging.level.org.onap.pnfsimulator=TRACE
+logging.file=logs/log/application.log \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java
new file mode 100644
index 000000000..4331195c9
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/JSONObjectFactoryTest.java
@@ -0,0 +1,73 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.message;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.onap.pnfsimulator.message.MessageConstants.*;
+
+import org.json.JSONObject;
+import org.junit.jupiter.api.Test;
+
+public class JSONObjectFactoryTest {
+
+ @Test
+ public void generateConstantCommonEventHeader_shouldCreateProperly(){
+ JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
+ assertEquals(8,commonEventHeader.toMap().size());
+ assertTrue(commonEventHeader.has(EVENT_ID));
+ 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(PRIORITY),PRIORITY_NORMAL);
+ assertEquals(commonEventHeader.get(SEQUENCE),SEQUENCE_NUMBER);
+ assertEquals(commonEventHeader.get(VERSION),VERSION_NUMBER);
+ assertEquals(commonEventHeader.get(VES_EVENT_LISTENER_VERSION),VES_EVENT_LISTENER_VERSION_NUMBER);
+ }
+
+ @Test
+ public void generateConstantPnfRegistrationFields_shouldCreateProperly(){
+ JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields();
+ assertEquals(3,pnfRegistrationFields.toMap().size());
+ assertTrue(pnfRegistrationFields.has(PNF_REGISTRATION_FIELDS_VERSION));
+ assertEquals(pnfRegistrationFields.get(PNF_REGISTRATION_FIELDS_VERSION), PNF_REGISTRATION_FIELDS_VERSION_VALUE);
+ assertTrue(pnfRegistrationFields.has(PNF_LAST_SERVICE_DATE));
+ assertTrue(pnfRegistrationFields.has(PNF_MANUFACTURE_DATE));
+ }
+
+ @Test
+ public void generateEventId_shouldCreateProperly(){
+ String eventId = JSONObjectFactory.generateEventId();
+ 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/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java
new file mode 100644
index 000000000..aadb54cdc
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/message/MessageProviderTest.java
@@ -0,0 +1,115 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.message;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+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 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;
+
+ @BeforeAll
+ public static void setup() {
+ messageProvider = new MessageProvider();
+ }
+
+ @Test
+ public void createMessage_should_throw_when_given_empty_arguments() {
+ assertThrows(IllegalArgumentException.class,
+ () -> 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(), 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()
+ .forEach((key, val) -> assertTrue(commonEventHeader.has(key),
+ () -> String.format("Key %s is not present", key)));
+
+ expectedPnfRegistrationFields
+ .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 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"));
+
+ }
+
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTaskTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTaskTest.java
new file mode 100644
index 000000000..df5a13db2
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfConfigurationCheckingTaskTest.java
@@ -0,0 +1,95 @@
+/// *
+// * ============LICENSE_START=======================================================
+// * PNF-REGISTRATION-HANDLER
+// * ================================================================================
+// * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+// * ================================================================================
+// * Licensed under the Apache License, Version 2.0 (the "License");
+// * you may not use this file except in compliance with the License.
+// * You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// * ============LICENSE_END=========================================================
+// */
+//
+// package org.onap.pnfsimulator.netconfmonitor;
+//
+// import static org.mockito.ArgumentMatchers.any;
+// import static org.mockito.Mockito.never;
+// import static org.mockito.Mockito.verify;
+// import static org.mockito.Mockito.when;
+//
+// import com.tailf.jnc.JNCException;
+// import java.io.IOException;
+// import org.junit.jupiter.api.BeforeEach;
+// import org.junit.jupiter.api.Test;
+// import org.mockito.Mock;
+// import org.mockito.MockitoAnnotations;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
+//
+// class NetconfConfigurationCheckingTaskTest {
+//
+// private NetconfConfigurationCheckingTask checkingTask;
+//
+// @Mock
+// private NetconfConfigurationReader reader;
+// @Mock
+// private NetconfConfigurationWriter writer;
+// @Mock
+// private NetconfConfigurationCache cache;
+//
+// @BeforeEach
+// void setup() {
+// MockitoAnnotations.initMocks(this);
+// checkingTask = new NetconfConfigurationCheckingTask(reader, writer, cache);
+// }
+//
+// @Test
+// void run_should_update_configuration_when_changed() throws IOException, JNCException {
+// String configuration = "newConfiguration";
+// when(reader.read()).thenReturn(configuration);
+// when(cache.getConfiguration()).thenReturn("oldConfiguration");
+//
+// checkingTask.run();
+//
+// verify(reader).read();
+// verify(cache).getConfiguration();
+// verify(writer).writeToFile(configuration);
+// verify(cache).update(configuration);
+// }
+//
+// @Test
+// void run_should_not_update_configuration_when_same() throws IOException, JNCException {
+// String configuration = "configuration";
+// when(reader.read()).thenReturn(configuration);
+// when(cache.getConfiguration()).thenReturn("configuration");
+//
+// checkingTask.run();
+//
+// verify(reader).read();
+// verify(cache).getConfiguration();
+// verify(writer, never()).writeToFile(configuration);
+// verify(cache, never()).update(configuration);
+// }
+//
+// @Test
+// void run_should_not_take_any_action_when_failed_to_read_configuration() throws IOException,
+/// JNCException {
+// when(reader.read()).thenThrow(new IOException());
+//
+// checkingTask.run();
+//
+// verify(reader).read();
+// verify(cache, never()).getConfiguration();
+// verify(writer, never()).writeToFile(any());
+// verify(cache, never()).update(any());
+// }
+// }
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfigurationTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfigurationTest.java
new file mode 100644
index 000000000..3ff234b27
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceConfigurationTest.java
@@ -0,0 +1,72 @@
+/// *
+// * ============LICENSE_START=======================================================
+// * PNF-REGISTRATION-HANDLER
+// * ================================================================================
+// * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+// * ================================================================================
+// * Licensed under the Apache License, Version 2.0 (the "License");
+// * you may not use this file except in compliance with the License.
+// * You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// * ============LICENSE_END=========================================================
+// */
+//
+// package org.onap.pnfsimulator.netconfmonitor;
+//
+// import static org.junit.jupiter.api.Assertions.assertNotNull;
+// import static org.mockito.ArgumentMatchers.any;
+// import static org.mockito.Mockito.doReturn;
+// import static org.mockito.Mockito.mock;
+// import static org.mockito.Mockito.spy;
+// import static org.mockito.Mockito.verify;
+//
+// import com.tailf.jnc.JNCException;
+// import com.tailf.jnc.NetconfSession;
+// import java.io.IOException;
+// import org.junit.jupiter.api.BeforeEach;
+// import org.junit.jupiter.api.Test;
+// import org.mockito.Mock;
+//
+// class NetconfMonitorServiceConfigurationTest {
+//
+// private NetconfMonitorServiceConfiguration configuration;
+//
+// @Mock
+// private NetconfSession netconfSession;
+//
+// @BeforeEach
+// void setup() {
+// netconfSession = mock(NetconfSession.class);
+// configuration = spy(new NetconfMonitorServiceConfiguration());
+// }
+//
+// @Test
+// void readNetconfConfiguration() throws IOException, JNCException {
+// doReturn(netconfSession).when(configuration).createNetconfSession(any());
+//
+// assertNotNull(configuration.configurationReader());
+// verify(configuration).createNetconfSession(any());
+// }
+//
+// @Test
+// void configurationCacheIsNotNull() {
+// assertNotNull(configuration.configurationCache());
+// }
+//
+// @Test
+// void netconfConfigurationWriterIsNotNull() {
+// assertNotNull(configuration.netconfConfigurationWriter());
+// }
+//
+// @Test
+// void timerIsNotNull() {
+// assertNotNull(configuration.timer());
+// }
+// }
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceTest.java
new file mode 100644
index 000000000..f8690c5ce
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/NetconfMonitorServiceTest.java
@@ -0,0 +1,73 @@
+/// *
+// * ============LICENSE_START=======================================================
+// * PNF-REGISTRATION-HANDLER
+// * ================================================================================
+// * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+// * ================================================================================
+// * Licensed under the Apache License, Version 2.0 (the "License");
+// * you may not use this file except in compliance with the License.
+// * You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// * ============LICENSE_END=========================================================
+// */
+//
+// package org.onap.pnfsimulator.netconfmonitor;
+//
+// import static org.mockito.ArgumentMatchers.anyString;
+// import static org.mockito.Mockito.any;
+// import static org.mockito.Mockito.anyLong;
+// import static org.mockito.Mockito.doNothing;
+// import static org.mockito.Mockito.times;
+// import static org.mockito.Mockito.verify;
+// import static org.mockito.Mockito.when;
+//
+// import com.tailf.jnc.JNCException;
+// import java.io.IOException;
+// import java.util.Timer;
+// import org.junit.jupiter.api.BeforeEach;
+// import org.junit.jupiter.api.Test;
+// import org.mockito.Mock;
+// import org.mockito.MockitoAnnotations;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
+// import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
+//
+// class NetconfMonitorServiceTest {
+//
+// private NetconfMonitorService service;
+//
+// @Mock
+// private Timer timer;
+// @Mock
+// private NetconfConfigurationReader reader;
+// @Mock
+// private NetconfConfigurationWriter writer;
+// @Mock
+// private NetconfConfigurationCache cache;
+//
+// @BeforeEach
+// void setup() {
+// MockitoAnnotations.initMocks(this);
+// service = new NetconfMonitorService(timer, reader, writer, cache);
+// }
+//
+// @Test
+// void startNetconfService() throws IOException, JNCException {
+// when(reader.read()).thenReturn("message");
+// doNothing().when(writer).writeToFile(anyString());
+// doNothing().when(cache).update(anyString());
+//
+// service.start();
+//
+// verify(cache, times(1)).update(anyString());
+// verify(writer, times(1)).writeToFile(anyString());
+// verify(timer, times(1)).scheduleAtFixedRate(any(), anyLong(), anyLong());
+// }
+// }
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCacheTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCacheTest.java
new file mode 100644
index 000000000..56f62ac50
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationCacheTest.java
@@ -0,0 +1,38 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.netconfmonitor.netconf;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+public class NetconfConfigurationCacheTest {
+
+ private static final String CONFIGURATION = "sampleConfiguration";
+
+ @Test
+ void changeConfigurationAfterUpdate() {
+ NetconfConfigurationCache configurationCache = new NetconfConfigurationCache();
+ configurationCache.update(CONFIGURATION);
+
+ assertEquals(CONFIGURATION, configurationCache.getConfiguration());
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReaderTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReaderTest.java
new file mode 100644
index 000000000..65b2bc32e
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationReaderTest.java
@@ -0,0 +1,70 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.netconfmonitor.netconf;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.tailf.jnc.Element;
+import com.tailf.jnc.JNCException;
+import com.tailf.jnc.NetconfSession;
+import com.tailf.jnc.NodeSet;
+import java.io.IOException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+class NetconfConfigurationReaderTest {
+
+ private static final String NETCONF_MODEL_PATH = "";
+ private static final String EXPECTED_STRING_XML = "<?xml version=\"1.0\"?>";
+ private NetconfConfigurationReader reader;
+
+ @Mock
+ private NetconfSession netconfSession;
+ @Mock
+ private NodeSet nodeSet;
+ @Mock
+ private Element element;
+
+ @BeforeEach
+ void setup() {
+ MockitoAnnotations.initMocks(this);
+ reader = new NetconfConfigurationReader(netconfSession, NETCONF_MODEL_PATH);
+ }
+
+ @Test
+ void properlyReadXML() throws IOException, JNCException {
+ when(netconfSession.getConfig(anyString())).thenReturn(nodeSet);
+ when(nodeSet.first()).thenReturn(element);
+ when(element.toXMLString()).thenReturn(EXPECTED_STRING_XML);
+
+ String result = reader.read();
+
+ verify(netconfSession).getConfig(anyString());
+ verify(nodeSet).first();
+ verify(element).toXMLString();
+ assertEquals(EXPECTED_STRING_XML, result);
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriterTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriterTest.java
new file mode 100644
index 000000000..2baee21b7
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/netconfmonitor/netconf/NetconfConfigurationWriterTest.java
@@ -0,0 +1,67 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.netconfmonitor.netconf;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.apache.commons.io.FileUtils;
+import org.junit.Rule;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
+import org.junit.rules.TemporaryFolder;
+
+@EnableRuleMigrationSupport
+class NetconfConfigurationWriterTest {
+
+ private static final String TEST_CONFIGURATION = "test-configuration";
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Test
+ void writeToFile_should_write_sample_config_when_directory_exists() throws IOException {
+ File file = temporaryFolder.newFolder("temp");
+ NetconfConfigurationWriter configurationWriter = new NetconfConfigurationWriter(file.getPath());
+
+ configurationWriter.writeToFile(TEST_CONFIGURATION);
+
+ File[] files = file.listFiles();
+ assertEquals(1, files.length);
+
+ String content = FileUtils.readFileToString(files[0], "UTF-8");
+ assertEquals(TEST_CONFIGURATION, content);
+ }
+
+ @Test
+ void writeToFile_should_not_write_config_when_directory_doesnt_exist() {
+ String logFolderPath = "/not/existing/logs";
+ NetconfConfigurationWriter configurationWriter = new NetconfConfigurationWriter(logFolderPath);
+
+ configurationWriter.writeToFile(TEST_CONFIGURATION);
+
+ assertFalse(Files.exists(Paths.get(logFolderPath)));
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
new file mode 100644
index 000000000..3603480bf
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/SimulatorControllerTest.java
@@ -0,0 +1,197 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.rest;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import java.time.Duration;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.pnfsimulator.simulator.Simulator;
+import org.onap.pnfsimulator.simulator.SimulatorFactory;
+import org.onap.pnfsimulator.simulator.client.HttpClientAdapter;
+import org.onap.pnfsimulator.simulator.validation.JSONValidator;
+import org.onap.pnfsimulator.simulator.validation.ValidationException;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+
+class SimulatorControllerTest {
+
+ private static final String START_URL = "/simulator/start";
+ private static final String STOP_URL = "/simulator/stop";
+ private static final String STATUS_URL = "/simulator/status";
+ private static final String JSON_MSG_EXPRESSION = "$.message";
+ 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/v7\",\n" +
+ " \"testDuration\": \"10\",\n" +
+ " \"messageInterval\": \"1\"\n" +
+ " },\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" +
+ " \"mes\": {\n" +
+ " \"vesServerUrl\": \"http://10.154.187.70:8080/eventListener/v5\",\n" +
+ " \"testDuration\": \"10\",\n" +
+ " \"messageInterval\": \"1\"\n" +
+ " },\n" +
+ " \"messageParams\": {\n" +
+ " \"sourceName\": \"val12\",\n" +
+ " \"sourceId\": \"val13\",\n" +
+ " \"reportingEntityName\": \"val14\"\n" +
+ " }\n" +
+ "}\n";
+
+ private MockMvc mockMvc;
+
+ @InjectMocks
+ private SimulatorController controller;
+
+ @Mock
+ private SimulatorFactory factory;
+ @Mock
+ private JSONValidator validator;
+
+ private Simulator simulator;
+
+ @BeforeEach
+ void setup() {
+ MockitoAnnotations.initMocks(this);
+ simulator = createEndlessSimulator();
+ mockMvc = MockMvcBuilders
+ .standaloneSetup(controller)
+ .build();
+ }
+
+ private Simulator createEndlessSimulator() {
+ return spy(Simulator.builder()
+ .withCustomHttpClientAdapter(mock(HttpClientAdapter.class))
+ .withInterval(Duration.ofMinutes(1))
+ .build());
+ }
+
+ @Test
+ void wrongJSONFormatOnStart() throws Exception {
+ 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))
+ .andExpect(status().isBadRequest())
+ .andExpect(jsonPath("$.message").value("Cannot start simulator - Json format " +
+ "is not compatible with schema definitions"));
+ verify(validator).validate(anyString(), anyString());
+ }
+
+ @Test
+ void startSimulatorProperly() throws Exception {
+ startSimulator();
+
+ verify(validator).validate(anyString(), anyString());
+ verify(factory).create(any(),any(), any(),any());
+ verify(simulator).start();
+ }
+
+ @Test
+ void notStartWhenAlreadyRunning() throws Exception {
+ startSimulator();
+
+ mockMvc
+ .perform(post(START_URL).content(PROPER_JSON))
+ .andExpect(status().isBadRequest())
+ .andExpect(jsonPath(JSON_MSG_EXPRESSION).value("Cannot start simulator since it's already running"));
+ }
+
+ @Test
+ void stopSimulatorWhenRunning() throws Exception {
+ startSimulator();
+
+ mockMvc
+ .perform(post(STOP_URL))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath(JSON_MSG_EXPRESSION).value("Simulator successfully stopped"));
+ }
+
+ @Test
+ void getNotRunningMessageWhenOff() throws Exception {
+ mockMvc
+ .perform(post(STOP_URL))
+ .andExpect(status().isBadRequest())
+ .andExpect(jsonPath(JSON_MSG_EXPRESSION).value("Cannot stop simulator, because it's not running"));
+ }
+
+ @Test
+ void getRunningStatusWhenOn() throws Exception {
+ startSimulator();
+
+ mockMvc
+ .perform(get(STATUS_URL))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath(JSON_STATUS_EXPRESSION).value("RUNNING"));
+ }
+
+ @Test
+ void getNotRunningStatusWhenOff() throws Exception {
+ mockMvc
+ .perform(get(STATUS_URL))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath(JSON_STATUS_EXPRESSION).value("NOT RUNNING"));
+ }
+
+ private void startSimulator() throws Exception {
+ when(factory.create(any(), any(), any(),any())).thenReturn(simulator);
+
+ mockMvc
+ .perform(post(START_URL).content(PROPER_JSON))
+ .andExpect(status().isOk())
+ .andExpect(jsonPath(JSON_MSG_EXPRESSION).value("Simulator started"));
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/DateUtilTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/DateUtilTest.java
new file mode 100644
index 000000000..99b9af7ec
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/DateUtilTest.java
@@ -0,0 +1,38 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.rest.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import org.junit.jupiter.api.Test;
+
+class DateUtilTest {
+
+ @Test
+ void getFormattedDate() {
+ Calendar currentCalendar = Calendar.getInstance();
+ String expectedResult = String.valueOf(currentCalendar.get(Calendar.YEAR));
+
+ assertEquals(expectedResult, DateUtil.getTimestamp(new SimpleDateFormat("yyyy")));
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/ResponseBuilderTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/ResponseBuilderTest.java
new file mode 100644
index 000000000..59e1e3b4f
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/rest/util/ResponseBuilderTest.java
@@ -0,0 +1,65 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.rest.util;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+
+public class ResponseBuilderTest {
+
+
+ private static final HttpStatus SAMPLE_STATUS = HttpStatus.OK;
+
+ @Test
+ void response_should_have_empty_body_when_built_immediately() {
+ ResponseEntity responseEntity = ResponseBuilder.status(SAMPLE_STATUS).build();
+
+ assertAll(
+ () -> assertEquals(responseEntity.getStatusCode(), SAMPLE_STATUS),
+ () -> assertNull(responseEntity.getBody())
+ );
+ }
+
+ @Test
+ void builder_should_set_response_status_and_body() {
+ String key = "key";
+ String value = "value";
+ ResponseEntity response = ResponseBuilder
+ .status(SAMPLE_STATUS)
+ .put(key, value)
+ .build();
+
+ Map<String, Object> body = (Map<String, Object>) response.getBody();
+
+ assertAll(
+ () -> assertEquals(SAMPLE_STATUS, response.getStatusCode()),
+ () -> assertEquals(value, body.get(key))
+ );
+ }
+
+
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorFactoryTest.java
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/SimulatorTest.java
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
new file mode 100644
index 000000000..7511084c4
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/TestMessages.java
@@ -0,0 +1,116 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+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(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" +
+ " \"vesServerUrl\": \"http://10.42.111.42:8080/eventListener/v5\",\n" +
+ " \"messageInterval\": \"1\"\n" +
+ "}");
+
+
+ static final Optional<JSONObject> INVALID_PNF_REGISTRATION_PARAMS_1 = Optional.of(new JSONObject(
+ "{\n" +
+ " \"pnfSerialNumber\": \"val1\",\n" +
+ " \"pnfVendorName\": \"val2\",\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" +
+ "}"));
+
+ static final Optional<JSONObject> INVALID_PNF_REGISTRATION_PARAMS_2 = Optional.of(new JSONObject(
+ "{\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" +
+ "}"));
+
+ static final Optional<JSONObject> INVALID_PNF_REGISTRATION_PARAMS_3 = Optional.of(new JSONObject(
+ "{\n" +
+ " \"pnfSerialNumber\": \"val1\",\n" +
+ " \"pnfOamIpv4Address\": \"val3\",\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" +
+ "}"));
+
+ 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/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java
new file mode 100644
index 000000000..a4fb9eb04
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/client/HttpClientAdapterImplTest.java
@@ -0,0 +1,71 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator.client;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import java.io.IOException;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+
+class HttpClientAdapterImplTest {
+
+ private HttpClientAdapter adapter;
+
+ @Mock
+ private HttpClient httpClient;
+ @Mock
+ private HttpResponse httpResponse;
+
+ @BeforeEach
+ void setup() {
+ initMocks(this);
+ adapter = new HttpClientAdapterImpl(httpClient);
+ }
+
+ @Test
+ void send_should_successfully_send_request_given_valid_url() throws IOException {
+ doReturn(httpResponse).when(httpClient).execute(any());
+
+ adapter.send("test-msg", "http://valid-url");
+
+ verify(httpClient).execute(any());
+ verify(httpResponse).getStatusLine();
+ }
+
+ @Test
+ void send_should_not_send_request_given_invalid_url() throws IOException {
+ doThrow(new IOException("test")).when(httpClient).execute(any());
+
+ adapter.send("test-msg", "http://invalid-url");
+
+ verify(httpClient).execute(any());
+ verify(httpResponse, never()).getStatusLine();
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/validation/JSONValidatorTest.java b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/validation/JSONValidatorTest.java
new file mode 100644
index 000000000..30dfe065e
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/java/org/onap/pnfsimulator/simulator/validation/JSONValidatorTest.java
@@ -0,0 +1,123 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.pnfsimulator.simulator.validation;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import com.github.fge.jsonschema.core.exceptions.InvalidSchemaException;
+import com.github.fge.jsonschema.core.exceptions.ProcessingException;
+import java.io.IOException;
+import java.net.URL;
+import org.json.JSONObject;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+class JSONValidatorTest {
+
+ private final static String VALID_SCHEMA_NAME = "valid-test-schema.json";
+ private final static String INVALID_SCHEMA_NAME = "invalid-test-schema.json";
+
+ private JSONValidator validator;
+
+ @BeforeEach
+ void setUp() {
+ validator = new JSONValidator();
+ }
+
+ @Test
+ void validate_should_not_throw_given_valid_json() throws ProcessingException, IOException, ValidationException {
+ validator.validate(getValidJsonString(), getResourcePath(VALID_SCHEMA_NAME));
+ }
+
+ @Test
+ void validate_should_not_throw_when_optional_parameter_missing()
+ throws ProcessingException, IOException, ValidationException {
+
+ String invalidJsonString = new JSONObject()
+ .put("key1", "value1")
+ .put("key2", "value2")
+ .toString();
+
+ validator.validate(invalidJsonString, getResourcePath(VALID_SCHEMA_NAME));
+ }
+
+ @Test
+ void validate_should_throw_when_mandatory_parameter_missing() {
+
+ String invalidJsonString = new JSONObject()
+ .put("key1", "value1")
+ .put("key3", "value3")
+ .toString();
+
+ assertThrows(
+ ValidationException.class,
+ () -> validator.validate(invalidJsonString, getResourcePath(VALID_SCHEMA_NAME)));
+ }
+
+ @Test
+ void validate_should_throw_when_invalid_json_format() {
+ String invalidJsonString = "{" +
+ "\"key1\": \"value1\"" +
+ "\"key2\": \"value2" +
+ "}";
+
+ assertThrows(
+ IOException.class,
+ () -> validator.validate(invalidJsonString, getResourcePath(VALID_SCHEMA_NAME)));
+ }
+
+ @Test
+ void validate_should_throw_when_invalid_schema_format() {
+ assertThrows(
+ InvalidSchemaException.class,
+ () -> validator.validate(getValidJsonString(), getResourcePath(INVALID_SCHEMA_NAME)));
+ }
+
+ @Test
+ void validate_should_throw_when_invalid_schema_path() {
+
+ assertThrows(
+ IOException.class,
+ () -> validator.validate(getValidJsonString(), "/not/existing/path/schema.json"));
+ }
+
+ private String getResourcePath(String schemaFileName) {
+ URL result = getClass()
+ .getClassLoader()
+ .getResource(schemaFileName);
+
+ if (result == null) {
+ throw new IllegalArgumentException("Given file doesn't exist");
+ } else {
+ return result
+ .toString()
+ .replace("file:", "");
+ }
+ }
+
+ private String getValidJsonString() {
+ return new JSONObject()
+ .put("key1", "value1")
+ .put("key2", "value2")
+ .put("key3", "value3")
+ .toString();
+ }
+} \ No newline at end of file
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/invalid-test-schema.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/invalid-test-schema.json
new file mode 100644
index 000000000..8c37c822b
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/invalid-test-schema.json
@@ -0,0 +1,19 @@
+{
+ "type": "object",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "properties": {
+ "key1": {
+ "type": "string"
+ },
+ "key2": {
+ "type": "string"
+ },
+ "key3": {
+ "type": "string"
+ },
+ "required": [
+ "key1",
+ "key2"
+ ]
+ }
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/logback-test.xml b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/logback-test.xml
new file mode 100644
index 000000000..d7966fe60
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/logback-test.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration complete="true" compact="true">
+
+ <Property name="outputFilename" value="pnfsimulator_output"/>
+ <Property name="log-path" value="${java.io.tmpdir}"/>
+ <property name="maxFileSize" value="50MB"/>
+ <property name="maxHistory" value="30"/>
+ <property name="totalSizeCap" value="10GB"/>
+
+ <appender name="Console" target="SYSTEM_OUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <Pattern>%nopexception%logger
+ |%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC}
+ |%level
+ |%replace(%replace(%message){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%mdc){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%rootException){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%marker){'\t','\\\\t'}){'\n','\\\\n'}
+ |%thread
+ |%n</Pattern>
+ </encoder>
+ </appender>
+
+ <appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <encoder>
+ <pattern>%nopexception%logger
+ |%date{yyyy-MM-dd'T'HH:mm:ss.SSSXXX,UTC}
+ |%level
+ |%replace(%replace(%message){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%mdc){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%rootException){'\t','\\\\t'}){'\n','\\\\n'}
+ |%replace(%replace(%marker){'\t','\\\\t'}){'\n','\\\\n'}
+ |%thread
+ |%n</pattern>
+ </encoder>
+ <File>${log-path}/${outputFilename}.log</File>
+ <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+ <FileNamePattern>${log-path}/${outputFilename}.%d{yyyy-MM-dd}.%i.log.zip</FileNamePattern>
+ <MaxFileSize>${maxFileSize}</MaxFileSize>
+ <MaxHistory>${maxHistory}</MaxHistory>
+ <TotalSizeCap>${totalSizeCap}</TotalSizeCap>
+ </rollingPolicy>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="Console" />
+ <appender-ref ref="ROLLING-FILE" />
+ </root>
+</Configuration>
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validCommonEventHeaderParams.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validCommonEventHeaderParams.json
new file mode 100644
index 000000000..e0f455045
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/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/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validNotificationParams.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validNotificationParams.json
new file mode 100644
index 000000000..f7f463d3d
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/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/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validPnfRegistrationParams.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validPnfRegistrationParams.json
new file mode 100644
index 000000000..b95f8e60a
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/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/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validSimulatorParams.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/org/onap/pnfsimulator/simulator/validSimulatorParams.json
new file mode 100644
index 000000000..6485ee4a4
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/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/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/valid-test-schema.json b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/valid-test-schema.json
new file mode 100644
index 000000000..26e48a5e8
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/src/test/resources/valid-test-schema.json
@@ -0,0 +1,19 @@
+{
+ "type": "object",
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "properties": {
+ "key1": {
+ "type": "string"
+ },
+ "key2": {
+ "type": "string"
+ },
+ "key3": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "key1",
+ "key2"
+ ]
+}
diff --git a/test/mocks/mass-pnf-sim/pnf-sim-lightweight/templates/file_template_new.xml.gz b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/templates/file_template_new.xml.gz
new file mode 100644
index 000000000..0e6624a09
--- /dev/null
+++ b/test/mocks/mass-pnf-sim/pnf-sim-lightweight/templates/file_template_new.xml.gz
Binary files differ