2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
29 "github.com/stretchr/testify/assert"
37 msgr rmrCgo.RmrMessenger
40 func TestLogger(t *testing.T) {
42 data := map[string]interface{}{"messageType": 1001, "ranIp": "10.0.0.3", "ranPort": 879, "ranName": "test1"}
43 b := new(bytes.Buffer)
44 _ = json.NewEncoder(b).Encode(data)
45 req := tests.GetHttpRequest()
46 boo, _ := ioutil.ReadAll(req.Body)
47 log.Debugf("#rmr_c_go_api_test.TestLogger - request header: %v\n; request body: %s\n", req.Header, string(boo))
50 func TestNewMBufSuccess(t *testing.T) {
51 var msgSrc unsafe.Pointer
52 msg := rmrCgo.NewMBuf(tests.MessageType, len(tests.DummyPayload), "RanName", &tests.DummyPayload, &tests.DummyXAction, msgSrc)
54 assert.NotEmpty(t, msg.Payload)
55 assert.NotEmpty(t, msg.XAction)
56 assert.Equal(t, msg.MType, tests.MessageType)
57 assert.Equal(t, msg.Meid, "RanName")
58 assert.Equal(t, msg.Len, len(tests.DummyPayload))
61 /*func TestIsReadySuccess(t *testing.T) {
64 initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
65 if msgr == nil || !msgr.IsReady() {
66 t.Errorf("#rmr_c_go_api_test.TestIsReadySuccess - The rmr router is not ready")
70 func TestSendRecvMsgSuccess(t *testing.T) {
73 initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
74 if msgr == nil || !msgr.IsReady() {
75 t.Errorf("#rmr_c_go_api_test.TestSendRecvMsgSuccess - The rmr router is not ready")
77 msg := rmrCgo.NewMBuf(1, tests.MaxMsgSize, "test 1", &tests.DummyPayload, &tests.DummyXAction)
78 log.Debugf("#rmr_c_go_api_test.TestSendRecvMsgSuccess - Going to send the message: %#v\n", msg)
79 result, err := msgr.SendMsg(msg, true)
82 assert.NotNil(t, result)
84 msgR, err := msgr.RecvMsg()
87 assert.NotNil(t, msgR)
91 func TestSendMsgRmrInvalidMsgNumError(t *testing.T) {
94 initRmr(tests.GetPort(), tests.MaxMsgSize, tests.Flags, log)
95 if msgr == nil || !msgr.IsReady() {
96 t.Errorf("#rmr_c_go_api_test.TestSendMsgRmrInvalidMsgNumError - The rmr router is not ready")
99 msg := rmrCgo.NewMBuf(10, tests.MaxMsgSize, "test 1", &tests.DummyPayload, &tests.DummyXAction)
100 log.Debugf("#rmr_c_go_api_test.TestSendMsgRmrInvalidMsgNumError - Going to send the message: %#v\n", msg)
101 result, err := msgr.SendMsg(msg, true)
103 assert.NotNil(t, err)
104 assert.Nil(t, result)
109 func TestSendMsgRmrInvalidPortError(t *testing.T) {
112 initRmr("tcp:"+strconv.Itoa(5555), tests.MaxMsgSize, tests.Flags, log)
113 if msgr == nil || !msgr.IsReady() {
114 t.Errorf("#rmr_c_go_api_test.TestSendMsgRmrInvalidPortError - The rmr router is not ready")
117 msg := rmrCgo.NewMBuf(1, tests.MaxMsgSize, "test 1", &tests.DummyPayload, &tests.DummyXAction)
118 log.Debugf("#rmr_c_go_api_test.TestSendMsgRmrInvalidPortError - Going to send the message: %#v\n", msg)
119 result, err := msgr.SendMsg(msg, true)
121 assert.NotNil(t, err)
122 assert.Nil(t, result)
127 func initRmr(port string, maxMsgSize int, flags int, log *logger.Logger) {
128 var ctx *rmrCgo.Context
129 msgr = ctx.Init(port, maxMsgSize, flags, log)
132 func initLog(t *testing.T) *logger.Logger {
133 log, err := logger.InitLogger(logger.DebugLevel)
135 t.Errorf("#rmr_c_go_api_test.initLog - failed to initialize logger, error: %s", err)
140 func TestString(t *testing.T){
141 var msgSrc unsafe.Pointer
142 msg := rmrCgo.NewMBuf(tests.MessageType, len(tests.DummyPayload), "RanName", &tests.DummyPayload, &tests.DummyXAction, msgSrc)
148 func TestGetMsgSrc(t *testing.T){
149 var msgSrc unsafe.Pointer
150 msg := rmrCgo.NewMBuf(tests.MessageType, len(tests.DummyPayload), "RanName", &tests.DummyPayload, &tests.DummyXAction, msgSrc)
151 ret := msg.GetMsgSrc()