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.
21 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
22 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
23 "github.com/golang/protobuf/proto"
24 "github.com/stretchr/testify/assert"
28 var namespace = "namespace"
30 func TestInit(t *testing.T) {
33 assert.NotNil(t, readerPool)
34 assert.NotNil(t, readerPool.New)
35 assert.NotNil(t, readerPool.Destroy)
36 available, created := readerPool.Stats()
37 assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
38 assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
41 func TestInitPool(t *testing.T) {
43 sdlInstanceMock := new(MockSdlInstance)
44 initPool(1, func() interface{} {
45 sdlI := common.ISdlInstance(sdlInstanceMock)
46 return &rNibReaderInstance{sdl: &sdlI, namespace: namespace}
48 func(obj interface{}) {
51 assert.NotNil(t, readerPool)
52 assert.NotNil(t, readerPool.New)
53 assert.NotNil(t, readerPool.Destroy)
54 available, created := readerPool.Stats()
55 assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
56 assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
59 func initSdlInstanceMock(namespace string, poolSize int) *MockSdlInstance {
60 sdlInstanceMock := new(MockSdlInstance)
61 initPool(poolSize, func() interface{} {
62 sdlI := common.ISdlInstance(sdlInstanceMock)
63 return &rNibReaderInstance{sdl: &sdlI, namespace: namespace}
65 func(obj interface{}) {
68 return sdlInstanceMock
71 func TestGetNodeB(t *testing.T) {
74 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
76 nb := entities.NodebInfo{}
77 nb.ConnectionStatus = 1
81 cell := entities.ServedCellInfo{Tac: "tac"}
82 enb.ServedCells = []*entities.ServedCellInfo{&cell}
83 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
85 data, err := proto.Marshal(&nb)
87 t.Errorf("#rNibReader_test.TestGetNb - Failed to marshal ENB instance. Error: %v", err)
89 ret := map[string]interface{}{"RAN:" + name: string(data)}
90 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
91 getNb, er := w.GetNodeb(name)
93 assert.Equal(t, getNb.Ip, nb.Ip)
94 assert.Equal(t, getNb.Port, nb.Port)
95 assert.Equal(t, getNb.ConnectionStatus, nb.ConnectionStatus)
96 assert.Len(t, getNb.GetEnb().GetServedCells(), 1)
97 assert.Equal(t, getNb.GetEnb().GetServedCells()[0].Tac, nb.GetEnb().GetServedCells()[0].Tac)
100 func TestGetNodeBNotFoundFailure(t *testing.T) {
103 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
106 var ret map[string]interface{}
107 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
108 getNb, er := w.GetNodeb(name)
111 assert.Equal(t, 1, er.GetCode())
112 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: RAN:name", er.Error())
115 func TestGetNodeBUnmarshalFailure(t *testing.T) {
118 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
121 ret := make(map[string]interface{}, 1)
122 ret["RAN:"+name] = "data"
123 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
124 getNb, er := w.GetNodeb(name)
127 assert.Equal(t, 2, er.GetCode())
128 assert.EqualValues(t, "2 INTERNAL_ERROR - proto: can't skip unknown wire type 4", er.Error())
131 func TestGetNodeBSdlgoFailure(t *testing.T) {
133 errMsg := "expected Sdlgo error"
134 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
136 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
138 e := errors.New(errMsg)
139 var ret map[string]interface{}
140 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
141 getNb, er := w.GetNodeb(name)
144 assert.Equal(t, 2, er.GetCode())
145 assert.EqualValues(t, errMsgExpected, er.Error())
148 func TestGetNodeBCellsListEnb(t *testing.T) {
151 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
153 nb := entities.NodebInfo{}
154 nb.ConnectionStatus = 1
157 enb := entities.Enb{}
158 cell := entities.ServedCellInfo{Tac: "tac"}
159 enb.ServedCells = []*entities.ServedCellInfo{&cell}
160 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
162 data, err := proto.Marshal(&nb)
164 t.Errorf("#rNibReader_test.GetNodeBCellsList - Failed to marshal ENB instance. Error: %v", err)
166 ret := map[string]interface{}{"RAN:" + name: string(data)}
167 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
168 cells, er := w.GetCellList(name)
170 assert.NotNil(t, cells)
171 assert.Len(t, cells.GetServedCellInfos().GetServedCells(), 1)
172 retCell := cells.GetServedCellInfos().GetServedCells()[0]
173 assert.Equal(t, retCell.Tac, "tac")
176 func TestGetNodeBCellsListGnb(t *testing.T) {
179 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
181 nb := entities.NodebInfo{}
182 nb.ConnectionStatus = 1
185 nb.NodeType = entities.Node_GNB
186 gnb := entities.Gnb{}
187 cell := entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{NrPci: 10}}
188 gnb.ServedNrCells = []*entities.ServedNRCell{&cell}
189 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
191 data, err := proto.Marshal(&nb)
193 t.Errorf("#rNibReader_test.GetNodeBCellsList - Failed to marshal GNB instance. Error: %v", err)
195 ret := map[string]interface{}{"RAN:" + name: string(data)}
196 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
197 cells, er := w.GetCellList(name)
199 assert.NotNil(t, cells)
200 assert.Len(t, cells.GetServedNrCells().GetServedCells(), 1)
201 retCell := cells.GetServedNrCells().GetServedCells()[0]
202 assert.Equal(t, retCell.GetServedNrCellInformation().GetNrPci(), uint32(10))
205 func TestGetNodeBCellsListNodeUnmarshalFailure(t *testing.T) {
208 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
211 ret := make(map[string]interface{}, 1)
212 ret["RAN:"+name] = "data"
213 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
214 cells, er := w.GetCellList(name)
217 assert.Equal(t, 2, er.GetCode())
218 assert.EqualValues(t, "2 INTERNAL_ERROR - proto: can't skip unknown wire type 4", er.Error())
221 func TestGetNodeBCellsListNodeNotFoundFailure(t *testing.T) {
224 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
227 var ret map[string]interface{}
228 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
229 cells, er := w.GetCellList(name)
232 assert.Equal(t, 1, er.GetCode())
233 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: RAN:name", er.Error())
236 func TestGetNodeBCellsListNotFoundFailureEnb(t *testing.T) {
239 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
241 nb := entities.NodebInfo{}
242 nb.ConnectionStatus = 1
245 enb := entities.Enb{}
246 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
248 data, err := proto.Marshal(&nb)
250 t.Errorf("#rNibReader_test.TestGetNbCellsListNotFoundFailure - Failed to marshal ENB instance. Error: %v", err)
252 ret := map[string]interface{}{"RAN:" + name: string(data)}
253 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
254 _, er := w.GetCellList(name)
256 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.GetCellList - served cells not found. Responding node RAN name: name.", er.Error())
259 func TestGetNodeBCellsListNotFoundFailureGnb(t *testing.T) {
262 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
264 nb := entities.NodebInfo{}
265 nb.ConnectionStatus = 1
268 gnb := entities.Gnb{}
269 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
271 data, err := proto.Marshal(&nb)
273 t.Errorf("#rNibReader_test.TestGetNbCellsListNotFoundFailure - Failed to marshal ENB instance. Error: %v", err)
275 ret := map[string]interface{}{"RAN:" + name: string(data)}
276 sdlInstanceMock.On("Get", []string{"RAN:" + name}).Return(ret, e)
277 _, er := w.GetCellList(name)
279 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.GetCellList - served cells not found. Responding node RAN name: name.", er.Error())
282 func TestCloseOnClosedPoolFailure(t *testing.T) {
284 instanceMock := initSdlInstanceMock(namespace, 1)
285 w1 := GetRNibReader()
287 available, created := readerPool.Stats()
288 assert.Equal(t, 1, available, "number of available objects in the readerPool should be 1")
289 assert.Equal(t, 1, created, "number of created objects in the readerPool should be 1")
291 instanceMock.On("Close").Return(e)
293 assert.Panics(t, func() { Close() })
296 func TestCloseFailure(t *testing.T) {
298 instanceMock := initSdlInstanceMock(namespace, 2)
299 w1 := GetRNibReader()
301 available, created := readerPool.Stats()
302 assert.Equal(t, 1, available, "number of available objects in the readerPool should be 1")
303 assert.Equal(t, 1, created, "number of created objects in the readerPool should be 1")
304 e := errors.New("expected error")
305 instanceMock.On("Close").Return(e)
307 available, created = readerPool.Stats()
308 assert.Equal(t, 0, available, "number of available objects in the readerPool should be 0")
309 assert.Equal(t, 0, created, "number of created objects in the readerPool should be 0")
312 func TestGetListGnbIdsUnmarshalFailure(t *testing.T) {
314 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
317 sdlInstanceMock.On("GetMembers", GnbType).Return([]string{"data"}, e)
318 ids, er := w.GetListGnbIds()
321 assert.Equal(t, 2, er.GetCode())
322 assert.Equal(t, "2 INTERNAL_ERROR - proto: can't skip unknown wire type 4", er.Error())
325 func TestGetListGnbIdsSdlgoFailure(t *testing.T) {
326 errMsg := "expected Sdlgo error"
327 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
329 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
331 e := errors.New(errMsg)
333 sdlInstanceMock.On("GetMembers", GnbType).Return(data, e)
334 ids, er := w.GetListGnbIds()
337 assert.Equal(t, 2, er.GetCode())
338 assert.EqualValues(t, errMsgExpected, er.Error())
341 func TestGetListNodesIdsGnbSdlgoFailure(t *testing.T) {
344 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
350 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
352 data, err := proto.Marshal(nbIdentity)
354 t.Errorf("#rNibReader_test.TestGetListNodesIdsGnbSdlgoFailure - Failed to marshal nodeb identity entity. Error: %v", err)
356 sdlInstanceMock.On("GetMembers", EnbType).Return([]string{string(data)}, nilError)
358 errMsg := "expected Sdlgo error"
359 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
360 expectedError := errors.New(errMsg)
362 sdlInstanceMock.On("GetMembers", GnbType).Return(nilData, expectedError)
364 ids, er := w.GetListNodebIds()
367 assert.Equal(t, 2, er.GetCode())
368 assert.EqualValues(t, errMsgExpected, er.Error())
371 func TestGetListNodesIdsEnbSdlgoFailure(t *testing.T) {
374 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
380 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
382 data, err := proto.Marshal(nbIdentity)
384 t.Errorf("#rNibReader_test.TestGetListNodesIdsEnbSdlgoFailure - Failed to marshal nodeb identity entity. Error: %v", err)
386 sdlInstanceMock.On("GetMembers", GnbType).Return([]string{string(data)}, nilError)
388 errMsg := "expected Sdlgo error"
389 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
390 expectedError := errors.New(errMsg)
392 sdlInstanceMock.On("GetMembers", EnbType).Return(nilData, expectedError)
394 ids, er := w.GetListNodebIds()
397 assert.Equal(t, 2, er.GetCode())
398 assert.EqualValues(t, errMsgExpected, er.Error())
401 func TestGetListNodesIdsEnbSdlgoSuccess(t *testing.T) {
404 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
410 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
412 data, err := proto.Marshal(nbIdentity)
414 t.Errorf("#rNibReader_test.TestGetListNodesIdsEnbSdlgoFailure - Failed to marshal nodeb identity entity. Error: %v", err)
416 sdlInstanceMock.On("GetMembers", GnbType).Return([]string{string(data)}, nilError)
417 sdlInstanceMock.On("GetMembers", EnbType).Return([]string{string(data)}, nilError)
419 ids, er := w.GetListNodebIds()
421 assert.NotNil(t, ids)
422 assert.Len(t, ids, 2)
425 func TestGetListEnbIdsUnmarshalFailure(t *testing.T) {
427 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
430 sdlInstanceMock.On("GetMembers", EnbType).Return([]string{"data"}, e)
431 ids, er := w.GetListEnbIds()
434 assert.Equal(t, 2, er.GetCode())
435 assert.Equal(t, "2 INTERNAL_ERROR - proto: can't skip unknown wire type 4", er.Error())
438 func TestGetListEnbIdsOneId(t *testing.T) {
443 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
445 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
447 data, err := proto.Marshal(nbIdentity)
449 t.Errorf("#rNibReader_test.TestGetListEnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
451 sdlInstanceMock.On("GetMembers", EnbType).Return([]string{string(data)}, e)
452 ids, er := w.GetListEnbIds()
454 assert.Len(t, *ids, 1)
455 assert.Equal(t, (*ids)[0].GetInventoryName(), name)
456 assert.Equal(t, (*ids)[0].GetGlobalNbId().GetPlmnId(), nbIdentity.GetGlobalNbId().GetPlmnId())
457 assert.Equal(t, (*ids)[0].GetGlobalNbId().GetNbId(), nbIdentity.GetGlobalNbId().GetNbId())
460 func TestGetListEnbIdsNoIds(t *testing.T) {
462 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
465 sdlInstanceMock.On("GetMembers", EnbType).Return([]string{}, e)
466 ids, er := w.GetListEnbIds()
468 assert.Len(t, *ids, 0)
471 func TestGetListEnbIds(t *testing.T) {
477 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
479 idsData := make([]string, listSize)
480 idsEntities := make([]*entities.NbIdentity, listSize)
481 for i := 0; i < listSize; i++ {
482 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: string(plmnId + i), NbId: string(nbId + i)}}
483 data, err := proto.Marshal(nbIdentity)
485 t.Errorf("#rNibReader_test.TestGetListEnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
487 idsData[i] = string(data)
488 idsEntities[i] = nbIdentity
491 sdlInstanceMock.On("GetMembers", EnbType).Return(idsData, e)
492 ids, er := w.GetListEnbIds()
494 assert.Len(t, *ids, listSize)
495 for i, id := range *ids {
496 assert.Equal(t, id.GetInventoryName(), name)
497 assert.Equal(t, id.GetGlobalNbId().GetPlmnId(), idsEntities[i].GetGlobalNbId().GetPlmnId())
498 assert.Equal(t, id.GetGlobalNbId().GetNbId(), idsEntities[i].GetGlobalNbId().GetNbId())
502 func TestGetListGnbIdsOneId(t *testing.T) {
507 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
509 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
511 data, err := proto.Marshal(nbIdentity)
513 t.Errorf("#rNibReader_test.TestGetListGnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
515 sdlInstanceMock.On("GetMembers", GnbType).Return([]string{string(data)}, e)
516 ids, er := w.GetListGnbIds()
518 assert.Len(t, *ids, 1)
519 assert.Equal(t, (*ids)[0].GetInventoryName(), name)
520 assert.Equal(t, (*ids)[0].GetGlobalNbId().GetPlmnId(), nbIdentity.GetGlobalNbId().GetPlmnId())
521 assert.Equal(t, (*ids)[0].GetGlobalNbId().GetNbId(), nbIdentity.GetGlobalNbId().GetNbId())
524 func TestGetListGnbIdsNoIds(t *testing.T) {
526 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
529 sdlInstanceMock.On("GetMembers", GnbType).Return([]string{}, e)
530 ids, er := w.GetListGnbIds()
532 assert.Len(t, *ids, 0)
535 func TestGetListGnbIds(t *testing.T) {
541 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
543 idsData := make([]string, listSize)
544 idsEntities := make([]*entities.NbIdentity, listSize)
545 for i := 0; i < listSize; i++ {
546 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: string(plmnId + i), NbId: string(nbId + i)}}
547 data, err := proto.Marshal(nbIdentity)
549 t.Errorf("#rNibReader_test.TestGetListGnbIds - Failed to marshal nodeb identity entity. Error: %v", err)
551 idsData[i] = string(data)
552 idsEntities[i] = nbIdentity
555 sdlInstanceMock.On("GetMembers", GnbType).Return(idsData, e)
556 ids, er := w.GetListGnbIds()
558 assert.Len(t, *ids, listSize)
559 for i, id := range *ids {
560 assert.Equal(t, id.GetInventoryName(), name)
561 assert.Equal(t, id.GetGlobalNbId().GetPlmnId(), idsEntities[i].GetGlobalNbId().GetPlmnId())
562 assert.Equal(t, id.GetGlobalNbId().GetNbId(), idsEntities[i].GetGlobalNbId().GetNbId())
566 func TestGetListEnbIdsSdlgoFailure(t *testing.T) {
567 errMsg := "expected Sdlgo error"
568 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
570 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
572 e := errors.New(errMsg)
574 sdlInstanceMock.On("GetMembers", EnbType).Return(data, e)
575 ids, er := w.GetListEnbIds()
578 assert.Equal(t, 2, er.GetCode())
579 assert.EqualValues(t, errMsgExpected, er.Error())
582 func TestGetCountGnbListOneId(t *testing.T) {
584 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
587 sdlInstanceMock.On("GroupSize", GnbType).Return(1, e)
588 count, er := w.GetCountGnbList()
590 assert.Equal(t, count, 1)
593 func TestGetCountGnbList(t *testing.T) {
595 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
598 sdlInstanceMock.On("GroupSize", GnbType).Return(3, e)
599 count, er := w.GetCountGnbList()
601 assert.Equal(t, count, 3)
604 func TestGetCountGnbListSdlgoFailure(t *testing.T) {
605 errMsg := "expected Sdlgo error"
606 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
608 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
610 e := errors.New(errMsg)
612 sdlInstanceMock.On("GroupSize", GnbType).Return(count, e)
613 count, er := w.GetCountGnbList()
615 assert.Equal(t, 0, count)
616 assert.Equal(t, 2, er.GetCode())
617 assert.EqualValues(t, errMsgExpected, er.Error())
620 func TestGetCell(t *testing.T) {
624 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
626 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: &entities.ServedCellInfo{Pci: pci}}}
627 cellData, err := proto.Marshal(&cellEntity)
629 t.Errorf("#rNibReader_test.TestGetCell - Failed to marshal Cell entity. Error: %v", err)
632 key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
634 t.Errorf("#rNibReader_test.TestGetCell - failed to validate key parameter")
636 ret := map[string]interface{}{key: string(cellData)}
637 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
638 cell, er := w.GetCell(name, pci)
640 assert.NotNil(t, cell)
641 assert.Equal(t, cell.Type, entities.Cell_LTE_CELL)
642 assert.NotNil(t, cell.GetServedCellInfo())
643 assert.Equal(t, cell.GetServedCellInfo().GetPci(), pci)
646 func TestGetCellNotFoundFailure(t *testing.T) {
650 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
653 var ret map[string]interface{}
654 key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
656 t.Errorf("#rNibReader_test.TestGetCellNotFoundFailure - failed to validate key parameter")
658 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
659 cell, er := w.GetCell(name, pci)
662 assert.Equal(t, 1, er.GetCode())
663 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getCellByKey - cell not found, key: PCI:name:00", er.Error())
666 func TestGetCellUnmarshalFailure(t *testing.T) {
670 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
673 ret := make(map[string]interface{}, 1)
674 key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
676 t.Errorf("#rNibReader_test.TestGetCellUnmarshalFailure - failed to validate key parameter")
679 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
680 cell, er := w.GetCell(name, pci)
683 assert.Equal(t, 2, er.GetCode())
684 assert.EqualValues(t, "2 INTERNAL_ERROR - proto: can't skip unknown wire type 4", er.Error())
687 func TestGetCellSdlgoFailure(t *testing.T) {
690 errMsg := "expected Sdlgo error"
691 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
693 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
695 e := errors.New(errMsg)
696 var ret map[string]interface{}
697 key, rNibErr := common.ValidateAndBuildCellNamePciKey(name, pci)
699 t.Errorf("#rNibReader_test.TestGetCellSdlgoFailure - failed to validate key parameter")
701 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
702 cell, er := w.GetCell(name, pci)
705 assert.Equal(t, 2, er.GetCode())
706 assert.EqualValues(t, errMsgExpected, er.Error())
709 func TestGetNodebById(t *testing.T) {
711 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
713 nb := entities.NodebInfo{NodeType: entities.Node_ENB}
714 nb.ConnectionStatus = 1
717 enb := entities.Enb{}
718 cell := entities.ServedCellInfo{Tac: "tac"}
719 enb.ServedCells = []*entities.ServedCellInfo{&cell}
720 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
722 data, err := proto.Marshal(&nb)
724 t.Errorf("#rNibReader_test.TestGetNodebById - Failed to marshal ENB instance. Error: %v", err)
729 key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
731 t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
733 ret := map[string]interface{}{key: string(data)}
734 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
735 globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
736 getNb, er := w.GetNodebByGlobalNbId(entities.Node_ENB, globalNbId)
738 assert.Equal(t, getNb.Ip, nb.Ip)
739 assert.Equal(t, getNb.Port, nb.Port)
740 assert.Equal(t, getNb.ConnectionStatus, nb.ConnectionStatus)
741 assert.Len(t, getNb.GetEnb().GetServedCells(), 1)
742 assert.Equal(t, getNb.GetEnb().GetServedCells()[0].Tac, nb.GetEnb().GetServedCells()[0].Tac)
745 func TestGetNodebByIdNotFoundFailureEnb(t *testing.T) {
749 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
752 key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
754 t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
756 var ret map[string]interface{}
757 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
758 globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
759 getNb, er := w.GetNodebByGlobalNbId(entities.Node_ENB, globalNbId)
762 assert.Equal(t, 1, er.GetCode())
763 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: ENB:02f829:4a952a0a", er.Error())
766 func TestGetNodebByIdNotFoundFailureGnb(t *testing.T) {
770 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
773 key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_GNB.String(), plmnId, nbId)
775 t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
777 var ret map[string]interface{}
778 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
779 globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
780 getNb, er := w.GetNodebByGlobalNbId(entities.Node_GNB, globalNbId)
783 assert.Equal(t, 1, er.GetCode())
784 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getNodeb - responding node not found. Key: GNB:02f829:4a952a0a", er.Error())
787 func TestGetNodeByIdUnmarshalFailure(t *testing.T) {
791 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
793 key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_ENB.String(), plmnId, nbId)
795 t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
798 ret := make(map[string]interface{}, 1)
800 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
801 globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
802 getNb, er := w.GetNodebByGlobalNbId(entities.Node_ENB, globalNbId)
805 assert.Equal(t, 2, er.GetCode())
806 assert.EqualValues(t, "2 INTERNAL_ERROR - proto: can't skip unknown wire type 4", er.Error())
809 func TestGetNodeByIdSdlgoFailure(t *testing.T) {
812 errMsg := "expected Sdlgo error"
813 errMsgExpected := "2 INTERNAL_ERROR - expected Sdlgo error"
815 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
817 key, rNibErr := common.ValidateAndBuildNodeBIdKey(entities.Node_GNB.String(), plmnId, nbId)
819 t.Errorf("Failed to validate nodeb identity, plmnId: %s, nbId: %s", plmnId, nbId)
821 e := errors.New(errMsg)
822 var ret map[string]interface{}
823 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
824 globalNbId := &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
825 getNb, er := w.GetNodebByGlobalNbId(entities.Node_GNB, globalNbId)
828 assert.Equal(t, 2, er.GetCode())
829 assert.EqualValues(t, errMsgExpected, er.Error())
832 func TestGetCellById(t *testing.T) {
836 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
838 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: &entities.ServedCellInfo{Pci: pci}}}
839 cellData, err := proto.Marshal(&cellEntity)
841 t.Errorf("#rNibReader_test.TestGetCellById - Failed to marshal Cell entity. Error: %v", err)
844 key, rNibErr := common.ValidateAndBuildCellIdKey(cellId)
846 t.Errorf("#rNibReader_test.TestGetCellById - failed to validate key parameter")
848 ret := map[string]interface{}{key: string(cellData)}
849 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
850 cell, er := w.GetCellById(entities.Cell_LTE_CELL, cellId)
852 assert.NotNil(t, cell)
853 assert.Equal(t, cell.Type, entities.Cell_LTE_CELL)
854 assert.NotNil(t, cell.GetServedCellInfo())
855 assert.Equal(t, cell.GetServedCellInfo().GetPci(), pci)
858 func TestGetCellByIdNotFoundFailureEnb(t *testing.T) {
861 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
864 var ret map[string]interface{}
865 key, rNibErr := common.ValidateAndBuildCellIdKey(cellId)
867 t.Errorf("#rNibReader_test.TestGetCellByIdNotFoundFailure - failed to validate key parameter")
869 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
870 cell, er := w.GetCellById(entities.Cell_LTE_CELL, cellId)
873 assert.Equal(t, 1, er.GetCode())
874 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getCellByKey - cell not found, key: CELL:bbbb", er.Error())
877 func TestGetCellByIdNotFoundFailureGnb(t *testing.T) {
880 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
883 var ret map[string]interface{}
884 key, rNibErr := common.ValidateAndBuildNrCellIdKey(cellId)
886 t.Errorf("#rNibReader_test.TestGetCellByIdNotFoundFailure - failed to validate key parameter")
888 sdlInstanceMock.On("Get", []string{key}).Return(ret, e)
889 cell, er := w.GetCellById(entities.Cell_NR_CELL, cellId)
892 assert.Equal(t, 1, er.GetCode())
893 assert.EqualValues(t, "1 RESOURCE_NOT_FOUND - #rNibReader.getCellByKey - cell not found, key: NRCELL:bbbb", er.Error())
896 func TestGetCellByIdTypeValidationFailure(t *testing.T) {
899 initSdlInstanceMock(namespace, 1)
901 cell, er := w.GetCellById(5, cellId)
904 assert.Equal(t, 3, er.GetCode())
905 assert.EqualValues(t, "3 VALIDATION_ERROR - #rNibReader.GetCellById - invalid cell type: 5", er.Error())
908 func TestGetCellByIdValidationFailureGnb(t *testing.T) {
911 initSdlInstanceMock(namespace, 1)
913 cell, er := w.GetCellById(entities.Cell_NR_CELL, cellId)
916 assert.Equal(t, 3, er.GetCode())
917 assert.EqualValues(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNrCellIdKey - an empty cell id received", er.Error())
920 func TestGetCellByIdValidationFailureEnb(t *testing.T) {
923 initSdlInstanceMock(namespace, 1)
925 cell, er := w.GetCellById(entities.Cell_LTE_CELL, cellId)
928 assert.Equal(t, 3, er.GetCode())
929 assert.EqualValues(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", er.Error())
934 //func TestGetEnbInteg(t *testing.T){
935 // name := "nameEnb1"
936 // Init("namespace", 1)
937 // w := GetRNibReader()
938 // nb, err := w.GetNodeb(name)
942 // fmt.Printf("#TestGetEnbInteg - responding node type: %v\n", nb)
946 //func TestGetEnbCellsInteg(t *testing.T){
947 // name := "nameEnb1"
948 // Init("namespace", 1)
949 // w := GetRNibReader()
950 // cells, err := w.GetCellList(name)
953 // } else if cells != nil{
954 // for _, cell := range cells.GetServedCellInfos().ServedCells{
955 // fmt.Printf("responding node type Cell: %v\n", *cell)
960 //func TestGetGnbInteg(t *testing.T){
961 // name := "nameGnb1"
962 // Init("namespace", 1)
963 // w := GetRNibReader()
964 // nb, err := w.GetNodeb(name)
968 // fmt.Printf("#TestGetGnbInteg - responding node type: %v\n", nb)
972 //func TestGetGnbCellsInteg(t *testing.T){
973 // name := "nameGnb1"
974 // Init("namespace", 1)
975 // w := GetRNibReader()
976 // cells, err := w.GetCellList(name)
979 // } else if cells != nil{
980 // for _, cell := range cells.GetServedNrCells().ServedCells{
981 // fmt.Printf("responding node type NR Cell: %v\n", *cell)
986 //func TestGetListEnbIdsInteg(t *testing.T) {
987 // Init("namespace", 1)
988 // w := GetRNibReader()
989 // ids, err := w.GetListEnbIds()
993 // for _, id := range *ids{
994 // fmt.Printf("#TestGetListEnbIdsInteg - ENB ID: %s\n", id)
999 //func TestGetListGnbIdsInteg(t *testing.T) {
1000 // Init("namespace", 1)
1001 // w := GetRNibReader()
1002 // ids, err := w.GetListGnbIds()
1006 // for _, id := range *ids{
1007 // fmt.Printf("#TestGetListGnbIdsInteg - GNB ID: %s\n", id)
1012 //func TestGetCountGnbListInteg(t *testing.T) {
1013 // Init("namespace", 1)
1014 // w := GetRNibReader()
1015 // count, err := w.GetCountGnbList()
1019 // fmt.Printf("#TestGetCountGnbListInteg - count Gnb list: %d\n", count)
1023 //func TestGetGnbCellInteg(t *testing.T){
1024 // name := "nameGnb7"
1026 // Init("namespace", 1)
1027 // w := GetRNibReader()
1028 // cell, err := w.GetCell(name, uint32(pci))
1031 // } else if cell != nil{
1032 // fmt.Printf("responding node type NR Cell: %v\n", cell.GetServedNrCell())
1036 //func TestGetEnbCellInteg(t *testing.T) {
1037 // name := "nameEnb1"
1039 // Init("namespace", 1)
1040 // w := GetRNibReader()
1041 // cell, err := w.GetCell(name, uint32(pci))
1044 // } else if cell != nil {
1045 // fmt.Printf("responding node type LTE Cell: %v\n", cell.GetServedCellInfo())
1049 //func TestGetEnbCellByIdInteg(t *testing.T){
1050 // Init("namespace", 1)
1051 // w := GetRNibReader()
1052 // cell, err := w.GetCellById(entities.Cell_NR_CELL, "45d")
1055 // } else if cell != nil{
1056 // fmt.Printf("responding node type NR Cell: %v\n", cell.GetServedNrCell())