blob: 618eb4b27b16fad945fe739e497362886fef2905 [file] [log] [blame]
ss412g07ef76d2019-08-12 17:26:40 +03001//
2// Copyright 2019 AT&T Intellectual Property
3// Copyright 2019 Nokia
4//
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
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
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.
nm755n15d39822019-11-28 16:56:00 +000016
17// This source code is part of the near-RT RIC (RAN Intelligent Controller)
18// platform project (RICP).
19
ss412g07ef76d2019-08-12 17:26:40 +030020package rNibWriter
21
22import (
Idan Shalom14eb5132020-07-06 09:41:46 +000023 "e2mgr/configuration"
ss412g07ef76d2019-08-12 17:26:40 +030024 "e2mgr/mocks"
ss412gefcb4522019-12-02 16:59:19 +020025 "encoding/json"
ss412g07ef76d2019-08-12 17:26:40 +030026 "errors"
27 "fmt"
is005q19bf35e2019-08-12 18:59:29 +030028 "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"
ss412g07ef76d2019-08-12 17:26:40 +030030 "github.com/golang/protobuf/proto"
ss412g07ef76d2019-08-12 17:26:40 +030031 "github.com/stretchr/testify/assert"
32 "testing"
33 "time"
34)
35
idanshal08bbf912020-04-20 17:11:33 +030036var namespace = "namespace"
Idan Shalom14eb5132020-07-06 09:41:46 +000037
idanshald916e2a2020-04-22 15:56:43 +030038const (
39 RanName = "test"
40)
idanshal08bbf912020-04-20 17:11:33 +030041
ss412gefcb4522019-12-02 16:59:19 +020042func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
43 sdlInstanceMock = new(mocks.MockSdlInstance)
Idan Shalom14eb5132020-07-06 09:41:46 +000044 w = GetRNibWriter(sdlInstanceMock, configuration.RnibWriterConfig{StateChangeMessageChannel: "RAN_CONNECTION_STATUS_CHANGE", RanManipulationMessageChannel: "RAN_MANIPULATION"})
ss412gefcb4522019-12-02 16:59:19 +020045 return
ss412g07ef76d2019-08-12 17:26:40 +030046}
47
idanshal08bbf912020-04-20 17:11:33 +030048func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo {
49 nodebInfo := &entities.NodebInfo{
50 RanName: inventoryName,
51 GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId},
52 NodeType: nodeType,
53 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
54 }
55
56 if nodeType == entities.Node_ENB {
57 nodebInfo.Configuration = &entities.NodebInfo_Enb{
58 Enb: &entities.Enb{},
59 }
60 } else if nodeType == entities.Node_GNB {
61 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
62 Gnb: &entities.Gnb{},
63 }
64 }
65
66 return nodebInfo
67}
68
69func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
70
71 servedNrCells := []*entities.ServedNRCell{}
72
idanshald916e2a2020-04-22 15:56:43 +030073 for i, v := range cellIds {
idanshal08bbf912020-04-20 17:11:33 +030074 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
75 CellId: v,
76 ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
77 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
78
79 },
80 },
81 NrMode: entities.Nr_FDD,
idanshald916e2a2020-04-22 15:56:43 +030082 NrPci: uint32(i + 1),
idanshal08bbf912020-04-20 17:11:33 +030083 ServedPlmns: []string{"whatever"},
84 }})
85 }
86
87 return servedNrCells
88}
89
idanshald916e2a2020-04-22 15:56:43 +030090func TestRemoveServedNrCellsSuccess(t *testing.T) {
91 w, sdlInstanceMock := initSdlInstanceMock(namespace)
92 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
93 sdlInstanceMock.On("Remove", buildCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil)
94 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
95 assert.Nil(t, err)
96}
97
98func TestRemoveServedNrCellsFailure(t *testing.T) {
99 w, sdlInstanceMock := initSdlInstanceMock(namespace)
100 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
101 sdlInstanceMock.On("Remove", buildCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error"))
102 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
103 assert.IsType(t, &common.InternalError{}, err)
104}
105
idanshal08bbf912020-04-20 17:11:33 +0300106func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
107 w, sdlInstanceMock := initSdlInstanceMock(namespace)
108 servedNrCells := generateServedNrCells("test1", "test2")
109 nodebInfo := &entities.NodebInfo{}
110 sdlInstanceMock.AssertNotCalled(t, "Set")
111 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
112 assert.IsType(t, &common.ValidationError{}, rNibErr)
113}
114
115func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
116 inventoryName := "name"
117 plmnId := "02f829"
118 nbId := "4a952a0a"
119 w, sdlInstanceMock := initSdlInstanceMock(namespace)
120 servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
121 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
122 nodebInfo.GetGnb().ServedNrCells = servedNrCells
123 sdlInstanceMock.AssertNotCalled(t, "Set")
124 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
125 assert.IsType(t, &common.ValidationError{}, rNibErr)
126}
127
128func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
129
130 nodebInfoData, err := proto.Marshal(nodebInfo)
131 if err != nil {
132 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
133 }
134
135 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
136 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
137 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
138
139 for _, v := range servedNrCells {
140
141 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
142 cellData, err := proto.Marshal(&cellEntity)
143
144 if err != nil {
145 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
146 }
147
148 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
149 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
150 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
151 }
152
153 return setExpected
154}
155
156func TestUpdateGnbCellsSdlFailure(t *testing.T) {
157 inventoryName := "name"
158 plmnId := "02f829"
159 nbId := "4a952a0a"
160 w, sdlInstanceMock := initSdlInstanceMock(namespace)
161 servedNrCells := generateServedNrCells("test1", "test2")
162 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
163 nodebInfo.GetGnb().ServedNrCells = servedNrCells
164 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
165 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(errors.New("expected error"))
166 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
167 assert.IsType(t, &common.InternalError{}, rNibErr)
168}
169
170func TestUpdateGnbCellsSuccess(t *testing.T) {
171 inventoryName := "name"
172 plmnId := "02f829"
173 nbId := "4a952a0a"
174 w, sdlInstanceMock := initSdlInstanceMock(namespace)
175 servedNrCells := generateServedNrCells("test1", "test2")
176 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
177 nodebInfo.GetGnb().ServedNrCells = servedNrCells
178 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
179 var e error
180 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
181 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
182 assert.Nil(t, rNibErr)
183}
ss412g07ef76d2019-08-12 17:26:40 +0300184
is005q19e72a52019-08-26 17:56:18 +0300185func TestUpdateNodebInfoSuccess(t *testing.T) {
186 inventoryName := "name"
187 plmnId := "02f829"
188 nbId := "4a952a0a"
ss412gefcb4522019-12-02 16:59:19 +0200189 w, sdlInstanceMock := initSdlInstanceMock(namespace)
idanshal08bbf912020-04-20 17:11:33 +0300190 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
is005q19e72a52019-08-26 17:56:18 +0300191 data, err := proto.Marshal(nodebInfo)
192 if err != nil {
193 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
194 }
195 var e error
196 var setExpected []interface{}
197
198 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
199 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
200 setExpected = append(setExpected, nodebNameKey, data)
201 setExpected = append(setExpected, nodebIdKey, data)
202
203 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
204
205 rNibErr := w.UpdateNodebInfo(nodebInfo)
206 assert.Nil(t, rNibErr)
207}
208
209func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
210 inventoryName := "name"
211 plmnId := "02f829"
212 nbId := "4a952a0a"
ss412gefcb4522019-12-02 16:59:19 +0200213 w, sdlInstanceMock := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300214 nodebInfo := &entities.NodebInfo{}
215 data, err := proto.Marshal(nodebInfo)
216 if err != nil {
217 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
218 }
219 var e error
220 var setExpected []interface{}
221
222 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
223 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
224 setExpected = append(setExpected, nodebNameKey, data)
225 setExpected = append(setExpected, nodebIdKey, data)
226
227 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
228
229 rNibErr := w.UpdateNodebInfo(nodebInfo)
230
231 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300232 assert.IsType(t, &common.ValidationError{}, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300233}
234
is005q26473192019-08-28 17:51:37 +0300235func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
is005q19e72a52019-08-26 17:56:18 +0300236 inventoryName := "name"
ss412gefcb4522019-12-02 16:59:19 +0200237 w, sdlInstanceMock := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300238 nodebInfo := &entities.NodebInfo{}
239 nodebInfo.RanName = inventoryName
240 data, err := proto.Marshal(nodebInfo)
241 if err != nil {
242 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
243 }
244 var e error
245 var setExpected []interface{}
246
247 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
is005q19e72a52019-08-26 17:56:18 +0300248 setExpected = append(setExpected, nodebNameKey, data)
is005q19e72a52019-08-26 17:56:18 +0300249 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
250
251 rNibErr := w.UpdateNodebInfo(nodebInfo)
252
is005q26473192019-08-28 17:51:37 +0300253 assert.Nil(t, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300254}
255
ss412g07ef76d2019-08-12 17:26:40 +0300256func TestSaveEnb(t *testing.T) {
257 name := "name"
258 ranName := "RAN:" + name
ss412gefcb4522019-12-02 16:59:19 +0200259 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300260 nb := entities.NodebInfo{}
Idan Shalom14eb5132020-07-06 09:41:46 +0000261 nb.RanName = name
ss412g07ef76d2019-08-12 17:26:40 +0300262 nb.NodeType = entities.Node_ENB
263 nb.ConnectionStatus = 1
264 nb.Ip = "localhost"
265 nb.Port = 5656
266 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300267 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
268 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
ss412g07ef76d2019-08-12 17:26:40 +0300269 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300270 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300271 data, err := proto.Marshal(&nb)
272 if err != nil {
273 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
274 }
275 var e error
276
277 cellData, err := proto.Marshal(&cellEntity)
278 if err != nil {
279 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
280 }
281 var setExpected []interface{}
282 setExpected = append(setExpected, ranName, data)
283 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
284 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
285 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
286
Idan Shalom14eb5132020-07-06 09:41:46 +0000287 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", name + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300288
289 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
290 if err != nil {
291 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
292 }
293 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
294
is005q19e72a52019-08-26 17:56:18 +0300295 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ns019t57c3fae2019-08-12 20:08:49 +0300296 nbIdData, err = proto.Marshal(nbIdentity)
ss412g07ef76d2019-08-12 17:26:40 +0300297 if err != nil {
298 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
299 }
300 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300301
ss412g07ef76d2019-08-12 17:26:40 +0300302 rNibErr := w.SaveNodeb(nbIdentity, &nb)
303 assert.Nil(t, rNibErr)
304}
305
306func TestSaveEnbCellIdValidationFailure(t *testing.T) {
307 name := "name"
ss412gefcb4522019-12-02 16:59:19 +0200308 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300309 nb := entities.NodebInfo{}
310 nb.NodeType = entities.Node_ENB
311 nb.ConnectionStatus = 1
312 nb.Ip = "localhost"
313 nb.Port = 5656
314 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300315 cell := &entities.ServedCellInfo{Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300316 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300317 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300318
is005q19e72a52019-08-26 17:56:18 +0300319 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300320 rNibErr := w.SaveNodeb(nbIdentity, &nb)
321 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300322 assert.IsType(t, &common.ValidationError{}, rNibErr)
323 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300324}
325
326func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200327 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300328 nb := entities.NodebInfo{}
329 nb.NodeType = entities.Node_ENB
330 nb.ConnectionStatus = 1
331 nb.Ip = "localhost"
332 nb.Port = 5656
333 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300334 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300335 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300336 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300337
is005q19e72a52019-08-26 17:56:18 +0300338 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300339 rNibErr := w.SaveNodeb(nbIdentity, &nb)
340 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300341 assert.IsType(t, &common.ValidationError{}, rNibErr)
342 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300343}
344
ss412g07ef76d2019-08-12 17:26:40 +0300345func TestSaveGnbCellIdValidationFailure(t *testing.T) {
346 name := "name"
ss412gefcb4522019-12-02 16:59:19 +0200347 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300348 nb := entities.NodebInfo{}
349 nb.NodeType = entities.Node_GNB
350 nb.ConnectionStatus = 1
351 nb.Ip = "localhost"
352 nb.Port = 5656
353 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300354 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
355 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
ss412g07ef76d2019-08-12 17:26:40 +0300356 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
is005q19e72a52019-08-26 17:56:18 +0300357 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
ss412g07ef76d2019-08-12 17:26:40 +0300358
is005q19e72a52019-08-26 17:56:18 +0300359 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300360 rNibErr := w.SaveNodeb(nbIdentity, &nb)
361 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300362 assert.IsType(t, &common.ValidationError{}, rNibErr)
363 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300364}
365
366func TestSaveGnb(t *testing.T) {
367 name := "name"
368 ranName := "RAN:" + name
ss412gefcb4522019-12-02 16:59:19 +0200369 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300370 nb := entities.NodebInfo{}
371 nb.NodeType = entities.Node_GNB
372 nb.ConnectionStatus = 1
373 nb.Ip = "localhost"
374 nb.Port = 5656
375 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300376 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
377 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
378 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
ss412g07ef76d2019-08-12 17:26:40 +0300379 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
is005q19e72a52019-08-26 17:56:18 +0300380 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
ss412g07ef76d2019-08-12 17:26:40 +0300381 data, err := proto.Marshal(&nb)
382 if err != nil {
383 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
384 }
385 var e error
386
ss412g07ef76d2019-08-12 17:26:40 +0300387 cellData, err := proto.Marshal(&cellEntity)
388 if err != nil {
389 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
390 }
391 var setExpected []interface{}
392 setExpected = append(setExpected, ranName, data)
393 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
394 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
395 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
396
397 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
is005q19e72a52019-08-26 17:56:18 +0300398 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300399 nbIdData, err := proto.Marshal(nbIdentity)
400 if err != nil {
401 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
402 }
403 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
404
ns019t57c3fae2019-08-12 20:08:49 +0300405 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
406 if err != nil {
407 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
408 }
409 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
410
ss412g07ef76d2019-08-12 17:26:40 +0300411 rNibErr := w.SaveNodeb(nbIdentity, &nb)
412 assert.Nil(t, rNibErr)
413}
414
415func TestSaveRanLoadInformationSuccess(t *testing.T) {
416 inventoryName := "name"
417 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
418
419 if validationErr != nil {
420 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
421 }
422
ss412gefcb4522019-12-02 16:59:19 +0200423 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300424
ss412g07ef76d2019-08-12 17:26:40 +0300425 ranLoadInformation := generateRanLoadInformation()
426 data, err := proto.Marshal(ranLoadInformation)
427
428 if err != nil {
429 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
430 }
431
432 var e error
433 var setExpected []interface{}
434 setExpected = append(setExpected, loadKey, data)
435 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
436
ss412g07ef76d2019-08-12 17:26:40 +0300437 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
438 assert.Nil(t, rNibErr)
439}
440
441func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
442 inventoryName := "name2"
ss412gefcb4522019-12-02 16:59:19 +0200443 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300444
445 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
is005q19e72a52019-08-26 17:56:18 +0300446 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300447 assert.Equal(t, expectedErr, err)
448}
449
450func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
451 inventoryName := ""
ss412gefcb4522019-12-02 16:59:19 +0200452 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300453
is005q19e72a52019-08-26 17:56:18 +0300454 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300455 assert.NotNil(t, err)
irina006fbce2019-09-05 16:11:02 +0300456 assert.IsType(t, &common.ValidationError{}, err)
ss412g07ef76d2019-08-12 17:26:40 +0300457}
458
459func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
460 inventoryName := "name2"
461
462 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
463
464 if validationErr != nil {
465 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
466 }
467
ss412gefcb4522019-12-02 16:59:19 +0200468 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300469
470 ranLoadInformation := generateRanLoadInformation()
471 data, err := proto.Marshal(ranLoadInformation)
472
473 if err != nil {
474 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
475 }
476
ss412g07ef76d2019-08-12 17:26:40 +0300477 expectedErr := errors.New("expected error")
478 var setExpected []interface{}
479 setExpected = append(setExpected, loadKey, data)
480 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
481
ss412g07ef76d2019-08-12 17:26:40 +0300482 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
483 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300484 assert.IsType(t, &common.InternalError{}, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300485}
486
487func generateCellLoadInformation() *entities.CellLoadInformation {
488 cellLoadInformation := entities.CellLoadInformation{}
489
490 cellLoadInformation.CellId = "123"
491
492 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
493 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
494
495 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
is005q19e72a52019-08-26 17:56:18 +0300496 TargetCellId: "456",
497 UlHighInterferenceIndication: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300498 }
499
is005q19e72a52019-08-26 17:56:18 +0300500 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
ss412g07ef76d2019-08-12 17:26:40 +0300501
502 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
is005q19e72a52019-08-26 17:56:18 +0300503 RntpPerPrb: "xxx",
504 RntpThreshold: entities.RntpThreshold_NEG_4,
ss412g07ef76d2019-08-12 17:26:40 +0300505 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
is005q19e72a52019-08-26 17:56:18 +0300506 PB: 1,
507 PdcchInterferenceImpact: 2,
ss412g07ef76d2019-08-12 17:26:40 +0300508 EnhancedRntp: &entities.EnhancedRntp{
is005q19e72a52019-08-26 17:56:18 +0300509 EnhancedRntpBitmap: "xxx",
510 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
511 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
ss412g07ef76d2019-08-12 17:26:40 +0300512 },
513 }
514
515 cellLoadInformation.AbsInformation = &entities.AbsInformation{
is005q19e72a52019-08-26 17:56:18 +0300516 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
517 AbsPatternInfo: "xxx",
518 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
519 MeasurementSubset: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300520 }
521
522 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
523
524 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
is005q19e72a52019-08-26 17:56:18 +0300525 AssociatedSubframes: "xxx",
526 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
ss412g07ef76d2019-08-12 17:26:40 +0300527 }
528
529 compInformationItem := &entities.CompInformationItem{
idanshal08bbf912020-04-20 17:11:33 +0300530 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
is005q19e72a52019-08-26 17:56:18 +0300531 BenefitMetric: 50,
ss412g07ef76d2019-08-12 17:26:40 +0300532 }
533
534 cellLoadInformation.CompInformation = &entities.CompInformation{
is005q19e72a52019-08-26 17:56:18 +0300535 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
536 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
ss412g07ef76d2019-08-12 17:26:40 +0300537 }
538
539 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
is005q19e72a52019-08-26 17:56:18 +0300540 State: entities.NaicsState_NAICS_ACTIVE,
541 TransmissionModes: "xxx",
542 PB: 2,
543 PAList: []entities.PA{entities.PA_DB_NEG_3},
ss412g07ef76d2019-08-12 17:26:40 +0300544 }
545
546 return &cellLoadInformation
547}
548
549func generateRanLoadInformation() *entities.RanLoadInformation {
550 ranLoadInformation := entities.RanLoadInformation{}
551
is005q19bf35e2019-08-12 18:59:29 +0300552 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
ss412g07ef76d2019-08-12 17:26:40 +0300553
554 cellLoadInformation := generateCellLoadInformation()
555 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
556
557 return &ranLoadInformation
558}
559
560func TestSaveNilEntityFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200561 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300562 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
563 nbIdentity := &entities.NbIdentity{}
564 actualErr := w.SaveNodeb(nbIdentity, nil)
565 assert.Equal(t, expectedErr, actualErr)
566}
567
568func TestSaveUnknownTypeEntityFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200569 w, _ := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300570 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300571 nb := &entities.NodebInfo{}
572 nb.Port = 5656
573 nb.Ip = "localhost"
574 actualErr := w.SaveNodeb(nbIdentity, nb)
ss412ga07b8592020-06-16 21:51:33 +0300575 assert.IsType(t, &common.ValidationError{}, actualErr)
ss412g07ef76d2019-08-12 17:26:40 +0300576}
577
578func TestSaveEntityFailure(t *testing.T) {
579 name := "name"
580 plmnId := "02f829"
581 nbId := "4a952a0a"
582
ss412gefcb4522019-12-02 16:59:19 +0200583 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300584 gnb := entities.NodebInfo{}
585 gnb.NodeType = entities.Node_GNB
586 data, err := proto.Marshal(&gnb)
587 if err != nil {
588 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
589 }
is005q19e72a52019-08-26 17:56:18 +0300590 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
ss412g07ef76d2019-08-12 17:26:40 +0300591 setExpected := []interface{}{"RAN:" + name, data}
is005q19e72a52019-08-26 17:56:18 +0300592 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
ss412g07ef76d2019-08-12 17:26:40 +0300593 expectedErr := errors.New("expected error")
594 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
595 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
596 assert.NotEmpty(t, rNibErr)
597}
598
ss412g07ef76d2019-08-12 17:26:40 +0300599func TestGetRNibWriter(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200600 received, _ := initSdlInstanceMock(namespace)
601 assert.NotEmpty(t, received)
ss412g07ef76d2019-08-12 17:26:40 +0300602}
603
ss412gefcb4522019-12-02 16:59:19 +0200604func TestSaveE2TInstanceSuccess(t *testing.T) {
605 address := "10.10.2.15:9800"
606 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
607
608 if validationErr != nil {
609 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
610 }
611
612 w, sdlInstanceMock := initSdlInstanceMock(namespace)
613
614 e2tInstance := generateE2tInstance(address)
615 data, err := json.Marshal(e2tInstance)
616
617 if err != nil {
618 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
619 }
620
ss412g07ef76d2019-08-12 17:26:40 +0300621 var e error
ss412gefcb4522019-12-02 16:59:19 +0200622 var setExpected []interface{}
623 setExpected = append(setExpected, loadKey, data)
624 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
625
626 rNibErr := w.SaveE2TInstance(e2tInstance)
627 assert.Nil(t, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300628}
629
ss412gefcb4522019-12-02 16:59:19 +0200630func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
631 w, _ := initSdlInstanceMock(namespace)
632 var address string
Irina49144462020-04-07 16:37:20 +0300633 e2tInstance := entities.NewE2TInstance(address, "test")
ss412gefcb4522019-12-02 16:59:19 +0200634 err := w.SaveE2TInstance(e2tInstance)
635 assert.NotNil(t, err)
636 assert.IsType(t, &common.ValidationError{}, err)
637}
638
639func TestSaveE2TInstanceSdlFailure(t *testing.T) {
640 address := "10.10.2.15:9800"
641 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
642
643 if validationErr != nil {
644 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
645 }
646
647 w, sdlInstanceMock := initSdlInstanceMock(namespace)
648
649 e2tInstance := generateE2tInstance(address)
650 data, err := json.Marshal(e2tInstance)
651
652 if err != nil {
653 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
654 }
655
656 expectedErr := errors.New("expected error")
657 var setExpected []interface{}
658 setExpected = append(setExpected, loadKey, data)
659 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
660
661 rNibErr := w.SaveE2TInstance(e2tInstance)
662 assert.NotNil(t, rNibErr)
663 assert.IsType(t, &common.InternalError{}, rNibErr)
664}
665
666func generateE2tInstance(address string) *entities.E2TInstance {
Irina49144462020-04-07 16:37:20 +0300667 e2tInstance := entities.NewE2TInstance(address, "pod test")
ss412gefcb4522019-12-02 16:59:19 +0200668
669 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
670
671 return e2tInstance
672}
673
674func TestSaveE2TAddressesSuccess(t *testing.T) {
675 address := "10.10.2.15:9800"
676 w, sdlInstanceMock := initSdlInstanceMock(namespace)
677
678 e2tAddresses := []string{address}
679 data, err := json.Marshal(e2tAddresses)
680
681 if err != nil {
682 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
683 }
684
ss412g07ef76d2019-08-12 17:26:40 +0300685 var e error
ss412gefcb4522019-12-02 16:59:19 +0200686 var setExpected []interface{}
687 setExpected = append(setExpected, E2TAddressesKey, data)
688 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
689
690 rNibErr := w.SaveE2TAddresses(e2tAddresses)
691 assert.Nil(t, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300692}
693
ss412gefcb4522019-12-02 16:59:19 +0200694func TestSaveE2TAddressesSdlFailure(t *testing.T) {
695 address := "10.10.2.15:9800"
696 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300697
ss412gefcb4522019-12-02 16:59:19 +0200698 e2tAddresses := []string{address}
699 data, err := json.Marshal(e2tAddresses)
700
701 if err != nil {
702 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
703 }
704
705 expectedErr := errors.New("expected error")
706 var setExpected []interface{}
707 setExpected = append(setExpected, E2TAddressesKey, data)
708 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
709
710 rNibErr := w.SaveE2TAddresses(e2tAddresses)
711 assert.NotNil(t, rNibErr)
712 assert.IsType(t, &common.InternalError{}, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300713}
714
Amichaif846c592020-01-08 16:45:07 +0200715func TestRemoveE2TInstanceSuccess(t *testing.T) {
716 address := "10.10.2.15:9800"
717 w, sdlInstanceMock := initSdlInstanceMock(namespace)
718
719 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
720 var e error
721 sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
722
723 rNibErr := w.RemoveE2TInstance(address)
724 assert.Nil(t, rNibErr)
725 sdlInstanceMock.AssertExpectations(t)
726}
727
728func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
729 address := "10.10.2.15:9800"
730 w, sdlInstanceMock := initSdlInstanceMock(namespace)
731
732 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
733 expectedErr := errors.New("expected error")
734 sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
735
736 rNibErr := w.RemoveE2TInstance(address)
737 assert.IsType(t, &common.InternalError{}, rNibErr)
738}
739
740func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
741 w, sdlInstanceMock := initSdlInstanceMock(namespace)
742
743 rNibErr := w.RemoveE2TInstance("")
744 assert.IsType(t, &common.ValidationError{}, rNibErr)
745 sdlInstanceMock.AssertExpectations(t)
746}
747
ss412ga07b8592020-06-16 21:51:33 +0300748func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
749 inventoryName := "name"
750 plmnId := "02f829"
751 nbId := "4a952a0a"
752 channelName := "RAN_CONNECT_STATE_CHANGE"
753 eventName := inventoryName + "_" + "CONNECTED"
Idan Shalom14eb5132020-07-06 09:41:46 +0000754 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412ga07b8592020-06-16 21:51:33 +0300755 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
756 data, err := proto.Marshal(nodebInfo)
757 if err != nil {
758 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
759 }
760 var e error
761 var setExpected []interface{}
762
763 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
764 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
765 setExpected = append(setExpected, nodebNameKey, data)
766 setExpected = append(setExpected, nodebIdKey, data)
767
idanshal1766b712020-06-22 12:41:02 +0300768 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300769
770 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
771 assert.Nil(t, rNibErr)
772}
773
774func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
775 inventoryName := "name"
776 plmnId := "02f829"
777 nbId := "4a952a0a"
778 channelName := "RAN_CONNECT_STATE_CHANGE"
779 eventName := inventoryName + "_" + "CONNECTED"
780 w, sdlInstanceMock := initSdlInstanceMock(namespace)
781 nodebInfo := &entities.NodebInfo{}
782 data, err := proto.Marshal(nodebInfo)
783 if err != nil {
784 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
785 }
786 var e error
787 var setExpected []interface{}
788
789 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
790 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
791 setExpected = append(setExpected, nodebNameKey, data)
792 setExpected = append(setExpected, nodebIdKey, data)
793
idanshal1766b712020-06-22 12:41:02 +0300794 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300795
796 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
797
798 assert.NotNil(t, rNibErr)
799 assert.IsType(t, &common.ValidationError{}, rNibErr)
800}
801
802func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) {
803 inventoryName := "name"
804 channelName := "RAN_CONNECT_STATE_CHANGE"
805 eventName := inventoryName + "_" + "CONNECTED"
806 w, sdlInstanceMock := initSdlInstanceMock(namespace)
807 nodebInfo := &entities.NodebInfo{}
808 nodebInfo.RanName = inventoryName
809 data, err := proto.Marshal(nodebInfo)
810 if err != nil {
811 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
812 }
813 var e error
814 var setExpected []interface{}
815
816 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
817 setExpected = append(setExpected, nodebNameKey, data)
idanshal1766b712020-06-22 12:41:02 +0300818 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300819
820 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
821
822 assert.Nil(t, rNibErr)
823}
824
825func TestSaveGeneralConfiguration(t *testing.T) {
826 w, sdlInstanceMock := initSdlInstanceMock(namespace)
827
828 key := common.BuildGeneralConfigurationKey()
829 configurationData := "{\"enableRic\":true}"
830 configuration := &entities.GeneralConfiguration{}
831 configuration.EnableRic = true
832
Idan Shalom14eb5132020-07-06 09:41:46 +0000833 sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
ss412ga07b8592020-06-16 21:51:33 +0300834 rNibErr := w.SaveGeneralConfiguration(configuration)
835
836 assert.Nil(t, rNibErr)
837 sdlInstanceMock.AssertExpectations(t)
838}
839
840func TestSaveGeneralConfigurationDbError(t *testing.T) {
841 w, sdlInstanceMock := initSdlInstanceMock(namespace)
842
843 key := common.BuildGeneralConfigurationKey()
844 configurationData := "{\"enableRic\":true}"
845 configuration := &entities.GeneralConfiguration{}
846 configuration.EnableRic = true
847
848 expectedErr := errors.New("expected error")
849
Idan Shalom14eb5132020-07-06 09:41:46 +0000850 sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
ss412ga07b8592020-06-16 21:51:33 +0300851 rNibErr := w.SaveGeneralConfiguration(configuration)
852
853 assert.NotNil(t, rNibErr)
854}
855
ss412g07ef76d2019-08-12 17:26:40 +0300856//Integration tests
857//
ns019t57c3fae2019-08-12 20:08:49 +0300858//func TestSaveEnbGnbInteg(t *testing.T){
ss412g07ef76d2019-08-12 17:26:40 +0300859// for i := 0; i<10; i++{
860// Init("e2Manager", 1)
861// w := GetRNibWriter()
862// nb := entities.NodebInfo{}
863// nb.NodeType = entities.Node_ENB
864// nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
865// nb.Ip = "localhost"
866// nb.Port = uint32(5656 + i)
867// enb := entities.Enb{}
868// cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
869// cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
870// cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
871// enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
872// nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
873// plmnId := 0x02f828
874// nbId := 0x4a952a0a
ss412ga07b8592020-06-16 21:51:33 +0300875// nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
ss412g07ef76d2019-08-12 17:26:40 +0300876// err := w.SaveNodeb(nbIdentity, &nb)
877// if err != nil{
878// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
879// }
880//
881// nb1 := entities.NodebInfo{}
882// nb1.NodeType = entities.Node_GNB
ns019t57c3fae2019-08-12 20:08:49 +0300883// nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
ss412g07ef76d2019-08-12 17:26:40 +0300884// nb1.Ip = "localhost"
885// nb1.Port = uint32(6565 + i)
886// gnb := entities.Gnb{}
887// gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
888// gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
889// gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
890// gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
891// nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
ss412ga07b8592020-06-16 21:51:33 +0300892// nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
ss412g07ef76d2019-08-12 17:26:40 +0300893// err = w.SaveNodeb(nbIdentity, &nb1)
894// if err != nil{
895// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
896// }
897// }
898//}
ns019t57c3fae2019-08-12 20:08:49 +0300899//
900//func TestSaveNbRanNamesInteg(t *testing.T){
901// for i := 0; i<10; i++{
902// Init("e2Manager", 1)
903// w := GetRNibWriter()
904// nb := entities.NodebInfo{}
905// nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
906// nb.Ip = "localhost"
907// nb.Port = uint32(5656 + i)
908// nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
909// err := w.SaveNodeb(nbIdentity, &nb)
910// if err != nil{
911// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
912// }
913// }
914//}
915//
ss412g07ef76d2019-08-12 17:26:40 +0300916//func TestSaveRanLoadInformationInteg(t *testing.T){
917// Init("e2Manager", 1)
918// w := GetRNibWriter()
919// ranLoadInformation := generateRanLoadInformation()
920// err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
921// if err != nil{
922// t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)
923// }
is005q19e72a52019-08-26 17:56:18 +0300924//}