+ 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)
+
+ sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", RanName + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
+
+ rNibErr := w.AddEnb(&nb)
+ assert.Nil(t, rNibErr)
+}
+
+func TestAddEnbCellIdValidationFailure(t *testing.T) {
+ w, _ := initSdlInstanceMock(namespace)
+ 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, _ := initSdlInstanceMock(namespace)
+ 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 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 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 TestUpdateNbIdentityAddFailure(t *testing.T) {
+ w, sdlInstanceMock := initSdlInstanceMock(namespace)
+ nbIdentity := &entities.NbIdentity{InventoryName: "ran1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED, GlobalNbId: &entities.GlobalNbId{PlmnId: "plmnId1", NbId: "nbId1"}}