2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 // Copyright 2023 Capgemini
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
10 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
18 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 // platform project (RICP).
29 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
30 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
31 "github.com/golang/protobuf/proto"
32 "github.com/stretchr/testify/assert"
37 var namespace = common.GetRNibNamespace()
45 func initSdlMock() (w RNibWriter, sdlMock *mocks.MockSdlSyncStorage) {
46 sdlMock = new(mocks.MockSdlSyncStorage)
47 w = GetRNibWriter(sdlMock, configuration.RnibWriterConfig{StateChangeMessageChannel: "RAN_CONNECTION_STATUS_CHANGE", RanManipulationMessageChannel: "RAN_MANIPULATION"})
51 func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo {
52 nodebInfo := &entities.NodebInfo{
53 RanName: inventoryName,
54 GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId},
56 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
59 if nodeType == entities.Node_ENB {
60 nodebInfo.Configuration = &entities.NodebInfo_Enb{
63 } else if nodeType == entities.Node_GNB {
64 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
72 func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
74 var servedNrCells []*entities.ServedNRCell
76 for i, v := range cellIds {
77 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
79 ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
80 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{},
82 NrMode: entities.Nr_FDD,
84 ServedPlmns: []string{"whatever"},
91 func generateServedCells(cellIds ...string) []*entities.ServedCellInfo {
93 var servedCells []*entities.ServedCellInfo
95 for i, v := range cellIds {
96 servedCells = append(servedCells, &entities.ServedCellInfo{
98 ChoiceEutraMode: &entities.ChoiceEUTRAMode{
99 Fdd: &entities.FddInfo{},
102 BroadcastPlmns: []string{"whatever"},
109 func generateServedCellInfos(cellIds ...string) []*entities.ServedCellInfo {
111 servedCells := []*entities.ServedCellInfo{}
113 for i, v := range cellIds {
114 servedCells = append(servedCells, &entities.ServedCellInfo{
123 func TestRemoveServedNrCellsSuccess(t *testing.T) {
124 w, sdlMock := initSdlMock()
125 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
126 sdlMock.On("Remove", namespace, buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil)
127 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
131 func TestRemoveServedNrCellsFailure(t *testing.T) {
132 w, sdlMock := initSdlMock()
133 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
134 sdlMock.On("Remove", namespace, buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error"))
135 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
136 assert.IsType(t, &common.InternalError{}, err)
139 func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
140 w, sdlMock := initSdlMock()
141 servedNrCells := generateServedNrCells("test1", "test2")
142 nodebInfo := &entities.NodebInfo{}
143 sdlMock.AssertNotCalled(t, "SetAndPublish")
144 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
145 assert.IsType(t, &common.ValidationError{}, rNibErr)
148 func TestAddNbIdentitySuccess(t *testing.T) {
149 w, sdlMock := initSdlMock()
151 nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
152 nbIdData, err := proto.Marshal(nbIdentity)
154 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySuccess - Failed to marshal NodeB Identity entity. Error: %v", err)
157 sdlMock.On("AddMember", namespace, "ENB", []interface{}{nbIdData}).Return(nil)
158 rNibErr := w.AddNbIdentity(entities.Node_ENB, nbIdentity)
159 assert.Nil(t, rNibErr)
162 func TestAddNbIdentityMarshalNilFailure(t *testing.T) {
163 w, _ := initSdlMock()
165 rNibErr := w.AddNbIdentity(entities.Node_ENB, nil)
166 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
167 assert.Equal(t, expectedErr, rNibErr)
170 func TestAddNbIdentitySdlFailure(t *testing.T) {
171 w, sdlMock := initSdlMock()
173 nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
174 nbIdData, err := proto.Marshal(nbIdentity)
176 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySdlFailure - Failed to marshal NodeB Identity entity. Error: %v", err)
179 sdlMock.On("AddMember", namespace, "ENB", []interface{}{nbIdData}).Return(errors.New("expected error"))
180 rNibErr := w.AddNbIdentity(entities.Node_ENB, nbIdentity)
181 assert.IsType(t, &common.InternalError{}, rNibErr)
184 func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
185 inventoryName := "name"
188 w, sdlMock := initSdlMock()
189 servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
190 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
191 nodebInfo.GetGnb().ServedNrCells = servedNrCells
192 sdlMock.AssertNotCalled(t, "SetAndPublish")
193 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
194 assert.IsType(t, &common.ValidationError{}, rNibErr)
197 func getUpdateEnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
199 nodebInfoData, err := proto.Marshal(nodebInfo)
201 t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
204 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
205 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId,nodebInfo.CuUpId,nodebInfo.DuId)
206 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
208 for _, cell := range servedCells {
210 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
211 cellData, err := proto.Marshal(&cellEntity)
214 t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
217 nrCellIdKey, _ := common.ValidateAndBuildCellIdKey(cell.GetCellId())
218 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, cell.GetPci())
219 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
225 func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
227 nodebInfoData, err := proto.Marshal(nodebInfo)
229 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
232 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
233 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId,nodebInfo.CuUpId,nodebInfo.DuId)
234 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
236 for _, v := range servedNrCells {
238 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
239 cellData, err := proto.Marshal(&cellEntity)
242 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
245 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
246 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
247 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
253 func TestUpdateGnbCellsSdlFailure(t *testing.T) {
254 inventoryName := "name"
257 w, sdlMock := initSdlMock()
258 servedNrCells := generateServedNrCells("test1", "test2")
259 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
260 nodebInfo.GetGnb().ServedNrCells = servedNrCells
261 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
262 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
263 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
264 assert.IsType(t, &common.InternalError{}, rNibErr)
267 func TestUpdateGnbCellsRnibKeyValidationError(t *testing.T) {
268 //Empty RAN name fails RNIB validation
272 w, _ := initSdlMock()
273 servedNrCells := generateServedNrCells("test1", "test2")
274 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
275 nodebInfo.GetGnb().ServedNrCells = servedNrCells
277 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
278 assert.IsType(t, &common.ValidationError{}, rNibErr)
281 func TestUpdateGnbCellsSuccess(t *testing.T) {
282 inventoryName := "name"
285 w, sdlMock := initSdlMock()
286 servedNrCells := generateServedNrCells("test1", "test2")
287 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
288 nodebInfo.GetGnb().ServedNrCells = servedNrCells
289 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
291 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
292 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
293 assert.Nil(t, rNibErr)
296 func TestUpdateNodebInfoSuccess(t *testing.T) {
297 inventoryName := "name"
300 w, sdlMock := initSdlMock()
301 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
302 data, err := proto.Marshal(nodebInfo)
304 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
307 var setExpected []interface{}
309 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
310 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
311 setExpected = append(setExpected, nodebNameKey, data)
312 setExpected = append(setExpected, nodebIdKey, data)
314 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
316 rNibErr := w.UpdateNodebInfo(nodebInfo)
317 assert.Nil(t, rNibErr)
318 sdlMock.AssertExpectations(t)
321 func TestUpdateNodebInfoAndPublishSuccess(t *testing.T) {
322 inventoryName := "name"
325 w, sdlMock := initSdlMock()
326 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
327 data, err := proto.Marshal(nodebInfo)
329 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
332 var setExpected []interface{}
334 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
335 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
336 setExpected = append(setExpected, nodebNameKey, data)
337 setExpected = append(setExpected, nodebIdKey, data)
339 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
341 rNibErr := w.UpdateNodebInfoAndPublish(nodebInfo)
342 assert.Nil(t, rNibErr)
343 sdlMock.AssertExpectations(t)
346 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
347 inventoryName := "name"
350 w, sdlMock := initSdlMock()
351 nodebInfo := &entities.NodebInfo{}
352 data, err := proto.Marshal(nodebInfo)
354 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
357 var setExpected []interface{}
359 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
360 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
361 setExpected = append(setExpected, nodebNameKey, data)
362 setExpected = append(setExpected, nodebIdKey, data)
364 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
366 rNibErr := w.UpdateNodebInfo(nodebInfo)
368 assert.NotNil(t, rNibErr)
369 assert.IsType(t, &common.ValidationError{}, rNibErr)
372 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
373 inventoryName := "name"
374 w, sdlMock := initSdlMock()
375 nodebInfo := &entities.NodebInfo{}
376 nodebInfo.RanName = inventoryName
377 data, err := proto.Marshal(nodebInfo)
379 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
382 var setExpected []interface{}
384 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
385 setExpected = append(setExpected, nodebNameKey, data)
386 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
388 rNibErr := w.UpdateNodebInfo(nodebInfo)
390 assert.Nil(t, rNibErr)
393 func TestUpdateNodebInfoSdlSetFailure(t *testing.T) {
394 inventoryName := "name"
397 w, sdlMock := initSdlMock()
398 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
399 data, err := proto.Marshal(nodebInfo)
401 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
403 e := errors.New("expected error")
404 var setExpected []interface{}
406 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
407 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
408 setExpected = append(setExpected, nodebNameKey, data)
409 setExpected = append(setExpected, nodebIdKey, data)
411 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
413 rNibErr := w.UpdateNodebInfo(nodebInfo)
414 assert.NotNil(t, rNibErr)
415 assert.IsType(t, &common.InternalError{}, rNibErr)
416 sdlMock.AssertExpectations(t)
419 func TestSaveEnb(t *testing.T) {
420 ranName := "RAN:" + RanName
421 w, sdlMock := initSdlMock()
422 nb := entities.NodebInfo{
424 NodeType: entities.Node_ENB,
425 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
428 GlobalNbId: &entities.GlobalNbId{
434 enb := entities.Enb{}
435 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
436 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
437 enb.ServedCells = []*entities.ServedCellInfo{cell}
438 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
439 data, err := proto.Marshal(&nb)
441 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
445 cellData, err := proto.Marshal(&cellEntity)
447 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
449 var setExpected []interface{}
450 setExpected = append(setExpected, ranName, data)
451 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
452 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
453 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetPci()), cellData)
455 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
456 rNibErr := w.SaveNodeb(&nb)
457 assert.Nil(t, rNibErr)
460 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
461 w, _ := initSdlMock()
462 nb := entities.NodebInfo{}
464 nb.NodeType = entities.Node_ENB
465 nb.ConnectionStatus = 1
468 enb := entities.Enb{}
469 cell := &entities.ServedCellInfo{Pci: 3}
470 enb.ServedCells = []*entities.ServedCellInfo{cell}
471 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
472 rNibErr := w.SaveNodeb(&nb)
473 assert.NotNil(t, rNibErr)
474 assert.IsType(t, &common.ValidationError{}, rNibErr)
475 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
478 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
479 w, _ := initSdlMock()
480 nb := entities.NodebInfo{
481 NodeType: entities.Node_ENB,
482 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
485 GlobalNbId: &entities.GlobalNbId{
490 enb := entities.Enb{}
491 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
492 enb.ServedCells = []*entities.ServedCellInfo{cell}
493 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
494 rNibErr := w.SaveNodeb(&nb)
495 assert.NotNil(t, rNibErr)
496 assert.IsType(t, &common.ValidationError{}, rNibErr)
497 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
500 func TestSaveEnbGlobalNbIdPlmnValidationFailure(t *testing.T) {
501 w, _ := initSdlMock()
502 nb := entities.NodebInfo{
504 NodeType: entities.Node_ENB,
505 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
508 GlobalNbId: &entities.GlobalNbId{
510 //Empty PLMNID fails RNIB validation
514 enb := entities.Enb{}
515 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
516 enb.ServedCells = []*entities.ServedCellInfo{cell}
517 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
518 rNibErr := w.SaveNodeb(&nb)
519 assert.NotNil(t, rNibErr)
520 assert.IsType(t, &common.ValidationError{}, rNibErr)
521 assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", rNibErr.Error())
524 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
525 w, _ := initSdlMock()
526 nb := entities.NodebInfo{}
528 nb.NodeType = entities.Node_GNB
529 nb.ConnectionStatus = 1
532 gnb := entities.Gnb{}
533 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
534 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
535 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
536 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
538 rNibErr := w.SaveNodeb(&nb)
539 assert.NotNil(t, rNibErr)
540 assert.IsType(t, &common.ValidationError{}, rNibErr)
541 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
544 func TestSaveGnb(t *testing.T) {
545 ranName := "RAN:" + RanName
546 w, sdlMock := initSdlMock()
547 nb := entities.NodebInfo{
549 NodeType: entities.Node_GNB,
551 GlobalNbId: &entities.GlobalNbId{
559 gnb := entities.Gnb{}
560 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
561 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
562 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
563 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
564 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
565 data, err := proto.Marshal(&nb)
567 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
571 cellData, err := proto.Marshal(&cellEntity)
573 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
575 var setExpected []interface{}
576 setExpected = append(setExpected, ranName, data)
577 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
578 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
579 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetServedNrCellInformation().GetNrPci()), cellData)
581 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
582 rNibErr := w.SaveNodeb(&nb)
583 assert.Nil(t, rNibErr)
586 func TestSaveRanLoadInformationSuccess(t *testing.T) {
587 inventoryName := "name"
588 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
590 if validationErr != nil {
591 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
594 w, sdlMock := initSdlMock()
596 ranLoadInformation := generateRanLoadInformation()
597 data, err := proto.Marshal(ranLoadInformation)
600 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
604 var setExpected []interface{}
605 setExpected = append(setExpected, loadKey, data)
606 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
608 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
609 assert.Nil(t, rNibErr)
612 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
613 inventoryName := "name2"
614 w, _ := initSdlMock()
616 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
617 err := w.SaveRanLoadInformation(inventoryName, nil)
618 assert.Equal(t, expectedErr, err)
621 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
623 w, _ := initSdlMock()
625 err := w.SaveRanLoadInformation(inventoryName, nil)
626 assert.NotNil(t, err)
627 assert.IsType(t, &common.ValidationError{}, err)
630 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
631 inventoryName := "name2"
633 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
635 if validationErr != nil {
636 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
639 w, sdlMock := initSdlMock()
641 ranLoadInformation := generateRanLoadInformation()
642 data, err := proto.Marshal(ranLoadInformation)
645 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
648 expectedErr := errors.New("expected error")
649 var setExpected []interface{}
650 setExpected = append(setExpected, loadKey, data)
651 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
653 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
654 assert.NotNil(t, rNibErr)
655 assert.IsType(t, &common.InternalError{}, rNibErr)
658 func generateCellLoadInformation() *entities.CellLoadInformation {
659 cellLoadInformation := entities.CellLoadInformation{}
661 cellLoadInformation.CellId = "123"
663 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
664 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
666 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
668 UlHighInterferenceIndication: "xxx",
671 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
673 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
675 RntpThreshold: entities.RntpThreshold_NEG_4,
676 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
678 PdcchInterferenceImpact: 2,
679 EnhancedRntp: &entities.EnhancedRntp{
680 EnhancedRntpBitmap: "xxx",
681 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
682 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
686 cellLoadInformation.AbsInformation = &entities.AbsInformation{
687 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
688 AbsPatternInfo: "xxx",
689 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
690 MeasurementSubset: "xxx",
693 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
695 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
696 AssociatedSubframes: "xxx",
697 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
700 compInformationItem := &entities.CompInformationItem{
701 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
705 cellLoadInformation.CompInformation = &entities.CompInformation{
706 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
707 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
710 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
711 State: entities.NaicsState_NAICS_ACTIVE,
712 TransmissionModes: "xxx",
714 PAList: []entities.PA{entities.PA_DB_NEG_3},
717 return &cellLoadInformation
720 func generateRanLoadInformation() *entities.RanLoadInformation {
721 ranLoadInformation := entities.RanLoadInformation{}
723 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
725 cellLoadInformation := generateCellLoadInformation()
726 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
728 return &ranLoadInformation
731 func TestSaveNilEntityFailure(t *testing.T) {
732 w, _ := initSdlMock()
733 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
734 actualErr := w.SaveNodeb(nil)
735 assert.Equal(t, expectedErr, actualErr)
738 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
739 w, _ := initSdlMock()
740 nb := &entities.NodebInfo{}
743 actualErr := w.SaveNodeb(nb)
744 assert.IsType(t, &common.ValidationError{}, actualErr)
747 func TestSaveEntitySetFailure(t *testing.T) {
752 w, sdlMock := initSdlMock()
753 gnb := entities.NodebInfo{
755 NodeType: entities.Node_GNB,
757 GlobalNbId: &entities.GlobalNbId{
764 data, err := proto.Marshal(&gnb)
766 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
768 setExpected := []interface{}{"RAN:" + name, data}
769 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
770 expectedErr := errors.New("expected error")
771 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
772 rNibErr := w.SaveNodeb(&gnb)
773 assert.NotEmpty(t, rNibErr)
776 func TestSaveEntitySetAndPublishFailure(t *testing.T) {
781 w, sdlMock := initSdlMock()
782 enb := entities.NodebInfo{
784 NodeType: entities.Node_ENB,
786 GlobalNbId: &entities.GlobalNbId{
793 data, err := proto.Marshal(&enb)
795 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
797 setExpected := []interface{}{"RAN:" + name, data}
798 setExpected = append(setExpected, "ENB:"+plmnId+":"+nbId, data)
799 expectedErr := errors.New("expected error")
800 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", name + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(expectedErr)
801 rNibErr := w.AddEnb(&enb)
802 assert.NotEmpty(t, rNibErr)
805 func TestGetRNibWriter(t *testing.T) {
806 received, _ := initSdlMock()
807 assert.NotEmpty(t, received)
810 func TestSaveE2TInstanceSuccess(t *testing.T) {
811 address := "10.10.2.15:9800"
812 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
814 if validationErr != nil {
815 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
818 w, sdlMock := initSdlMock()
820 e2tInstance := generateE2tInstance(address)
821 data, err := json.Marshal(e2tInstance)
824 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
828 var setExpected []interface{}
829 setExpected = append(setExpected, loadKey, data)
830 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
832 rNibErr := w.SaveE2TInstance(e2tInstance)
833 assert.Nil(t, rNibErr)
836 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
837 w, _ := initSdlMock()
839 e2tInstance := entities.NewE2TInstance(address, "test")
840 err := w.SaveE2TInstance(e2tInstance)
841 assert.NotNil(t, err)
842 assert.IsType(t, &common.ValidationError{}, err)
845 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
846 address := "10.10.2.15:9800"
847 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
849 if validationErr != nil {
850 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
853 w, sdlMock := initSdlMock()
855 e2tInstance := generateE2tInstance(address)
856 data, err := json.Marshal(e2tInstance)
859 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
862 expectedErr := errors.New("expected error")
863 var setExpected []interface{}
864 setExpected = append(setExpected, loadKey, data)
865 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
867 rNibErr := w.SaveE2TInstance(e2tInstance)
868 assert.NotNil(t, rNibErr)
869 assert.IsType(t, &common.InternalError{}, rNibErr)
872 func generateE2tInstance(address string) *entities.E2TInstance {
873 e2tInstance := entities.NewE2TInstance(address, "pod test")
875 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
880 func TestSaveE2TAddressesSuccess(t *testing.T) {
881 address := "10.10.2.15:9800"
882 w, sdlMock := initSdlMock()
884 e2tAddresses := []string{address}
885 data, err := json.Marshal(e2tAddresses)
888 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
892 var setExpected []interface{}
893 setExpected = append(setExpected, E2TAddressesKey, data)
894 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
896 rNibErr := w.SaveE2TAddresses(e2tAddresses)
897 assert.Nil(t, rNibErr)
900 func TestSaveE2TAddressesSdlFailure(t *testing.T) {
901 address := "10.10.2.15:9800"
902 w, sdlMock := initSdlMock()
904 e2tAddresses := []string{address}
905 data, err := json.Marshal(e2tAddresses)
908 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
911 expectedErr := errors.New("expected error")
912 var setExpected []interface{}
913 setExpected = append(setExpected, E2TAddressesKey, data)
914 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
916 rNibErr := w.SaveE2TAddresses(e2tAddresses)
917 assert.NotNil(t, rNibErr)
918 assert.IsType(t, &common.InternalError{}, rNibErr)
921 func TestRemoveE2TInstanceSuccess(t *testing.T) {
922 address := "10.10.2.15:9800"
923 w, sdlMock := initSdlMock()
925 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
927 sdlMock.On("Remove", namespace, e2tAddresses).Return(e)
929 rNibErr := w.RemoveE2TInstance(address)
930 assert.Nil(t, rNibErr)
931 sdlMock.AssertExpectations(t)
934 func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
935 address := "10.10.2.15:9800"
936 w, sdlMock := initSdlMock()
938 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
939 expectedErr := errors.New("expected error")
940 sdlMock.On("Remove", namespace, e2tAddresses).Return(expectedErr)
942 rNibErr := w.RemoveE2TInstance(address)
943 assert.IsType(t, &common.InternalError{}, rNibErr)
946 func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
947 w, sdlMock := initSdlMock()
949 rNibErr := w.RemoveE2TInstance("")
950 assert.IsType(t, &common.ValidationError{}, rNibErr)
951 sdlMock.AssertExpectations(t)
954 func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
955 inventoryName := "name"
958 channelName := "RAN_CONNECTION_STATUS_CHANGE"
959 eventName := inventoryName + "_" + "CONNECTED"
960 w, sdlMock := initSdlMock()
961 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
962 data, err := proto.Marshal(nodebInfo)
964 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
967 var setExpected []interface{}
969 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
970 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
971 setExpected = append(setExpected, nodebNameKey, data)
972 setExpected = append(setExpected, nodebIdKey, data)
974 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
976 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
977 assert.Nil(t, rNibErr)
980 func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
981 inventoryName := "name"
984 channelName := "RAN_CONNECTION_STATUS_CHANGE"
985 eventName := inventoryName + "_" + "CONNECTED"
986 w, sdlMock := initSdlMock()
987 nodebInfo := &entities.NodebInfo{}
988 data, err := proto.Marshal(nodebInfo)
990 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
993 var setExpected []interface{}
995 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
996 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
997 setExpected = append(setExpected, nodebNameKey, data)
998 setExpected = append(setExpected, nodebIdKey, data)
1000 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
1002 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
1004 assert.NotNil(t, rNibErr)
1005 assert.IsType(t, &common.ValidationError{}, rNibErr)
1008 func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) {
1009 inventoryName := "name"
1010 channelName := "RAN_CONNECTION_STATUS_CHANGE"
1011 eventName := inventoryName + "_" + "CONNECTED"
1012 w, sdlMock := initSdlMock()
1013 nodebInfo := &entities.NodebInfo{}
1014 nodebInfo.RanName = inventoryName
1015 data, err := proto.Marshal(nodebInfo)
1017 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
1020 var setExpected []interface{}
1022 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1023 setExpected = append(setExpected, nodebNameKey, data)
1024 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
1026 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
1028 assert.Nil(t, rNibErr)
1031 func TestUpdateNodebInfoOnConnectionStatusInversionSdlFailure(t *testing.T) {
1032 inventoryName := "name"
1035 channelName := "RAN_CONNECTION_STATUS_CHANGE"
1036 eventName := inventoryName + "_" + "CONNECTED"
1037 w, sdlMock := initSdlMock()
1038 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1039 data, err := proto.Marshal(nodebInfo)
1041 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
1043 e := errors.New("expected error")
1044 var setExpected []interface{}
1046 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1047 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1048 setExpected = append(setExpected, nodebNameKey, data)
1049 setExpected = append(setExpected, nodebIdKey, data)
1051 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
1053 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
1054 assert.NotNil(t, rNibErr)
1055 assert.IsType(t, &common.InternalError{}, rNibErr)
1058 func TestSaveGeneralConfiguration(t *testing.T) {
1059 w, sdlMock := initSdlMock()
1061 key := common.BuildGeneralConfigurationKey()
1062 configurationData := "{\"enableRic\":true}"
1063 configuration := &entities.GeneralConfiguration{}
1064 configuration.EnableRic = true
1066 sdlMock.On("Set", namespace, []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
1067 rNibErr := w.SaveGeneralConfiguration(configuration)
1069 assert.Nil(t, rNibErr)
1070 sdlMock.AssertExpectations(t)
1073 func TestSaveGeneralConfigurationDbError(t *testing.T) {
1074 w, sdlMock := initSdlMock()
1076 key := common.BuildGeneralConfigurationKey()
1077 configurationData := "{\"enableRic\":true}"
1078 configuration := &entities.GeneralConfiguration{}
1079 configuration.EnableRic = true
1081 expectedErr := errors.New("expected error")
1083 sdlMock.On("Set", namespace, []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
1084 rNibErr := w.SaveGeneralConfiguration(configuration)
1086 assert.NotNil(t, rNibErr)
1089 func TestRemoveServedCellsFailure(t *testing.T) {
1090 w, sdlMock := initSdlMock()
1091 servedCellsToRemove := generateServedCells("whatever1", "whatever2")
1092 expectedErr := errors.New("expected error")
1093 sdlMock.On("Remove", namespace, buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(expectedErr)
1095 rNibErr := w.RemoveServedCells(RanName, servedCellsToRemove)
1097 assert.NotNil(t, rNibErr)
1100 func TestRemoveServedCellsSuccess(t *testing.T) {
1101 w, sdlMock := initSdlMock()
1102 servedCellsToRemove := generateServedCells("whatever1", "whatever2")
1103 sdlMock.On("Remove", namespace, buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(nil)
1104 err := w.RemoveServedCells(RanName, servedCellsToRemove)
1108 func TestUpdateEnbInvalidNodebInfoFailure(t *testing.T) {
1109 w, sdlMock := initSdlMock()
1110 servedCells := generateServedCells("test1", "test2")
1111 nodebInfo := &entities.NodebInfo{}
1112 sdlMock.AssertNotCalled(t, "SetAndPublish")
1113 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1114 assert.IsType(t, &common.ValidationError{}, rNibErr)
1117 func TestUpdateEnbInvalidCellFailure(t *testing.T) {
1118 inventoryName := "name"
1121 w, sdlMock := initSdlMock()
1122 servedCells := []*entities.ServedCellInfo{{CellId: ""}}
1123 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1124 nodebInfo.GetEnb().ServedCells = servedCells
1125 sdlMock.AssertNotCalled(t, "SetAndPublish")
1126 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1127 assert.IsType(t, &common.ValidationError{}, rNibErr)
1130 func TestUpdateEnbRnibKeyValidationError(t *testing.T) {
1131 //Empty RAN name fails RNIB validation
1135 w, _ := initSdlMock()
1136 servedCells := generateServedCells("test1", "test2")
1137 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1138 nodebInfo.GetEnb().ServedCells = servedCells
1140 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1141 assert.IsType(t, &common.ValidationError{}, rNibErr)
1144 func TestUpdateEnbSdlFailure(t *testing.T) {
1145 inventoryName := "name"
1148 w, sdlMock := initSdlMock()
1149 servedCells := generateServedCells("test1", "test2")
1150 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1151 nodebInfo.GetEnb().ServedCells = servedCells
1152 setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
1153 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
1154 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1155 assert.IsType(t, &common.InternalError{}, rNibErr)
1158 func TestUpdateEnbSuccess(t *testing.T) {
1159 inventoryName := "name"
1162 w, sdlMock := initSdlMock()
1163 servedCells := generateServedCells("test1", "test2")
1164 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1165 nodebInfo.GetEnb().ServedCells = servedCells
1166 setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
1169 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
1170 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1171 assert.Nil(t, rNibErr)
1174 func getUpdateEnbSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
1176 nodebInfoData, err := proto.Marshal(nodebInfo)
1178 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal NodeB entity. Error: %s", err)
1181 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
1182 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId,nodebInfo.CuUpId,nodebInfo.DuId)
1183 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
1185 for _, v := range servedCells {
1187 cellEntity := entities.ServedCellInfo{CellId: "some cell id", EutraMode: entities.Eutra_FDD, CsgId: "some csg id"}
1188 cellData, err := proto.Marshal(&cellEntity)
1191 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal cell entity. Error: %s", err)
1194 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetCellId())
1195 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetPci())
1196 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
1201 func TestRemoveEnbSuccess(t *testing.T) {
1202 inventoryName := "name"
1205 channelName := "RAN_MANIPULATION"
1206 eventName := inventoryName + "_" + "DELETED"
1207 w, sdlMock := initSdlMock()
1208 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1209 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1213 expectedKeys := []string{}
1214 cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
1215 cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
1216 cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
1217 cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
1218 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1219 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1220 expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
1221 sdlMock.On("RemoveAndPublish", namespace, []string{channelName, eventName}, expectedKeys).Return(e)
1223 rNibErr := w.RemoveEnb(nodebInfo)
1224 assert.Nil(t, rNibErr)
1225 sdlMock.AssertExpectations(t)
1228 func TestRemoveEnbRnibKeyValidationError(t *testing.T) {
1229 //Empty RAN name fails RNIB key validation
1233 w, _ := initSdlMock()
1234 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1235 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1237 rNibErr := w.RemoveEnb(nodebInfo)
1238 assert.NotNil(t, rNibErr)
1241 func TestRemoveEnbRemoveAndPublishError(t *testing.T) {
1242 inventoryName := "name"
1245 channelName := "RAN_MANIPULATION"
1246 eventName := inventoryName + "_" + "DELETED"
1247 w, sdlMock := initSdlMock()
1248 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1249 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1251 expectedKeys := []string{}
1252 cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
1253 cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
1254 cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
1255 cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
1256 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1257 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1258 expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
1259 sdlMock.On("RemoveAndPublish", namespace, []string{channelName, eventName}, expectedKeys).Return(errors.New("for test"))
1261 rNibErr := w.RemoveEnb(nodebInfo)
1262 assert.NotNil(t, rNibErr)
1263 sdlMock.AssertExpectations(t)
1266 func TestRemoveNbIdentitySuccess(t *testing.T) {
1267 w, sdlMock := initSdlMock()
1268 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1269 nbIdData, err := proto.Marshal(nbIdentity)
1271 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1274 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(nil)
1276 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1277 assert.Nil(t, rNibErr)
1278 sdlMock.AssertExpectations(t)
1281 func TestRemoveNbIdentityMarshalNilFailure(t *testing.T) {
1282 w, _ := initSdlMock()
1284 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nil)
1285 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1286 assert.Equal(t, expectedErr, rNibErr)
1289 func TestRemoveNbIdentityError(t *testing.T) {
1290 w, sdlMock := initSdlMock()
1291 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1292 nbIdData, err := proto.Marshal(nbIdentity)
1294 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1297 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1299 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1300 assert.NotNil(t, rNibErr)
1301 sdlMock.AssertExpectations(t)
1304 func TestAddEnb(t *testing.T) {
1305 ranName := "RAN:" + RanName
1306 w, sdlMock := initSdlMock()
1307 nb := entities.NodebInfo{
1309 NodeType: entities.Node_ENB,
1310 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1313 GlobalNbId: &entities.GlobalNbId{
1319 enb := entities.Enb{}
1320 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
1321 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
1322 enb.ServedCells = []*entities.ServedCellInfo{cell}
1323 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1324 data, err := proto.Marshal(&nb)
1326 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
1330 cellData, err := proto.Marshal(&cellEntity)
1332 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
1334 var setExpected []interface{}
1335 setExpected = append(setExpected, ranName, data)
1336 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
1337 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
1338 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetPci()), cellData)
1340 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", RanName + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
1342 rNibErr := w.AddEnb(&nb)
1343 assert.Nil(t, rNibErr)
1346 func TestAddEnbMarshalNilFailure(t *testing.T) {
1347 w, _ := initSdlMock()
1349 rNibErr := w.AddEnb(nil)
1350 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1351 assert.Equal(t, expectedErr, rNibErr)
1354 func TestAddEnbCellIdValidationFailure(t *testing.T) {
1355 w, _ := initSdlMock()
1356 nb := entities.NodebInfo{}
1358 nb.NodeType = entities.Node_ENB
1359 nb.ConnectionStatus = 1
1362 enb := entities.Enb{}
1363 cell := &entities.ServedCellInfo{Pci: 3}
1364 enb.ServedCells = []*entities.ServedCellInfo{cell}
1365 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1366 rNibErr := w.AddEnb(&nb)
1367 assert.NotNil(t, rNibErr)
1368 assert.IsType(t, &common.ValidationError{}, rNibErr)
1369 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
1372 func TestAddEnbInventoryNameValidationFailure(t *testing.T) {
1373 w, _ := initSdlMock()
1374 nb := entities.NodebInfo{
1375 NodeType: entities.Node_ENB,
1376 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1379 GlobalNbId: &entities.GlobalNbId{
1384 enb := entities.Enb{}
1385 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
1386 enb.ServedCells = []*entities.ServedCellInfo{cell}
1387 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1388 rNibErr := w.AddEnb(&nb)
1389 assert.NotNil(t, rNibErr)
1390 assert.IsType(t, &common.ValidationError{}, rNibErr)
1391 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
1394 func TestAddEnbGlobalNbIdPlmnValidationFailure(t *testing.T) {
1395 w, _ := initSdlMock()
1396 nb := entities.NodebInfo{
1398 NodeType: entities.Node_ENB,
1399 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1402 GlobalNbId: &entities.GlobalNbId{
1404 //Empty PLMNID fails RNIB validation
1408 enb := entities.Enb{}
1409 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
1410 enb.ServedCells = []*entities.ServedCellInfo{cell}
1411 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1412 rNibErr := w.AddEnb(&nb)
1413 assert.NotNil(t, rNibErr)
1414 assert.IsType(t, &common.ValidationError{}, rNibErr)
1415 assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", rNibErr.Error())
1418 func TestUpdateNbIdentityOneMemberSuccess(t *testing.T) {
1419 w, sdlMock := initSdlMock()
1421 proto, nbIdentity := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1422 val := []interface{}{proto}
1424 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), val).Return(nil)
1426 protoAdd, nbIdentityAdd := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1427 sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), []interface{}{protoAdd}).Return(nil)
1429 newNbIdIdentities := []*entities.NbIdentity{nbIdentityAdd}
1430 oldNbIdIdentities := []*entities.NbIdentity{nbIdentity}
1432 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1433 assert.Nil(t, rNibErr)
1434 sdlMock.AssertExpectations(t)
1437 func TestUpdateNbIdentitySuccess(t *testing.T) {
1438 w, sdlMock := initSdlMock()
1440 var nbIdIdentitiesProtoToRemove []interface{}
1441 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1442 protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
1443 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1444 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
1445 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
1447 var nbIdIdentitiesProtoToAdd []interface{}
1448 protoRan1Add, _ := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1449 protoRan2Add, _ := createNbIdentityProto(t, "ran2_add", "plmnId2_add", "nbId2_add", entities.ConnectionStatus_CONNECTED)
1450 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan1Add)
1451 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan2Add)
1452 sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToAdd).Return(nil)
1454 var newNbIdIdentities []*entities.NbIdentity
1455 firstNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"}}
1456 secondNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2_add", NbId: "nbId2_add"}}
1457 newNbIdIdentities = append(newNbIdIdentities, firstNewNbIdIdentity)
1458 newNbIdIdentities = append(newNbIdIdentities, secondNewNbIdIdentity)
1460 var oldNbIdIdentities []*entities.NbIdentity
1461 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1462 secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
1463 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1464 oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
1466 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1467 assert.Nil(t, rNibErr)
1468 sdlMock.AssertExpectations(t)
1471 func TestUpdateNbIdentityOldIdentityMarshalNilFailure(t *testing.T) {
1472 w, _ := initSdlMock()
1474 oldNbIdIdentities := []*entities.NbIdentity{nil}
1475 newNbIdIdentities := []*entities.NbIdentity{
1476 &entities.NbIdentity{
1477 InventoryName: "ran1_add",
1478 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1479 GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"},
1483 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1484 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1485 assert.Equal(t, expectedErr, rNibErr)
1488 func TestUpdateNbIdentityNewIdentityMarshalNilFailure(t *testing.T) {
1489 w, sdlMock := initSdlMock()
1491 var nbIdIdentitiesProtoToRemove []interface{}
1492 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1493 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1494 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
1496 oldNbIdIdentities := []*entities.NbIdentity{
1497 &entities.NbIdentity{
1498 InventoryName: "ran1",
1499 ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
1500 GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"},
1503 newNbIdIdentities := []*entities.NbIdentity{nil}
1505 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1506 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1507 assert.Equal(t, expectedErr, rNibErr)
1510 func TestUpdateNbIdentityRemoveFailure(t *testing.T) {
1511 w, sdlMock := initSdlMock()
1513 var nbIdIdentitiesProtoToRemove []interface{}
1514 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1515 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1516 protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
1517 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
1519 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(fmt.Errorf("for test"))
1521 var oldNbIdIdentities []*entities.NbIdentity
1522 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1523 secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
1524 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1525 oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
1527 var newNbIdIdentities []*entities.NbIdentity
1529 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1530 assert.NotNil(t, rNibErr)
1531 sdlMock.AssertExpectations(t)
1534 func TestUpdateNbIdentitySdlAddMemberFailure(t *testing.T) {
1535 w, sdlMock := initSdlMock()
1537 var nbIdIdentitiesProtoToRemove []interface{}
1538 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1539 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1540 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
1542 var nbIdIdentitiesProtoToAdd []interface{}
1543 protoRan1Add, _ := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1544 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan1Add)
1545 sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToAdd).Return(fmt.Errorf("for test"))
1547 var oldNbIdIdentities []*entities.NbIdentity
1548 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1549 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1551 var newNbIdIdentities []*entities.NbIdentity
1552 firstNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"}}
1553 newNbIdIdentities = append(newNbIdIdentities, firstNewNbIdIdentity)
1555 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1556 assert.NotNil(t, rNibErr)
1557 sdlMock.AssertExpectations(t)
1560 func TestUpdateNbIdentityAddFailure(t *testing.T) {
1561 w, sdlMock := initSdlMock()
1562 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1563 nbIdData, err := proto.Marshal(nbIdentity)
1565 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1567 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1569 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1570 assert.NotNil(t, rNibErr)
1571 sdlMock.AssertExpectations(t)
1574 func TestUpdateNbIdentityNoNbIdentityToRemove(t *testing.T) {
1575 w, sdlMock := initSdlMock()
1576 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1577 nbIdData, err := proto.Marshal(nbIdentity)
1579 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1581 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1583 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1584 assert.NotNil(t, rNibErr)
1585 sdlMock.AssertExpectations(t)
1588 func TestUpdateNbIdentityNoNbIdentityToAdd(t *testing.T) {
1589 w, sdlMock := initSdlMock()
1590 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1591 nbIdData, err := proto.Marshal(nbIdentity)
1593 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1595 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1597 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1598 assert.NotNil(t, rNibErr)
1599 sdlMock.AssertExpectations(t)
1602 func createNbIdentityProto(t *testing.T, ranName string, plmnId string, nbId string, connectionStatus entities.ConnectionStatus) ([]byte, *entities.NbIdentity) {
1603 nbIdentity := &entities.NbIdentity{InventoryName: ranName, ConnectionStatus: connectionStatus, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
1604 nbIdData, err := proto.Marshal(nbIdentity)
1606 t.Errorf("#createNbIdentityProto - failed to Marshal NbIdentity")
1608 return nbIdData, nbIdentity