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.
18 package rmrmsghandlers
25 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
28 "github.com/stretchr/testify/assert"
33 func TestX2ResetRequestNotifSuccess(t *testing.T) {
35 payload := []byte("payload")
36 readerMock := &mocks.RnibReaderMock{}
37 readerProvider := func() reader.RNibReader {
41 h := NewX2ResetRequestNotificationHandler(readerProvider)
43 xaction := []byte("RanName")
44 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
45 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
46 StartTime: time.Now(), TransactionId: string(xaction)}
48 nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED,}
50 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
52 messageChannel := make(chan *models.NotificationResponse)
54 go h.Handle(log,nil, ¬ificationRequest, messageChannel)
56 result := <-messageChannel
57 assert.Equal(t, result.RanName, mBuf.Meid)
58 assert.Equal(t, result.MgsType, rmrCgo.RIC_X2_RESET_RESP)
61 func TestHandleX2ResetRequestNotifShuttingDownStatus(t *testing.T) {
64 readerMock := &mocks.RnibReaderMock{}
65 readerProvider := func() reader.RNibReader {
69 h := NewX2ResetRequestNotificationHandler(readerProvider)
71 xaction := []byte("RanName")
72 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
73 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
74 StartTime: time.Now(), TransactionId: string(xaction)}
76 nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,}
79 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
81 h.Handle(log,nil, ¬ificationRequest, nil)
84 func TestHandleX2ResetRequestNotifDisconnectStatus(t *testing.T) {
87 readerMock := &mocks.RnibReaderMock{}
88 readerProvider := func() reader.RNibReader {
92 h := NewX2ResetRequestNotificationHandler(readerProvider)
94 xaction := []byte("RanName")
95 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
96 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
97 StartTime: time.Now(), TransactionId: string(xaction)}
99 nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_DISCONNECTED,}
102 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
104 h.Handle(log,nil, ¬ificationRequest, nil)
107 func TestHandleX2ResetRequestNotifGetNodebFailed(t *testing.T){
111 readerMock := &mocks.RnibReaderMock{}
112 readerProvider := func() reader.RNibReader {
116 h := NewX2ResetRequestNotificationHandler(readerProvider)
117 xaction := []byte("RanName")
118 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
119 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
120 StartTime: time.Now(), TransactionId: string(xaction)}
122 var nb *entities.NodebInfo
123 rnibErr := &common.ResourceNotFoundError{}
124 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
126 h.Handle(log,nil, ¬ificationRequest, nil)