[RIC-430] - Update Connection Status on RAN List - release tag 5.4.5
[ric-plt/e2mgr.git] / E2Manager / rNibWriter / rNibWriter_test.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
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
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16
17 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20 package rNibWriter
21
22 import (
23         "e2mgr/configuration"
24         "e2mgr/mocks"
25         "encoding/json"
26         "errors"
27         "fmt"
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"
32         "testing"
33         "time"
34 )
35
36 var namespace = "namespace"
37
38 const (
39         RanName = "test"
40         PlmnId = "02f829"
41         NbId = "4a952a0a"
42 )
43
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"})
47         return
48 }
49
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},
54                 NodeType:         nodeType,
55                 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
56         }
57
58         if nodeType == entities.Node_ENB {
59                 nodebInfo.Configuration = &entities.NodebInfo_Enb{
60                         Enb: &entities.Enb{},
61                 }
62         } else if nodeType == entities.Node_GNB {
63                 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
64                         Gnb: &entities.Gnb{},
65                 }
66         }
67
68         return nodebInfo
69 }
70
71 func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
72
73         var servedNrCells []*entities.ServedNRCell
74
75         for i, v := range cellIds {
76                 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
77                         CellId: v,
78                         ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
79                                 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
80
81                                 },
82                         },
83                         NrMode:      entities.Nr_FDD,
84                         NrPci:       uint32(i + 1),
85                         ServedPlmns: []string{"whatever"},
86                 }})
87         }
88
89         return servedNrCells
90 }
91
92 func generateServedCells(cellIds ...string) []*entities.ServedCellInfo {
93
94         var servedCells []*entities.ServedCellInfo
95
96         for i, v := range cellIds {
97                 servedCells = append(servedCells, &entities.ServedCellInfo{
98                         CellId: v,
99                         ChoiceEutraMode: &entities.ChoiceEUTRAMode{
100                                 Fdd: &entities.FddInfo{},
101                         },
102                         Pci:            uint32(i + 1),
103                         BroadcastPlmns: []string{"whatever"},
104                 })
105         }
106
107         return servedCells
108 }
109
110 func generateServedCellInfos(cellIds ...string) []*entities.ServedCellInfo {
111
112         servedCells := []*entities.ServedCellInfo{}
113
114         for i, v := range cellIds {
115                 servedCells = append(servedCells, &entities.ServedCellInfo{
116                         CellId: v,
117                         Pci:    uint32(i + 1),
118                 })
119         }
120
121         return servedCells
122 }
123
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)
129         assert.Nil(t, err)
130 }
131
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)
138 }
139
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)
147 }
148
149 func TestAddNbIdentitySuccess(t *testing.T) {
150         w, sdlInstanceMock := initSdlInstanceMock(namespace)
151
152         nbIdentity :=  &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
153         nbIdData, err := proto.Marshal(nbIdentity)
154         if err != nil {
155                 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySuccess - Failed to marshal NodeB Identity entity. Error: %v", err)
156         }
157
158         sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(nil)
159         rNibErr := w.AddNbIdentity(entities.Node_ENB,nbIdentity)
160         assert.Nil(t, rNibErr)
161 }
162
163 func TestAddNbIdentitySdlFailure(t *testing.T) {
164         w, sdlInstanceMock := initSdlInstanceMock(namespace)
165
166         nbIdentity :=  &entities.NbIdentity{InventoryName: RanName, GlobalNbId: &entities.GlobalNbId{PlmnId: PlmnId, NbId: NbId}}
167         nbIdData, err := proto.Marshal(nbIdentity)
168         if err != nil {
169                 t.Fatalf("#rNibWriter_test.TestAddNbIdentitySdlFailure - Failed to marshal NodeB Identity entity. Error: %v", err)
170         }
171
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)
175 }
176
177 func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
178         inventoryName := "name"
179         plmnId := "02f829"
180         nbId := "4a952a0a"
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)
188 }
189
190 func getUpdateEnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
191
192         nodebInfoData, err := proto.Marshal(nodebInfo)
193         if err != nil {
194                 t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
195         }
196
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}
200
201         for _, cell := range servedCells {
202
203                 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
204                 cellData, err := proto.Marshal(&cellEntity)
205
206                 if err != nil {
207                         t.Fatalf("#rNibWriter_test.getUpdateEnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
208                 }
209
210                 nrCellIdKey, _ := common.ValidateAndBuildCellIdKey(cell.GetCellId())
211                 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, cell.GetPci())
212                 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
213         }
214
215         return setExpected
216 }
217
218 func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
219
220         nodebInfoData, err := proto.Marshal(nodebInfo)
221         if err != nil {
222                 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
223         }
224
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}
228
229         for _, v := range servedNrCells {
230
231                 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
232                 cellData, err := proto.Marshal(&cellEntity)
233
234                 if err != nil {
235                         t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
236                 }
237
238                 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
239                 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
240                 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
241         }
242
243         return setExpected
244 }
245
246 func TestUpdateGnbCellsSdlFailure(t *testing.T) {
247         inventoryName := "name"
248         plmnId := "02f829"
249         nbId := "4a952a0a"
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)
258 }
259
260 func TestUpdateGnbCellsSuccess(t *testing.T) {
261         inventoryName := "name"
262         plmnId := "02f829"
263         nbId := "4a952a0a"
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)
269         var e error
270         sdlInstanceMock.On("SetAndPublish",[]string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
271         rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
272         assert.Nil(t, rNibErr)
273 }
274
275 func TestUpdateNodebInfoSuccess(t *testing.T) {
276         inventoryName := "name"
277         plmnId := "02f829"
278         nbId := "4a952a0a"
279         w, sdlInstanceMock := initSdlInstanceMock(namespace)
280         nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
281         data, err := proto.Marshal(nodebInfo)
282         if err != nil {
283                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
284         }
285         var e error
286         var setExpected []interface{}
287
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)
292
293         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
294
295         rNibErr := w.UpdateNodebInfo(nodebInfo)
296         assert.Nil(t, rNibErr)
297         sdlInstanceMock.AssertExpectations(t)
298 }
299
300 func TestUpdateNodebInfoAndPublishSuccess(t *testing.T) {
301         inventoryName := "name"
302         plmnId := "02f829"
303         nbId := "4a952a0a"
304         w, sdlInstanceMock := initSdlInstanceMock(namespace)
305         nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
306         data, err := proto.Marshal(nodebInfo)
307         if err != nil {
308                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
309         }
310         var e error
311         var setExpected []interface{}
312
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)
317
318         sdlInstanceMock.On("SetAndPublish",[]string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
319
320         rNibErr := w.UpdateNodebInfoAndPublish(nodebInfo)
321         assert.Nil(t, rNibErr)
322         sdlInstanceMock.AssertExpectations(t)
323 }
324
325
326 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
327         inventoryName := "name"
328         plmnId := "02f829"
329         nbId := "4a952a0a"
330         w, sdlInstanceMock := initSdlInstanceMock(namespace)
331         nodebInfo := &entities.NodebInfo{}
332         data, err := proto.Marshal(nodebInfo)
333         if err != nil {
334                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
335         }
336         var e error
337         var setExpected []interface{}
338
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)
343
344         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
345
346         rNibErr := w.UpdateNodebInfo(nodebInfo)
347
348         assert.NotNil(t, rNibErr)
349         assert.IsType(t, &common.ValidationError{}, rNibErr)
350 }
351
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)
358         if err != nil {
359                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
360         }
361         var e error
362         var setExpected []interface{}
363
364         nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
365         setExpected = append(setExpected, nodebNameKey, data)
366         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
367
368         rNibErr := w.UpdateNodebInfo(nodebInfo)
369
370         assert.Nil(t, rNibErr)
371 }
372
373 func TestSaveEnb(t *testing.T) {
374         ranName := "RAN:" + RanName
375         w, sdlInstanceMock := initSdlInstanceMock(namespace)
376         nb := entities.NodebInfo{
377                 RanName:          RanName,
378                 NodeType:         entities.Node_ENB,
379                 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
380                 Ip:               "localhost",
381                 Port:             5656,
382                 GlobalNbId: &entities.GlobalNbId{
383                         NbId:   "4a952a0a",
384                         PlmnId: "02f829",
385                 },
386         }
387
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)
394         if err != nil {
395                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
396         }
397         var e error
398
399         cellData, err := proto.Marshal(&cellEntity)
400         if err != nil {
401                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
402         }
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)
408
409         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
410         rNibErr := w.SaveNodeb(&nb)
411         assert.Nil(t, rNibErr)
412 }
413
414 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
415         w, _ := initSdlInstanceMock(namespace)
416         nb := entities.NodebInfo{}
417         nb.RanName = "name"
418         nb.NodeType = entities.Node_ENB
419         nb.ConnectionStatus = 1
420         nb.Ip = "localhost"
421         nb.Port = 5656
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())
430 }
431
432 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
433         w, _ := initSdlInstanceMock(namespace)
434         nb := entities.NodebInfo{
435                 NodeType:         entities.Node_ENB,
436                 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
437                 Ip:               "localhost",
438                 Port:             5656,
439                 GlobalNbId: &entities.GlobalNbId{
440                         NbId:   "4a952a0a",
441                         PlmnId: "02f829",
442                 },
443         }
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())
452 }
453
454 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
455         w, _ := initSdlInstanceMock(namespace)
456         nb := entities.NodebInfo{}
457         nb.RanName = "name"
458         nb.NodeType = entities.Node_GNB
459         nb.ConnectionStatus = 1
460         nb.Ip = "localhost"
461         nb.Port = 5656
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}
467
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())
472 }
473
474 func TestSaveGnb(t *testing.T) {
475         ranName := "RAN:" + RanName
476         w, sdlInstanceMock := initSdlInstanceMock(namespace)
477         nb := entities.NodebInfo{
478                 RanName: RanName,
479                 NodeType:         entities.Node_GNB,
480                 ConnectionStatus: 1,
481                 GlobalNbId: &entities.GlobalNbId{
482                         NbId:   "4a952a0a",
483                         PlmnId: "02f829",
484                 },
485                 Ip:   "localhost",
486                 Port: 5656,
487         }
488
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)
496         if err != nil {
497                 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
498         }
499         var e error
500
501         cellData, err := proto.Marshal(&cellEntity)
502         if err != nil {
503                 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
504         }
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)
510
511         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
512         rNibErr := w.SaveNodeb(&nb)
513         assert.Nil(t, rNibErr)
514 }
515
516 func TestSaveRanLoadInformationSuccess(t *testing.T) {
517         inventoryName := "name"
518         loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
519
520         if validationErr != nil {
521                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
522         }
523
524         w, sdlInstanceMock := initSdlInstanceMock(namespace)
525
526         ranLoadInformation := generateRanLoadInformation()
527         data, err := proto.Marshal(ranLoadInformation)
528
529         if err != nil {
530                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
531         }
532
533         var e error
534         var setExpected []interface{}
535         setExpected = append(setExpected, loadKey, data)
536         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
537
538         rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
539         assert.Nil(t, rNibErr)
540 }
541
542 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
543         inventoryName := "name2"
544         w, _ := initSdlInstanceMock(namespace)
545
546         expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
547         err := w.SaveRanLoadInformation(inventoryName, nil)
548         assert.Equal(t, expectedErr, err)
549 }
550
551 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
552         inventoryName := ""
553         w, _ := initSdlInstanceMock(namespace)
554
555         err := w.SaveRanLoadInformation(inventoryName, nil)
556         assert.NotNil(t, err)
557         assert.IsType(t, &common.ValidationError{}, err)
558 }
559
560 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
561         inventoryName := "name2"
562
563         loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
564
565         if validationErr != nil {
566                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
567         }
568
569         w, sdlInstanceMock := initSdlInstanceMock(namespace)
570
571         ranLoadInformation := generateRanLoadInformation()
572         data, err := proto.Marshal(ranLoadInformation)
573
574         if err != nil {
575                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
576         }
577
578         expectedErr := errors.New("expected error")
579         var setExpected []interface{}
580         setExpected = append(setExpected, loadKey, data)
581         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
582
583         rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
584         assert.NotNil(t, rNibErr)
585         assert.IsType(t, &common.InternalError{}, rNibErr)
586 }
587
588 func generateCellLoadInformation() *entities.CellLoadInformation {
589         cellLoadInformation := entities.CellLoadInformation{}
590
591         cellLoadInformation.CellId = "123"
592
593         ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
594         cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
595
596         ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
597                 TargetCellId:                 "456",
598                 UlHighInterferenceIndication: "xxx",
599         }
600
601         cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
602
603         cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
604                 RntpPerPrb:                       "xxx",
605                 RntpThreshold:                    entities.RntpThreshold_NEG_4,
606                 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
607                 PB:                               1,
608                 PdcchInterferenceImpact:          2,
609                 EnhancedRntp: &entities.EnhancedRntp{
610                         EnhancedRntpBitmap:     "xxx",
611                         RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
612                         EnhancedRntpStartTime:  &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
613                 },
614         }
615
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",
621         }
622
623         cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
624
625         cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
626                 AssociatedSubframes:                       "xxx",
627                 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
628         }
629
630         compInformationItem := &entities.CompInformationItem{
631                 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
632                 BenefitMetric:      50,
633         }
634
635         cellLoadInformation.CompInformation = &entities.CompInformation{
636                 CompInformationItems:     []*entities.CompInformationItem{compInformationItem},
637                 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
638         }
639
640         cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
641                 State:             entities.NaicsState_NAICS_ACTIVE,
642                 TransmissionModes: "xxx",
643                 PB:                2,
644                 PAList:            []entities.PA{entities.PA_DB_NEG_3},
645         }
646
647         return &cellLoadInformation
648 }
649
650 func generateRanLoadInformation() *entities.RanLoadInformation {
651         ranLoadInformation := entities.RanLoadInformation{}
652
653         ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
654
655         cellLoadInformation := generateCellLoadInformation()
656         ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
657
658         return &ranLoadInformation
659 }
660
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)
666 }
667
668 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
669         w, _ := initSdlInstanceMock(namespace)
670         nb := &entities.NodebInfo{}
671         nb.Port = 5656
672         nb.Ip = "localhost"
673         actualErr := w.SaveNodeb(nb)
674         assert.IsType(t, &common.ValidationError{}, actualErr)
675 }
676
677 func TestSaveEntitySetFailure(t *testing.T) {
678         name := "name"
679         plmnId := "02f829"
680         nbId := "4a952a0a"
681
682         w, sdlInstanceMock := initSdlInstanceMock(namespace)
683         gnb := entities.NodebInfo{
684                 RanName: name,
685                 NodeType:         entities.Node_GNB,
686                 ConnectionStatus: 1,
687                 GlobalNbId: &entities.GlobalNbId{
688                         NbId:   nbId,
689                         PlmnId: plmnId,
690                 },
691                 Ip:   "localhost",
692                 Port: 5656,
693         }
694         data, err := proto.Marshal(&gnb)
695         if err != nil {
696                 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
697         }
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)
704 }
705
706 func TestSaveEntitySetAndPublishFailure(t *testing.T) {
707         name := "name"
708         plmnId := "02f829"
709         nbId := "4a952a0a"
710
711         w, sdlInstanceMock := initSdlInstanceMock(namespace)
712         enb := entities.NodebInfo{
713                 RanName: name,
714                 NodeType:         entities.Node_ENB,
715                 ConnectionStatus: 1,
716                 GlobalNbId: &entities.GlobalNbId{
717                         NbId:   nbId,
718                         PlmnId: plmnId,
719                 },
720                 Ip:   "localhost",
721                 Port: 5656,
722         }
723         data, err := proto.Marshal(&enb)
724         if err != nil {
725                 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
726         }
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)
733 }
734
735 func TestGetRNibWriter(t *testing.T) {
736         received, _ := initSdlInstanceMock(namespace)
737         assert.NotEmpty(t, received)
738 }
739
740 func TestSaveE2TInstanceSuccess(t *testing.T) {
741         address := "10.10.2.15:9800"
742         loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
743
744         if validationErr != nil {
745                 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
746         }
747
748         w, sdlInstanceMock := initSdlInstanceMock(namespace)
749
750         e2tInstance := generateE2tInstance(address)
751         data, err := json.Marshal(e2tInstance)
752
753         if err != nil {
754                 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
755         }
756
757         var e error
758         var setExpected []interface{}
759         setExpected = append(setExpected, loadKey, data)
760         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
761
762         rNibErr := w.SaveE2TInstance(e2tInstance)
763         assert.Nil(t, rNibErr)
764 }
765
766 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
767         w, _ := initSdlInstanceMock(namespace)
768         var address string
769         e2tInstance := entities.NewE2TInstance(address, "test")
770         err := w.SaveE2TInstance(e2tInstance)
771         assert.NotNil(t, err)
772         assert.IsType(t, &common.ValidationError{}, err)
773 }
774
775 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
776         address := "10.10.2.15:9800"
777         loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
778
779         if validationErr != nil {
780                 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
781         }
782
783         w, sdlInstanceMock := initSdlInstanceMock(namespace)
784
785         e2tInstance := generateE2tInstance(address)
786         data, err := json.Marshal(e2tInstance)
787
788         if err != nil {
789                 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
790         }
791
792         expectedErr := errors.New("expected error")
793         var setExpected []interface{}
794         setExpected = append(setExpected, loadKey, data)
795         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
796
797         rNibErr := w.SaveE2TInstance(e2tInstance)
798         assert.NotNil(t, rNibErr)
799         assert.IsType(t, &common.InternalError{}, rNibErr)
800 }
801
802 func generateE2tInstance(address string) *entities.E2TInstance {
803         e2tInstance := entities.NewE2TInstance(address, "pod test")
804
805         e2tInstance.AssociatedRanList = []string{"test1", "test2"}
806
807         return e2tInstance
808 }
809
810 func TestSaveE2TAddressesSuccess(t *testing.T) {
811         address := "10.10.2.15:9800"
812         w, sdlInstanceMock := initSdlInstanceMock(namespace)
813
814         e2tAddresses := []string{address}
815         data, err := json.Marshal(e2tAddresses)
816
817         if err != nil {
818                 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
819         }
820
821         var e error
822         var setExpected []interface{}
823         setExpected = append(setExpected, E2TAddressesKey, data)
824         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
825
826         rNibErr := w.SaveE2TAddresses(e2tAddresses)
827         assert.Nil(t, rNibErr)
828 }
829
830 func TestSaveE2TAddressesSdlFailure(t *testing.T) {
831         address := "10.10.2.15:9800"
832         w, sdlInstanceMock := initSdlInstanceMock(namespace)
833
834         e2tAddresses := []string{address}
835         data, err := json.Marshal(e2tAddresses)
836
837         if err != nil {
838                 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
839         }
840
841         expectedErr := errors.New("expected error")
842         var setExpected []interface{}
843         setExpected = append(setExpected, E2TAddressesKey, data)
844         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
845
846         rNibErr := w.SaveE2TAddresses(e2tAddresses)
847         assert.NotNil(t, rNibErr)
848         assert.IsType(t, &common.InternalError{}, rNibErr)
849 }
850
851 func TestRemoveE2TInstanceSuccess(t *testing.T) {
852         address := "10.10.2.15:9800"
853         w, sdlInstanceMock := initSdlInstanceMock(namespace)
854
855         e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
856         var e error
857         sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
858
859         rNibErr := w.RemoveE2TInstance(address)
860         assert.Nil(t, rNibErr)
861         sdlInstanceMock.AssertExpectations(t)
862 }
863
864 func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
865         address := "10.10.2.15:9800"
866         w, sdlInstanceMock := initSdlInstanceMock(namespace)
867
868         e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
869         expectedErr := errors.New("expected error")
870         sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
871
872         rNibErr := w.RemoveE2TInstance(address)
873         assert.IsType(t, &common.InternalError{}, rNibErr)
874 }
875
876 func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
877         w, sdlInstanceMock := initSdlInstanceMock(namespace)
878
879         rNibErr := w.RemoveE2TInstance("")
880         assert.IsType(t, &common.ValidationError{}, rNibErr)
881         sdlInstanceMock.AssertExpectations(t)
882 }
883
884 func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
885         inventoryName := "name"
886         plmnId := "02f829"
887         nbId := "4a952a0a"
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)
893         if err != nil {
894                 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
895         }
896         var e error
897         var setExpected []interface{}
898
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)
903
904         sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
905
906         rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
907         assert.Nil(t, rNibErr)
908 }
909
910 func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
911         inventoryName := "name"
912         plmnId := "02f829"
913         nbId := "4a952a0a"
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)
919         if err != nil {
920                 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
921         }
922         var e error
923         var setExpected []interface{}
924
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)
929
930         sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
931
932         rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
933
934         assert.NotNil(t, rNibErr)
935         assert.IsType(t, &common.ValidationError{}, rNibErr)
936 }
937
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)
946         if err != nil {
947                 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
948         }
949         var e error
950         var setExpected []interface{}
951
952         nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
953         setExpected = append(setExpected, nodebNameKey, data)
954         sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
955
956         rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
957
958         assert.Nil(t, rNibErr)
959 }
960
961 func TestSaveGeneralConfiguration(t *testing.T) {
962         w, sdlInstanceMock := initSdlInstanceMock(namespace)
963
964         key := common.BuildGeneralConfigurationKey()
965         configurationData := "{\"enableRic\":true}"
966         configuration := &entities.GeneralConfiguration{}
967         configuration.EnableRic = true
968
969         sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
970         rNibErr := w.SaveGeneralConfiguration(configuration)
971
972         assert.Nil(t, rNibErr)
973         sdlInstanceMock.AssertExpectations(t)
974 }
975
976 func TestSaveGeneralConfigurationDbError(t *testing.T) {
977         w, sdlInstanceMock := initSdlInstanceMock(namespace)
978
979         key := common.BuildGeneralConfigurationKey()
980         configurationData := "{\"enableRic\":true}"
981         configuration := &entities.GeneralConfiguration{}
982         configuration.EnableRic = true
983
984         expectedErr := errors.New("expected error")
985
986         sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
987         rNibErr := w.SaveGeneralConfiguration(configuration)
988
989         assert.NotNil(t, rNibErr)
990 }
991
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)
997
998         rNibErr := w.RemoveServedCells(RanName, servedCellsToRemove)
999
1000         assert.NotNil(t, rNibErr)
1001 }
1002
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)
1008         assert.Nil(t, err)
1009 }
1010
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)
1018 }
1019
1020 func TestUpdateEnbInvalidCellFailure(t *testing.T) {
1021         inventoryName := "name"
1022         plmnId := "02f829"
1023         nbId := "4a952a0a"
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)
1031 }
1032
1033 func TestUpdateEnbSdlFailure(t *testing.T) {
1034         inventoryName := "name"
1035         plmnId := "02f829"
1036         nbId := "4a952a0a"
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)
1045 }
1046
1047 func TestUpdateEnbSuccess(t *testing.T) {
1048         inventoryName := "name"
1049         plmnId := "02f829"
1050         nbId := "4a952a0a"
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)
1056
1057         var e error
1058         sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
1059         rNibErr := w.UpdateEnb(nodebInfo, servedCells)
1060         assert.Nil(t, rNibErr)
1061 }
1062
1063 func getUpdateEnbSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
1064
1065         nodebInfoData, err := proto.Marshal(nodebInfo)
1066         if err != nil {
1067                 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal NodeB entity. Error: %s", err)
1068         }
1069
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}
1073
1074         for _, v := range servedCells {
1075
1076                 cellEntity := entities.ServedCellInfo{CellId: "some cell id", EutraMode: entities.Eutra_FDD, CsgId: "some csg id"}
1077                 cellData, err := proto.Marshal(&cellEntity)
1078
1079                 if err != nil {
1080                         t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal cell entity. Error: %s", err)
1081                 }
1082
1083                 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetCellId())
1084                 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetPci())
1085                 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
1086         }
1087         return setExpected
1088 }
1089
1090 func TestRemoveEnbSuccess(t *testing.T) {
1091         inventoryName := "name"
1092         plmnId := "02f829"
1093         nbId := "4a952a0a"
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")
1099
1100         var e error
1101
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)
1111
1112         rNibErr := w.RemoveEnb(nodebInfo)
1113         assert.Nil(t, rNibErr)
1114         sdlInstanceMock.AssertExpectations(t)
1115 }
1116
1117 func TestRemoveEnbRemoveAndPublishError(t *testing.T) {
1118         inventoryName := "name"
1119         plmnId := "02f829"
1120         nbId := "4a952a0a"
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")
1126
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"))
1136
1137         rNibErr := w.RemoveEnb(nodebInfo)
1138         assert.NotNil(t, rNibErr)
1139         sdlInstanceMock.AssertExpectations(t)
1140 }
1141
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)
1146         if err != nil {
1147                 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1148         }
1149
1150         sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(nil)
1151
1152         rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1153         assert.Nil(t, rNibErr)
1154         sdlInstanceMock.AssertExpectations(t)
1155 }
1156
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)
1161         if err != nil {
1162                 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1163         }
1164
1165         sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1166
1167         rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1168         assert.NotNil(t, rNibErr)
1169         sdlInstanceMock.AssertExpectations(t)
1170 }
1171
1172 func TestAddEnb(t *testing.T) {
1173         ranName := "RAN:" + RanName
1174         w, sdlInstanceMock := initSdlInstanceMock(namespace)
1175         nb := entities.NodebInfo{
1176                 RanName:          RanName,
1177                 NodeType:         entities.Node_ENB,
1178                 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1179                 Ip:               "localhost",
1180                 Port:             5656,
1181                 GlobalNbId: &entities.GlobalNbId{
1182                         NbId:   "4a952a0a",
1183                         PlmnId: "02f829",
1184                 },
1185         }
1186
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)
1193         if err != nil {
1194                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
1195         }
1196         var e error
1197
1198         cellData, err := proto.Marshal(&cellEntity)
1199         if err != nil {
1200                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
1201         }
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)
1207
1208         sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", RanName + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
1209
1210         rNibErr := w.AddEnb(&nb)
1211         assert.Nil(t, rNibErr)
1212 }
1213
1214 func TestAddEnbCellIdValidationFailure(t *testing.T) {
1215         w, _ := initSdlInstanceMock(namespace)
1216         nb := entities.NodebInfo{}
1217         nb.RanName = "name"
1218         nb.NodeType = entities.Node_ENB
1219         nb.ConnectionStatus = 1
1220         nb.Ip = "localhost"
1221         nb.Port = 5656
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())
1230 }
1231
1232 func TestAddEnbInventoryNameValidationFailure(t *testing.T) {
1233         w, _ := initSdlInstanceMock(namespace)
1234         nb := entities.NodebInfo{
1235                 NodeType:         entities.Node_ENB,
1236                 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
1237                 Ip:               "localhost",
1238                 Port:             5656,
1239                 GlobalNbId: &entities.GlobalNbId{
1240                         NbId:   "4a952a0a",
1241                         PlmnId: "02f829",
1242                 },
1243         }
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())
1252 }
1253
1254 func TestUpdateNbIdentityOneMemberSuccess(t *testing.T) {
1255         w, sdlInstanceMock := initSdlInstanceMock(namespace)
1256
1257         proto, nbIdentity := createNbIdentityProto(t, "ran1", "plmnId1", "nbId1", entities.ConnectionStatus_DISCONNECTED)
1258         val := []interface{}{proto}
1259
1260         sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), val).Return(nil)
1261
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)
1264
1265         newNbIdIdentities := []*entities.NbIdentity{nbIdentityAdd}
1266         oldNbIdIdentities := []*entities.NbIdentity{nbIdentity}
1267
1268         rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1269         assert.Nil(t, rNibErr)
1270         sdlInstanceMock.AssertExpectations(t)
1271 }
1272
1273 func TestUpdateNbIdentitySuccess(t *testing.T) {
1274         w, sdlInstanceMock := initSdlInstanceMock(namespace)
1275
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)
1282
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)
1289
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)
1295
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)
1301
1302         rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1303         assert.Nil(t, rNibErr)
1304         sdlInstanceMock.AssertExpectations(t)
1305 }
1306
1307 func TestUpdateNbIdentityRemoveFailure(t *testing.T) {
1308         w, sdlInstanceMock := initSdlInstanceMock(namespace)
1309
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)
1315
1316         sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), nbIdIdentitiesProtoToRemove).Return(fmt.Errorf("for test"))
1317
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)
1323
1324         var newNbIdIdentities []*entities.NbIdentity
1325
1326         rNibErr := w.UpdateNbIdentities(entities.Node_ENB, oldNbIdIdentities, newNbIdIdentities)
1327         assert.NotNil(t, rNibErr)
1328         sdlInstanceMock.AssertExpectations(t)
1329 }
1330
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)
1335         if err != nil {
1336                 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1337         }
1338         sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1339
1340         rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1341         assert.NotNil(t, rNibErr)
1342         sdlInstanceMock.AssertExpectations(t)
1343 }
1344
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)
1349         if err != nil {
1350                 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1351         }
1352         sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1353
1354         rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1355         assert.NotNil(t, rNibErr)
1356         sdlInstanceMock.AssertExpectations(t)
1357 }
1358
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)
1363         if err != nil {
1364                 t.Errorf("#TestRemoveNbIdentitySuccess - failed to Marshal NbIdentity")
1365         }
1366         sdlInstanceMock.On("RemoveMember", entities.Node_ENB.String(), []interface{}{nbIdData}).Return(fmt.Errorf("for test"))
1367
1368         rNibErr := w.RemoveNbIdentity(entities.Node_ENB, nbIdentity)
1369         assert.NotNil(t, rNibErr)
1370         sdlInstanceMock.AssertExpectations(t)
1371 }
1372
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)
1376         if err != nil {
1377                 t.Errorf("#createNbIdentityProto - failed to Marshal NbIdentity")
1378         }
1379         return nbIdData, nbIdentity
1380 }