2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
29 "github.com/golang/protobuf/proto"
30 "github.com/stretchr/testify/assert"
35 var namespace = "namespace"
37 func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
38 sdlInstanceMock = new(mocks.MockSdlInstance)
39 w = GetRNibWriter(sdlInstanceMock)
43 func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo {
44 nodebInfo := &entities.NodebInfo{
45 RanName: inventoryName,
46 GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId},
48 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
51 if nodeType == entities.Node_ENB {
52 nodebInfo.Configuration = &entities.NodebInfo_Enb{
55 } else if nodeType == entities.Node_GNB {
56 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
64 func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
66 servedNrCells := []*entities.ServedNRCell{}
68 for _, v := range cellIds {
69 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
71 ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
72 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
76 NrMode: entities.Nr_FDD,
78 ServedPlmns: []string{"whatever"},
85 func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
86 w, sdlInstanceMock := initSdlInstanceMock(namespace)
87 servedNrCells := generateServedNrCells("test1", "test2")
88 nodebInfo := &entities.NodebInfo{}
89 sdlInstanceMock.AssertNotCalled(t, "Set")
90 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
91 assert.IsType(t, &common.ValidationError{}, rNibErr)
94 func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
95 inventoryName := "name"
98 w, sdlInstanceMock := initSdlInstanceMock(namespace)
99 servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
100 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
101 nodebInfo.GetGnb().ServedNrCells = servedNrCells
102 sdlInstanceMock.AssertNotCalled(t, "Set")
103 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
104 assert.IsType(t, &common.ValidationError{}, rNibErr)
107 func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
109 nodebInfoData, err := proto.Marshal(nodebInfo)
111 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
114 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
115 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
116 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
118 for _, v := range servedNrCells {
120 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
121 cellData, err := proto.Marshal(&cellEntity)
124 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
127 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
128 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
129 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
135 func TestUpdateGnbCellsSdlFailure(t *testing.T) {
136 inventoryName := "name"
139 w, sdlInstanceMock := initSdlInstanceMock(namespace)
140 servedNrCells := generateServedNrCells("test1", "test2")
141 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
142 nodebInfo.GetGnb().ServedNrCells = servedNrCells
143 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
144 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(errors.New("expected error"))
145 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
146 assert.IsType(t, &common.InternalError{}, rNibErr)
149 func TestUpdateGnbCellsSuccess(t *testing.T) {
150 inventoryName := "name"
153 w, sdlInstanceMock := initSdlInstanceMock(namespace)
154 servedNrCells := generateServedNrCells("test1", "test2")
155 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
156 nodebInfo.GetGnb().ServedNrCells = servedNrCells
157 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
159 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
160 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
161 assert.Nil(t, rNibErr)
164 func TestUpdateNodebInfoSuccess(t *testing.T) {
165 inventoryName := "name"
168 w, sdlInstanceMock := initSdlInstanceMock(namespace)
169 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
170 data, err := proto.Marshal(nodebInfo)
172 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
175 var setExpected []interface{}
177 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
178 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
179 setExpected = append(setExpected, nodebNameKey, data)
180 setExpected = append(setExpected, nodebIdKey, data)
182 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
184 rNibErr := w.UpdateNodebInfo(nodebInfo)
185 assert.Nil(t, rNibErr)
188 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
189 inventoryName := "name"
192 w, sdlInstanceMock := initSdlInstanceMock(namespace)
193 nodebInfo := &entities.NodebInfo{}
194 data, err := proto.Marshal(nodebInfo)
196 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
199 var setExpected []interface{}
201 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
202 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
203 setExpected = append(setExpected, nodebNameKey, data)
204 setExpected = append(setExpected, nodebIdKey, data)
206 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
208 rNibErr := w.UpdateNodebInfo(nodebInfo)
210 assert.NotNil(t, rNibErr)
211 assert.IsType(t, &common.ValidationError{}, rNibErr)
214 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
215 inventoryName := "name"
216 w, sdlInstanceMock := initSdlInstanceMock(namespace)
217 nodebInfo := &entities.NodebInfo{}
218 nodebInfo.RanName = inventoryName
219 data, err := proto.Marshal(nodebInfo)
221 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
224 var setExpected []interface{}
226 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
227 setExpected = append(setExpected, nodebNameKey, data)
228 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
230 rNibErr := w.UpdateNodebInfo(nodebInfo)
232 assert.Nil(t, rNibErr)
235 func TestSaveEnb(t *testing.T) {
237 ranName := "RAN:" + name
238 w, sdlInstanceMock := initSdlInstanceMock(namespace)
239 nb := entities.NodebInfo{}
240 nb.NodeType = entities.Node_ENB
241 nb.ConnectionStatus = 1
244 enb := entities.Enb{}
245 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
246 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
247 enb.ServedCells = []*entities.ServedCellInfo{cell}
248 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
249 data, err := proto.Marshal(&nb)
251 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
255 cellData, err := proto.Marshal(&cellEntity)
257 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
259 var setExpected []interface{}
260 setExpected = append(setExpected, ranName, data)
261 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
262 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
263 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
265 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
267 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
269 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
271 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
273 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
274 nbIdData, err = proto.Marshal(nbIdentity)
276 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
278 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
280 rNibErr := w.SaveNodeb(nbIdentity, &nb)
281 assert.Nil(t, rNibErr)
284 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
286 w, _ := initSdlInstanceMock(namespace)
287 nb := entities.NodebInfo{}
288 nb.NodeType = entities.Node_ENB
289 nb.ConnectionStatus = 1
292 enb := entities.Enb{}
293 cell := &entities.ServedCellInfo{Pci: 3}
294 enb.ServedCells = []*entities.ServedCellInfo{cell}
295 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
297 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
298 rNibErr := w.SaveNodeb(nbIdentity, &nb)
299 assert.NotNil(t, rNibErr)
300 assert.IsType(t, &common.ValidationError{}, rNibErr)
301 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
304 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
305 w, _ := initSdlInstanceMock(namespace)
306 nb := entities.NodebInfo{}
307 nb.NodeType = entities.Node_ENB
308 nb.ConnectionStatus = 1
311 enb := entities.Enb{}
312 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
313 enb.ServedCells = []*entities.ServedCellInfo{cell}
314 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
316 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
317 rNibErr := w.SaveNodeb(nbIdentity, &nb)
318 assert.NotNil(t, rNibErr)
319 assert.IsType(t, &common.ValidationError{}, rNibErr)
320 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
323 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
325 w, _ := initSdlInstanceMock(namespace)
326 nb := entities.NodebInfo{}
327 nb.NodeType = entities.Node_GNB
328 nb.ConnectionStatus = 1
331 gnb := entities.Gnb{}
332 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
333 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
334 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
335 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
337 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
338 rNibErr := w.SaveNodeb(nbIdentity, &nb)
339 assert.NotNil(t, rNibErr)
340 assert.IsType(t, &common.ValidationError{}, rNibErr)
341 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
344 func TestSaveGnb(t *testing.T) {
346 ranName := "RAN:" + name
347 w, sdlInstanceMock := initSdlInstanceMock(namespace)
348 nb := entities.NodebInfo{}
349 nb.NodeType = entities.Node_GNB
350 nb.ConnectionStatus = 1
353 gnb := entities.Gnb{}
354 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
355 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
356 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
357 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
358 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
359 data, err := proto.Marshal(&nb)
361 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
365 cellData, err := proto.Marshal(&cellEntity)
367 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
369 var setExpected []interface{}
370 setExpected = append(setExpected, ranName, data)
371 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
372 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
373 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
375 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
376 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
377 nbIdData, err := proto.Marshal(nbIdentity)
379 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
381 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
383 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
385 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
387 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
389 rNibErr := w.SaveNodeb(nbIdentity, &nb)
390 assert.Nil(t, rNibErr)
393 func TestSaveRanLoadInformationSuccess(t *testing.T) {
394 inventoryName := "name"
395 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
397 if validationErr != nil {
398 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
401 w, sdlInstanceMock := initSdlInstanceMock(namespace)
403 ranLoadInformation := generateRanLoadInformation()
404 data, err := proto.Marshal(ranLoadInformation)
407 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
411 var setExpected []interface{}
412 setExpected = append(setExpected, loadKey, data)
413 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
415 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
416 assert.Nil(t, rNibErr)
419 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
420 inventoryName := "name2"
421 w, _ := initSdlInstanceMock(namespace)
423 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
424 err := w.SaveRanLoadInformation(inventoryName, nil)
425 assert.Equal(t, expectedErr, err)
428 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
430 w, _ := initSdlInstanceMock(namespace)
432 err := w.SaveRanLoadInformation(inventoryName, nil)
433 assert.NotNil(t, err)
434 assert.IsType(t, &common.ValidationError{}, err)
437 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
438 inventoryName := "name2"
440 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
442 if validationErr != nil {
443 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
446 w, sdlInstanceMock := initSdlInstanceMock(namespace)
448 ranLoadInformation := generateRanLoadInformation()
449 data, err := proto.Marshal(ranLoadInformation)
452 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
455 expectedErr := errors.New("expected error")
456 var setExpected []interface{}
457 setExpected = append(setExpected, loadKey, data)
458 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
460 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
461 assert.NotNil(t, rNibErr)
462 assert.IsType(t, &common.InternalError{}, rNibErr)
465 func generateCellLoadInformation() *entities.CellLoadInformation {
466 cellLoadInformation := entities.CellLoadInformation{}
468 cellLoadInformation.CellId = "123"
470 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
471 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
473 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
475 UlHighInterferenceIndication: "xxx",
478 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
480 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
482 RntpThreshold: entities.RntpThreshold_NEG_4,
483 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
485 PdcchInterferenceImpact: 2,
486 EnhancedRntp: &entities.EnhancedRntp{
487 EnhancedRntpBitmap: "xxx",
488 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
489 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
493 cellLoadInformation.AbsInformation = &entities.AbsInformation{
494 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
495 AbsPatternInfo: "xxx",
496 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
497 MeasurementSubset: "xxx",
500 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
502 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
503 AssociatedSubframes: "xxx",
504 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
507 compInformationItem := &entities.CompInformationItem{
508 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
512 cellLoadInformation.CompInformation = &entities.CompInformation{
513 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
514 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
517 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
518 State: entities.NaicsState_NAICS_ACTIVE,
519 TransmissionModes: "xxx",
521 PAList: []entities.PA{entities.PA_DB_NEG_3},
524 return &cellLoadInformation
527 func generateRanLoadInformation() *entities.RanLoadInformation {
528 ranLoadInformation := entities.RanLoadInformation{}
530 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
532 cellLoadInformation := generateCellLoadInformation()
533 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
535 return &ranLoadInformation
538 func TestSaveNilEntityFailure(t *testing.T) {
539 w, _ := initSdlInstanceMock(namespace)
540 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
541 nbIdentity := &entities.NbIdentity{}
542 actualErr := w.SaveNodeb(nbIdentity, nil)
543 assert.Equal(t, expectedErr, actualErr)
546 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
547 w, _ := initSdlInstanceMock(namespace)
548 expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")
549 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
550 nb := &entities.NodebInfo{}
553 actualErr := w.SaveNodeb(nbIdentity, nb)
554 assert.Equal(t, expectedErr, actualErr)
557 func TestSaveEntityFailure(t *testing.T) {
562 w, sdlInstanceMock := initSdlInstanceMock(namespace)
563 gnb := entities.NodebInfo{}
564 gnb.NodeType = entities.Node_GNB
565 data, err := proto.Marshal(&gnb)
567 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
569 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
570 setExpected := []interface{}{"RAN:" + name, data}
571 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
572 expectedErr := errors.New("expected error")
573 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
574 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
575 assert.NotEmpty(t, rNibErr)
578 func TestGetRNibWriter(t *testing.T) {
579 received, _ := initSdlInstanceMock(namespace)
580 assert.NotEmpty(t, received)
583 func TestSaveE2TInstanceSuccess(t *testing.T) {
584 address := "10.10.2.15:9800"
585 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
587 if validationErr != nil {
588 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
591 w, sdlInstanceMock := initSdlInstanceMock(namespace)
593 e2tInstance := generateE2tInstance(address)
594 data, err := json.Marshal(e2tInstance)
597 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
601 var setExpected []interface{}
602 setExpected = append(setExpected, loadKey, data)
603 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
605 rNibErr := w.SaveE2TInstance(e2tInstance)
606 assert.Nil(t, rNibErr)
609 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
610 w, _ := initSdlInstanceMock(namespace)
612 e2tInstance := entities.NewE2TInstance(address, "test")
613 err := w.SaveE2TInstance(e2tInstance)
614 assert.NotNil(t, err)
615 assert.IsType(t, &common.ValidationError{}, err)
618 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
619 address := "10.10.2.15:9800"
620 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
622 if validationErr != nil {
623 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
626 w, sdlInstanceMock := initSdlInstanceMock(namespace)
628 e2tInstance := generateE2tInstance(address)
629 data, err := json.Marshal(e2tInstance)
632 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
635 expectedErr := errors.New("expected error")
636 var setExpected []interface{}
637 setExpected = append(setExpected, loadKey, data)
638 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
640 rNibErr := w.SaveE2TInstance(e2tInstance)
641 assert.NotNil(t, rNibErr)
642 assert.IsType(t, &common.InternalError{}, rNibErr)
645 func generateE2tInstance(address string) *entities.E2TInstance {
646 e2tInstance := entities.NewE2TInstance(address, "pod test")
648 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
653 func TestSaveE2TAddressesSuccess(t *testing.T) {
654 address := "10.10.2.15:9800"
655 w, sdlInstanceMock := initSdlInstanceMock(namespace)
657 e2tAddresses := []string{address}
658 data, err := json.Marshal(e2tAddresses)
661 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
665 var setExpected []interface{}
666 setExpected = append(setExpected, E2TAddressesKey, data)
667 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
669 rNibErr := w.SaveE2TAddresses(e2tAddresses)
670 assert.Nil(t, rNibErr)
673 func TestSaveE2TAddressesSdlFailure(t *testing.T) {
674 address := "10.10.2.15:9800"
675 w, sdlInstanceMock := initSdlInstanceMock(namespace)
677 e2tAddresses := []string{address}
678 data, err := json.Marshal(e2tAddresses)
681 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
684 expectedErr := errors.New("expected error")
685 var setExpected []interface{}
686 setExpected = append(setExpected, E2TAddressesKey, data)
687 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
689 rNibErr := w.SaveE2TAddresses(e2tAddresses)
690 assert.NotNil(t, rNibErr)
691 assert.IsType(t, &common.InternalError{}, rNibErr)
694 func TestRemoveE2TInstanceSuccess(t *testing.T) {
695 address := "10.10.2.15:9800"
696 w, sdlInstanceMock := initSdlInstanceMock(namespace)
698 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
700 sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
702 rNibErr := w.RemoveE2TInstance(address)
703 assert.Nil(t, rNibErr)
704 sdlInstanceMock.AssertExpectations(t)
707 func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
708 address := "10.10.2.15:9800"
709 w, sdlInstanceMock := initSdlInstanceMock(namespace)
711 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
712 expectedErr := errors.New("expected error")
713 sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
715 rNibErr := w.RemoveE2TInstance(address)
716 assert.IsType(t, &common.InternalError{}, rNibErr)
719 func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
720 w, sdlInstanceMock := initSdlInstanceMock(namespace)
722 rNibErr := w.RemoveE2TInstance("")
723 assert.IsType(t, &common.ValidationError{}, rNibErr)
724 sdlInstanceMock.AssertExpectations(t)
729 //func TestSaveEnbGnbInteg(t *testing.T){
730 // for i := 0; i<10; i++{
731 // Init("e2Manager", 1)
732 // w := GetRNibWriter()
733 // nb := entities.NodebInfo{}
734 // nb.NodeType = entities.Node_ENB
735 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
736 // nb.Ip = "localhost"
737 // nb.Port = uint32(5656 + i)
738 // enb := entities.Enb{}
739 // cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
740 // cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
741 // cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
742 // enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
743 // nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
744 // plmnId := 0x02f828
745 // nbId := 0x4a952a0a
746 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
747 // err := w.SaveNodeb(nbIdentity, &nb)
749 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
752 // nb1 := entities.NodebInfo{}
753 // nb1.NodeType = entities.Node_GNB
754 // nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
755 // nb1.Ip = "localhost"
756 // nb1.Port = uint32(6565 + i)
757 // gnb := entities.Gnb{}
758 // gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
759 // gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
760 // gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
761 // gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
762 // nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
763 // nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
764 // err = w.SaveNodeb(nbIdentity, &nb1)
766 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
771 //func TestSaveNbRanNamesInteg(t *testing.T){
772 // for i := 0; i<10; i++{
773 // Init("e2Manager", 1)
774 // w := GetRNibWriter()
775 // nb := entities.NodebInfo{}
776 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
777 // nb.Ip = "localhost"
778 // nb.Port = uint32(5656 + i)
779 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
780 // err := w.SaveNodeb(nbIdentity, &nb)
782 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
787 //func TestSaveRanLoadInformationInteg(t *testing.T){
788 // Init("e2Manager", 1)
789 // w := GetRNibWriter()
790 // ranLoadInformation := generateRanLoadInformation()
791 // err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
793 // t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)