2 // Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 // platform project (RICP).
19 package rmrmsghandlers
31 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
32 "github.com/stretchr/testify/assert"
33 "github.com/stretchr/testify/mock"
37 E2nodeConfigUpdateXmlPath = "../../tests/resources/configurationUpdate/e2NodeConfigurationUpdate.xml"
38 E2nodeConfigUpdateOnlyAdditionXmlPath = "../../tests/resources/configurationUpdate/e2NodeConfigurationUpdateOnlyAddition.xml"
39 E2nodeConfigUpdateOnlyAdditionAndUpdateXmlPath = "../../tests/resources/configurationUpdate/e2NodeConfigurationUpdateAdditionAndUpdateOnly.xml"
42 func initE2nodeConfigMocks(t *testing.T) (*E2nodeConfigUpdateNotificationHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.RmrMessengerMock) {
43 logger := tests.InitLog(t)
44 config := &configuration.Configuration{
45 RnibRetryIntervalMs: 10,
46 MaxRnibConnectionAttempts: 3,
47 RnibWriter: configuration.RnibWriterConfig{
48 StateChangeMessageChannel: StateChangeMessageChannel,
54 }{Mcc: "327", Mnc: "94", RicId: "AACCE"}}
55 readerMock := &mocks.RnibReaderMock{}
56 writerMock := &mocks.RnibWriterMock{}
57 rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock)
58 rmrMessengerMock := &mocks.RmrMessengerMock{}
59 rmrSender := tests.InitRmrSender(rmrMessengerMock, logger)
60 handler := NewE2nodeConfigUpdateNotificationHandler(logger, rnibDataService, rmrSender)
61 return handler, readerMock, writerMock, rmrMessengerMock
64 func TestE2nodeConfigUpdatetNotificationHandler(t *testing.T) {
65 e2NodeConfigUpdateXml := utils.ReadXmlFile(t, E2nodeConfigUpdateOnlyAdditionXmlPath)
66 handler, readerMock, writerMock, rmrMessengerMock := initE2nodeConfigMocks(t)
67 var nodebInfo = &entities.NodebInfo{
68 RanName: gnbNodebRanName,
69 AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
70 ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
71 NodeType: entities.Node_GNB,
72 Configuration: &entities.NodebInfo_Gnb{
76 readerMock.On("GetNodeb", gnbNodebRanName).Return(nodebInfo, nil)
77 writerMock.On("UpdateNodebInfoAndPublish", mock.Anything).Return(nil)
79 rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(&rmrCgo.MBuf{}, errEmpty)
80 notificationRequest := &models.NotificationRequest{RanName: gnbNodebRanName, Payload: append([]byte(""), e2NodeConfigUpdateXml...)}
81 handler.Handle(notificationRequest)
82 readerMock.AssertExpectations(t)
83 writerMock.AssertExpectations(t)
86 func TestE2nodeConfigUpdatetParseFail(t *testing.T) {
87 handler, _, _, _ := initE2nodeConfigMocks(t)
88 badxml := []byte("abc")
89 e2nodeConfig, err := handler.parseE2NodeConfigurationUpdate(badxml)
91 var expected *models.E2nodeConfigurationUpdateMessage
92 assert.Equal(t, expected, e2nodeConfig)
96 func TestHandleAddAndUpdateConfig(t *testing.T) {
97 e2NodeConfigUpdateXml := utils.ReadXmlFile(t, E2nodeConfigUpdateOnlyAdditionAndUpdateXmlPath)
99 handler, readerMock, writerMock, rmrMessengerMock := initE2nodeConfigMocks(t)
100 var nodebInfo = &entities.NodebInfo{
101 RanName: gnbNodebRanName,
102 AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
103 ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
104 NodeType: entities.Node_GNB,
105 Configuration: &entities.NodebInfo_Gnb{
106 Gnb: &entities.Gnb{},
109 readerMock.On("GetNodeb", gnbNodebRanName).Return(nodebInfo, nil)
110 writerMock.On("UpdateNodebInfoAndPublish", mock.Anything).Return(nil)
112 rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(&rmrCgo.MBuf{}, errEmpty)
114 notificationRequest := &models.NotificationRequest{RanName: gnbNodebRanName, Payload: append([]byte(""), e2NodeConfigUpdateXml...)}
116 handler.Handle(notificationRequest)
118 t.Logf("len of addtionList : %d", len(nodebInfo.GetGnb().NodeConfigs))
120 assert.Equal(t, 5, len(nodebInfo.GetGnb().NodeConfigs))
121 assert.Equal(t, "nginterf", nodebInfo.GetGnb().NodeConfigs[0].GetE2NodeComponentInterfaceTypeNG().AmfName)
122 assert.Equal(t, "72 65 71 70 61 72 73", string(nodebInfo.GetGnb().NodeConfigs[0].E2NodeComponentRequestPart))
123 assert.Equal(t, "72 65 73 70 61 72 73", string(nodebInfo.GetGnb().NodeConfigs[0].E2NodeComponentResponsePart))
125 writerMock.AssertExpectations(t)
126 readerMock.AssertExpectations(t)
129 func TestHandleAddandDeleteConfig(t *testing.T) {
130 e2NodeConfigUpdateXml := utils.ReadXmlFile(t, E2nodeConfigUpdateXmlPath)
132 handler, readerMock, writerMock, rmrMessengerMock := initE2nodeConfigMocks(t)
133 var nodebInfo = &entities.NodebInfo{
134 RanName: gnbNodebRanName,
135 AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
136 ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
137 NodeType: entities.Node_GNB,
138 Configuration: &entities.NodebInfo_Gnb{
139 Gnb: &entities.Gnb{},
142 readerMock.On("GetNodeb", gnbNodebRanName).Return(nodebInfo, nil)
143 writerMock.On("UpdateNodebInfoAndPublish", mock.Anything).Return(nil)
145 rmrMessengerMock.On("SendMsg", mock.Anything, mock.Anything).Return(&rmrCgo.MBuf{}, errEmpty)
147 notificationRequest := &models.NotificationRequest{RanName: gnbNodebRanName, Payload: append([]byte(""), e2NodeConfigUpdateXml...)}
149 handler.Handle(notificationRequest)
151 t.Logf("len of nodeconfig : %d", len(nodebInfo.GetGnb().NodeConfigs))
153 assert.Equal(t, 0, len(nodebInfo.GetGnb().NodeConfigs))
155 writerMock.AssertExpectations(t)
156 readerMock.AssertExpectations(t)