2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
29 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
30 "github.com/golang/protobuf/proto"
31 "github.com/stretchr/testify/assert"
36 var namespace = common.GetRNibNamespace()
44 func initSdlMock() (w RNibWriter, sdlMock *mocks.MockSdlSyncStorage) {
45 sdlMock = new(mocks.MockSdlSyncStorage)
46 w = GetRNibWriter(sdlMock, configuration.RnibWriterConfig{StateChangeMessageChannel: "RAN_CONNECTION_STATUS_CHANGE", RanManipulationMessageChannel: "RAN_MANIPULATION"})
50 func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo {
51 nodebInfo := &entities.NodebInfo{
52 RanName: inventoryName,
53 GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId},
55 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
58 if nodeType == entities.Node_ENB {
59 nodebInfo.Configuration = &entities.NodebInfo_Enb{
62 } else if nodeType == entities.Node_GNB {
63 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
71 func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
73 var servedNrCells []*entities.ServedNRCell
75 for i, v := range cellIds {
76 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
78 ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
79 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{},
81 NrMode: entities.Nr_FDD,
83 ServedPlmns: []string{"whatever"},
90 func generateServedCells(cellIds ...string) []*entities.ServedCellInfo {
92 var servedCells []*entities.ServedCellInfo
94 for i, v := range cellIds {
95 servedCells = append(servedCells, &entities.ServedCellInfo{
97 ChoiceEutraMode: &entities.ChoiceEUTRAMode{
98 Fdd: &entities.FddInfo{},
101 BroadcastPlmns: []string{"whatever"},
108 func generateServedCellInfos(cellIds ...string) []*entities.ServedCellInfo {
110 servedCells := []*entities.ServedCellInfo{}
112 for i, v := range cellIds {
113 servedCells = append(servedCells, &entities.ServedCellInfo{
122 func TestRemoveServedNrCellsSuccess(t *testing.T) {
123 w, sdlMock := initSdlMock()
124 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
125 sdlMock.On("Remove", namespace, buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil)
126 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
130 func TestRemoveServedNrCellsFailure(t *testing.T) {
131 w, sdlMock := initSdlMock()
132 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
133 sdlMock.On("Remove", namespace, buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error"))
134 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
135 assert.IsType(t, &common.InternalError{}, err)
138 func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
139 w, sdlMock := initSdlMock()
140 servedNrCells := generateServedNrCells("test1", "test2")
141 nodebInfo := &entities.NodebInfo{}
142 sdlMock.AssertNotCalled(t, "SetAndPublish")
143 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
144 assert.IsType(t, &common.ValidationError{}, rNibErr)
147 func TestAddNbIdentitySuccess(t *testing.T) {
148 w, sdlMock := initSdlMock()
150 nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
151 nbIdData, err := proto.Marshal(nbIdentity)
153 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySuccess - Failed to marshal NodeB Identity entity. Error: %v", err)
156 sdlMock.On("AddMember", namespace, "ENB", []interface{}{nbIdData}).Return(nil)
157 rNibErr := w.AddNbIdentity(entities.Node_ENB, nbIdentity)
158 assert.Nil(t, rNibErr)
161 func TestAddNbIdentityMarshalNilFailure(t *testing.T) {
162 w, _ := initSdlMock()
164 rNibErr := w.AddNbIdentity(entities.Node_ENB, nil)
165 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
166 assert.Equal(t, expectedErr, rNibErr)
169 func TestAddNbIdentitySdlFailure(t *testing.T) {
170 w, sdlMock := initSdlMock()
172 nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
173 nbIdData, err := proto.Marshal(nbIdentity)
175 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySdlFailure - Failed to marshal NodeB Identity entity. Error: %v", err)
178 sdlMock.On("AddMember", namespace, "ENB", []interface{}{nbIdData}).Return(errors.New("expected error"))
179 rNibErr := w.AddNbIdentity(entities.Node_ENB, nbIdentity)
180 assert.IsType(t, &common.InternalError{}, rNibErr)
183 func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
184 inventoryName := "name"
187 w, sdlMock := initSdlMock()
188 servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
189 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
190 nodebInfo.GetGnb().ServedNrCells = servedNrCells
191 sdlMock.AssertNotCalled(t, "SetAndPublish")
192 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
193 assert.IsType(t, &common.ValidationError{}, rNibErr)
196 func getUpdateEnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
198 nodebInfoData, err := proto.Marshal(nodebInfo)
200 t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
203 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
204 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
205 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
207 for _, cell := range servedCells {
209 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
210 cellData, err := proto.Marshal(&cellEntity)
213 t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
216 nrCellIdKey, _ := common.ValidateAndBuildCellIdKey(cell.GetCellId())
217 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, cell.GetPci())
218 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
224 func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
226 nodebInfoData, err := proto.Marshal(nodebInfo)
228 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
231 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
232 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
233 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
235 for _, v := range servedNrCells {
237 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
238 cellData, err := proto.Marshal(&cellEntity)
241 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
244 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
245 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
246 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
252 func TestUpdateGnbCellsSdlFailure(t *testing.T) {
253 inventoryName := "name"
256 w, sdlMock := initSdlMock()
257 servedNrCells := generateServedNrCells("test1", "test2")
258 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
259 nodebInfo.GetGnb().ServedNrCells = servedNrCells
260 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
261 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
262 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
263 assert.IsType(t, &common.InternalError{}, rNibErr)
266 func TestUpdateGnbCellsRnibKeyValidationError(t *testing.T) {
267 //Empty RAN name fails RNIB validation
271 w, _ := initSdlMock()
272 servedNrCells := generateServedNrCells("test1", "test2")
273 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
274 nodebInfo.GetGnb().ServedNrCells = servedNrCells
276 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
277 assert.IsType(t, &common.ValidationError{}, rNibErr)
280 func TestUpdateGnbCellsSuccess(t *testing.T) {
281 inventoryName := "name"
284 w, sdlMock := initSdlMock()
285 servedNrCells := generateServedNrCells("test1", "test2")
286 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
287 nodebInfo.GetGnb().ServedNrCells = servedNrCells
288 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
290 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
291 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
292 assert.Nil(t, rNibErr)
295 func TestUpdateNodebInfoSuccess(t *testing.T) {
296 inventoryName := "name"
299 w, sdlMock := initSdlMock()
300 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
301 data, err := proto.Marshal(nodebInfo)
303 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
306 var setExpected []interface{}
308 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
309 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
310 setExpected = append(setExpected, nodebNameKey, data)
311 setExpected = append(setExpected, nodebIdKey, data)
313 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
315 rNibErr := w.UpdateNodebInfo(nodebInfo)
316 assert.Nil(t, rNibErr)
317 sdlMock.AssertExpectations(t)
320 func TestUpdateNodebInfoAndPublishSuccess(t *testing.T) {
321 inventoryName := "name"
324 w, sdlMock := initSdlMock()
325 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
326 data, err := proto.Marshal(nodebInfo)
328 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
331 var setExpected []interface{}
333 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
334 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
335 setExpected = append(setExpected, nodebNameKey, data)
336 setExpected = append(setExpected, nodebIdKey, data)
338 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
340 rNibErr := w.UpdateNodebInfoAndPublish(nodebInfo)
341 assert.Nil(t, rNibErr)
342 sdlMock.AssertExpectations(t)
345 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
346 inventoryName := "name"
349 w, sdlMock := initSdlMock()
350 nodebInfo := &entities.NodebInfo{}
351 data, err := proto.Marshal(nodebInfo)
353 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
356 var setExpected []interface{}
358 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
359 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
360 setExpected = append(setExpected, nodebNameKey, data)
361 setExpected = append(setExpected, nodebIdKey, data)
363 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
365 rNibErr := w.UpdateNodebInfo(nodebInfo)
367 assert.NotNil(t, rNibErr)
368 assert.IsType(t, &common.ValidationError{}, rNibErr)
371 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
372 inventoryName := "name"
373 w, sdlMock := initSdlMock()
374 nodebInfo := &entities.NodebInfo{}
375 nodebInfo.RanName = inventoryName
376 data, err := proto.Marshal(nodebInfo)
378 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
381 var setExpected []interface{}
383 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
384 setExpected = append(setExpected, nodebNameKey, data)
385 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
387 rNibErr := w.UpdateNodebInfo(nodebInfo)
389 assert.Nil(t, rNibErr)
392 func TestUpdateNodebInfoSdlSetFailure(t *testing.T) {
393 inventoryName := "name"
396 w, sdlMock := initSdlMock()
397 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
398 data, err := proto.Marshal(nodebInfo)
400 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
402 e := errors.New("expected error")
403 var setExpected []interface{}
405 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
406 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
407 setExpected = append(setExpected, nodebNameKey, data)
408 setExpected = append(setExpected, nodebIdKey, data)
410 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
412 rNibErr := w.UpdateNodebInfo(nodebInfo)
413 assert.NotNil(t, rNibErr)
414 assert.IsType(t, &common.InternalError{}, rNibErr)
415 sdlMock.AssertExpectations(t)
418 func TestSaveEnb(t *testing.T) {
419 ranName := "RAN:" + RanName
420 w, sdlMock := initSdlMock()
421 nb := entities.NodebInfo{
423 NodeType: entities.Node_ENB,
424 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
427 GlobalNbId: &entities.GlobalNbId{
433 enb := entities.Enb{}
434 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
435 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
436 enb.ServedCells = []*entities.ServedCellInfo{cell}
437 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
438 data, err := proto.Marshal(&nb)
440 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
444 cellData, err := proto.Marshal(&cellEntity)
446 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
448 var setExpected []interface{}
449 setExpected = append(setExpected, ranName, data)
450 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
451 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
452 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetPci()), cellData)
454 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
455 rNibErr := w.SaveNodeb(&nb)
456 assert.Nil(t, rNibErr)
459 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
460 w, _ := initSdlMock()
461 nb := entities.NodebInfo{}
463 nb.NodeType = entities.Node_ENB
464 nb.ConnectionStatus = 1
467 enb := entities.Enb{}
468 cell := &entities.ServedCellInfo{Pci: 3}
469 enb.ServedCells = []*entities.ServedCellInfo{cell}
470 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
471 rNibErr := w.SaveNodeb(&nb)
472 assert.NotNil(t, rNibErr)
473 assert.IsType(t, &common.ValidationError{}, rNibErr)
474 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
477 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
478 w, _ := initSdlMock()
479 nb := entities.NodebInfo{
480 NodeType: entities.Node_ENB,
481 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
484 GlobalNbId: &entities.GlobalNbId{
489 enb := entities.Enb{}
490 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
491 enb.ServedCells = []*entities.ServedCellInfo{cell}
492 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
493 rNibErr := w.SaveNodeb(&nb)
494 assert.NotNil(t, rNibErr)
495 assert.IsType(t, &common.ValidationError{}, rNibErr)
496 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
499 func TestSaveEnbGlobalNbIdPlmnValidationFailure(t *testing.T) {
500 w, _ := initSdlMock()
501 nb := entities.NodebInfo{
503 NodeType: entities.Node_ENB,
504 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
507 GlobalNbId: &entities.GlobalNbId{
509 //Empty PLMNID fails RNIB validation
513 enb := entities.Enb{}
514 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
515 enb.ServedCells = []*entities.ServedCellInfo{cell}
516 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
517 rNibErr := w.SaveNodeb(&nb)
518 assert.NotNil(t, rNibErr)
519 assert.IsType(t, &common.ValidationError{}, rNibErr)
520 assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", rNibErr.Error())
523 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
524 w, _ := initSdlMock()
525 nb := entities.NodebInfo{}
527 nb.NodeType = entities.Node_GNB
528 nb.ConnectionStatus = 1
531 gnb := entities.Gnb{}
532 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
533 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
534 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
535 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
537 rNibErr := w.SaveNodeb(&nb)
538 assert.NotNil(t, rNibErr)
539 assert.IsType(t, &common.ValidationError{}, rNibErr)
540 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
543 func TestSaveGnb(t *testing.T) {
544 ranName := "RAN:" + RanName
545 w, sdlMock := initSdlMock()
546 nb := entities.NodebInfo{
548 NodeType: entities.Node_GNB,
550 GlobalNbId: &entities.GlobalNbId{
558 gnb := entities.Gnb{}
559 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
560 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
561 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
562 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
563 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
564 data, err := proto.Marshal(&nb)
566 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
570 cellData, err := proto.Marshal(&cellEntity)
572 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
574 var setExpected []interface{}
575 setExpected = append(setExpected, ranName, data)
576 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
577 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
578 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetServedNrCellInformation().GetNrPci()), cellData)
580 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
581 rNibErr := w.SaveNodeb(&nb)
582 assert.Nil(t, rNibErr)
585 func TestSaveRanLoadInformationSuccess(t *testing.T) {
586 inventoryName := "name"
587 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
589 if validationErr != nil {
590 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
593 w, sdlMock := initSdlMock()
595 ranLoadInformation := generateRanLoadInformation()
596 data, err := proto.Marshal(ranLoadInformation)
599 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
603 var setExpected []interface{}
604 setExpected = append(setExpected, loadKey, data)
605 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
607 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
608 assert.Nil(t, rNibErr)
611 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
612 inventoryName := "name2"
613 w, _ := initSdlMock()
615 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
616 err := w.SaveRanLoadInformation(inventoryName, nil)
617 assert.Equal(t, expectedErr, err)
620 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
622 w, _ := initSdlMock()
624 err := w.SaveRanLoadInformation(inventoryName, nil)
625 assert.NotNil(t, err)
626 assert.IsType(t, &common.ValidationError{}, err)
629 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
630 inventoryName := "name2"
632 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
634 if validationErr != nil {
635 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
638 w, sdlMock := initSdlMock()
640 ranLoadInformation := generateRanLoadInformation()
641 data, err := proto.Marshal(ranLoadInformation)
644 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
647 expectedErr := errors.New("expected error")
648 var setExpected []interface{}
649 setExpected = append(setExpected, loadKey, data)
650 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
652 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
653 assert.NotNil(t, rNibErr)
654 assert.IsType(t, &common.InternalError{}, rNibErr)
657 func generateCellLoadInformation() *entities.CellLoadInformation {
658 cellLoadInformation := entities.CellLoadInformation{}
660 cellLoadInformation.CellId = "123"
662 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
663 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
665 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
667 UlHighInterferenceIndication: "xxx",
670 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
672 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
674 RntpThreshold: entities.RntpThreshold_NEG_4,
675 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
677 PdcchInterferenceImpact: 2,
678 EnhancedRntp: &entities.EnhancedRntp{
679 EnhancedRntpBitmap: "xxx",
680 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
681 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
685 cellLoadInformation.AbsInformation = &entities.AbsInformation{
686 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
687 AbsPatternInfo: "xxx",
688 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
689 MeasurementSubset: "xxx",
692 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
694 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
695 AssociatedSubframes: "xxx",
696 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
699 compInformationItem := &entities.CompInformationItem{
700 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
704 cellLoadInformation.CompInformation = &entities.CompInformation{
705 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
706 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
709 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
710 State: entities.NaicsState_NAICS_ACTIVE,
711 TransmissionModes: "xxx",
713 PAList: []entities.PA{entities.PA_DB_NEG_3},
716 return &cellLoadInformation
719 func generateRanLoadInformation() *entities.RanLoadInformation {
720 ranLoadInformation := entities.RanLoadInformation{}
722 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
724 cellLoadInformation := generateCellLoadInformation()
725 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
727 return &ranLoadInformation
730 func TestSaveNilEntityFailure(t *testing.T) {
731 w, _ := initSdlMock()
732 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
733 actualErr := w.SaveNodeb(nil)
734 assert.Equal(t, expectedErr, actualErr)
737 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
738 w, _ := initSdlMock()
739 nb := &entities.NodebInfo{}
742 actualErr := w.SaveNodeb(nb)
743 assert.IsType(t, &common.ValidationError{}, actualErr)
746 func TestSaveEntitySetFailure(t *testing.T) {
751 w, sdlMock := initSdlMock()
752 gnb := entities.NodebInfo{
754 NodeType: entities.Node_GNB,
756 GlobalNbId: &entities.GlobalNbId{
763 data, err := proto.Marshal(&gnb)
765 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
767 setExpected := []interface{}{"RAN:" + name, data}
768 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
769 expectedErr := errors.New("expected error")
770 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
771 rNibErr := w.SaveNodeb(&gnb)
772 assert.NotEmpty(t, rNibErr)
775 func TestSaveEntitySetAndPublishFailure(t *testing.T) {
780 w, sdlMock := initSdlMock()
781 enb := entities.NodebInfo{
783 NodeType: entities.Node_ENB,
785 GlobalNbId: &entities.GlobalNbId{
792 data, err := proto.Marshal(&enb)
794 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
796 setExpected := []interface{}{"RAN:" + name, data}
797 setExpected = append(setExpected, "ENB:"+plmnId+":"+nbId, data)
798 expectedErr := errors.New("expected error")
799 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", name + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(expectedErr)
800 rNibErr := w.AddEnb(&enb)
801 assert.NotEmpty(t, rNibErr)
804 func TestGetRNibWriter(t *testing.T) {
805 received, _ := initSdlMock()
806 assert.NotEmpty(t, received)
809 func TestSaveE2TInstanceSuccess(t *testing.T) {
810 address := "10.10.2.15:9800"
811 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
813 if validationErr != nil {
814 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
817 w, sdlMock := initSdlMock()
819 e2tInstance := generateE2tInstance(address)
820 data, err := json.Marshal(e2tInstance)
823 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
827 var setExpected []interface{}
828 setExpected = append(setExpected, loadKey, data)
829 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
831 rNibErr := w.SaveE2TInstance(e2tInstance)
832 assert.Nil(t, rNibErr)
835 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
836 w, _ := initSdlMock()
838 e2tInstance := entities.NewE2TInstance(address, "test")
839 err := w.SaveE2TInstance(e2tInstance)
840 assert.NotNil(t, err)
841 assert.IsType(t, &common.ValidationError{}, err)
844 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
845 address := "10.10.2.15:9800"
846 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
848 if validationErr != nil {
849 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
852 w, sdlMock := initSdlMock()
854 e2tInstance := generateE2tInstance(address)
855 data, err := json.Marshal(e2tInstance)
858 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
861 expectedErr := errors.New("expected error")
862 var setExpected []interface{}
863 setExpected = append(setExpected, loadKey, data)
864 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
866 rNibErr := w.SaveE2TInstance(e2tInstance)
867 assert.NotNil(t, rNibErr)
868 assert.IsType(t, &common.InternalError{}, rNibErr)
871 func generateE2tInstance(address string) *entities.E2TInstance {
872 e2tInstance := entities.NewE2TInstance(address, "pod test")
874 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
879 func TestSaveE2TAddressesSuccess(t *testing.T) {
880 address := "10.10.2.15:9800"
881 w, sdlMock := initSdlMock()
883 e2tAddresses := []string{address}
884 data, err := json.Marshal(e2tAddresses)
887 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
891 var setExpected []interface{}
892 setExpected = append(setExpected, E2TAddressesKey, data)
893 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(e)
895 rNibErr := w.SaveE2TAddresses(e2tAddresses)
896 assert.Nil(t, rNibErr)
899 func TestSaveE2TAddressesSdlFailure(t *testing.T) {
900 address := "10.10.2.15:9800"
901 w, sdlMock := initSdlMock()
903 e2tAddresses := []string{address}
904 data, err := json.Marshal(e2tAddresses)
907 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
910 expectedErr := errors.New("expected error")
911 var setExpected []interface{}
912 setExpected = append(setExpected, E2TAddressesKey, data)
913 sdlMock.On("Set", namespace, []interface{}{setExpected}).Return(expectedErr)
915 rNibErr := w.SaveE2TAddresses(e2tAddresses)
916 assert.NotNil(t, rNibErr)
917 assert.IsType(t, &common.InternalError{}, rNibErr)
920 func TestRemoveE2TInstanceSuccess(t *testing.T) {
921 address := "10.10.2.15:9800"
922 w, sdlMock := initSdlMock()
924 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
926 sdlMock.On("Remove", namespace, e2tAddresses).Return(e)
928 rNibErr := w.RemoveE2TInstance(address)
929 assert.Nil(t, rNibErr)
930 sdlMock.AssertExpectations(t)
933 func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
934 address := "10.10.2.15:9800"
935 w, sdlMock := initSdlMock()
937 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
938 expectedErr := errors.New("expected error")
939 sdlMock.On("Remove", namespace, e2tAddresses).Return(expectedErr)
941 rNibErr := w.RemoveE2TInstance(address)
942 assert.IsType(t, &common.InternalError{}, rNibErr)
945 func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
946 w, sdlMock := initSdlMock()
948 rNibErr := w.RemoveE2TInstance("")
949 assert.IsType(t, &common.ValidationError{}, rNibErr)
950 sdlMock.AssertExpectations(t)
953 func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
954 inventoryName := "name"
957 channelName := "RAN_CONNECTION_STATUS_CHANGE"
958 eventName := inventoryName + "_" + "CONNECTED"
959 w, sdlMock := initSdlMock()
960 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
961 data, err := proto.Marshal(nodebInfo)
963 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
966 var setExpected []interface{}
968 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
969 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
970 setExpected = append(setExpected, nodebNameKey, data)
971 setExpected = append(setExpected, nodebIdKey, data)
973 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
975 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
976 assert.Nil(t, rNibErr)
979 func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
980 inventoryName := "name"
983 channelName := "RAN_CONNECTION_STATUS_CHANGE"
984 eventName := inventoryName + "_" + "CONNECTED"
985 w, sdlMock := initSdlMock()
986 nodebInfo := &entities.NodebInfo{}
987 data, err := proto.Marshal(nodebInfo)
989 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
992 var setExpected []interface{}
994 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
995 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
996 setExpected = append(setExpected, nodebNameKey, data)
997 setExpected = append(setExpected, nodebIdKey, data)
999 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
1001 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
1003 assert.NotNil(t, rNibErr)
1004 assert.IsType(t, &common.ValidationError{}, rNibErr)
1007 func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) {
1008 inventoryName := "name"
1009 channelName := "RAN_CONNECTION_STATUS_CHANGE"
1010 eventName := inventoryName + "_" + "CONNECTED"
1011 w, sdlMock := initSdlMock()
1012 nodebInfo := &entities.NodebInfo{}
1013 nodebInfo.RanName = inventoryName
1014 data, err := proto.Marshal(nodebInfo)
1016 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
1019 var setExpected []interface{}
1021 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1022 setExpected = append(setExpected, nodebNameKey, data)
1023 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
1025 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
1027 assert.Nil(t, rNibErr)
1030 func TestUpdateNodebInfoOnConnectionStatusInversionSdlFailure(t *testing.T) {
1031 inventoryName := "name"
1034 channelName := "RAN_CONNECTION_STATUS_CHANGE"
1035 eventName := inventoryName + "_" + "CONNECTED"
1036 w, sdlMock := initSdlMock()
1037 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1038 data, err := proto.Marshal(nodebInfo)
1040 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
1042 e := errors.New("expected error")
1043 var setExpected []interface{}
1045 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1046 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1047 setExpected = append(setExpected, nodebNameKey, data)
1048 setExpected = append(setExpected, nodebIdKey, data)
1050 sdlMock.On("SetAndPublish", namespace, []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
1052 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
1053 assert.NotNil(t, rNibErr)
1054 assert.IsType(t, &common.InternalError{}, rNibErr)
1057 func TestSaveGeneralConfiguration(t *testing.T) {
1058 w, sdlMock := initSdlMock()
1060 key := common.BuildGeneralConfigurationKey()
1061 configurationData := "{\"enableRic\":true}"
1062 configuration := &entities.GeneralConfiguration{}
1063 configuration.EnableRic = true
1065 sdlMock.On("Set", namespace, []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
1066 rNibErr := w.SaveGeneralConfiguration(configuration)
1068 assert.Nil(t, rNibErr)
1069 sdlMock.AssertExpectations(t)
1072 func TestSaveGeneralConfigurationDbError(t *testing.T) {
1073 w, sdlMock := initSdlMock()
1075 key := common.BuildGeneralConfigurationKey()
1076 configurationData := "{\"enableRic\":true}"
1077 configuration := &entities.GeneralConfiguration{}
1078 configuration.EnableRic = true
1080 expectedErr := errors.New("expected error")
1082 sdlMock.On("Set", namespace, []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
1083 rNibErr := w.SaveGeneralConfiguration(configuration)
1085 assert.NotNil(t, rNibErr)
1088 func TestRemoveServedCellsFailure(t *testing.T) {
1089 w, sdlMock := initSdlMock()
1090 servedCellsToRemove := generateServedCells("whatever1", "whatever2")
1091 expectedErr := errors.New("expected error")
1092 sdlMock.On("Remove", namespace, buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(expectedErr)
1094 rNibErr := w.RemoveServedCells(RanName, servedCellsToRemove)
1096 assert.NotNil(t, rNibErr)
1099 func TestRemoveServedCellsSuccess(t *testing.T) {
1100 w, sdlMock := initSdlMock()
1101 servedCellsToRemove := generateServedCells("whatever1", "whatever2")
1102 sdlMock.On("Remove", namespace, buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(nil)
1103 err := w.RemoveServedCells(RanName, servedCellsToRemove)
1107 func TestUpdateEnbInvalidNodebInfoFailure(t *testing.T) {
1108 w, sdlMock := initSdlMock()
1109 servedCells := generateServedCells("test1", "test2")
1110 nodebInfo := &entities.NodebInfo{}
1111 sdlMock.AssertNotCalled(t, "SetAndPublish")
1112 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1113 assert.IsType(t, &common.ValidationError{}, rNibErr)
1116 func TestUpdateEnbInvalidCellFailure(t *testing.T) {
1117 inventoryName := "name"
1120 w, sdlMock := initSdlMock()
1121 servedCells := []*entities.ServedCellInfo{{CellId: ""}}
1122 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1123 nodebInfo.GetEnb().ServedCells = servedCells
1124 sdlMock.AssertNotCalled(t, "SetAndPublish")
1125 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1126 assert.IsType(t, &common.ValidationError{}, rNibErr)
1129 func TestUpdateEnbRnibKeyValidationError(t *testing.T) {
1130 //Empty RAN name fails RNIB validation
1134 w, _ := initSdlMock()
1135 servedCells := generateServedCells("test1", "test2")
1136 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1137 nodebInfo.GetEnb().ServedCells = servedCells
1139 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1140 assert.IsType(t, &common.ValidationError{}, rNibErr)
1143 func TestUpdateEnbSdlFailure(t *testing.T) {
1144 inventoryName := "name"
1147 w, sdlMock := initSdlMock()
1148 servedCells := generateServedCells("test1", "test2")
1149 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1150 nodebInfo.GetEnb().ServedCells = servedCells
1151 setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
1152 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
1153 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1154 assert.IsType(t, &common.InternalError{}, rNibErr)
1157 func TestUpdateEnbSuccess(t *testing.T) {
1158 inventoryName := "name"
1161 w, sdlMock := initSdlMock()
1162 servedCells := generateServedCells("test1", "test2")
1163 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1164 nodebInfo.GetEnb().ServedCells = servedCells
1165 setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
1168 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
1169 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1170 assert.Nil(t, rNibErr)
1173 func getUpdateEnbSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
1175 nodebInfoData, err := proto.Marshal(nodebInfo)
1177 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal NodeB entity. Error: %s", err)
1180 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
1181 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
1182 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
1184 for _, v := range servedCells {
1186 cellEntity := entities.ServedCellInfo{CellId: "some cell id", EutraMode: entities.Eutra_FDD, CsgId: "some csg id"}
1187 cellData, err := proto.Marshal(&cellEntity)
1190 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal cell entity. Error: %s", err)
1193 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetCellId())
1194 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetPci())
1195 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
1200 func TestRemoveEnbSuccess(t *testing.T) {
1201 inventoryName := "name"
1204 channelName := "RAN_MANIPULATION"
1205 eventName := inventoryName + "_" + "DELETED"
1206 w, sdlMock := initSdlMock()
1207 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1208 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1212 expectedKeys := []string{}
1213 cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
1214 cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
1215 cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
1216 cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
1217 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1218 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1219 expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
1220 sdlMock.On("RemoveAndPublish", namespace, []string{channelName, eventName}, expectedKeys).Return(e)
1222 rNibErr := w.RemoveEnb(nodebInfo)
1223 assert.Nil(t, rNibErr)
1224 sdlMock.AssertExpectations(t)
1227 func TestRemoveEnbRnibKeyValidationError(t *testing.T) {
1228 //Empty RAN name fails RNIB key validation
1232 w, _ := initSdlMock()
1233 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1234 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1236 rNibErr := w.RemoveEnb(nodebInfo)
1237 assert.NotNil(t, rNibErr)
1240 func TestRemoveEnbRemoveAndPublishError(t *testing.T) {
1241 inventoryName := "name"
1244 channelName := "RAN_MANIPULATION"
1245 eventName := inventoryName + "_" + "DELETED"
1246 w, sdlMock := initSdlMock()
1247 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1248 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1250 expectedKeys := []string{}
1251 cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
1252 cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
1253 cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
1254 cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
1255 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1256 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1257 expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
1258 sdlMock.On("RemoveAndPublish", namespace, []string{channelName, eventName}, expectedKeys).Return(errors.New("for test"))
1260 rNibErr := w.RemoveEnb(nodebInfo)
1261 assert.NotNil(t, rNibErr)
1262 sdlMock.AssertExpectations(t)
1265 func TestRemoveNbIdentitySuccess(t *testing.T) {
1266 w, sdlMock := initSdlMock()
1267 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1268 nbIdData, err := proto.Marshal(nbIdentity)
1270 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1273 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(nil)
1275 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1276 assert.Nil(t, rNibErr)
1277 sdlMock.AssertExpectations(t)
1280 func TestRemoveNbIdentityMarshalNilFailure(t *testing.T) {
1281 w, _ := initSdlMock()
1283 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nil)
1284 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1285 assert.Equal(t, expectedErr, rNibErr)
1288 func TestRemoveNbIdentityError(t *testing.T) {
1289 w, sdlMock := initSdlMock()
1290 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1291 nbIdData, err := proto.Marshal(nbIdentity)
1293 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1296 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1298 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1299 assert.NotNil(t, rNibErr)
1300 sdlMock.AssertExpectations(t)
1303 func TestAddEnb(t *testing.T) {
1304 ranName := "RAN:" + RanName
1305 w, sdlMock := initSdlMock()
1306 nb := entities.NodebInfo{
1308 NodeType: entities.Node_ENB,
1309 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1312 GlobalNbId: &entities.GlobalNbId{
1318 enb := entities.Enb{}
1319 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
1320 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
1321 enb.ServedCells = []*entities.ServedCellInfo{cell}
1322 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1323 data, err := proto.Marshal(&nb)
1325 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
1329 cellData, err := proto.Marshal(&cellEntity)
1331 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
1333 var setExpected []interface{}
1334 setExpected = append(setExpected, ranName, data)
1335 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
1336 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
1337 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetPci()), cellData)
1339 sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", RanName + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
1341 rNibErr := w.AddEnb(&nb)
1342 assert.Nil(t, rNibErr)
1345 func TestAddEnbMarshalNilFailure(t *testing.T) {
1346 w, _ := initSdlMock()
1348 rNibErr := w.AddEnb(nil)
1349 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1350 assert.Equal(t, expectedErr, rNibErr)
1353 func TestAddEnbCellIdValidationFailure(t *testing.T) {
1354 w, _ := initSdlMock()
1355 nb := entities.NodebInfo{}
1357 nb.NodeType = entities.Node_ENB
1358 nb.ConnectionStatus = 1
1361 enb := entities.Enb{}
1362 cell := &entities.ServedCellInfo{Pci: 3}
1363 enb.ServedCells = []*entities.ServedCellInfo{cell}
1364 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1365 rNibErr := w.AddEnb(&nb)
1366 assert.NotNil(t, rNibErr)
1367 assert.IsType(t, &common.ValidationError{}, rNibErr)
1368 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
1371 func TestAddEnbInventoryNameValidationFailure(t *testing.T) {
1372 w, _ := initSdlMock()
1373 nb := entities.NodebInfo{
1374 NodeType: entities.Node_ENB,
1375 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1378 GlobalNbId: &entities.GlobalNbId{
1383 enb := entities.Enb{}
1384 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
1385 enb.ServedCells = []*entities.ServedCellInfo{cell}
1386 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1387 rNibErr := w.AddEnb(&nb)
1388 assert.NotNil(t, rNibErr)
1389 assert.IsType(t, &common.ValidationError{}, rNibErr)
1390 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
1393 func TestAddEnbGlobalNbIdPlmnValidationFailure(t *testing.T) {
1394 w, _ := initSdlMock()
1395 nb := entities.NodebInfo{
1397 NodeType: entities.Node_ENB,
1398 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1401 GlobalNbId: &entities.GlobalNbId{
1403 //Empty PLMNID fails RNIB validation
1407 enb := entities.Enb{}
1408 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
1409 enb.ServedCells = []*entities.ServedCellInfo{cell}
1410 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1411 rNibErr := w.AddEnb(&nb)
1412 assert.NotNil(t, rNibErr)
1413 assert.IsType(t, &common.ValidationError{}, rNibErr)
1414 assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", rNibErr.Error())
1417 func TestUpdateNbIdentityOneMemberSuccess(t *testing.T) {
1418 w, sdlMock := initSdlMock()
1420 proto, nbIdentity := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1421 val := []interface{}{proto}
1423 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), val).Return(nil)
1425 protoAdd, nbIdentityAdd := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1426 sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), []interface{}{protoAdd}).Return(nil)
1428 newNbIdIdentities := []*entities.NbIdentity{nbIdentityAdd}
1429 oldNbIdIdentities := []*entities.NbIdentity{nbIdentity}
1431 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1432 assert.Nil(t, rNibErr)
1433 sdlMock.AssertExpectations(t)
1436 func TestUpdateNbIdentitySuccess(t *testing.T) {
1437 w, sdlMock := initSdlMock()
1439 var nbIdIdentitiesProtoToRemove []interface{}
1440 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1441 protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
1442 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1443 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
1444 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
1446 var nbIdIdentitiesProtoToAdd []interface{}
1447 protoRan1Add, _ := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1448 protoRan2Add, _ := createNbIdentityProto(t, "ran2_add", "plmnId2_add", "nbId2_add", entities.ConnectionStatus_CONNECTED)
1449 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan1Add)
1450 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan2Add)
1451 sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToAdd).Return(nil)
1453 var newNbIdIdentities []*entities.NbIdentity
1454 firstNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"}}
1455 secondNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2_add", NbId: "nbId2_add"}}
1456 newNbIdIdentities = append(newNbIdIdentities, firstNewNbIdIdentity)
1457 newNbIdIdentities = append(newNbIdIdentities, secondNewNbIdIdentity)
1459 var oldNbIdIdentities []*entities.NbIdentity
1460 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1461 secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
1462 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1463 oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
1465 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1466 assert.Nil(t, rNibErr)
1467 sdlMock.AssertExpectations(t)
1470 func TestUpdateNbIdentityOldIdentityMarshalNilFailure(t *testing.T) {
1471 w, _ := initSdlMock()
1473 oldNbIdIdentities := []*entities.NbIdentity{nil}
1474 newNbIdIdentities := []*entities.NbIdentity{
1475 &entities.NbIdentity{
1476 InventoryName: "ran1_add",
1477 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1478 GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"},
1482 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1483 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1484 assert.Equal(t, expectedErr, rNibErr)
1487 func TestUpdateNbIdentityNewIdentityMarshalNilFailure(t *testing.T) {
1488 w, sdlMock := initSdlMock()
1490 var nbIdIdentitiesProtoToRemove []interface{}
1491 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1492 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1493 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
1495 oldNbIdIdentities := []*entities.NbIdentity{
1496 &entities.NbIdentity{
1497 InventoryName: "ran1",
1498 ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
1499 GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"},
1502 newNbIdIdentities := []*entities.NbIdentity{nil}
1504 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
1505 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1506 assert.Equal(t, expectedErr, rNibErr)
1509 func TestUpdateNbIdentityRemoveFailure(t *testing.T) {
1510 w, sdlMock := initSdlMock()
1512 var nbIdIdentitiesProtoToRemove []interface{}
1513 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1514 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1515 protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
1516 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
1518 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(fmt.Errorf("for test"))
1520 var oldNbIdIdentities []*entities.NbIdentity
1521 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1522 secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
1523 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1524 oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
1526 var newNbIdIdentities []*entities.NbIdentity
1528 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1529 assert.NotNil(t, rNibErr)
1530 sdlMock.AssertExpectations(t)
1533 func TestUpdateNbIdentitySdlAddMemberFailure(t *testing.T) {
1534 w, sdlMock := initSdlMock()
1536 var nbIdIdentitiesProtoToRemove []interface{}
1537 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1538 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1539 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
1541 var nbIdIdentitiesProtoToAdd []interface{}
1542 protoRan1Add, _ := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1543 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan1Add)
1544 sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToAdd).Return(fmt.Errorf("for test"))
1546 var oldNbIdIdentities []*entities.NbIdentity
1547 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1548 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1550 var newNbIdIdentities []*entities.NbIdentity
1551 firstNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"}}
1552 newNbIdIdentities = append(newNbIdIdentities, firstNewNbIdIdentity)
1554 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1555 assert.NotNil(t, rNibErr)
1556 sdlMock.AssertExpectations(t)
1559 func TestUpdateNbIdentityAddFailure(t *testing.T) {
1560 w, sdlMock := initSdlMock()
1561 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1562 nbIdData, err := proto.Marshal(nbIdentity)
1564 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1566 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1568 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1569 assert.NotNil(t, rNibErr)
1570 sdlMock.AssertExpectations(t)
1573 func TestUpdateNbIdentityNoNbIdentityToRemove(t *testing.T) {
1574 w, sdlMock := initSdlMock()
1575 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1576 nbIdData, err := proto.Marshal(nbIdentity)
1578 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1580 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1582 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1583 assert.NotNil(t, rNibErr)
1584 sdlMock.AssertExpectations(t)
1587 func TestUpdateNbIdentityNoNbIdentityToAdd(t *testing.T) {
1588 w, sdlMock := initSdlMock()
1589 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1590 nbIdData, err := proto.Marshal(nbIdentity)
1592 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1594 sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1596 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1597 assert.NotNil(t, rNibErr)
1598 sdlMock.AssertExpectations(t)
1601 func createNbIdentityProto(t *testing.T, ranName string, plmnId string, nbId string, connectionStatus entities.ConnectionStatus) ([]byte, *entities.NbIdentity) {
1602 nbIdentity := &entities.NbIdentity{InventoryName: ranName, ConnectionStatus: connectionStatus, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
1603 nbIdData, err := proto.Marshal(nbIdentity)
1605 t.Errorf("#createNbIdentityProto - failed to Marshal NbIdentity")
1607 return nbIdData, nbIdentity