Merge "Improve unit test coverage"
[ric-plt/e2mgr.git] / E2Manager / rNibWriter / rNibWriter_test.go
index 4e0cdfc..dde1f3a 100644 (file)
@@ -37,8 +37,8 @@ var namespace = "namespace"
 
 const (
        RanName = "test"
-       PlmnId = "02f829"
-       NbId = "4a952a0a"
+       PlmnId  = "02f829"
+       NbId    = "4a952a0a"
 )
 
 func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
@@ -76,9 +76,7 @@ func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
                servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
                        CellId: v,
                        ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
-                               Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
-
-                               },
+                               Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{},
                        },
                        NrMode:      entities.Nr_FDD,
                        NrPci:       uint32(i + 1),
@@ -149,28 +147,36 @@ func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
 func TestAddNbIdentitySuccess(t *testing.T) {
        w, sdlInstanceMock := initSdlInstanceMock(namespace)
 
-       nbIdentity :=  &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
+       nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
        nbIdData, err := proto.Marshal(nbIdentity)
        if err != nil {
                t.Fatalf("#rNibWriter_test.TestAddNbIdentitySuccess - Failed to marshal NodeB Identity entity. Error: %v", err)
        }
 
        sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(nil)
-       rNibErr := w.AddNbIdentity(entities.Node_ENB,nbIdentity)
+       rNibErr := w.AddNbIdentity(entities.Node_ENB, nbIdentity)
        assert.Nil(t, rNibErr)
 }
 
+func TestAddNbIdentityMarshalNilFailure(t *testing.T) {
+       w, _ := initSdlInstanceMock(namespace)
+
+       rNibErr := w.AddNbIdentity(entities.Node_ENB, nil)
+       expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
+       assert.Equal(t, expectedErr, rNibErr)
+}
+
 func TestAddNbIdentitySdlFailure(t *testing.T) {
        w, sdlInstanceMock := initSdlInstanceMock(namespace)
 
-       nbIdentity :=  &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
+       nbIdentity := &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
        nbIdData, err := proto.Marshal(nbIdentity)
        if err != nil {
                t.Fatalf("#rNibWriter_test.TestAddNbIdentitySdlFailure - Failed to marshal NodeB Identity entity. Error: %v", err)
        }
 
        sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(errors.New("expected error"))
-       rNibErr := w.AddNbIdentity(entities.Node_ENB,nbIdentity)
+       rNibErr := w.AddNbIdentity(entities.Node_ENB, nbIdentity)
        assert.IsType(t, &common.InternalError{}, rNibErr)
 }
 
@@ -257,6 +263,20 @@ func TestUpdateGnbCellsSdlFailure(t *testing.T) {
        assert.IsType(t, &common.InternalError{}, rNibErr)
 }
 
+func TestUpdateGnbCellsRnibKeyValidationError(t *testing.T) {
+       //Empty RAN name fails RNIB validation
+       inventoryName := ""
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, _ := initSdlInstanceMock(namespace)
+       servedNrCells := generateServedNrCells("test1", "test2")
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
+       nodebInfo.GetGnb().ServedNrCells = servedNrCells
+
+       rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+}
+
 func TestUpdateGnbCellsSuccess(t *testing.T) {
        inventoryName := "name"
        plmnId := "02f829"
@@ -267,7 +287,7 @@ func TestUpdateGnbCellsSuccess(t *testing.T) {
        nodebInfo.GetGnb().ServedNrCells = servedNrCells
        setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
        var e error
-       sdlInstanceMock.On("SetAndPublish",[]string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
+       sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
        rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
        assert.Nil(t, rNibErr)
 }
@@ -294,6 +314,32 @@ func TestUpdateNodebInfoSuccess(t *testing.T) {
 
        rNibErr := w.UpdateNodebInfo(nodebInfo)
        assert.Nil(t, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNodebInfoAndPublishSuccess(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+       data, err := proto.Marshal(nodebInfo)
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
+       }
+       var e error
+       var setExpected []interface{}
+
+       nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+       nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
+       setExpected = append(setExpected, nodebNameKey, data)
+       setExpected = append(setExpected, nodebIdKey, data)
+
+       sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.UpdateNodebInfoAndPublish(nodebInfo)
+       assert.Nil(t, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
 }
 
 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
@@ -343,6 +389,32 @@ func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
        assert.Nil(t, rNibErr)
 }
 
+func TestUpdateNodebInfoSdlSetFailure(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+       data, err := proto.Marshal(nodebInfo)
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
+       }
+       e := errors.New("expected error")
+       var setExpected []interface{}
+
+       nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+       nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
+       setExpected = append(setExpected, nodebNameKey, data)
+       setExpected = append(setExpected, nodebIdKey, data)
+
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.UpdateNodebInfo(nodebInfo)
+       assert.NotNil(t, rNibErr)
+       assert.IsType(t, &common.InternalError{}, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
 func TestSaveEnb(t *testing.T) {
        ranName := "RAN:" + RanName
        w, sdlInstanceMock := initSdlInstanceMock(namespace)
@@ -424,6 +496,30 @@ func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
        assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
 }
 
+func TestSaveEnbGlobalNbIdPlmnValidationFailure(t *testing.T) {
+       w, _ := initSdlInstanceMock(namespace)
+       nb := entities.NodebInfo{
+               RanName:          RanName,
+               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.SaveNodeb(&nb)
+       assert.NotNil(t, rNibErr)
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+       assert.Equal(t, "#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received", rNibErr.Error())
+}
+
 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
        w, _ := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{}
@@ -448,7 +544,7 @@ func TestSaveGnb(t *testing.T) {
        ranName := "RAN:" + RanName
        w, sdlInstanceMock := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{
-               RanName: RanName,
+               RanName:          RanName,
                NodeType:         entities.Node_GNB,
                ConnectionStatus: 1,
                GlobalNbId: &entities.GlobalNbId{
@@ -654,7 +750,7 @@ func TestSaveEntitySetFailure(t *testing.T) {
 
        w, sdlInstanceMock := initSdlInstanceMock(namespace)
        gnb := entities.NodebInfo{
-               RanName: name,
+               RanName:          name,
                NodeType:         entities.Node_GNB,
                ConnectionStatus: 1,
                GlobalNbId: &entities.GlobalNbId{
@@ -683,7 +779,7 @@ func TestSaveEntitySetAndPublishFailure(t *testing.T) {
 
        w, sdlInstanceMock := initSdlInstanceMock(namespace)
        enb := entities.NodebInfo{
-               RanName: name,
+               RanName:          name,
                NodeType:         entities.Node_ENB,
                ConnectionStatus: 1,
                GlobalNbId: &entities.GlobalNbId{
@@ -931,6 +1027,33 @@ func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.
        assert.Nil(t, rNibErr)
 }
 
+func TestUpdateNodebInfoOnConnectionStatusInversionSdlFailure(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       channelName := "RAN_CONNECTION_STATUS_CHANGE"
+       eventName := inventoryName + "_" + "CONNECTED"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+       data, err := proto.Marshal(nodebInfo)
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
+       }
+       e := errors.New("expected error")
+       var setExpected []interface{}
+
+       nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+       nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
+       setExpected = append(setExpected, nodebNameKey, data)
+       setExpected = append(setExpected, nodebIdKey, data)
+
+       sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
+       assert.NotNil(t, rNibErr)
+       assert.IsType(t, &common.InternalError{}, rNibErr)
+}
+
 func TestSaveGeneralConfiguration(t *testing.T) {
        w, sdlInstanceMock := initSdlInstanceMock(namespace)
 
@@ -1003,6 +1126,20 @@ func TestUpdateEnbInvalidCellFailure(t *testing.T) {
        assert.IsType(t, &common.ValidationError{}, rNibErr)
 }
 
+func TestUpdateEnbRnibKeyValidationError(t *testing.T) {
+       //Empty RAN name fails RNIB validation
+       inventoryName := ""
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, _ := initSdlInstanceMock(namespace)
+       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"
@@ -1087,6 +1224,19 @@ func TestRemoveEnbSuccess(t *testing.T) {
        sdlInstanceMock.AssertExpectations(t)
 }
 
+func TestRemoveEnbRnibKeyValidationError(t *testing.T) {
+       //Empty RAN name fails RNIB key validation
+       inventoryName := ""
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, _ := initSdlInstanceMock(namespace)
+       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"
@@ -1127,6 +1277,14 @@ func TestRemoveNbIdentitySuccess(t *testing.T) {
        sdlInstanceMock.AssertExpectations(t)
 }
 
+func TestRemoveNbIdentityMarshalNilFailure(t *testing.T) {
+       w, _ := initSdlInstanceMock(namespace)
+
+       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, sdlInstanceMock := initSdlInstanceMock(namespace)
        nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}
@@ -1184,6 +1342,14 @@ func TestAddEnb(t *testing.T) {
        assert.Nil(t, rNibErr)
 }
 
+func TestAddEnbMarshalNilFailure(t *testing.T) {
+       w, _ := initSdlInstanceMock(namespace)
+
+       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, _ := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{}
@@ -1224,72 +1390,219 @@ func TestAddEnbInventoryNameValidationFailure(t *testing.T) {
        assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
 }
 
-//Integration tests
-//
-//func TestSaveEnbGnbInteg(t *testing.T){
-//     for i := 0; i<10; i++{
-//             Init("e2Manager", 1)
-//             w := GetRNibWriter()
-//             nb := entities.NodebInfo{}
-//             nb.NodeType = entities.Node_ENB
-//             nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
-//             nb.Ip = "localhost"
-//             nb.Port = uint32(5656 + i)
-//             enb := entities.Enb{}
-//             cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
-//             cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
-//             cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
-//             enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
-//             nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
-//             plmnId := 0x02f828
-//             nbId := 0x4a952a0a
-//             nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
-//             err := w.SaveNodeb(nbIdentity, &nb)
-//             if err != nil{
-//                     t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
-//             }
-//
-//             nb1 := entities.NodebInfo{}
-//             nb1.NodeType = entities.Node_GNB
-//             nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
-//             nb1.Ip = "localhost"
-//             nb1.Port =  uint32(6565 + i)
-//             gnb := entities.Gnb{}
-//             gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
-//             gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
-//             gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
-//             gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
-//             nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
-//             nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
-//             err = w.SaveNodeb(nbIdentity, &nb1)
-//             if err != nil{
-//                     t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
-//             }
-//     }
-//}
-//
-//func TestSaveNbRanNamesInteg(t *testing.T){
-//     for i := 0; i<10; i++{
-//             Init("e2Manager", 1)
-//             w := GetRNibWriter()
-//             nb := entities.NodebInfo{}
-//             nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
-//             nb.Ip = "localhost"
-//             nb.Port = uint32(5656 + i)
-//             nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
-//             err := w.SaveNodeb(nbIdentity, &nb)
-//             if err != nil{
-//                     t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
-//             }
-//     }
-//}
-//
-//func TestSaveRanLoadInformationInteg(t *testing.T){
-//             Init("e2Manager", 1)
-//             w := GetRNibWriter()
-//             ranLoadInformation := generateRanLoadInformation()
-//             err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
-//             if err != nil{
-//                     t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)
-//             }
-//}
+func TestAddEnbGlobalNbIdPlmnValidationFailure(t *testing.T) {
+       w, _ := initSdlInstanceMock(namespace)
+       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, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       proto, nbIdentity := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+       val := []interface{}{proto}
+
+       sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), val).Return(nil)
+
+       protoAdd, nbIdentityAdd := createNbIdentityProto(t, "ran1_add", "plmnId1_add", "nbId1_add", entities.ConnectionStatus_CONNECTED)
+       sdlInstanceMock.On("AddMember", 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)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentitySuccess(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       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)
+       sdlInstanceMock.On("RemoveMember", 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)
+       sdlInstanceMock.On("AddMember", 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)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityOldIdentityMarshalNilFailure(t *testing.T) {
+       w, _ := initSdlInstanceMock(namespace)
+
+       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, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       var nbIdIdentitiesProtoToRemove []interface{}
+       protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+       nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
+       sdlInstanceMock.On("RemoveMember", 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, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       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)
+
+       sdlInstanceMock.On("RemoveMember", 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)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentitySdlAddMemberFailure(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       var nbIdIdentitiesProtoToRemove []interface{}
+       protoRan1, _ := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
+       nbIdIdentitiesProtoToRemove = append(nbIdIdentitiesProtoToRemove, protoRan1)
+       sdlInstanceMock.On("RemoveMember", 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)
+       sdlInstanceMock.On("AddMember", 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)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityAddFailure(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       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")
+       }
+       sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
+
+       rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+       assert.NotNil(t, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityNoNbIdentityToRemove(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       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")
+       }
+       sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
+
+       rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+       assert.NotNil(t, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNbIdentityNoNbIdentityToAdd(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       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")
+       }
+       sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
+
+       rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
+       assert.NotNil(t, rNibErr)
+       sdlInstanceMock.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
+}