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).
21 package rmrmsghandlers
34 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
35 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
40 func initX2ResetRequestNotificationHandlerTest(t *testing.T) (X2ResetRequestNotificationHandler, *mocks.RnibReaderMock, *mocks.RmrMessengerMock) {
42 config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
43 readerMock := &mocks.RnibReaderMock{}
45 rnibDataService := services.NewRnibDataService(log, config, readerMock, nil)
47 rmrMessengerMock := &mocks.RmrMessengerMock{}
48 rmrSender := initRmrSender(rmrMessengerMock, log)
49 ranStatusChangeManager := managers.NewRanStatusChangeManager(log, rmrSender)
50 h := NewX2ResetRequestNotificationHandler(log, rnibDataService, ranStatusChangeManager, rmrSender)
51 return h, readerMock, rmrMessengerMock
54 func getRanRestartedMbuf(nodeType entities.Node_Type, messageDirection enums.MessageDirection) *rmrCgo.MBuf {
56 resourceStatusPayload := models.NewResourceStatusPayload(nodeType, messageDirection)
57 resourceStatusJson, _ := json.Marshal(resourceStatusPayload)
58 return rmrCgo.NewMBuf(rmrCgo.RAN_RESTARTED, len(resourceStatusJson), RanName, &resourceStatusJson, &xAction)
61 func TestHandleX2ResetRequestNotificationSuccess(t *testing.T) {
62 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
64 xAction := []byte("123456aa")
65 notificationRequest := models.NewNotificationRequest(ranName, []byte{}, time.Now(), xAction)
67 nb := &entities.NodebInfo{RanName: ranName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, NodeType: entities.Node_ENB}
69 readerMock.On("GetNodeb", ranName).Return(nb, err)
70 resetResponseMbuf := rmrCgo.NewMBuf(rmrCgo.RIC_X2_RESET_RESP, len(e2pdus.PackedX2ResetResponse), ranName, &e2pdus.PackedX2ResetResponse, &xAction)
71 rmrMessengerMock.On("SendMsg", resetResponseMbuf, true).Return(&rmrCgo.MBuf{}, err)
72 ranRestartedMbuf := getRanRestartedMbuf(nb.NodeType, enums.RAN_TO_RIC)
73 rmrMessengerMock.On("SendMsg", ranRestartedMbuf, true).Return(&rmrCgo.MBuf{}, err)
74 h.Handle(notificationRequest)
75 rmrMessengerMock.AssertCalled(t, "SendMsg", resetResponseMbuf, true)
76 rmrMessengerMock.AssertCalled(t, "SendMsg", ranRestartedMbuf, true)
79 func TestHandleX2ResetRequestNotificationShuttingDownStatus(t *testing.T) {
80 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
83 xAction := []byte("123456aa")
84 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xAction)
85 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
86 StartTime: time.Now(), TransactionId: xAction}
88 nb := &entities.NodebInfo{RanName: mBuf.Meid, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN,}
91 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
93 h.Handle(¬ificationRequest)
94 rmrMessengerMock.AssertNotCalled(t, "SendMsg")
97 func TestHandleX2ResetRequestNotificationDisconnectStatus(t *testing.T) {
98 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
100 xAction := []byte("123456aa")
101 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xAction)
102 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(), TransactionId: xAction}
103 nb := &entities.NodebInfo{RanName: mBuf.Meid, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,}
105 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
107 h.Handle(¬ificationRequest)
108 rmrMessengerMock.AssertNotCalled(t, "SendMsg")
111 func TestHandleX2ResetRequestNotificationGetNodebFailed(t *testing.T) {
113 h, readerMock, rmrMessengerMock := initX2ResetRequestNotificationHandlerTest(t)
116 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xAction)
117 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
118 StartTime: time.Now(), TransactionId: xAction}
120 var nb *entities.NodebInfo
121 rnibErr := &common.ResourceNotFoundError{}
122 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
124 h.Handle(¬ificationRequest)
125 rmrMessengerMock.AssertNotCalled(t, "SendMsg")