Add topic validation for dcaegen2 VES tests 83/110683/2
authorBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Wed, 29 Jul 2020 09:13:36 +0000 (11:13 +0200)
committerBartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Wed, 29 Jul 2020 10:19:21 +0000 (12:19 +0200)
Issue-ID: DCAEGEN2-1771
Signed-off-by: Bartosz Gardziejewski <bartosz.gardziejewski@nokia.com>
Change-Id: Ifb4f0f01ef3dcda366147d32c98a9be7890b6f56

tests/dcaegen2/testcases/01__no_auth_tests.robot
tests/dcaegen2/testcases/resources/DMaaP.py
tests/dcaegen2/testcases/resources/DcaeLibrary.py
tests/dcaegen2/testcases/resources/dcae_keywords.robot

index f05c0ce..7e7f976 100644 (file)
@@ -14,7 +14,7 @@ Publish Single VES VNF Measurement Event API V7
 Publish Single VES VNF Measurement Event with Standard Defined Fields API V7
     [Tags]    DCAE-VESC-R1
     [Documentation]   Post single event with valid data with Standard Defined Fields to /eventListener/v7 endpoint and expect 202 Response Status Code
-    Send Request And Validate Response  Publish Event To VES Collector  ${http_session}  ${VES_EVENTLISTENER_V7}  ${VES_VALID_JSON_V7_STND_DEF_FIELDS}  202  stndDefined-gNB-Nokia-PowerLost
+    Send Request And Validate Response  Publish Event To VES Collector  ${http_session}  ${VES_EVENTLISTENER_V7}  ${VES_VALID_JSON_V7_STND_DEF_FIELDS}  202  stndDefined-gNB-Nokia-PowerLost  unauthenticated.SEC_OTHER_OUTPUT
 
 Publish Single VES VNF Measurement Event with wrong JSON
     [Tags]    DCAE-VESC-R1
index 500afd5..4c24561 100644 (file)
@@ -106,14 +106,16 @@ class DMaaPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
         '''  
         
         if resp_code == 0:
+            topic = self.extract_topic_from_path()
             content_len = int(self.headers.getheader('content-length', 0))
             post_body = self.rfile.read(content_len)
             
             indx = post_body.index("{")
             if indx != 0:
                 post_body = post_body[indx:]
-            
-            if not enque_event(post_body):
+
+            event = "\""+topic+"\":" + post_body
+            if not enque_event(event):
                 print "enque event fails"
                    
             global EvtSchema
@@ -180,6 +182,9 @@ class DMaaPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
         '''
         return
 
+    def extract_topic_from_path(self):
+        return self.path["/events/".__len__():]
+
     def do_GET(self):
         """Serve a GET request."""
         f = self.send_head()
index 6b96826..a9d5def 100644 (file)
@@ -87,6 +87,18 @@ class DcaeLibrary(object):
         time.sleep(5)
         return
 
+    @staticmethod
+    def dmaap_message_receive_on_topic(evtobj, topic):
+
+        evt_str = DMaaP.deque_event()
+        while evt_str != None:
+            if evtobj in evt_str and topic in evt_str:
+                logger.info("DMaaP Receive Expected Publish Event:\n" + evt_str)
+                logger.info("On Expected Topic:\n" + topic)
+                return 'true'
+            evt_str = DMaaP.deque_event()
+        return 'false'
+
     @staticmethod
     def dmaap_message_receive(evtobj, action='contain'):
         
index 0735ce8..059372f 100644 (file)
@@ -141,19 +141,20 @@ Publish Event To VES Collector With Put Method
 
 Send Request And Validate Response
     [Documentation]  Post singel event to passed url with passed data and validate received response
-    [Arguments]  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${resp_code}  ${msg_code}=None
+    [Arguments]  ${keyword}  ${session}  ${evtpath}  ${evtjson}  ${resp_code}  ${msg_code}=None  ${topic}=None
     ${evtdata}=  Get Data From File  ${evtjson}
     ${resp}=  Run Keyword  ${keyword}  ${session}  ${evtpath}  ${evtdata}
     Log    Receive HTTPS Status code ${resp.status_code}
     Should Be Equal As Strings         ${resp.status_code}     ${resp_code}
     ${isEmpty}=   Is Json Empty    ${resp}
     Run Keyword If   '${isEmpty}' == False   Log  ${resp.json()}
-    Run Keyword If  '${msg_code}' != 'None'  Check Whether Message Received  ${msg_code}
+    Run Keyword If  '${msg_code}' != 'None'  Check Whether Message Received  ${msg_code}  ${topic}
 
 Check Whether Message Received
     [Documentation]  Validare if message has been received
-    [Arguments]  ${msg_code}
-    ${ret}=  DMaaP Message Receive  ${msg_code}
+    [Arguments]  ${msg_code}  ${topic}
+    ${ret}=  Run Keyword If  '${topic}' != 'None'  DMaaP Message Receive On Topic  ${msg_code}  ${topic}
+    ...  ELSE  DMaaP Message Receive  ${msg_code}
     Should Be Equal As Strings    ${ret}    true
 
 Send Request And Expect Error