Testcase for A1 Healthcheck added.
[ric-app/hw.git] / test / test_hc.h
1 /*
2 ==================================================================================
3
4         Copyright (c) 2018-2019 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 using namespace std;
34 TEST(Xapp, RMRHealthCheck){
35
36          int total_num_msgs = 2;
37          int num_attempts = 10;
38
39          std::unique_ptr<XappRmr> rmr;
40          rmr = std::make_unique<XappRmr>("4560",num_attempts);
41          rmr->xapp_rmr_init();
42
43          XappSettings config;
44
45          std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
46
47          std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
48
49          hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
50          sleep(5);
51
52          xapp_rmr_header hdr;
53          hdr.message_type = RIC_HEALTH_CHECK_REQ;
54          char strMsg[HC_MSG_SIZE];
55
56          for(int i = 0; i < total_num_msgs; i++){
57                  snprintf(strMsg,HC_MSG_SIZE, "HelloWorld: RMR Health Check %d", i);
58                  clock_gettime(CLOCK_REALTIME, &(hdr.ts));
59                  hdr.payload_length = strlen(strMsg);
60
61                  bool res = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
62                  usleep(1);
63          }
64          sleep(10);
65          hw_xapp->stop();
66          sleep(10);
67  };
68
69 TEST(Xapp, A1HealthCheck){
70
71         //Read the json file and send it using rmr.
72         string json = "{\"policy_type_id\": \"1\",\"policy_instance_id\":\"3d2157af-6a8f-4a7c-810f-38c2f824bf12\",\"operation\": \"CREATE\"}";
73         int n = json.length();
74         char strMsg[n + 1];
75         strcpy(strMsg, json.c_str());
76         Document d;
77         d.Parse(strMsg);
78
79         int num_attempts = 5;
80
81         std::unique_ptr<XappRmr> rmr;
82         rmr = std::make_unique<XappRmr>("4560",num_attempts);
83         rmr->xapp_rmr_init();
84
85         XappSettings config;
86
87         std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
88
89         std::unique_ptr<XappMsgHandler> mp_handler = std::make_unique<XappMsgHandler>("HW-Xapp-id");
90
91         hw_xapp->start_xapp_receiver(std::ref(*mp_handler));
92         sleep(5);
93
94         xapp_rmr_header hdr;
95         hdr.message_type = A1_POLICY_REQ;
96     clock_gettime(CLOCK_REALTIME, &(hdr.ts));
97
98
99         hdr.payload_length = strlen(strMsg);
100
101         bool res_msg1 = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
102         ASSERT_TRUE(res_msg1);
103
104         usleep(1);
105
106         bool res_msg2 = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
107         ASSERT_TRUE(res_msg2);
108
109         sleep(10);
110         hw_xapp->stop();
111         sleep(10);
112
113 }