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 = "namespace"
44 func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
45 sdlInstanceMock = new(mocks.MockSdlInstance)
46 w = GetRNibWriter(sdlInstanceMock, 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{
83 NrMode: entities.Nr_FDD,
85 ServedPlmns: []string{"whatever"},
92 func generateServedCells(cellIds ...string) []*entities.ServedCellInfo {
94 var servedCells []*entities.ServedCellInfo
96 for i, v := range cellIds {
97 servedCells = append(servedCells, &entities.ServedCellInfo{
99 ChoiceEutraMode: &entities.ChoiceEUTRAMode{
100 Fdd: &entities.FddInfo{},
103 BroadcastPlmns: []string{"whatever"},
110 func generateServedCellInfos(cellIds ...string) []*entities.ServedCellInfo {
112 servedCells := []*entities.ServedCellInfo{}
114 for i, v := range cellIds {
115 servedCells = append(servedCells, &entities.ServedCellInfo{
124 func TestRemoveServedNrCellsSuccess(t *testing.T) {
125 w, sdlInstanceMock := initSdlInstanceMock(namespace)
126 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
127 sdlInstanceMock.On("Remove", buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil)
128 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
132 func TestRemoveServedNrCellsFailure(t *testing.T) {
133 w, sdlInstanceMock := initSdlInstanceMock(namespace)
134 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
135 sdlInstanceMock.On("Remove", buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error"))
136 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
137 assert.IsType(t, &common.InternalError{}, err)
140 func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
141 w, sdlInstanceMock := initSdlInstanceMock(namespace)
142 servedNrCells := generateServedNrCells("test1", "test2")
143 nodebInfo := &entities.NodebInfo{}
144 sdlInstanceMock.AssertNotCalled(t, "SetAndPublish")
145 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
146 assert.IsType(t, &common.ValidationError{}, rNibErr)
149 func TestAddNbIdentitySuccess(t *testing.T) {
150 w, sdlInstanceMock := initSdlInstanceMock(namespace)
152 nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
153 nbIdData, err := proto.Marshal(nbIdentity)
155 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySuccess - Failed to marshal NodeB Identity entity. Error: %v", err)
158 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(nil)
159 rNibErr := w.AddNbIdentity(entities.Node_ENB,nbIdentity)
160 assert.Nil(t, rNibErr)
163 func TestAddNbIdentitySdlFailure(t *testing.T) {
164 w, sdlInstanceMock := initSdlInstanceMock(namespace)
166 nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
167 nbIdData, err := proto.Marshal(nbIdentity)
169 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySdlFailure - Failed to marshal NodeB Identity entity. Error: %v", err)
172 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(errors.New("expected error"))
173 rNibErr := w.AddNbIdentity(entities.Node_ENB,nbIdentity)
174 assert.IsType(t, &common.InternalError{}, rNibErr)
177 func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
178 inventoryName := "name"
181 w, sdlInstanceMock := initSdlInstanceMock(namespace)
182 servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
183 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
184 nodebInfo.GetGnb().ServedNrCells = servedNrCells
185 sdlInstanceMock.AssertNotCalled(t, "SetAndPublish")
186 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
187 assert.IsType(t, &common.ValidationError{}, rNibErr)
190 func getUpdateEnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
192 nodebInfoData, err := proto.Marshal(nodebInfo)
194 t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
197 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
198 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
199 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
201 for _, cell := range servedCells {
203 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
204 cellData, err := proto.Marshal(&cellEntity)
207 t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
210 nrCellIdKey, _ := common.ValidateAndBuildCellIdKey(cell.GetCellId())
211 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, cell.GetPci())
212 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
218 func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
220 nodebInfoData, err := proto.Marshal(nodebInfo)
222 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
225 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
226 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
227 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
229 for _, v := range servedNrCells {
231 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
232 cellData, err := proto.Marshal(&cellEntity)
235 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
238 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
239 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
240 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
246 func TestUpdateGnbCellsSdlFailure(t *testing.T) {
247 inventoryName := "name"
250 w, sdlInstanceMock := initSdlInstanceMock(namespace)
251 servedNrCells := generateServedNrCells("test1", "test2")
252 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
253 nodebInfo.GetGnb().ServedNrCells = servedNrCells
254 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
255 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
256 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
257 assert.IsType(t, &common.InternalError{}, rNibErr)
260 func TestUpdateGnbCellsSuccess(t *testing.T) {
261 inventoryName := "name"
264 w, sdlInstanceMock := initSdlInstanceMock(namespace)
265 servedNrCells := generateServedNrCells("test1", "test2")
266 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
267 nodebInfo.GetGnb().ServedNrCells = servedNrCells
268 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
270 sdlInstanceMock.On("SetAndPublish",[]string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
271 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
272 assert.Nil(t, rNibErr)
275 func TestUpdateNodebInfoSuccess(t *testing.T) {
276 inventoryName := "name"
279 w, sdlInstanceMock := initSdlInstanceMock(namespace)
280 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
281 data, err := proto.Marshal(nodebInfo)
283 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
286 var setExpected []interface{}
288 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
289 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
290 setExpected = append(setExpected, nodebNameKey, data)
291 setExpected = append(setExpected, nodebIdKey, data)
293 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
295 rNibErr := w.UpdateNodebInfo(nodebInfo)
296 assert.Nil(t, rNibErr)
297 sdlInstanceMock.AssertExpectations(t)
300 func TestUpdateNodebInfoAndPublishSuccess(t *testing.T) {
301 inventoryName := "name"
304 w, sdlInstanceMock := initSdlInstanceMock(namespace)
305 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
306 data, err := proto.Marshal(nodebInfo)
308 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
311 var setExpected []interface{}
313 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
314 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
315 setExpected = append(setExpected, nodebNameKey, data)
316 setExpected = append(setExpected, nodebIdKey, data)
318 sdlInstanceMock.On("SetAndPublish",[]string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
320 rNibErr := w.UpdateNodebInfoAndPublish(nodebInfo)
321 assert.Nil(t, rNibErr)
322 sdlInstanceMock.AssertExpectations(t)
326 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
327 inventoryName := "name"
330 w, sdlInstanceMock := initSdlInstanceMock(namespace)
331 nodebInfo := &entities.NodebInfo{}
332 data, err := proto.Marshal(nodebInfo)
334 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
337 var setExpected []interface{}
339 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
340 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
341 setExpected = append(setExpected, nodebNameKey, data)
342 setExpected = append(setExpected, nodebIdKey, data)
344 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
346 rNibErr := w.UpdateNodebInfo(nodebInfo)
348 assert.NotNil(t, rNibErr)
349 assert.IsType(t, &common.ValidationError{}, rNibErr)
352 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
353 inventoryName := "name"
354 w, sdlInstanceMock := initSdlInstanceMock(namespace)
355 nodebInfo := &entities.NodebInfo{}
356 nodebInfo.RanName = inventoryName
357 data, err := proto.Marshal(nodebInfo)
359 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
362 var setExpected []interface{}
364 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
365 setExpected = append(setExpected, nodebNameKey, data)
366 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
368 rNibErr := w.UpdateNodebInfo(nodebInfo)
370 assert.Nil(t, rNibErr)
373 func TestSaveEnb(t *testing.T) {
374 ranName := "RAN:" + RanName
375 w, sdlInstanceMock := initSdlInstanceMock(namespace)
376 nb := entities.NodebInfo{
378 NodeType: entities.Node_ENB,
379 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
382 GlobalNbId: &entities.GlobalNbId{
388 enb := entities.Enb{}
389 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
390 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
391 enb.ServedCells = []*entities.ServedCellInfo{cell}
392 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
393 data, err := proto.Marshal(&nb)
395 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
399 cellData, err := proto.Marshal(&cellEntity)
401 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
403 var setExpected []interface{}
404 setExpected = append(setExpected, ranName, data)
405 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
406 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
407 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetPci()), cellData)
409 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
410 rNibErr := w.SaveNodeb(&nb)
411 assert.Nil(t, rNibErr)
414 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
415 w, _ := initSdlInstanceMock(namespace)
416 nb := entities.NodebInfo{}
418 nb.NodeType = entities.Node_ENB
419 nb.ConnectionStatus = 1
422 enb := entities.Enb{}
423 cell := &entities.ServedCellInfo{Pci: 3}
424 enb.ServedCells = []*entities.ServedCellInfo{cell}
425 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
426 rNibErr := w.SaveNodeb(&nb)
427 assert.NotNil(t, rNibErr)
428 assert.IsType(t, &common.ValidationError{}, rNibErr)
429 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
432 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
433 w, _ := initSdlInstanceMock(namespace)
434 nb := entities.NodebInfo{
435 NodeType: entities.Node_ENB,
436 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
439 GlobalNbId: &entities.GlobalNbId{
444 enb := entities.Enb{}
445 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
446 enb.ServedCells = []*entities.ServedCellInfo{cell}
447 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
448 rNibErr := w.SaveNodeb(&nb)
449 assert.NotNil(t, rNibErr)
450 assert.IsType(t, &common.ValidationError{}, rNibErr)
451 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
454 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
455 w, _ := initSdlInstanceMock(namespace)
456 nb := entities.NodebInfo{}
458 nb.NodeType = entities.Node_GNB
459 nb.ConnectionStatus = 1
462 gnb := entities.Gnb{}
463 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
464 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
465 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
466 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
468 rNibErr := w.SaveNodeb(&nb)
469 assert.NotNil(t, rNibErr)
470 assert.IsType(t, &common.ValidationError{}, rNibErr)
471 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
474 func TestSaveGnb(t *testing.T) {
475 ranName := "RAN:" + RanName
476 w, sdlInstanceMock := initSdlInstanceMock(namespace)
477 nb := entities.NodebInfo{
479 NodeType: entities.Node_GNB,
481 GlobalNbId: &entities.GlobalNbId{
489 gnb := entities.Gnb{}
490 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
491 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
492 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
493 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
494 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
495 data, err := proto.Marshal(&nb)
497 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
501 cellData, err := proto.Marshal(&cellEntity)
503 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
505 var setExpected []interface{}
506 setExpected = append(setExpected, ranName, data)
507 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
508 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
509 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetServedNrCellInformation().GetNrPci()), cellData)
511 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
512 rNibErr := w.SaveNodeb(&nb)
513 assert.Nil(t, rNibErr)
516 func TestSaveRanLoadInformationSuccess(t *testing.T) {
517 inventoryName := "name"
518 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
520 if validationErr != nil {
521 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
524 w, sdlInstanceMock := initSdlInstanceMock(namespace)
526 ranLoadInformation := generateRanLoadInformation()
527 data, err := proto.Marshal(ranLoadInformation)
530 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
534 var setExpected []interface{}
535 setExpected = append(setExpected, loadKey, data)
536 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
538 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
539 assert.Nil(t, rNibErr)
542 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
543 inventoryName := "name2"
544 w, _ := initSdlInstanceMock(namespace)
546 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
547 err := w.SaveRanLoadInformation(inventoryName, nil)
548 assert.Equal(t, expectedErr, err)
551 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
553 w, _ := initSdlInstanceMock(namespace)
555 err := w.SaveRanLoadInformation(inventoryName, nil)
556 assert.NotNil(t, err)
557 assert.IsType(t, &common.ValidationError{}, err)
560 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
561 inventoryName := "name2"
563 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
565 if validationErr != nil {
566 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
569 w, sdlInstanceMock := initSdlInstanceMock(namespace)
571 ranLoadInformation := generateRanLoadInformation()
572 data, err := proto.Marshal(ranLoadInformation)
575 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
578 expectedErr := errors.New("expected error")
579 var setExpected []interface{}
580 setExpected = append(setExpected, loadKey, data)
581 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
583 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
584 assert.NotNil(t, rNibErr)
585 assert.IsType(t, &common.InternalError{}, rNibErr)
588 func generateCellLoadInformation() *entities.CellLoadInformation {
589 cellLoadInformation := entities.CellLoadInformation{}
591 cellLoadInformation.CellId = "123"
593 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
594 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
596 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
598 UlHighInterferenceIndication: "xxx",
601 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
603 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
605 RntpThreshold: entities.RntpThreshold_NEG_4,
606 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
608 PdcchInterferenceImpact: 2,
609 EnhancedRntp: &entities.EnhancedRntp{
610 EnhancedRntpBitmap: "xxx",
611 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
612 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
616 cellLoadInformation.AbsInformation = &entities.AbsInformation{
617 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
618 AbsPatternInfo: "xxx",
619 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
620 MeasurementSubset: "xxx",
623 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
625 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
626 AssociatedSubframes: "xxx",
627 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
630 compInformationItem := &entities.CompInformationItem{
631 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
635 cellLoadInformation.CompInformation = &entities.CompInformation{
636 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
637 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
640 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
641 State: entities.NaicsState_NAICS_ACTIVE,
642 TransmissionModes: "xxx",
644 PAList: []entities.PA{entities.PA_DB_NEG_3},
647 return &cellLoadInformation
650 func generateRanLoadInformation() *entities.RanLoadInformation {
651 ranLoadInformation := entities.RanLoadInformation{}
653 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
655 cellLoadInformation := generateCellLoadInformation()
656 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
658 return &ranLoadInformation
661 func TestSaveNilEntityFailure(t *testing.T) {
662 w, _ := initSdlInstanceMock(namespace)
663 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
664 actualErr := w.SaveNodeb(nil)
665 assert.Equal(t, expectedErr, actualErr)
668 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
669 w, _ := initSdlInstanceMock(namespace)
670 nb := &entities.NodebInfo{}
673 actualErr := w.SaveNodeb(nb)
674 assert.IsType(t, &common.ValidationError{}, actualErr)
677 func TestSaveEntitySetFailure(t *testing.T) {
682 w, sdlInstanceMock := initSdlInstanceMock(namespace)
683 gnb := entities.NodebInfo{
685 NodeType: entities.Node_GNB,
687 GlobalNbId: &entities.GlobalNbId{
694 data, err := proto.Marshal(&gnb)
696 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
698 setExpected := []interface{}{"RAN:" + name, data}
699 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
700 expectedErr := errors.New("expected error")
701 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
702 rNibErr := w.SaveNodeb(&gnb)
703 assert.NotEmpty(t, rNibErr)
706 func TestSaveEntitySetAndPublishFailure(t *testing.T) {
711 w, sdlInstanceMock := initSdlInstanceMock(namespace)
712 enb := entities.NodebInfo{
714 NodeType: entities.Node_ENB,
716 GlobalNbId: &entities.GlobalNbId{
723 data, err := proto.Marshal(&enb)
725 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
727 setExpected := []interface{}{"RAN:" + name, data}
728 setExpected = append(setExpected, "ENB:"+plmnId+":"+nbId, data)
729 expectedErr := errors.New("expected error")
730 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", name + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(expectedErr)
731 rNibErr := w.AddEnb(&enb)
732 assert.NotEmpty(t, rNibErr)
735 func TestGetRNibWriter(t *testing.T) {
736 received, _ := initSdlInstanceMock(namespace)
737 assert.NotEmpty(t, received)
740 func TestSaveE2TInstanceSuccess(t *testing.T) {
741 address := "10.10.2.15:9800"
742 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
744 if validationErr != nil {
745 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
748 w, sdlInstanceMock := initSdlInstanceMock(namespace)
750 e2tInstance := generateE2tInstance(address)
751 data, err := json.Marshal(e2tInstance)
754 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
758 var setExpected []interface{}
759 setExpected = append(setExpected, loadKey, data)
760 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
762 rNibErr := w.SaveE2TInstance(e2tInstance)
763 assert.Nil(t, rNibErr)
766 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
767 w, _ := initSdlInstanceMock(namespace)
769 e2tInstance := entities.NewE2TInstance(address, "test")
770 err := w.SaveE2TInstance(e2tInstance)
771 assert.NotNil(t, err)
772 assert.IsType(t, &common.ValidationError{}, err)
775 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
776 address := "10.10.2.15:9800"
777 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
779 if validationErr != nil {
780 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
783 w, sdlInstanceMock := initSdlInstanceMock(namespace)
785 e2tInstance := generateE2tInstance(address)
786 data, err := json.Marshal(e2tInstance)
789 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
792 expectedErr := errors.New("expected error")
793 var setExpected []interface{}
794 setExpected = append(setExpected, loadKey, data)
795 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
797 rNibErr := w.SaveE2TInstance(e2tInstance)
798 assert.NotNil(t, rNibErr)
799 assert.IsType(t, &common.InternalError{}, rNibErr)
802 func generateE2tInstance(address string) *entities.E2TInstance {
803 e2tInstance := entities.NewE2TInstance(address, "pod test")
805 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
810 func TestSaveE2TAddressesSuccess(t *testing.T) {
811 address := "10.10.2.15:9800"
812 w, sdlInstanceMock := initSdlInstanceMock(namespace)
814 e2tAddresses := []string{address}
815 data, err := json.Marshal(e2tAddresses)
818 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
822 var setExpected []interface{}
823 setExpected = append(setExpected, E2TAddressesKey, data)
824 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
826 rNibErr := w.SaveE2TAddresses(e2tAddresses)
827 assert.Nil(t, rNibErr)
830 func TestSaveE2TAddressesSdlFailure(t *testing.T) {
831 address := "10.10.2.15:9800"
832 w, sdlInstanceMock := initSdlInstanceMock(namespace)
834 e2tAddresses := []string{address}
835 data, err := json.Marshal(e2tAddresses)
838 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
841 expectedErr := errors.New("expected error")
842 var setExpected []interface{}
843 setExpected = append(setExpected, E2TAddressesKey, data)
844 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
846 rNibErr := w.SaveE2TAddresses(e2tAddresses)
847 assert.NotNil(t, rNibErr)
848 assert.IsType(t, &common.InternalError{}, rNibErr)
851 func TestRemoveE2TInstanceSuccess(t *testing.T) {
852 address := "10.10.2.15:9800"
853 w, sdlInstanceMock := initSdlInstanceMock(namespace)
855 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
857 sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
859 rNibErr := w.RemoveE2TInstance(address)
860 assert.Nil(t, rNibErr)
861 sdlInstanceMock.AssertExpectations(t)
864 func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
865 address := "10.10.2.15:9800"
866 w, sdlInstanceMock := initSdlInstanceMock(namespace)
868 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
869 expectedErr := errors.New("expected error")
870 sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
872 rNibErr := w.RemoveE2TInstance(address)
873 assert.IsType(t, &common.InternalError{}, rNibErr)
876 func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
877 w, sdlInstanceMock := initSdlInstanceMock(namespace)
879 rNibErr := w.RemoveE2TInstance("")
880 assert.IsType(t, &common.ValidationError{}, rNibErr)
881 sdlInstanceMock.AssertExpectations(t)
884 func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
885 inventoryName := "name"
888 channelName := "RAN_CONNECTION_STATUS_CHANGE"
889 eventName := inventoryName + "_" + "CONNECTED"
890 w, sdlInstanceMock := initSdlInstanceMock(namespace)
891 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
892 data, err := proto.Marshal(nodebInfo)
894 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
897 var setExpected []interface{}
899 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
900 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
901 setExpected = append(setExpected, nodebNameKey, data)
902 setExpected = append(setExpected, nodebIdKey, data)
904 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
906 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
907 assert.Nil(t, rNibErr)
910 func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
911 inventoryName := "name"
914 channelName := "RAN_CONNECTION_STATUS_CHANGE"
915 eventName := inventoryName + "_" + "CONNECTED"
916 w, sdlInstanceMock := initSdlInstanceMock(namespace)
917 nodebInfo := &entities.NodebInfo{}
918 data, err := proto.Marshal(nodebInfo)
920 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
923 var setExpected []interface{}
925 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
926 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
927 setExpected = append(setExpected, nodebNameKey, data)
928 setExpected = append(setExpected, nodebIdKey, data)
930 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
932 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
934 assert.NotNil(t, rNibErr)
935 assert.IsType(t, &common.ValidationError{}, rNibErr)
938 func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) {
939 inventoryName := "name"
940 channelName := "RAN_CONNECTION_STATUS_CHANGE"
941 eventName := inventoryName + "_" + "CONNECTED"
942 w, sdlInstanceMock := initSdlInstanceMock(namespace)
943 nodebInfo := &entities.NodebInfo{}
944 nodebInfo.RanName = inventoryName
945 data, err := proto.Marshal(nodebInfo)
947 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
950 var setExpected []interface{}
952 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
953 setExpected = append(setExpected, nodebNameKey, data)
954 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
956 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
958 assert.Nil(t, rNibErr)
961 func TestSaveGeneralConfiguration(t *testing.T) {
962 w, sdlInstanceMock := initSdlInstanceMock(namespace)
964 key := common.BuildGeneralConfigurationKey()
965 configurationData := "{\"enableRic\":true}"
966 configuration := &entities.GeneralConfiguration{}
967 configuration.EnableRic = true
969 sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
970 rNibErr := w.SaveGeneralConfiguration(configuration)
972 assert.Nil(t, rNibErr)
973 sdlInstanceMock.AssertExpectations(t)
976 func TestSaveGeneralConfigurationDbError(t *testing.T) {
977 w, sdlInstanceMock := initSdlInstanceMock(namespace)
979 key := common.BuildGeneralConfigurationKey()
980 configurationData := "{\"enableRic\":true}"
981 configuration := &entities.GeneralConfiguration{}
982 configuration.EnableRic = true
984 expectedErr := errors.New("expected error")
986 sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
987 rNibErr := w.SaveGeneralConfiguration(configuration)
989 assert.NotNil(t, rNibErr)
992 func TestRemoveServedCellsFailure(t *testing.T) {
993 w, sdlInstanceMock := initSdlInstanceMock(namespace)
994 servedCellsToRemove := generateServedCells("whatever1", "whatever2")
995 expectedErr := errors.New("expected error")
996 sdlInstanceMock.On("Remove", buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(expectedErr)
998 rNibErr := w.RemoveServedCells(RanName, servedCellsToRemove)
1000 assert.NotNil(t, rNibErr)
1003 func TestRemoveServedCellsSuccess(t *testing.T) {
1004 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1005 servedCellsToRemove := generateServedCells("whatever1", "whatever2")
1006 sdlInstanceMock.On("Remove", buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(nil)
1007 err := w.RemoveServedCells(RanName, servedCellsToRemove)
1011 func TestUpdateEnbInvalidNodebInfoFailure(t *testing.T) {
1012 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1013 servedCells := generateServedCells("test1", "test2")
1014 nodebInfo := &entities.NodebInfo{}
1015 sdlInstanceMock.AssertNotCalled(t, "SetAndPublish")
1016 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1017 assert.IsType(t, &common.ValidationError{}, rNibErr)
1020 func TestUpdateEnbInvalidCellFailure(t *testing.T) {
1021 inventoryName := "name"
1024 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1025 servedCells := []*entities.ServedCellInfo{{CellId: ""}}
1026 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1027 nodebInfo.GetEnb().ServedCells = servedCells
1028 sdlInstanceMock.AssertNotCalled(t, "SetAndPublish")
1029 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1030 assert.IsType(t, &common.ValidationError{}, rNibErr)
1033 func TestUpdateEnbSdlFailure(t *testing.T) {
1034 inventoryName := "name"
1037 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1038 servedCells := generateServedCells("test1", "test2")
1039 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1040 nodebInfo.GetEnb().ServedCells = servedCells
1041 setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
1042 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
1043 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1044 assert.IsType(t, &common.InternalError{}, rNibErr)
1047 func TestUpdateEnbSuccess(t *testing.T) {
1048 inventoryName := "name"
1051 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1052 servedCells := generateServedCells("test1", "test2")
1053 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1054 nodebInfo.GetEnb().ServedCells = servedCells
1055 setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
1058 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
1059 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1060 assert.Nil(t, rNibErr)
1063 func getUpdateEnbSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
1065 nodebInfoData, err := proto.Marshal(nodebInfo)
1067 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal NodeB entity. Error: %s", err)
1070 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
1071 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
1072 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
1074 for _, v := range servedCells {
1076 cellEntity := entities.ServedCellInfo{CellId: "some cell id", EutraMode: entities.Eutra_FDD, CsgId: "some csg id"}
1077 cellData, err := proto.Marshal(&cellEntity)
1080 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal cell entity. Error: %s", err)
1083 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetCellId())
1084 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetPci())
1085 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
1090 func TestRemoveEnbSuccess(t *testing.T) {
1091 inventoryName := "name"
1094 channelName := "RAN_MANIPULATION"
1095 eventName := inventoryName + "_" + "DELETED"
1096 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1097 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1098 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1102 expectedKeys := []string{}
1103 cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
1104 cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
1105 cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
1106 cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
1107 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1108 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1109 expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
1110 sdlInstanceMock.On("RemoveAndPublish", []string{channelName, eventName}, expectedKeys).Return(e)
1112 rNibErr := w.RemoveEnb(nodebInfo)
1113 assert.Nil(t, rNibErr)
1114 sdlInstanceMock.AssertExpectations(t)
1117 func TestRemoveEnbRemoveAndPublishError(t *testing.T) {
1118 inventoryName := "name"
1121 channelName := "RAN_MANIPULATION"
1122 eventName := inventoryName + "_" + "DELETED"
1123 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1124 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
1125 nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
1127 expectedKeys := []string{}
1128 cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
1129 cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
1130 cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
1131 cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
1132 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
1133 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
1134 expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
1135 sdlInstanceMock.On("RemoveAndPublish", []string{channelName, eventName}, expectedKeys).Return(errors.New("for test"))
1137 rNibErr := w.RemoveEnb(nodebInfo)
1138 assert.NotNil(t, rNibErr)
1139 sdlInstanceMock.AssertExpectations(t)
1142 func TestRemoveNbIdentitySuccess(t *testing.T) {
1143 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1144 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1145 nbIdData, err := proto.Marshal(nbIdentity)
1147 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1150 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(nil)
1152 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1153 assert.Nil(t, rNibErr)
1154 sdlInstanceMock.AssertExpectations(t)
1157 func TestRemoveNbIdentityError(t *testing.T) {
1158 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1159 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1160 nbIdData, err := proto.Marshal(nbIdentity)
1162 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1165 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1167 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1168 assert.NotNil(t, rNibErr)
1169 sdlInstanceMock.AssertExpectations(t)
1172 func TestAddEnb(t *testing.T) {
1173 ranName := "RAN:" + RanName
1174 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1175 nb := entities.NodebInfo{
1177 NodeType: entities.Node_ENB,
1178 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1181 GlobalNbId: &entities.GlobalNbId{
1187 enb := entities.Enb{}
1188 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
1189 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
1190 enb.ServedCells = []*entities.ServedCellInfo{cell}
1191 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1192 data, err := proto.Marshal(&nb)
1194 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
1198 cellData, err := proto.Marshal(&cellEntity)
1200 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
1202 var setExpected []interface{}
1203 setExpected = append(setExpected, ranName, data)
1204 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
1205 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
1206 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetPci()), cellData)
1208 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", RanName + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
1210 rNibErr := w.AddEnb(&nb)
1211 assert.Nil(t, rNibErr)
1214 func TestAddEnbCellIdValidationFailure(t *testing.T) {
1215 w, _ := initSdlInstanceMock(namespace)
1216 nb := entities.NodebInfo{}
1218 nb.NodeType = entities.Node_ENB
1219 nb.ConnectionStatus = 1
1222 enb := entities.Enb{}
1223 cell := &entities.ServedCellInfo{Pci: 3}
1224 enb.ServedCells = []*entities.ServedCellInfo{cell}
1225 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1226 rNibErr := w.AddEnb(&nb)
1227 assert.NotNil(t, rNibErr)
1228 assert.IsType(t, &common.ValidationError{}, rNibErr)
1229 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
1232 func TestAddEnbInventoryNameValidationFailure(t *testing.T) {
1233 w, _ := initSdlInstanceMock(namespace)
1234 nb := entities.NodebInfo{
1235 NodeType: entities.Node_ENB,
1236 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1239 GlobalNbId: &entities.GlobalNbId{
1244 enb := entities.Enb{}
1245 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
1246 enb.ServedCells = []*entities.ServedCellInfo{cell}
1247 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
1248 rNibErr := w.AddEnb(&nb)
1249 assert.NotNil(t, rNibErr)
1250 assert.IsType(t, &common.ValidationError{}, rNibErr)
1251 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
1254 func TestUpdateNbIdentityOneMemberSuccess(t *testing.T) {
1255 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1257 proto, nbIdentity := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1258 val := []interface{}{proto}
1260 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), val).Return(nil)
1262 protoAdd, nbIdentityAdd := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1263 sdlInstanceMock.On("AddMember", entities.Node_ENB.String(), []interface{}{protoAdd}).Return(nil)
1265 newNbIdIdentities := []*entities.NbIdentity{nbIdentityAdd}
1266 oldNbIdIdentities := []*entities.NbIdentity{nbIdentity}
1268 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1269 assert.Nil(t, rNibErr)
1270 sdlInstanceMock.AssertExpectations(t)
1273 func TestUpdateNbIdentitySuccess(t *testing.T) {
1274 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1276 var nbIdIdentitiesProtoToRemove []interface{}
1277 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1278 protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
1279 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1280 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
1281 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
1283 var nbIdIdentitiesProtoToAdd []interface{}
1284 protoRan1Add, _ := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
1285 protoRan2Add, _ := createNbIdentityProto(t, "ran2_add", "plmnId2_add", "nbId2_add", entities.ConnectionStatus_CONNECTED)
1286 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan1Add)
1287 nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan2Add)
1288 sdlInstanceMock.On("AddMember", entities.Node_ENB.String(), nbIdIdentitiesProtoToAdd).Return(nil)
1290 var newNbIdIdentities []*entities.NbIdentity
1291 firstNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"}}
1292 secondNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2_add", NbId: "nbId2_add"}}
1293 newNbIdIdentities = append(newNbIdIdentities, firstNewNbIdIdentity)
1294 newNbIdIdentities = append(newNbIdIdentities, secondNewNbIdIdentity)
1296 var oldNbIdIdentities []*entities.NbIdentity
1297 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1298 secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
1299 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1300 oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
1302 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1303 assert.Nil(t, rNibErr)
1304 sdlInstanceMock.AssertExpectations(t)
1307 func TestUpdateNbIdentityRemoveFailure(t *testing.T) {
1308 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1310 var nbIdIdentitiesProtoToRemove []interface{}
1311 protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1312 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
1313 protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
1314 nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
1316 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(fmt.Errorf("for test"))
1318 var oldNbIdIdentities []*entities.NbIdentity
1319 firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1320 secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
1321 oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
1322 oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
1324 var newNbIdIdentities []*entities.NbIdentity
1326 rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1327 assert.NotNil(t, rNibErr)
1328 sdlInstanceMock.AssertExpectations(t)
1331 func TestUpdateNbIdentityAddFailure(t *testing.T) {
1332 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1333 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1334 nbIdData, err := proto.Marshal(nbIdentity)
1336 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1338 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1340 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1341 assert.NotNil(t, rNibErr)
1342 sdlInstanceMock.AssertExpectations(t)
1345 func TestUpdateNbIdentityNoNbIdentityToRemove(t *testing.T) {
1346 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1347 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1348 nbIdData, err := proto.Marshal(nbIdentity)
1350 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1352 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1354 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1355 assert.NotNil(t, rNibErr)
1356 sdlInstanceMock.AssertExpectations(t)
1359 func TestUpdateNbIdentityNoNbIdentityToAdd(t *testing.T) {
1360 w, sdlInstanceMock := initSdlInstanceMock(namespace)
1361 nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
1362 nbIdData, err := proto.Marshal(nbIdentity)
1364 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1366 sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1368 rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1369 assert.NotNil(t, rNibErr)
1370 sdlInstanceMock.AssertExpectations(t)
1373 func createNbIdentityProto(t *testing.T, ranName string, plmnId string, nbId string, connectionStatus entities.ConnectionStatus) ([]byte, *entities.NbIdentity){
1374 nbIdentity := &entities.NbIdentity{InventoryName: ranName, ConnectionStatus: connectionStatus, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
1375 nbIdData, err := proto.Marshal(nbIdentity)
1377 t.Errorf("#createNbIdentityProto - failed to Marshal NbIdentity")
1379 return nbIdData, nbIdentity