From f8f4621e6fe5fd6497545083685910f3eb4230c8 Mon Sep 17 00:00:00 2001
From: Giacomo Bernini <g.bernini@nextworks.it>
Date: Thu, 21 Oct 2021 17:35:08 +0200
Subject: [PATCH] updated SOL005 NS PM job creeation and update with mandatory
 test notification endpoint

---
 .../IndividualPmJob.robot                     |  5 ++++
 .../IndividualThreshold.robot                 |  5 ++++
 .../NSPerformanceManagementKeywords.robot     | 30 +++++++++++++++++--
 .../NSPerformanceManagement-API/PMJobs.robot  |  4 +++
 .../Thresholds.robot                          |  5 ++++
 .../jsons/CreatePmJobRequest.json             |  2 +-
 .../jsons/CreateThresholdRequest.json         |  2 +-
 .../jsons/PmJobModifications.json             |  2 +-
 .../jsons/ThresholdModifications.json         |  2 +-
 9 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/SOL005/NSPerformanceManagement-API/IndividualPmJob.robot b/SOL005/NSPerformanceManagement-API/IndividualPmJob.robot
index 5220e858..3db56893 100644
--- a/SOL005/NSPerformanceManagement-API/IndividualPmJob.robot
+++ b/SOL005/NSPerformanceManagement-API/IndividualPmJob.robot
@@ -4,6 +4,11 @@ Resource          environment/variables.txt    # Generic Parameters
 Library           JSONLibrary
 Resource          NSPerformanceManagementKeywords.robot
 Library           REST    ${NFVO_SCHEMA}://${NFVO_HOST}:${NFVO_PORT}    ssl_verify=false
+Library           MockServerLibrary
+Library           Process
+
+Suite Setup       Create Sessions
+Suite Teardown    Terminate All Processes    kill=true
 
 *** Test Cases ***
 GET individual NS Performance Job
diff --git a/SOL005/NSPerformanceManagement-API/IndividualThreshold.robot b/SOL005/NSPerformanceManagement-API/IndividualThreshold.robot
index 1a55bfb7..2a61c5b1 100644
--- a/SOL005/NSPerformanceManagement-API/IndividualThreshold.robot
+++ b/SOL005/NSPerformanceManagement-API/IndividualThreshold.robot
@@ -6,6 +6,11 @@ Resource          NSPerformanceManagementKeywords.robot
 Library           JSONLibrary
 Library           REST    ${NFVO_SCHEMA}://${NFVO_HOST}:${NFVO_PORT}    ssl_verify=false
 Library           OperatingSystem
+Library           MockServerLibrary
+Library           Process
+
+Suite Setup       Create Sessions
+Suite Teardown    Terminate All Processes    kill=true
 
 *** Test Cases ***
 GET Individual Threshold
diff --git a/SOL005/NSPerformanceManagement-API/NSPerformanceManagementKeywords.robot b/SOL005/NSPerformanceManagement-API/NSPerformanceManagementKeywords.robot
index 69f8826c..29e0c562 100644
--- a/SOL005/NSPerformanceManagement-API/NSPerformanceManagementKeywords.robot
+++ b/SOL005/NSPerformanceManagement-API/NSPerformanceManagementKeywords.robot
@@ -92,10 +92,19 @@ Send Post Request Create new NS Performance Monitoring Job
     Set Headers    {"Content-Type": "${CONTENT_TYPE_JSON}"}
     Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"${AUTHORIZATION_HEADER}":"${AUTHORIZATION_TOKEN}"}
     ${template}=    Get File    jsons/CreatePmJobRequest.json
-    ${body}=        Format String   ${template}     pmJobId=${pmJobId}
+    ${body}=        Format String   ${template}     pmJobId=${pmJobId}    callbackUri=${callback_uri}   callbackEndpoint=${callback_endpoint}   callbackPort=${callback_port}    performanceMetric=${performanceMetric}    collectionPeriod=${collectionPeriod}    reportingPeriod=${reportingPeriod} 
+    Log  Creating mock request and response to handle GET operation on notification endpoint
+    &{notification_request}=  Create Mock Request Matcher	GET  ${callback_endpoint}
+    &{notification_response}=  Create Mock Response	status_code=204
+    Log    Issue the request
+    Create Mock Expectation  ${notification_request}  ${notification_response}
     POST    ${apiRoot}/${apiName}/${apiMajorVersion}/pm_jobs    ${body}
     ${output}=    Output    response
     Set Suite Variable    ${response}    ${output}
+    Log    Verify producer tested the notification endpoint
+	Verify Mock Expectation    ${notification_request}
+	Clear Requests    ${callback_endpoint}
+
     
 Send POST request for NS Performance Monitoring Job with unprocessable entity
     Log    trying to create a new NS PM Job
@@ -103,10 +112,18 @@ Send POST request for NS Performance Monitoring Job with unprocessable entity
     Set Headers    {"Content-Type": "${CONTENT_TYPE_JSON}"}
     Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"${AUTHORIZATION_HEADER}":"${AUTHORIZATION_TOKEN}"}
     ${template}=    Get File    jsons/CreatePmJobRequest.json
-    ${body}=        Format String   ${template}     objectInstanceIds=${objectInstanceIds}    callback_uri=${unreachable_callback_uri}:${callback_port}
+    ${body}=        Format String   ${template}     pmJobId=${pmJobId}    callbackUri=${callback_uri}   callbackEndpoint=${unreachable_callback_uri}   callbackPort=${callback_port}    performanceMetric=${performanceMetric}    collectionPeriod=${collectionPeriod}    reportingPeriod=${reportingPeriod} 
+    Log  Creating mock request and response to handle GET operation on notification endpoint
+    &{notification_request}=  Create Mock Request Matcher	GET  ${callback_endpoint}
+    &{notification_response}=  Create Mock Response	status_code=204
+    Log    Issue the request
+    Create Mock Expectation  ${notification_request}  ${notification_response}
     POST    ${apiRoot}/${apiName}/${apiMajorVersion}/pm_jobs    ${body}
     ${output}=    Output    response
     Set Suite Variable    ${response}    ${output}
+    Log    Verify producer tested the notification endpoint
+	Verify Mock Expectation    ${notification_request}
+	Clear Requests    ${callback_endpoint}
 
 Send PUT Request for all NS Performance Monitoring Jobs 
     Log    Trying to perform a PUT. This method should not be implemented
@@ -251,9 +268,18 @@ Send Patch request for individual NS Performance Job
     Set Headers  {"Content-Type": "${CONTENT_TYPE_PATCH}"}
     Run Keyword If    ${AUTH_USAGE} == 1    Set Headers    {"${AUTHORIZATION_HEADER}":"${AUTHORIZATION_TOKEN}"}
     ${body}=    Get File    jsons/PmJobModifications.json
+    ${body}=        Format String   ${body}     callbackUri=${callback_uri}   callbackEndpoint=${callback_endpoint}   callbackPort=${callback_port}
+    Log  Creating mock request and response to handle GET operation on notification endpoint
+    &{notification_request}=  Create Mock Request Matcher	GET  ${callback_endpoint}
+    &{notification_response}=  Create Mock Response	status_code=204
+    Log    Issue the request
+    Create Mock Expectation  ${notification_request}  ${notification_response}
     PATCH    ${apiRoot}/${apiName}/${apiMajorVersion}/pm_jobs/${pmJobId}    ${body}
     ${output}=    Output    response
     Set Suite Variable    ${response}    ${output}
+    Log    Verify producer tested the notification endpoint
+	Verify Mock Expectation    ${notification_request}
+	Clear Requests    ${callback_endpoint}
 
 Send Patch request for individual NS Performance Job - Etag mismatch 
     Log    Trying to perform a PATCH 
diff --git a/SOL005/NSPerformanceManagement-API/PMJobs.robot b/SOL005/NSPerformanceManagement-API/PMJobs.robot
index 40477081..bbb6ef7e 100644
--- a/SOL005/NSPerformanceManagement-API/PMJobs.robot
+++ b/SOL005/NSPerformanceManagement-API/PMJobs.robot
@@ -6,6 +6,10 @@ Library           JSONLibrary
 Library           OperatingSystem
 Library           REST    ${NFVO_SCHEMA}://${NFVO_HOST}:${NFVO_PORT}    ssl_verify=false
 Library           MockServerLibrary
+Library           Process
+
+Suite Setup       Create Sessions
+Suite Teardown    Terminate All Processes    kill=true
 
 *** Test Cases ***
 GET all NS Performance Monitoring Jobs
diff --git a/SOL005/NSPerformanceManagement-API/Thresholds.robot b/SOL005/NSPerformanceManagement-API/Thresholds.robot
index 6c662383..60f8f13a 100644
--- a/SOL005/NSPerformanceManagement-API/Thresholds.robot
+++ b/SOL005/NSPerformanceManagement-API/Thresholds.robot
@@ -6,6 +6,11 @@ Resource          NSPerformanceManagementKeywords.robot
 Library           JSONLibrary
 Library           REST    ${NFVO_SCHEMA}://${NFVO_HOST}:${NFVO_PORT}    ssl_verify=false
 Library           OperatingSystem
+Library           MockServerLibrary
+Library           Process
+
+Suite Setup       Create Sessions
+Suite Teardown    Terminate All Processes    kill=true
 
 *** Test Cases ***
 GET All Performance Thresholds
diff --git a/SOL005/NSPerformanceManagement-API/jsons/CreatePmJobRequest.json b/SOL005/NSPerformanceManagement-API/jsons/CreatePmJobRequest.json
index f9f66826..2f55c065 100644
--- a/SOL005/NSPerformanceManagement-API/jsons/CreatePmJobRequest.json
+++ b/SOL005/NSPerformanceManagement-API/jsons/CreatePmJobRequest.json
@@ -6,5 +6,5 @@
 		"collectionPeriod": {collectionPeriod},
 		"reportingPeriod": {reportingPeriod}
 	}},
-	"callbackUri": "{callback_uri}"
+	"callbackUri": "{callbackUri}:{callbackPort}{callbackEndpoint}"
 }}
\ No newline at end of file
diff --git a/SOL005/NSPerformanceManagement-API/jsons/CreateThresholdRequest.json b/SOL005/NSPerformanceManagement-API/jsons/CreateThresholdRequest.json
index 44a0b598..145f2d68 100644
--- a/SOL005/NSPerformanceManagement-API/jsons/CreateThresholdRequest.json
+++ b/SOL005/NSPerformanceManagement-API/jsons/CreateThresholdRequest.json
@@ -8,5 +8,5 @@
 			"hysteresis": {hysteresis}
 		}}	
 	}},
-	"callbackUri": "{callback_uri}"
+	"callbackUri": "{callbackUri}:{callbackPort}{callbackEndpoint}"
 }}
\ No newline at end of file
diff --git a/SOL005/NSPerformanceManagement-API/jsons/PmJobModifications.json b/SOL005/NSPerformanceManagement-API/jsons/PmJobModifications.json
index f66ab98e..3e630d3b 100644
--- a/SOL005/NSPerformanceManagement-API/jsons/PmJobModifications.json
+++ b/SOL005/NSPerformanceManagement-API/jsons/PmJobModifications.json
@@ -1,3 +1,3 @@
 {
-	"callbackUri": ""
+	"callbackUri": "{callbackUri}:{callbackPort}{callbackEndpoint}"
 }
\ No newline at end of file
diff --git a/SOL005/NSPerformanceManagement-API/jsons/ThresholdModifications.json b/SOL005/NSPerformanceManagement-API/jsons/ThresholdModifications.json
index 60c7f184..3e630d3b 100644
--- a/SOL005/NSPerformanceManagement-API/jsons/ThresholdModifications.json
+++ b/SOL005/NSPerformanceManagement-API/jsons/ThresholdModifications.json
@@ -1,3 +1,3 @@
 {
-	"callbackUri":""
+	"callbackUri": "{callbackUri}:{callbackPort}{callbackEndpoint}"
 }
\ No newline at end of file
-- 
GitLab