d07fbfef036deaa05d9ad005c85eba9693b3c257
[ric-app/hw.git] / test / test_hc.h
1 /*
2 ==================================================================================
3
4         Copyright (c) 2019-2020 AT&T Intellectual Property.
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 /*
19  * test_a1.h
20  *
21  *  Created on: Mar, 2020
22  *  Author: Shraboni Jana
23  */
24
25 #include<iostream>
26 #include<gtest/gtest.h>
27 #include<rapidjson/stringbuffer.h>
28 #include<rapidjson/writer.h>
29 #include<string.h>
30 #include "xapp.hpp"
31 #define HC_MSG_SIZE 512
32
33
34 using namespace std;
35 TEST(Xapp, RMRHealthCheck){
36
37          int total_num_msgs = 2;
38          int num_attempts = 10;
39
40          std::unique_ptr<XappRmr> rmr;
41          rmr = std::make_unique<XappRmr>("4560",num_attempts);
42          rmr->xapp_rmr_init(true);
43
44          XappSettings config;
45
46          std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
47
48          std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
49
50          hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
51          sleep(5);
52
53          xapp_rmr_header hdr;
54          hdr.message_type = RIC_HEALTH_CHECK_REQ;
55          char strMsg[HC_MSG_SIZE];
56
57          for(int i = 0; i < total_num_msgs; i++){
58                  snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i);
59                  clock_gettime(CLOCK_REALTIME, &(hdr.ts));
60                  hdr.payload_length = strlen(strMsg);
61
62                  bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
63                  usleep(1);
64          }
65          sleep(2);
66          hw_xapp->stop();
67
68 };
69
70 TEST(Xapp, A1HealthCheck){
71
72         //Read the json file and send it using rmr.
73         string json = "{\"policy_type_id\": \"1\",\"policy_instance_id\":\"3d2157af-6a8f-4a7c-810f-38c2f824bf12\",\"operation\": \"CREATE\"}";
74         int n = json.length();
75         char strMsg[n + 1];
76         strcpy(strMsg, json.c_str());
77         Document d;
78         d.Parse(strMsg);
79
80         int num_attempts = 5;
81
82         std::unique_ptr<XappRmr> rmr;
83         rmr = std::make_unique<XappRmr>("4560",num_attempts);
84         rmr->xapp_rmr_init(true);
85
86         XappSettings config;
87
88         std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
89
90         std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
91
92         hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
93         sleep(5);
94
95         xapp_rmr_header hdr;
96         hdr.message_type = A1_POLICY_REQ;
97     clock_gettime(CLOCK_REALTIME, &(hdr.ts));
98
99
100         hdr.payload_length = strlen(strMsg);
101
102         bool res_msg1 = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
103         ASSERT_TRUE(res_msg1);
104
105         usleep(1);
106
107         bool res_msg2 = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
108         ASSERT_TRUE(res_msg2);
109
110         sleep(2);
111         hw_xapp->stop();
112 }