+func TestRemoveServedCellsFailure(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ servedCellsToRemove := generateServedCells("whatever1", "whatever2")
+ expectedErr := errors.New("expected error")
+ sdlMock.On("Remove", namespace, buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(expectedErr)
+
+ rNibErr := w.RemoveServedCells(RanName, servedCellsToRemove)
+
+ assert.NotNil(t, rNibErr)
+}
+
+func TestRemoveServedCellsSuccess(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ servedCellsToRemove := generateServedCells("whatever1", "whatever2")
+ sdlMock.On("Remove", namespace, buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(nil)
+ err := w.RemoveServedCells(RanName, servedCellsToRemove)
+ assert.Nil(t, err)
+}
+
+func TestUpdateEnbInvalidNodebInfoFailure(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ servedCells := generateServedCells("test1", "test2")
+ nodebInfo := &entities.NodebInfo{}
+ sdlMock.AssertNotCalled(t, "SetAndPublish")
+ rNibErr := w.UpdateEnb(nodebInfo, servedCells)
+ assert.IsType(t, &common.ValidationError{}, rNibErr)
+}
+
+func TestUpdateEnbInvalidCellFailure(t *testing.T) {
+ inventoryName := "name"
+ plmnId := "02f829"
+ nbId := "4a952a0a"
+ w, sdlMock := initSdlMock()
+ servedCells := []*entities.ServedCellInfo{{CellId: ""}}
+ nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+ nodebInfo.GetEnb().ServedCells = servedCells
+ sdlMock.AssertNotCalled(t, "SetAndPublish")
+ rNibErr := w.UpdateEnb(nodebInfo, servedCells)
+ assert.IsType(t, &common.ValidationError{}, rNibErr)
+}
+
+func TestUpdateEnbRnibKeyValidationError(t *testing.T) {
+ //Empty RAN name fails RNIB validation
+ inventoryName := ""
+ plmnId := "02f829"
+ nbId := "4a952a0a"
+ w, _ := initSdlMock()
+ servedCells := generateServedCells("test1", "test2")
+ nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+ nodebInfo.GetEnb().ServedCells = servedCells
+
+ rNibErr := w.UpdateEnb(nodebInfo, servedCells)
+ assert.IsType(t, &common.ValidationError{}, rNibErr)
+}
+
+func TestUpdateEnbSdlFailure(t *testing.T) {
+ inventoryName := "name"
+ plmnId := "02f829"
+ nbId := "4a952a0a"
+ w, sdlMock := initSdlMock()
+ servedCells := generateServedCells("test1", "test2")
+ nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+ nodebInfo.GetEnb().ServedCells = servedCells
+ setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
+ sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
+ rNibErr := w.UpdateEnb(nodebInfo, servedCells)
+ assert.IsType(t, &common.InternalError{}, rNibErr)
+}
+
+func TestUpdateEnbSuccess(t *testing.T) {
+ inventoryName := "name"
+ plmnId := "02f829"
+ nbId := "4a952a0a"
+ w, sdlMock := initSdlMock()
+ servedCells := generateServedCells("test1", "test2")
+ nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+ nodebInfo.GetEnb().ServedCells = servedCells
+ setExpected := getUpdateEnbCellsSetExpected(t, nodebInfo, servedCells)
+
+ var e error
+ sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
+ rNibErr := w.UpdateEnb(nodebInfo, servedCells)
+ assert.Nil(t, rNibErr)
+}
+
+func getUpdateEnbSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
+
+ nodebInfoData, err := proto.Marshal(nodebInfo)
+ if err != nil {
+ t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal NodeB entity. Error: %s", err)
+ }
+
+ nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
+ nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
+ setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
+
+ for _, v := range servedCells {
+
+ cellEntity := entities.ServedCellInfo{CellId: "some cell id", EutraMode: entities.Eutra_FDD, CsgId: "some csg id"}
+ cellData, err := proto.Marshal(&cellEntity)
+
+ if err != nil {
+ t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal cell entity. Error: %s", err)
+ }
+
+ nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetCellId())
+ cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetPci())
+ setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
+ }
+ return setExpected
+}
+
+func TestRemoveEnbSuccess(t *testing.T) {
+ inventoryName := "name"
+ plmnId := "02f829"
+ nbId := "4a952a0a"
+ channelName := "RAN_MANIPULATION"
+ eventName := inventoryName + "_" + "DELETED"
+ w, sdlMock := initSdlMock()
+ nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+ nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
+
+ var e error
+
+ expectedKeys := []string{}
+ cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
+ cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
+ cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
+ cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
+ nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+ nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
+ expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
+ sdlMock.On("RemoveAndPublish", namespace, []string{channelName, eventName}, expectedKeys).Return(e)
+
+ rNibErr := w.RemoveEnb(nodebInfo)
+ assert.Nil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestRemoveEnbRnibKeyValidationError(t *testing.T) {
+ //Empty RAN name fails RNIB key validation
+ inventoryName := ""
+ plmnId := "02f829"
+ nbId := "4a952a0a"
+ w, _ := initSdlMock()
+ nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+ nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
+
+ rNibErr := w.RemoveEnb(nodebInfo)
+ assert.NotNil(t, rNibErr)
+}
+
+func TestRemoveEnbRemoveAndPublishError(t *testing.T) {
+ inventoryName := "name"
+ plmnId := "02f829"
+ nbId := "4a952a0a"
+ channelName := "RAN_MANIPULATION"
+ eventName := inventoryName + "_" + "DELETED"
+ w, sdlMock := initSdlMock()
+ nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+ nodebInfo.GetEnb().ServedCells = generateServedCellInfos("cell1", "cell2")
+
+ expectedKeys := []string{}
+ cell1Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[0].CellId)
+ cell1PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[0].Pci)
+ cell2Key := fmt.Sprintf("CELL:%s", nodebInfo.GetEnb().ServedCells[1].CellId)
+ cell2PciKey := fmt.Sprintf("PCI:%s:%02x", inventoryName, nodebInfo.GetEnb().ServedCells[1].Pci)
+ nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+ nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
+ expectedKeys = append(expectedKeys, cell1Key, cell1PciKey, cell2Key, cell2PciKey, nodebNameKey, nodebIdKey)
+ sdlMock.On("RemoveAndPublish", namespace, []string{channelName, eventName}, expectedKeys).Return(errors.New("for test"))
+
+ rNibErr := w.RemoveEnb(nodebInfo)
+ assert.NotNil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestRemoveNbIdentitySuccess(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ nbIdData, err := proto.Marshal(nbIdentity)
+ if err != nil {
+ t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
+ }
+
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(nil)
+
+ rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+ assert.Nil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestRemoveNbIdentityMarshalNilFailure(t *testing.T) {
+ w, _ := initSdlMock()
+
+ rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nil)
+ expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
+ assert.Equal(t, expectedErr, rNibErr)
+}
+
+func TestRemoveNbIdentityError(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ nbIdData, err := proto.Marshal(nbIdentity)
+ if err != nil {
+ t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
+ }
+
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
+
+ rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+ assert.NotNil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestAddEnb(t *testing.T) {
+ ranName := "RAN:" + RanName
+ w, sdlMock := initSdlMock()
+ nb := entities.NodebInfo{
+ RanName: RanName,
+ NodeType: entities.Node_ENB,
+ ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+ Ip: "localhost",
+ Port: 5656,
+ GlobalNbId: &entities.GlobalNbId{
+ NbId: "4a952a0a",
+ PlmnId: "02f829",
+ },
+ }
+
+ enb := entities.Enb{}
+ cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
+ cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
+ enb.ServedCells = []*entities.ServedCellInfo{cell}
+ nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
+ data, err := proto.Marshal(&nb)
+ if err != nil {
+ t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
+ }
+ var e error
+
+ cellData, err := proto.Marshal(&cellEntity)
+ if err != nil {
+ t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
+ }
+ var setExpected []interface{}
+ setExpected = append(setExpected, ranName, data)
+ setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
+ setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
+ setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", RanName, cell.GetPci()), cellData)
+
+ sdlMock.On("SetAndPublish", namespace, []string{"RAN_MANIPULATION", RanName + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
+
+ rNibErr := w.AddEnb(&nb)
+ assert.Nil(t, rNibErr)
+}
+
+func TestAddEnbMarshalNilFailure(t *testing.T) {
+ w, _ := initSdlMock()
+
+ rNibErr := w.AddEnb(nil)
+ expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
+ assert.Equal(t, expectedErr, rNibErr)
+}
+
+func TestAddEnbCellIdValidationFailure(t *testing.T) {
+ w, _ := initSdlMock()
+ nb := entities.NodebInfo{}
+ nb.RanName = "name"
+ nb.NodeType = entities.Node_ENB
+ nb.ConnectionStatus = 1
+ nb.Ip = "localhost"
+ nb.Port = 5656
+ enb := entities.Enb{}
+ cell := &entities.ServedCellInfo{Pci: 3}
+ enb.ServedCells = []*entities.ServedCellInfo{cell}
+ nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
+ rNibErr := w.AddEnb(&nb)
+ assert.NotNil(t, rNibErr)
+ assert.IsType(t, &common.ValidationError{}, rNibErr)
+ assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
+}
+
+func TestAddEnbInventoryNameValidationFailure(t *testing.T) {
+ w, _ := initSdlMock()
+ nb := entities.NodebInfo{
+ NodeType: entities.Node_ENB,
+ ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+ Ip: "localhost",
+ Port: 5656,
+ GlobalNbId: &entities.GlobalNbId{
+ NbId: "4a952a0a",
+ PlmnId: "02f829",
+ },
+ }
+ enb := entities.Enb{}
+ cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
+ enb.ServedCells = []*entities.ServedCellInfo{cell}
+ nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
+ rNibErr := w.AddEnb(&nb)
+ assert.NotNil(t, rNibErr)
+ assert.IsType(t, &common.ValidationError{}, rNibErr)
+ assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
+}
+
+func TestAddEnbGlobalNbIdPlmnValidationFailure(t *testing.T) {
+ w, _ := initSdlMock()
+ nb := entities.NodebInfo{
+ RanName: "name",
+ NodeType: entities.Node_ENB,
+ ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+ Ip: "localhost",
+ Port: 5656,
+ GlobalNbId: &entities.GlobalNbId{
+ NbId: "4a952a0a",
+ //Empty PLMNID fails RNIB validation
+ PlmnId: "",
+ },
+ }
+ enb := entities.Enb{}
+ cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
+ enb.ServedCells = []*entities.ServedCellInfo{cell}
+ nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
+ rNibErr := w.AddEnb(&nb)
+ assert.NotNil(t, rNibErr)
+ assert.IsType(t, &common.ValidationError{}, rNibErr)
+ assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", rNibErr.Error())
+}
+
+func TestUpdateNbIdentityOneMemberSuccess(t *testing.T) {
+ w, sdlMock := initSdlMock()
+
+ proto, nbIdentity := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+ val := []interface{}{proto}
+
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), val).Return(nil)
+
+ protoAdd, nbIdentityAdd := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
+ sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), []interface{}{protoAdd}).Return(nil)
+
+ newNbIdIdentities := []*entities.NbIdentity{nbIdentityAdd}
+ oldNbIdIdentities := []*entities.NbIdentity{nbIdentity}
+
+ rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
+ assert.Nil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentitySuccess(t *testing.T) {
+ w, sdlMock := initSdlMock()
+
+ var nbIdIdentitiesProtoToRemove []interface{}
+ protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+ protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
+ nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
+ nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
+
+ var nbIdIdentitiesProtoToAdd []interface{}
+ protoRan1Add, _ := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
+ protoRan2Add, _ := createNbIdentityProto(t, "ran2_add", "plmnId2_add", "nbId2_add", entities.ConnectionStatus_CONNECTED)
+ nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan1Add)
+ nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan2Add)
+ sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToAdd).Return(nil)
+
+ var newNbIdIdentities []*entities.NbIdentity
+ firstNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"}}
+ secondNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2_add", NbId: "nbId2_add"}}
+ newNbIdIdentities = append(newNbIdIdentities, firstNewNbIdIdentity)
+ newNbIdIdentities = append(newNbIdIdentities, secondNewNbIdIdentity)
+
+ var oldNbIdIdentities []*entities.NbIdentity
+ firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
+ oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
+ oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
+
+ rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
+ assert.Nil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityOldIdentityMarshalNilFailure(t *testing.T) {
+ w, _ := initSdlMock()
+
+ oldNbIdIdentities := []*entities.NbIdentity{nil}
+ newNbIdIdentities := []*entities.NbIdentity{
+ &entities.NbIdentity{
+ InventoryName: "ran1_add",
+ ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+ GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"},
+ },
+ }
+
+ expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
+ rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
+ assert.Equal(t, expectedErr, rNibErr)
+}
+
+func TestUpdateNbIdentityNewIdentityMarshalNilFailure(t *testing.T) {
+ w, sdlMock := initSdlMock()
+
+ var nbIdIdentitiesProtoToRemove []interface{}
+ protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+ nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
+
+ oldNbIdIdentities := []*entities.NbIdentity{
+ &entities.NbIdentity{
+ InventoryName: "ran1",
+ ConnectionStatus: entities.ConnectionStatus_DISCONNECTED,
+ GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"},
+ },
+ }
+ newNbIdIdentities := []*entities.NbIdentity{nil}
+
+ expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
+ rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
+ assert.Equal(t, expectedErr, rNibErr)
+}
+
+func TestUpdateNbIdentityRemoveFailure(t *testing.T) {
+ w, sdlMock := initSdlMock()
+
+ var nbIdIdentitiesProtoToRemove []interface{}
+ protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+ nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
+ protoRan2, _ := createNbIdentityProto(t, "ran2", "plmnId2", "nbId2", entities.ConnectionStatus_DISCONNECTED)
+ nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan2)
+
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(fmt.Errorf("for test"))
+
+ var oldNbIdIdentities []*entities.NbIdentity
+ firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ secondOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId2", NbId: "nbId2"}}
+ oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
+ oldNbIdIdentities = append(oldNbIdIdentities, secondOldNbIdIdentity)
+
+ var newNbIdIdentities []*entities.NbIdentity
+
+ rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
+ assert.NotNil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentitySdlAddMemberFailure(t *testing.T) {
+ w, sdlMock := initSdlMock()
+
+ var nbIdIdentitiesProtoToRemove []interface{}
+ protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+ nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(nil)
+
+ var nbIdIdentitiesProtoToAdd []interface{}
+ protoRan1Add, _ := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
+ nbIdIdentitiesProtoToAdd = append(nbIdIdentitiesProtoToAdd, protoRan1Add)
+ sdlMock.On("AddMember", namespace, entities.Node_ENB.String(), nbIdIdentitiesProtoToAdd).Return(fmt.Errorf("for test"))
+
+ var oldNbIdIdentities []*entities.NbIdentity
+ firstOldNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ oldNbIdIdentities = append(oldNbIdIdentities, firstOldNbIdIdentity)
+
+ var newNbIdIdentities []*entities.NbIdentity
+ firstNewNbIdIdentity := &entities.NbIdentity{InventoryName: "ran1_add", ConnectionStatus: entities.ConnectionStatus_CONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1_add", NbId: "nbId1_add"}}
+ newNbIdIdentities = append(newNbIdIdentities, firstNewNbIdIdentity)
+
+ rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
+ assert.NotNil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityAddFailure(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ nbIdData, err := proto.Marshal(nbIdentity)
+ if err != nil {
+ t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
+ }
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
+
+ rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+ assert.NotNil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityNoNbIdentityToRemove(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ nbIdData, err := proto.Marshal(nbIdentity)
+ if err != nil {
+ t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
+ }
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
+
+ rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+ assert.NotNil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityNoNbIdentityToAdd(t *testing.T) {
+ w, sdlMock := initSdlMock()
+ nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
+ nbIdData, err := proto.Marshal(nbIdentity)
+ if err != nil {
+ t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
+ }
+ sdlMock.On("RemoveMember", namespace, entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
+
+ rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+ assert.NotNil(t, rNibErr)
+ sdlMock.AssertExpectations(t)
+}
+
+func createNbIdentityProto(t *testing.T, ranName string, plmnId string, nbId string, connectionStatus entities.ConnectionStatus) ([]byte, *entities.NbIdentity) {
+ nbIdentity := &entities.NbIdentity{InventoryName: ranName, ConnectionStatus: connectionStatus, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
+ nbIdData, err := proto.Marshal(nbIdentity)
+ if err != nil {
+ t.Errorf("#createNbIdentityProto - failed to Marshal NbIdentity")
+ }
+ return nbIdData, nbIdentity
+}