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
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
29 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
30 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
31 "github.com/stretchr/testify/assert"
36 func initX2ResetRequestNotifHandlerTest(t *testing.T) (*logger.Logger, X2ResetRequestNotificationHandler, *mocks.RnibReaderMock) {
38 config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
39 readerMock := &mocks.RnibReaderMock{}
40 readerProvider := func() reader.RNibReader {
43 rnibDataService := services.NewRnibDataService(log, config, readerProvider, nil)
45 h := NewX2ResetRequestNotificationHandler(rnibDataService)
46 return log, h, readerMock
49 func TestX2ResetRequestNotifSuccess(t *testing.T) {
50 log, h, readerMock := initX2ResetRequestNotifHandlerTest(t)
52 payload := []byte("payload")
54 xaction := []byte("RanName")
55 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xaction)
56 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
57 StartTime: time.Now(), TransactionId: string(xaction)}
59 nb := &entities.NodebInfo{RanName: mBuf.Meid, ConnectionStatus: entities.ConnectionStatus_CONNECTED,}
61 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
63 messageChannel := make(chan *models.NotificationResponse)
65 go h.Handle(log, ¬ificationRequest, messageChannel)
67 result := <-messageChannel
68 assert.Equal(t, result.RanName, mBuf.Meid)
69 assert.Equal(t, result.MgsType, rmrCgo.RIC_X2_RESET_RESP)
72 func TestHandleX2ResetRequestNotifShuttingDownStatus(t *testing.T) {
73 log, h, readerMock := initX2ResetRequestNotifHandlerTest(t)
76 xaction := []byte("RanName")
77 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xaction)
78 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
79 StartTime: time.Now(), TransactionId: string(xaction)}
81 nb := &entities.NodebInfo{RanName: mBuf.Meid, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN,}
84 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
86 h.Handle(log, ¬ificationRequest, nil)
89 func TestHandleX2ResetRequestNotifDisconnectStatus(t *testing.T) {
90 log, h, readerMock := initX2ResetRequestNotifHandlerTest(t)
93 xaction := []byte("RanName")
94 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xaction)
95 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
96 StartTime: time.Now(), TransactionId: string(xaction)}
98 nb := &entities.NodebInfo{RanName: mBuf.Meid, ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,}
101 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
103 h.Handle(log, ¬ificationRequest, nil)
106 func TestHandleX2ResetRequestNotifGetNodebFailed(t *testing.T) {
108 log, h, readerMock := initX2ResetRequestNotifHandlerTest(t)
110 xaction := []byte("RanName")
111 mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload), "RanName", &payload, &xaction)
112 notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload,
113 StartTime: time.Now(), TransactionId: string(xaction)}
115 var nb *entities.NodebInfo
116 rnibErr := &common.ResourceNotFoundError{}
117 readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
119 h.Handle(log, ¬ificationRequest, nil)