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.
25 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
27 "github.com/golang/protobuf/proto"
28 "github.com/stretchr/testify/assert"
33 func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
34 sdlInstanceMock = new(mocks.MockSdlInstance)
35 w = GetRNibWriter(sdlInstanceMock)
39 var namespace = "namespace"
41 func TestUpdateNodebInfoSuccess(t *testing.T) {
42 inventoryName := "name"
45 w, sdlInstanceMock := initSdlInstanceMock(namespace)
46 nodebInfo := &entities.NodebInfo{}
47 nodebInfo.RanName = inventoryName
48 nodebInfo.GlobalNbId = &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
49 nodebInfo.NodeType = entities.Node_ENB
50 nodebInfo.ConnectionStatus = 1
52 nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
53 data, err := proto.Marshal(nodebInfo)
55 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
58 var setExpected []interface{}
60 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
61 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
62 setExpected = append(setExpected, nodebNameKey, data)
63 setExpected = append(setExpected, nodebIdKey, data)
65 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
67 rNibErr := w.UpdateNodebInfo(nodebInfo)
68 assert.Nil(t, rNibErr)
71 func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
72 inventoryName := "name"
75 w, sdlInstanceMock := initSdlInstanceMock(namespace)
76 nodebInfo := &entities.NodebInfo{}
77 data, err := proto.Marshal(nodebInfo)
79 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
82 var setExpected []interface{}
84 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
85 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
86 setExpected = append(setExpected, nodebNameKey, data)
87 setExpected = append(setExpected, nodebIdKey, data)
89 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
91 rNibErr := w.UpdateNodebInfo(nodebInfo)
93 assert.NotNil(t, rNibErr)
94 assert.IsType(t, &common.ValidationError{}, rNibErr)
97 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
98 inventoryName := "name"
99 w, sdlInstanceMock := initSdlInstanceMock(namespace)
100 nodebInfo := &entities.NodebInfo{}
101 nodebInfo.RanName = inventoryName
102 data, err := proto.Marshal(nodebInfo)
104 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
107 var setExpected []interface{}
109 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
110 setExpected = append(setExpected, nodebNameKey, data)
111 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
113 rNibErr := w.UpdateNodebInfo(nodebInfo)
115 assert.Nil(t, rNibErr)
118 func TestSaveEnb(t *testing.T) {
120 ranName := "RAN:" + name
121 w, sdlInstanceMock := initSdlInstanceMock(namespace)
122 nb := entities.NodebInfo{}
123 nb.NodeType = entities.Node_ENB
124 nb.ConnectionStatus = 1
127 enb := entities.Enb{}
128 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
129 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
130 enb.ServedCells = []*entities.ServedCellInfo{cell}
131 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
132 data, err := proto.Marshal(&nb)
134 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
138 cellData, err := proto.Marshal(&cellEntity)
140 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
142 var setExpected []interface{}
143 setExpected = append(setExpected, ranName, data)
144 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
145 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
146 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
148 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
150 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
152 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
154 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
156 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
157 nbIdData, err = proto.Marshal(nbIdentity)
159 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
161 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
163 rNibErr := w.SaveNodeb(nbIdentity, &nb)
164 assert.Nil(t, rNibErr)
167 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
169 w, _ := initSdlInstanceMock(namespace)
170 nb := entities.NodebInfo{}
171 nb.NodeType = entities.Node_ENB
172 nb.ConnectionStatus = 1
175 enb := entities.Enb{}
176 cell := &entities.ServedCellInfo{Pci: 3}
177 enb.ServedCells = []*entities.ServedCellInfo{cell}
178 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
180 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
181 rNibErr := w.SaveNodeb(nbIdentity, &nb)
182 assert.NotNil(t, rNibErr)
183 assert.IsType(t, &common.ValidationError{}, rNibErr)
184 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
187 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
188 w, _ := initSdlInstanceMock(namespace)
189 nb := entities.NodebInfo{}
190 nb.NodeType = entities.Node_ENB
191 nb.ConnectionStatus = 1
194 enb := entities.Enb{}
195 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
196 enb.ServedCells = []*entities.ServedCellInfo{cell}
197 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
199 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
200 rNibErr := w.SaveNodeb(nbIdentity, &nb)
201 assert.NotNil(t, rNibErr)
202 assert.IsType(t, &common.ValidationError{}, rNibErr)
203 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
206 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
208 w, _ := initSdlInstanceMock(namespace)
209 nb := entities.NodebInfo{}
210 nb.NodeType = entities.Node_GNB
211 nb.ConnectionStatus = 1
214 gnb := entities.Gnb{}
215 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
216 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
217 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
218 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
220 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
221 rNibErr := w.SaveNodeb(nbIdentity, &nb)
222 assert.NotNil(t, rNibErr)
223 assert.IsType(t, &common.ValidationError{}, rNibErr)
224 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
227 func TestSaveGnb(t *testing.T) {
229 ranName := "RAN:" + name
230 w, sdlInstanceMock := initSdlInstanceMock(namespace)
231 nb := entities.NodebInfo{}
232 nb.NodeType = entities.Node_GNB
233 nb.ConnectionStatus = 1
236 gnb := entities.Gnb{}
237 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
238 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
239 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
240 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
241 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
242 data, err := proto.Marshal(&nb)
244 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
248 cellData, err := proto.Marshal(&cellEntity)
250 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
252 var setExpected []interface{}
253 setExpected = append(setExpected, ranName, data)
254 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
255 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
256 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
258 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
259 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
260 nbIdData, err := proto.Marshal(nbIdentity)
262 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
264 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
266 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
268 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
270 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
272 rNibErr := w.SaveNodeb(nbIdentity, &nb)
273 assert.Nil(t, rNibErr)
276 func TestSaveRanLoadInformationSuccess(t *testing.T) {
277 inventoryName := "name"
278 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
280 if validationErr != nil {
281 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
284 w, sdlInstanceMock := initSdlInstanceMock(namespace)
286 ranLoadInformation := generateRanLoadInformation()
287 data, err := proto.Marshal(ranLoadInformation)
290 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
294 var setExpected []interface{}
295 setExpected = append(setExpected, loadKey, data)
296 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
298 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
299 assert.Nil(t, rNibErr)
302 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
303 inventoryName := "name2"
304 w, _ := initSdlInstanceMock(namespace)
306 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
307 err := w.SaveRanLoadInformation(inventoryName, nil)
308 assert.Equal(t, expectedErr, err)
311 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
313 w, _ := initSdlInstanceMock(namespace)
315 err := w.SaveRanLoadInformation(inventoryName, nil)
316 assert.NotNil(t, err)
317 assert.IsType(t, &common.ValidationError{}, err)
320 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
321 inventoryName := "name2"
323 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
325 if validationErr != nil {
326 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
329 w, sdlInstanceMock := initSdlInstanceMock(namespace)
331 ranLoadInformation := generateRanLoadInformation()
332 data, err := proto.Marshal(ranLoadInformation)
335 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
338 expectedErr := errors.New("expected error")
339 var setExpected []interface{}
340 setExpected = append(setExpected, loadKey, data)
341 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
343 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
344 assert.NotNil(t, rNibErr)
345 assert.IsType(t, &common.InternalError{}, rNibErr)
348 func generateCellLoadInformation() *entities.CellLoadInformation {
349 cellLoadInformation := entities.CellLoadInformation{}
351 cellLoadInformation.CellId = "123"
353 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
354 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
356 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
358 UlHighInterferenceIndication: "xxx",
361 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
363 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
365 RntpThreshold: entities.RntpThreshold_NEG_4,
366 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
368 PdcchInterferenceImpact: 2,
369 EnhancedRntp: &entities.EnhancedRntp{
370 EnhancedRntpBitmap: "xxx",
371 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
372 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
376 cellLoadInformation.AbsInformation = &entities.AbsInformation{
377 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
378 AbsPatternInfo: "xxx",
379 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
380 MeasurementSubset: "xxx",
383 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
385 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
386 AssociatedSubframes: "xxx",
387 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
390 compInformationItem := &entities.CompInformationItem{
391 CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis: "xxx"}},
395 cellLoadInformation.CompInformation = &entities.CompInformation{
396 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
397 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
400 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
401 State: entities.NaicsState_NAICS_ACTIVE,
402 TransmissionModes: "xxx",
404 PAList: []entities.PA{entities.PA_DB_NEG_3},
407 return &cellLoadInformation
410 func generateRanLoadInformation() *entities.RanLoadInformation {
411 ranLoadInformation := entities.RanLoadInformation{}
413 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
415 cellLoadInformation := generateCellLoadInformation()
416 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
418 return &ranLoadInformation
421 func TestSaveNilEntityFailure(t *testing.T) {
422 w, _ := initSdlInstanceMock(namespace)
423 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
424 nbIdentity := &entities.NbIdentity{}
425 actualErr := w.SaveNodeb(nbIdentity, nil)
426 assert.Equal(t, expectedErr, actualErr)
429 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
430 w, _ := initSdlInstanceMock(namespace)
431 expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")
432 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
433 nb := &entities.NodebInfo{}
436 actualErr := w.SaveNodeb(nbIdentity, nb)
437 assert.Equal(t, expectedErr, actualErr)
440 func TestSaveEntityFailure(t *testing.T) {
445 w, sdlInstanceMock := initSdlInstanceMock(namespace)
446 gnb := entities.NodebInfo{}
447 gnb.NodeType = entities.Node_GNB
448 data, err := proto.Marshal(&gnb)
450 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
452 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
453 setExpected := []interface{}{"RAN:" + name, data}
454 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
455 expectedErr := errors.New("expected error")
456 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
457 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
458 assert.NotEmpty(t, rNibErr)
461 func TestGetRNibWriter(t *testing.T) {
462 received, _ := initSdlInstanceMock(namespace)
463 assert.NotEmpty(t, received)
468 //func TestSaveEnbGnbInteg(t *testing.T){
469 // for i := 0; i<10; i++{
470 // Init("e2Manager", 1)
471 // w := GetRNibWriter()
472 // nb := entities.NodebInfo{}
473 // nb.NodeType = entities.Node_ENB
474 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
475 // nb.Ip = "localhost"
476 // nb.Port = uint32(5656 + i)
477 // enb := entities.Enb{}
478 // cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
479 // cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
480 // cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
481 // enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
482 // nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
483 // plmnId := 0x02f828
484 // nbId := 0x4a952a0a
485 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
486 // err := w.SaveNodeb(nbIdentity, &nb)
488 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
491 // nb1 := entities.NodebInfo{}
492 // nb1.NodeType = entities.Node_GNB
493 // nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
494 // nb1.Ip = "localhost"
495 // nb1.Port = uint32(6565 + i)
496 // gnb := entities.Gnb{}
497 // gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
498 // gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
499 // gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
500 // gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
501 // nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
502 // nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
503 // err = w.SaveNodeb(nbIdentity, &nb1)
505 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
510 //func TestSaveNbRanNamesInteg(t *testing.T){
511 // for i := 0; i<10; i++{
512 // Init("e2Manager", 1)
513 // w := GetRNibWriter()
514 // nb := entities.NodebInfo{}
515 // nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
516 // nb.Ip = "localhost"
517 // nb.Port = uint32(5656 + i)
518 // nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
519 // err := w.SaveNodeb(nbIdentity, &nb)
521 // t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
526 //func TestSaveRanLoadInformationInteg(t *testing.T){
527 // Init("e2Manager", 1)
528 // w := GetRNibWriter()
529 // ranLoadInformation := generateRanLoadInformation()
530 // err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
532 // t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)
536 func TestSaveE2TInstanceSuccess(t *testing.T) {
537 address := "10.10.2.15:9800"
538 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
540 if validationErr != nil {
541 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
544 w, sdlInstanceMock := initSdlInstanceMock(namespace)
546 e2tInstance := generateE2tInstance(address)
547 data, err := json.Marshal(e2tInstance)
550 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
554 var setExpected []interface{}
555 setExpected = append(setExpected, loadKey, data)
556 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
558 rNibErr := w.SaveE2TInstance(e2tInstance)
559 assert.Nil(t, rNibErr)
562 func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
563 w, _ := initSdlInstanceMock(namespace)
565 e2tInstance := entities.NewE2TInstance(address)
566 err := w.SaveE2TInstance(e2tInstance)
567 assert.NotNil(t, err)
568 assert.IsType(t, &common.ValidationError{}, err)
571 func TestSaveE2TInstanceSdlFailure(t *testing.T) {
572 address := "10.10.2.15:9800"
573 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
575 if validationErr != nil {
576 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
579 w, sdlInstanceMock := initSdlInstanceMock(namespace)
581 e2tInstance := generateE2tInstance(address)
582 data, err := json.Marshal(e2tInstance)
585 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
588 expectedErr := errors.New("expected error")
589 var setExpected []interface{}
590 setExpected = append(setExpected, loadKey, data)
591 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
593 rNibErr := w.SaveE2TInstance(e2tInstance)
594 assert.NotNil(t, rNibErr)
595 assert.IsType(t, &common.InternalError{}, rNibErr)
598 func generateE2tInstance(address string) *entities.E2TInstance {
599 e2tInstance := entities.NewE2TInstance(address)
601 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
606 func TestSaveE2TInfoListSuccess(t *testing.T) {
607 address := "10.10.2.15:9800"
608 w, sdlInstanceMock := initSdlInstanceMock(namespace)
610 e2tAddresses := []string{address}
611 data, err := json.Marshal(e2tAddresses)
614 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
618 var setExpected []interface{}
619 setExpected = append(setExpected, E2TAddressesKey, data)
620 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
622 rNibErr := w.SaveE2TAddresses(e2tAddresses)
623 assert.Nil(t, rNibErr)
626 func TestSaveE2TInfoListSdlFailure(t *testing.T) {
627 address := "10.10.2.15:9800"
628 w, sdlInstanceMock := initSdlInstanceMock(namespace)
630 e2tAddresses := []string{address}
631 data, err := json.Marshal(e2tAddresses)
634 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
637 expectedErr := errors.New("expected error")
638 var setExpected []interface{}
639 setExpected = append(setExpected, E2TAddressesKey, data)
640 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
642 rNibErr := w.SaveE2TAddresses(e2tAddresses)
643 assert.NotNil(t, rNibErr)
644 assert.IsType(t, &common.InternalError{}, rNibErr)