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"
40 func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
41 sdlInstanceMock = new(mocks.MockSdlInstance)
42 w = GetRNibWriter(sdlInstanceMock)
46 func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo {
47 nodebInfo := &entities.NodebInfo{
48 RanName: inventoryName,
49 GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId},
51 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
54 if nodeType == entities.Node_ENB {
55 nodebInfo.Configuration = &entities.NodebInfo_Enb{
58 } else if nodeType == entities.Node_GNB {
59 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
67 func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
69 servedNrCells := []*entities.ServedNRCell{}
71 for i, v := range cellIds {
72 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
74 ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
75 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
79 NrMode: entities.Nr_FDD,
81 ServedPlmns: []string{"whatever"},
88 func TestRemoveServedNrCellsSuccess(t *testing.T) {
89 w, sdlInstanceMock := initSdlInstanceMock(namespace)
90 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
91 sdlInstanceMock.On("Remove", buildCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil)
92 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
96 func TestRemoveServedNrCellsFailure(t *testing.T) {
97 w, sdlInstanceMock := initSdlInstanceMock(namespace)
98 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
99 sdlInstanceMock.On("Remove", buildCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error"))
100 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
101 assert.IsType(t, &common.InternalError{}, err)
104 func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
105 w, sdlInstanceMock := initSdlInstanceMock(namespace)
106 servedNrCells := generateServedNrCells("test1", "test2")
107 nodebInfo := &entities.NodebInfo{}
108 sdlInstanceMock.AssertNotCalled(t, "Set")
109 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
110 assert.IsType(t, &common.ValidationError{}, rNibErr)
113 func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
114 inventoryName := "name"
117 w, sdlInstanceMock := initSdlInstanceMock(namespace)
118 servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
119 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
120 nodebInfo.GetGnb().ServedNrCells = servedNrCells
121 sdlInstanceMock.AssertNotCalled(t, "Set")
122 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
123 assert.IsType(t, &common.ValidationError{}, rNibErr)
126 func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
128 nodebInfoData, err := proto.Marshal(nodebInfo)
130 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
133 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
134 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
135 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
137 for _, v := range servedNrCells {
139 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
140 cellData, err := proto.Marshal(&cellEntity)
143 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
146 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
147 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
148 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
154 func TestUpdateGnbCellsSdlFailure(t *testing.T) {
155 inventoryName := "name"
158 w, sdlInstanceMock := initSdlInstanceMock(namespace)
159 servedNrCells := generateServedNrCells("test1", "test2")
160 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
161 nodebInfo.GetGnb().ServedNrCells = servedNrCells
162 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
163 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(errors.New("expected error"))
164 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
165 assert.IsType(t, &common.InternalError{}, rNibErr)
168 func TestUpdateGnbCellsSuccess(t *testing.T) {
169 inventoryName := "name"
172 w, sdlInstanceMock := initSdlInstanceMock(namespace)
173 servedNrCells := generateServedNrCells("test1", "test2")
174 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
175 nodebInfo.GetGnb().ServedNrCells = servedNrCells
176 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
178 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
179 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
180 assert.Nil(t, rNibErr)
183 func TestUpdateNodebInfoSuccess(t *testing.T) {
184 inventoryName := "name"
187 w, sdlInstanceMock := initSdlInstanceMock(namespace)
188 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
189 data, err := proto.Marshal(nodebInfo)
191 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
194 var setExpected []interface{}
196 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
197 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
198 setExpected = append(setExpected, nodebNameKey, data)
199 setExpected = append(setExpected, nodebIdKey, data)
201 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
203 rNibErr := w.UpdateNodebInfo(nodebInfo)
204 assert.Nil(t, rNibErr)
207 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
208 inventoryName := "name"
211 w, sdlInstanceMock := initSdlInstanceMock(namespace)
212 nodebInfo := &entities.NodebInfo{}
213 data, err := proto.Marshal(nodebInfo)
215 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
218 var setExpected []interface{}
220 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
221 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
222 setExpected = append(setExpected, nodebNameKey, data)
223 setExpected = append(setExpected, nodebIdKey, data)
225 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
227 rNibErr := w.UpdateNodebInfo(nodebInfo)
229 assert.NotNil(t, rNibErr)
230 assert.IsType(t, &common.ValidationError{}, rNibErr)
233 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
234 inventoryName := "name"
235 w, sdlInstanceMock := initSdlInstanceMock(namespace)
236 nodebInfo := &entities.NodebInfo{}
237 nodebInfo.RanName = inventoryName
238 data, err := proto.Marshal(nodebInfo)
240 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
243 var setExpected []interface{}
245 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
246 setExpected = append(setExpected, nodebNameKey, data)
247 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
249 rNibErr := w.UpdateNodebInfo(nodebInfo)
251 assert.Nil(t, rNibErr)
254 func TestSaveEnb(t *testing.T) {
256 ranName := "RAN:" + name
257 w, sdlInstanceMock := initSdlInstanceMock(namespace)
258 nb := entities.NodebInfo{}
259 nb.NodeType = entities.Node_ENB
260 nb.ConnectionStatus = 1
263 enb := entities.Enb{}
264 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
265 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
266 enb.ServedCells = []*entities.ServedCellInfo{cell}
267 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
268 data, err := proto.Marshal(&nb)
270 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
274 cellData, err := proto.Marshal(&cellEntity)
276 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
278 var setExpected []interface{}
279 setExpected = append(setExpected, ranName, data)
280 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
281 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
282 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
284 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
286 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
288 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
290 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
292 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
293 nbIdData, err = proto.Marshal(nbIdentity)
295 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
297 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
299 rNibErr := w.SaveNodeb(nbIdentity, &nb)
300 assert.Nil(t, rNibErr)
303 func TestSaveEnbCellIdValidationFailure(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{Pci: 3}
313 enb.ServedCells = []*entities.ServedCellInfo{cell}
314 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
316 nbIdentity := &entities.NbIdentity{InventoryName: name, 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.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
323 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
324 w, _ := initSdlInstanceMock(namespace)
325 nb := entities.NodebInfo{}
326 nb.NodeType = entities.Node_ENB
327 nb.ConnectionStatus = 1
330 enb := entities.Enb{}
331 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
332 enb.ServedCells = []*entities.ServedCellInfo{cell}
333 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
335 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
336 rNibErr := w.SaveNodeb(nbIdentity, &nb)
337 assert.NotNil(t, rNibErr)
338 assert.IsType(t, &common.ValidationError{}, rNibErr)
339 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
342 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
344 w, _ := initSdlInstanceMock(namespace)
345 nb := entities.NodebInfo{}
346 nb.NodeType = entities.Node_GNB
347 nb.ConnectionStatus = 1
350 gnb := entities.Gnb{}
351 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
352 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
353 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
354 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
356 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
357 rNibErr := w.SaveNodeb(nbIdentity, &nb)
358 assert.NotNil(t, rNibErr)
359 assert.IsType(t, &common.ValidationError{}, rNibErr)
360 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
363 func TestSaveGnb(t *testing.T) {
365 ranName := "RAN:" + name
366 w, sdlInstanceMock := initSdlInstanceMock(namespace)
367 nb := entities.NodebInfo{}
368 nb.NodeType = entities.Node_GNB
369 nb.ConnectionStatus = 1
372 gnb := entities.Gnb{}
373 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
374 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
375 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
376 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
377 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
378 data, err := proto.Marshal(&nb)
380 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
384 cellData, err := proto.Marshal(&cellEntity)
386 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
388 var setExpected []interface{}
389 setExpected = append(setExpected, ranName, data)
390 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
391 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
392 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
394 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
395 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
396 nbIdData, err := proto.Marshal(nbIdentity)
398 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
400 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
402 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
404 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
406 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
408 rNibErr := w.SaveNodeb(nbIdentity, &nb)
409 assert.Nil(t, rNibErr)
412 func TestSaveRanLoadInformationSuccess(t *testing.T) {
413 inventoryName := "name"
414 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
416 if validationErr != nil {
417 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
420 w, sdlInstanceMock := initSdlInstanceMock(namespace)
422 ranLoadInformation := generateRanLoadInformation()
423 data, err := proto.Marshal(ranLoadInformation)
426 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
430 var setExpected []interface{}
431 setExpected = append(setExpected, loadKey, data)
432 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
434 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
435 assert.Nil(t, rNibErr)
438 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
439 inventoryName := "name2"
440 w, _ := initSdlInstanceMock(namespace)
442 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
443 err := w.SaveRanLoadInformation(inventoryName, nil)
444 assert.Equal(t, expectedErr, err)
447 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
449 w, _ := initSdlInstanceMock(namespace)
451 err := w.SaveRanLoadInformation(inventoryName, nil)
452 assert.NotNil(t, err)
453 assert.IsType(t, &common.ValidationError{}, err)
456 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
457 inventoryName := "name2"
459 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
461 if validationErr != nil {
462 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
465 w, sdlInstanceMock := initSdlInstanceMock(namespace)
467 ranLoadInformation := generateRanLoadInformation()
468 data, err := proto.Marshal(ranLoadInformation)
471 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
474 expectedErr := errors.New("expected error")
475 var setExpected []interface{}
476 setExpected = append(setExpected, loadKey, data)
477 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
479 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
480 assert.NotNil(t, rNibErr)
481 assert.IsType(t, &common.InternalError{}, rNibErr)
484 func generateCellLoadInformation() *entities.CellLoadInformation {
485 cellLoadInformation := entities.CellLoadInformation{}
487 cellLoadInformation.CellId = "123"
489 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
490 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
492 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
494 UlHighInterferenceIndication: "xxx",
497 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
499 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
501 RntpThreshold: entities.RntpThreshold_NEG_4,
502 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
504 PdcchInterferenceImpact: 2,
505 EnhancedRntp: &entities.EnhancedRntp{
506 EnhancedRntpBitmap: "xxx",
507 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
508 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
512 cellLoadInformation.AbsInformation = &entities.AbsInformation{
513 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
514 AbsPatternInfo: "xxx",
515 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
516 MeasurementSubset: "xxx",
519 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
521 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
522 AssociatedSubframes: "xxx",
523 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
526 compInformationItem := &entities.CompInformationItem{
527 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
531 cellLoadInformation.CompInformation = &entities.CompInformation{
532 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
533 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
536 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
537 State: entities.NaicsState_NAICS_ACTIVE,
538 TransmissionModes: "xxx",
540 PAList: []entities.PA{entities.PA_DB_NEG_3},
543 return &cellLoadInformation
546 func generateRanLoadInformation() *entities.RanLoadInformation {
547 ranLoadInformation := entities.RanLoadInformation{}
549 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
551 cellLoadInformation := generateCellLoadInformation()
552 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
554 return &ranLoadInformation
557 func TestSaveNilEntityFailure(t *testing.T) {
558 w, _ := initSdlInstanceMock(namespace)
559 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
560 nbIdentity := &entities.NbIdentity{}
561 actualErr := w.SaveNodeb(nbIdentity, nil)
562 assert.Equal(t, expectedErr, actualErr)
565 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
566 w, _ := initSdlInstanceMock(namespace)
567 expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")
568 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
569 nb := &entities.NodebInfo{}
572 actualErr := w.SaveNodeb(nbIdentity, nb)
573 assert.Equal(t, expectedErr, actualErr)
576 func TestSaveEntityFailure(t *testing.T) {
581 w, sdlInstanceMock := initSdlInstanceMock(namespace)
582 gnb := entities.NodebInfo{}
583 gnb.NodeType = entities.Node_GNB
584 data, err := proto.Marshal(&gnb)
586 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
588 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
589 setExpected := []interface{}{"RAN:" + name, data}
590 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
591 expectedErr := errors.New("expected error")
592 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
593 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
594 assert.NotEmpty(t, rNibErr)
597 func TestGetRNibWriter(t *testing.T) {
598 received, _ := initSdlInstanceMock(namespace)
599 assert.NotEmpty(t, received)
602 func TestSaveE2TInstanceSuccess(t *testing.T) {
603 address := "10.10.2.15:9800"
604 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
606 if validationErr != nil {
607 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
610 w, sdlInstanceMock := initSdlInstanceMock(namespace)
612 e2tInstance := generateE2tInstance(address)
613 data, err := json.Marshal(e2tInstance)
616 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
620 var setExpected []interface{}
621 setExpected = append(setExpected, loadKey, data)
622 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
624 rNibErr := w.SaveE2TInstance(e2tInstance)
625 assert.Nil(t, rNibErr)
628 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
629 w, _ := initSdlInstanceMock(namespace)
631 e2tInstance := entities.NewE2TInstance(address, "test")
632 err := w.SaveE2TInstance(e2tInstance)
633 assert.NotNil(t, err)
634 assert.IsType(t, &common.ValidationError{}, err)
637 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
638 address := "10.10.2.15:9800"
639 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
641 if validationErr != nil {
642 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
645 w, sdlInstanceMock := initSdlInstanceMock(namespace)
647 e2tInstance := generateE2tInstance(address)
648 data, err := json.Marshal(e2tInstance)
651 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
654 expectedErr := errors.New("expected error")
655 var setExpected []interface{}
656 setExpected = append(setExpected, loadKey, data)
657 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
659 rNibErr := w.SaveE2TInstance(e2tInstance)
660 assert.NotNil(t, rNibErr)
661 assert.IsType(t, &common.InternalError{}, rNibErr)
664 func generateE2tInstance(address string) *entities.E2TInstance {
665 e2tInstance := entities.NewE2TInstance(address, "pod test")
667 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
672 func TestSaveE2TAddressesSuccess(t *testing.T) {
673 address := "10.10.2.15:9800"
674 w, sdlInstanceMock := initSdlInstanceMock(namespace)
676 e2tAddresses := []string{address}
677 data, err := json.Marshal(e2tAddresses)
680 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
684 var setExpected []interface{}
685 setExpected = append(setExpected, E2TAddressesKey, data)
686 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
688 rNibErr := w.SaveE2TAddresses(e2tAddresses)
689 assert.Nil(t, rNibErr)
692 func TestSaveE2TAddressesSdlFailure(t *testing.T) {
693 address := "10.10.2.15:9800"
694 w, sdlInstanceMock := initSdlInstanceMock(namespace)
696 e2tAddresses := []string{address}
697 data, err := json.Marshal(e2tAddresses)
700 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
703 expectedErr := errors.New("expected error")
704 var setExpected []interface{}
705 setExpected = append(setExpected, E2TAddressesKey, data)
706 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
708 rNibErr := w.SaveE2TAddresses(e2tAddresses)
709 assert.NotNil(t, rNibErr)
710 assert.IsType(t, &common.InternalError{}, rNibErr)
713 func TestRemoveE2TInstanceSuccess(t *testing.T) {
714 address := "10.10.2.15:9800"
715 w, sdlInstanceMock := initSdlInstanceMock(namespace)
717 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
719 sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
721 rNibErr := w.RemoveE2TInstance(address)
722 assert.Nil(t, rNibErr)
723 sdlInstanceMock.AssertExpectations(t)
726 func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
727 address := "10.10.2.15:9800"
728 w, sdlInstanceMock := initSdlInstanceMock(namespace)
730 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
731 expectedErr := errors.New("expected error")
732 sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
734 rNibErr := w.RemoveE2TInstance(address)
735 assert.IsType(t, &common.InternalError{}, rNibErr)
738 func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
739 w, sdlInstanceMock := initSdlInstanceMock(namespace)
741 rNibErr := w.RemoveE2TInstance("")
742 assert.IsType(t, &common.ValidationError{}, rNibErr)
743 sdlInstanceMock.AssertExpectations(t)
748 //func TestSaveEnbGnbInteg(t *testing.T){
749 // for i := 0; i<10; i++{
750 // Init("e2Manager", 1)
751 // w := GetRNibWriter()
752 // nb := entities.NodebInfo{}
753 // nb.NodeType = entities.Node_ENB
754 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
755 // nb.Ip = "localhost"
756 // nb.Port = uint32(5656 + i)
757 // enb := entities.Enb{}
758 // cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
759 // cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
760 // cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
761 // enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
762 // nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
763 // plmnId := 0x02f828
764 // nbId := 0x4a952a0a
765 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
766 // err := w.SaveNodeb(nbIdentity, &nb)
768 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
771 // nb1 := entities.NodebInfo{}
772 // nb1.NodeType = entities.Node_GNB
773 // nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
774 // nb1.Ip = "localhost"
775 // nb1.Port = uint32(6565 + i)
776 // gnb := entities.Gnb{}
777 // gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
778 // gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
779 // gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
780 // gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
781 // nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
782 // nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
783 // err = w.SaveNodeb(nbIdentity, &nb1)
785 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
790 //func TestSaveNbRanNamesInteg(t *testing.T){
791 // for i := 0; i<10; i++{
792 // Init("e2Manager", 1)
793 // w := GetRNibWriter()
794 // nb := entities.NodebInfo{}
795 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
796 // nb.Ip = "localhost"
797 // nb.Port = uint32(5656 + i)
798 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
799 // err := w.SaveNodeb(nbIdentity, &nb)
801 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
806 //func TestSaveRanLoadInformationInteg(t *testing.T){
807 // Init("e2Manager", 1)
808 // w := GetRNibWriter()
809 // ranLoadInformation := generateRanLoadInformation()
810 // err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
812 // t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)