d831c96414cf37ef351a5631761ecee8b62cf94a
[ric-app/hw.git] / test / test_subs.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 #ifndef TEST_TEST_SUBS_H_
20 #define TEST_TEST_SUBS_H_
21
22 #include<iostream>
23 #include<gtest/gtest.h>
24 #include "xapp.hpp"
25 #define BUFFER_SIZE 1024
26
27 using namespace std;
28 //generating a E2AP Subscription Message
29 TEST(SUBSCRIPTION, Request){
30
31
32         subscription_helper  din;
33         subscription_helper  dout;
34
35         subscription_request sub_req;
36         subscription_request sub_recv;
37
38         unsigned char buf[BUFFER_SIZE];
39         size_t buf_size = BUFFER_SIZE;
40         bool res;
41
42
43         //Random Data  for request
44         int request_id = 1;
45         int function_id = 0;
46         std::string event_def = "HelloWorld Event Definition";
47
48         din.set_request(request_id);
49         din.set_function_id(function_id);
50         din.set_event_def(event_def.c_str(), event_def.length());
51
52         std::string act_def = "HelloWorld Action Definition";
53
54         din.add_action(1,1,(void*)act_def.c_str(), act_def.length(), 0);
55
56         res = sub_req.encode_e2ap_subscription(&buf[0], &buf_size, din);
57         ASSERT_TRUE(res);
58
59
60
61 }
62
63 //create a MOck e2term
64 TEST (MOCK, E2TERM){
65
66          const char* meid = "test1";
67          const char* sub_id = "sub1";
68          //Send the Subscription Response.
69          xapp_rmr_header hdr;
70          hdr.message_type = RIC_SUB_RESP;
71          clock_gettime(CLOCK_REALTIME, &(hdr.ts));
72          const char* strMsg = "Subscription Response for MEID: test1";
73          hdr.payload_length = strlen(strMsg);
74          strcpy((char*)hdr.meid, meid);
75          strcpy((char*)hdr.sid,sub_id);
76          int total_num_msgs = 2;
77          int num_attempts = 10;
78
79          std::unique_ptr<XappRmr> rmr;
80          rmr = std::make_unique<XappRmr>("4591",num_attempts);
81          rmr->xapp_rmr_init(true);
82
83          XappSettings config;
84
85          std::unique_ptr<Xapp> hw_xapp = std::make_unique<Xapp>(std::ref(config),std::ref(*rmr));
86          while(1){
87                  bool res_msg = rmr->xapp_rmr_send(&hdr,(void*)strMsg);
88                  if(res_msg){
89                          mdclog_write(MDCLOG_INFO, "Message Sent Successfully");
90                          break;
91                  }
92                  sleep(10);
93          }
94 }
95
96 #endif /* TEST_TEST_SUBS_H_ */