Merge "Fix PM_MAPPER_01 test - use a non-generic log"
[integration/csit.git] / tests / dcaegen2 / testcases / resources / DMaaP.py
index 779397e..4c24561 100644 (file)
@@ -106,20 +106,22 @@ 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
             try:
                 if EvtSchema is None:
-                    with open(DcaeVariables.CommonEventSchemaV5) as opened_file:
+                    with open(DcaeVariables.CommonEventSchema) as opened_file:
                         EvtSchema = json.load(opened_file)
                 decoded_body = json.loads(post_body)
                 jsonschema.validate(decoded_body, 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()
@@ -368,8 +373,8 @@ class DMaaPHandler(BaseHTTPServer.BaseHTTPRequestHandler):
 
 
 def test(handler_class=DMaaPHandler, server_class=BaseHTTPServer.HTTPServer, protocol="HTTP/1.0", port=3904):
-    print "Load event schema file: " + DcaeVariables.CommonEventSchemaV5
-    with open(DcaeVariables.CommonEventSchemaV5) as opened_file:
+    print "Load event schema file: " + DcaeVariables.CommonEventSchema
+    with open(DcaeVariables.CommonEventSchema) as opened_file:
         global EvtSchema
         EvtSchema = json.load(opened_file)
         
@@ -394,8 +399,8 @@ def _main_(handler_class=DMaaPHandler, server_class=BaseHTTPServer.HTTPServer, p
     else:
         port = 3904
     
-    print "Load event schema file: " + DcaeVariables.CommonEventSchemaV5
-    with open(DcaeVariables.CommonEventSchemaV5) as opened_file:
+    print "Load event schema file: " + DcaeVariables.CommonEventSchema
+    with open(DcaeVariables.CommonEventSchema) as opened_file:
         global EvtSchema
         EvtSchema = json.load(opened_file)