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).
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"
36 func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
37 sdlInstanceMock = new(mocks.MockSdlInstance)
38 w = GetRNibWriter(sdlInstanceMock)
42 var namespace = "namespace"
44 func TestUpdateNodebInfoSuccess(t *testing.T) {
45 inventoryName := "name"
48 w, sdlInstanceMock := initSdlInstanceMock(namespace)
49 nodebInfo := &entities.NodebInfo{}
50 nodebInfo.RanName = inventoryName
51 nodebInfo.GlobalNbId = &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
52 nodebInfo.NodeType = entities.Node_ENB
53 nodebInfo.ConnectionStatus = 1
55 nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
56 data, err := proto.Marshal(nodebInfo)
58 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
61 var setExpected []interface{}
63 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
64 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
65 setExpected = append(setExpected, nodebNameKey, data)
66 setExpected = append(setExpected, nodebIdKey, data)
68 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
70 rNibErr := w.UpdateNodebInfo(nodebInfo)
71 assert.Nil(t, rNibErr)
74 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
75 inventoryName := "name"
78 w, sdlInstanceMock := initSdlInstanceMock(namespace)
79 nodebInfo := &entities.NodebInfo{}
80 data, err := proto.Marshal(nodebInfo)
82 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
85 var setExpected []interface{}
87 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
88 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
89 setExpected = append(setExpected, nodebNameKey, data)
90 setExpected = append(setExpected, nodebIdKey, data)
92 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
94 rNibErr := w.UpdateNodebInfo(nodebInfo)
96 assert.NotNil(t, rNibErr)
97 assert.IsType(t, &common.ValidationError{}, rNibErr)
100 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
101 inventoryName := "name"
102 w, sdlInstanceMock := initSdlInstanceMock(namespace)
103 nodebInfo := &entities.NodebInfo{}
104 nodebInfo.RanName = inventoryName
105 data, err := proto.Marshal(nodebInfo)
107 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
110 var setExpected []interface{}
112 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
113 setExpected = append(setExpected, nodebNameKey, data)
114 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
116 rNibErr := w.UpdateNodebInfo(nodebInfo)
118 assert.Nil(t, rNibErr)
121 func TestSaveEnb(t *testing.T) {
123 ranName := "RAN:" + name
124 w, sdlInstanceMock := initSdlInstanceMock(namespace)
125 nb := entities.NodebInfo{}
126 nb.NodeType = entities.Node_ENB
127 nb.ConnectionStatus = 1
130 enb := entities.Enb{}
131 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
132 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
133 enb.ServedCells = []*entities.ServedCellInfo{cell}
134 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
135 data, err := proto.Marshal(&nb)
137 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
141 cellData, err := proto.Marshal(&cellEntity)
143 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
145 var setExpected []interface{}
146 setExpected = append(setExpected, ranName, data)
147 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
148 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
149 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
151 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
153 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
155 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
157 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
159 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
160 nbIdData, err = proto.Marshal(nbIdentity)
162 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
164 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
166 rNibErr := w.SaveNodeb(nbIdentity, &nb)
167 assert.Nil(t, rNibErr)
170 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
172 w, _ := initSdlInstanceMock(namespace)
173 nb := entities.NodebInfo{}
174 nb.NodeType = entities.Node_ENB
175 nb.ConnectionStatus = 1
178 enb := entities.Enb{}
179 cell := &entities.ServedCellInfo{Pci: 3}
180 enb.ServedCells = []*entities.ServedCellInfo{cell}
181 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
183 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
184 rNibErr := w.SaveNodeb(nbIdentity, &nb)
185 assert.NotNil(t, rNibErr)
186 assert.IsType(t, &common.ValidationError{}, rNibErr)
187 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
190 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
191 w, _ := initSdlInstanceMock(namespace)
192 nb := entities.NodebInfo{}
193 nb.NodeType = entities.Node_ENB
194 nb.ConnectionStatus = 1
197 enb := entities.Enb{}
198 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
199 enb.ServedCells = []*entities.ServedCellInfo{cell}
200 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
202 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
203 rNibErr := w.SaveNodeb(nbIdentity, &nb)
204 assert.NotNil(t, rNibErr)
205 assert.IsType(t, &common.ValidationError{}, rNibErr)
206 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
209 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
211 w, _ := initSdlInstanceMock(namespace)
212 nb := entities.NodebInfo{}
213 nb.NodeType = entities.Node_GNB
214 nb.ConnectionStatus = 1
217 gnb := entities.Gnb{}
218 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
219 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
220 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
221 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
223 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
224 rNibErr := w.SaveNodeb(nbIdentity, &nb)
225 assert.NotNil(t, rNibErr)
226 assert.IsType(t, &common.ValidationError{}, rNibErr)
227 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
230 func TestSaveGnb(t *testing.T) {
232 ranName := "RAN:" + name
233 w, sdlInstanceMock := initSdlInstanceMock(namespace)
234 nb := entities.NodebInfo{}
235 nb.NodeType = entities.Node_GNB
236 nb.ConnectionStatus = 1
239 gnb := entities.Gnb{}
240 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
241 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
242 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
243 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
244 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
245 data, err := proto.Marshal(&nb)
247 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
251 cellData, err := proto.Marshal(&cellEntity)
253 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
255 var setExpected []interface{}
256 setExpected = append(setExpected, ranName, data)
257 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
258 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
259 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
261 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
262 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
263 nbIdData, err := proto.Marshal(nbIdentity)
265 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
267 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
269 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
271 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
273 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
275 rNibErr := w.SaveNodeb(nbIdentity, &nb)
276 assert.Nil(t, rNibErr)
279 func TestSaveRanLoadInformationSuccess(t *testing.T) {
280 inventoryName := "name"
281 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
283 if validationErr != nil {
284 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
287 w, sdlInstanceMock := initSdlInstanceMock(namespace)
289 ranLoadInformation := generateRanLoadInformation()
290 data, err := proto.Marshal(ranLoadInformation)
293 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
297 var setExpected []interface{}
298 setExpected = append(setExpected, loadKey, data)
299 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
301 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
302 assert.Nil(t, rNibErr)
305 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
306 inventoryName := "name2"
307 w, _ := initSdlInstanceMock(namespace)
309 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
310 err := w.SaveRanLoadInformation(inventoryName, nil)
311 assert.Equal(t, expectedErr, err)
314 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
316 w, _ := initSdlInstanceMock(namespace)
318 err := w.SaveRanLoadInformation(inventoryName, nil)
319 assert.NotNil(t, err)
320 assert.IsType(t, &common.ValidationError{}, err)
323 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
324 inventoryName := "name2"
326 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
328 if validationErr != nil {
329 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
332 w, sdlInstanceMock := initSdlInstanceMock(namespace)
334 ranLoadInformation := generateRanLoadInformation()
335 data, err := proto.Marshal(ranLoadInformation)
338 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
341 expectedErr := errors.New("expected error")
342 var setExpected []interface{}
343 setExpected = append(setExpected, loadKey, data)
344 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
346 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
347 assert.NotNil(t, rNibErr)
348 assert.IsType(t, &common.InternalError{}, rNibErr)
351 func generateCellLoadInformation() *entities.CellLoadInformation {
352 cellLoadInformation := entities.CellLoadInformation{}
354 cellLoadInformation.CellId = "123"
356 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
357 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
359 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
361 UlHighInterferenceIndication: "xxx",
364 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
366 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
368 RntpThreshold: entities.RntpThreshold_NEG_4,
369 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
371 PdcchInterferenceImpact: 2,
372 EnhancedRntp: &entities.EnhancedRntp{
373 EnhancedRntpBitmap: "xxx",
374 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
375 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
379 cellLoadInformation.AbsInformation = &entities.AbsInformation{
380 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
381 AbsPatternInfo: "xxx",
382 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
383 MeasurementSubset: "xxx",
386 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
388 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
389 AssociatedSubframes: "xxx",
390 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
393 compInformationItem := &entities.CompInformationItem{
394 CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis: "xxx"}},
398 cellLoadInformation.CompInformation = &entities.CompInformation{
399 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
400 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
403 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
404 State: entities.NaicsState_NAICS_ACTIVE,
405 TransmissionModes: "xxx",
407 PAList: []entities.PA{entities.PA_DB_NEG_3},
410 return &cellLoadInformation
413 func generateRanLoadInformation() *entities.RanLoadInformation {
414 ranLoadInformation := entities.RanLoadInformation{}
416 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
418 cellLoadInformation := generateCellLoadInformation()
419 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
421 return &ranLoadInformation
424 func TestSaveNilEntityFailure(t *testing.T) {
425 w, _ := initSdlInstanceMock(namespace)
426 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
427 nbIdentity := &entities.NbIdentity{}
428 actualErr := w.SaveNodeb(nbIdentity, nil)
429 assert.Equal(t, expectedErr, actualErr)
432 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
433 w, _ := initSdlInstanceMock(namespace)
434 expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")
435 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
436 nb := &entities.NodebInfo{}
439 actualErr := w.SaveNodeb(nbIdentity, nb)
440 assert.Equal(t, expectedErr, actualErr)
443 func TestSaveEntityFailure(t *testing.T) {
448 w, sdlInstanceMock := initSdlInstanceMock(namespace)
449 gnb := entities.NodebInfo{}
450 gnb.NodeType = entities.Node_GNB
451 data, err := proto.Marshal(&gnb)
453 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
455 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
456 setExpected := []interface{}{"RAN:" + name, data}
457 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
458 expectedErr := errors.New("expected error")
459 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
460 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
461 assert.NotEmpty(t, rNibErr)
464 func TestGetRNibWriter(t *testing.T) {
465 received, _ := initSdlInstanceMock(namespace)
466 assert.NotEmpty(t, received)
469 func TestSaveE2TInstanceSuccess(t *testing.T) {
470 address := "10.10.2.15:9800"
471 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
473 if validationErr != nil {
474 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
477 w, sdlInstanceMock := initSdlInstanceMock(namespace)
479 e2tInstance := generateE2tInstance(address)
480 data, err := json.Marshal(e2tInstance)
483 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
487 var setExpected []interface{}
488 setExpected = append(setExpected, loadKey, data)
489 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
491 rNibErr := w.SaveE2TInstance(e2tInstance)
492 assert.Nil(t, rNibErr)
495 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
496 w, _ := initSdlInstanceMock(namespace)
498 e2tInstance := entities.NewE2TInstance(address)
499 err := w.SaveE2TInstance(e2tInstance)
500 assert.NotNil(t, err)
501 assert.IsType(t, &common.ValidationError{}, err)
504 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
505 address := "10.10.2.15:9800"
506 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
508 if validationErr != nil {
509 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
512 w, sdlInstanceMock := initSdlInstanceMock(namespace)
514 e2tInstance := generateE2tInstance(address)
515 data, err := json.Marshal(e2tInstance)
518 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
521 expectedErr := errors.New("expected error")
522 var setExpected []interface{}
523 setExpected = append(setExpected, loadKey, data)
524 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
526 rNibErr := w.SaveE2TInstance(e2tInstance)
527 assert.NotNil(t, rNibErr)
528 assert.IsType(t, &common.InternalError{}, rNibErr)
531 func generateE2tInstance(address string) *entities.E2TInstance {
532 e2tInstance := entities.NewE2TInstance(address)
534 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
539 func TestSaveE2TAddressesSuccess(t *testing.T) {
540 address := "10.10.2.15:9800"
541 w, sdlInstanceMock := initSdlInstanceMock(namespace)
543 e2tAddresses := []string{address}
544 data, err := json.Marshal(e2tAddresses)
547 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
551 var setExpected []interface{}
552 setExpected = append(setExpected, E2TAddressesKey, data)
553 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
555 rNibErr := w.SaveE2TAddresses(e2tAddresses)
556 assert.Nil(t, rNibErr)
559 func TestSaveE2TAddressesSdlFailure(t *testing.T) {
560 address := "10.10.2.15:9800"
561 w, sdlInstanceMock := initSdlInstanceMock(namespace)
563 e2tAddresses := []string{address}
564 data, err := json.Marshal(e2tAddresses)
567 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
570 expectedErr := errors.New("expected error")
571 var setExpected []interface{}
572 setExpected = append(setExpected, E2TAddressesKey, data)
573 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
575 rNibErr := w.SaveE2TAddresses(e2tAddresses)
576 assert.NotNil(t, rNibErr)
577 assert.IsType(t, &common.InternalError{}, rNibErr)
580 func TestRemoveE2TInstanceSuccess(t *testing.T) {
581 address := "10.10.2.15:9800"
582 w, sdlInstanceMock := initSdlInstanceMock(namespace)
584 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
586 sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
588 rNibErr := w.RemoveE2TInstance(address)
589 assert.Nil(t, rNibErr)
590 sdlInstanceMock.AssertExpectations(t)
593 func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
594 address := "10.10.2.15:9800"
595 w, sdlInstanceMock := initSdlInstanceMock(namespace)
597 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
598 expectedErr := errors.New("expected error")
599 sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
601 rNibErr := w.RemoveE2TInstance(address)
602 assert.IsType(t, &common.InternalError{}, rNibErr)
605 func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
606 w, sdlInstanceMock := initSdlInstanceMock(namespace)
608 rNibErr := w.RemoveE2TInstance("")
609 assert.IsType(t, &common.ValidationError{}, rNibErr)
610 sdlInstanceMock.AssertExpectations(t)
615 //func TestSaveEnbGnbInteg(t *testing.T){
616 // for i := 0; i<10; i++{
617 // Init("e2Manager", 1)
618 // w := GetRNibWriter()
619 // nb := entities.NodebInfo{}
620 // nb.NodeType = entities.Node_ENB
621 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
622 // nb.Ip = "localhost"
623 // nb.Port = uint32(5656 + i)
624 // enb := entities.Enb{}
625 // cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
626 // cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
627 // cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
628 // enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
629 // nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
630 // plmnId := 0x02f828
631 // nbId := 0x4a952a0a
632 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
633 // err := w.SaveNodeb(nbIdentity, &nb)
635 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
638 // nb1 := entities.NodebInfo{}
639 // nb1.NodeType = entities.Node_GNB
640 // nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
641 // nb1.Ip = "localhost"
642 // nb1.Port = uint32(6565 + i)
643 // gnb := entities.Gnb{}
644 // gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
645 // gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
646 // gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
647 // gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
648 // nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
649 // nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
650 // err = w.SaveNodeb(nbIdentity, &nb1)
652 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
657 //func TestSaveNbRanNamesInteg(t *testing.T){
658 // for i := 0; i<10; i++{
659 // Init("e2Manager", 1)
660 // w := GetRNibWriter()
661 // nb := entities.NodebInfo{}
662 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
663 // nb.Ip = "localhost"
664 // nb.Port = uint32(5656 + i)
665 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
666 // err := w.SaveNodeb(nbIdentity, &nb)
668 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
673 //func TestSaveRanLoadInformationInteg(t *testing.T){
674 // Init("e2Manager", 1)
675 // w := GetRNibWriter()
676 // ranLoadInformation := generateRanLoadInformation()
677 // err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
679 // t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)