tests for ssl connection for PRH, AAI and DmaaP
[integration/csit.git] / tests / dcaegen2 / prh-testcases / resources / simulator / DMaaP.py
1 import re
2 import time
3 from http.server import BaseHTTPRequestHandler
4 import httpServerLib
5
6 posted_event_from_prh = b'Empty'
7 received_event_to_get_method = b'Empty'
8
9
10 class DmaapSetup(BaseHTTPRequestHandler):
11
12     def do_PUT(self):
13         if re.search('/set_get_event', self.path):
14             global received_event_to_get_method
15             content_length = int(self.headers['Content-Length'])
16             received_event_to_get_method = self.rfile.read(content_length)
17             httpServerLib.header_200_and_json(self)
18
19         return
20
21     def do_GET(self):
22         if re.search('/events/pnfReady', self.path):
23             httpServerLib.header_200_and_json(self)
24             self.wfile.write(posted_event_from_prh)
25
26         return
27
28     def do_POST(self):
29         if re.search('/reset', self.path):
30             global posted_event_from_prh
31             global received_event_to_get_method
32             posted_event_from_prh = b'Empty'
33             received_event_to_get_method = b'Empty'
34             httpServerLib.header_200_and_json(self)
35
36         return
37
38
39 class DMaaPHandler(BaseHTTPRequestHandler):
40
41     def do_POST(self):
42         if re.search('/events/unauthenticated.PNF_READY', self.path):
43             global posted_event_from_prh
44             content_length = int(self.headers['Content-Length'])
45             posted_event_from_prh = self.rfile.read(content_length)
46             httpServerLib.header_200_and_json(self)
47
48         return
49
50     def do_GET(self):
51         if re.search('/events/unauthenticated.VES_PNFREG_OUTPUT/OpenDcae-c12/c12', self.path):
52             httpServerLib.header_200_and_json(self)
53             self.wfile.write(received_event_to_get_method)
54
55         return
56
57
58 def _main_(handler_class=DMaaPHandler, protocol="HTTP/1.0"):
59     handler_class.protocol_version = protocol
60     httpServerLib.start_http_endpoint(2222, DMaaPHandler)
61     httpServerLib.start_https_endpoint(2223, DMaaPHandler)
62     httpServerLib.start_http_endpoint(2224, DmaapSetup)
63     while 1:
64         time.sleep(10)
65
66
67 if __name__ == '__main__':
68     _main_()