blob: ec21c3f9228d0701ae44d660089bd600ec6209db [file] [log] [blame]
ss412g07ef76d2019-08-12 17:26:40 +03001//
2// Copyright 2019 AT&T Intellectual Property
3// Copyright 2019 Nokia
4//
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
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
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.
nm755n15d39822019-11-28 16:56:00 +000016
17// This source code is part of the near-RT RIC (RAN Intelligent Controller)
18// platform project (RICP).
19
ss412g07ef76d2019-08-12 17:26:40 +030020package rNibWriter
21
22import (
ss412g07ef76d2019-08-12 17:26:40 +030023 "e2mgr/mocks"
ss412gefcb4522019-12-02 16:59:19 +020024 "encoding/json"
ss412g07ef76d2019-08-12 17:26:40 +030025 "errors"
26 "fmt"
is005q19bf35e2019-08-12 18:59:29 +030027 "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"
ss412g07ef76d2019-08-12 17:26:40 +030029 "github.com/golang/protobuf/proto"
ss412g07ef76d2019-08-12 17:26:40 +030030 "github.com/stretchr/testify/assert"
31 "testing"
32 "time"
33)
34
idanshal08bbf912020-04-20 17:11:33 +030035var namespace = "namespace"
idanshald916e2a2020-04-22 15:56:43 +030036const (
37 RanName = "test"
38)
idanshal08bbf912020-04-20 17:11:33 +030039
ss412gefcb4522019-12-02 16:59:19 +020040func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
41 sdlInstanceMock = new(mocks.MockSdlInstance)
42 w = GetRNibWriter(sdlInstanceMock)
43 return
ss412g07ef76d2019-08-12 17:26:40 +030044}
45
idanshal08bbf912020-04-20 17:11:33 +030046func 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},
50 NodeType: nodeType,
51 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
52 }
53
54 if nodeType == entities.Node_ENB {
55 nodebInfo.Configuration = &entities.NodebInfo_Enb{
56 Enb: &entities.Enb{},
57 }
58 } else if nodeType == entities.Node_GNB {
59 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
60 Gnb: &entities.Gnb{},
61 }
62 }
63
64 return nodebInfo
65}
66
67func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
68
69 servedNrCells := []*entities.ServedNRCell{}
70
idanshald916e2a2020-04-22 15:56:43 +030071 for i, v := range cellIds {
idanshal08bbf912020-04-20 17:11:33 +030072 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
73 CellId: v,
74 ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
75 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
76
77 },
78 },
79 NrMode: entities.Nr_FDD,
idanshald916e2a2020-04-22 15:56:43 +030080 NrPci: uint32(i + 1),
idanshal08bbf912020-04-20 17:11:33 +030081 ServedPlmns: []string{"whatever"},
82 }})
83 }
84
85 return servedNrCells
86}
87
idanshald916e2a2020-04-22 15:56:43 +030088func 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)
93 assert.Nil(t, err)
94}
95
96func 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)
102}
103
idanshal08bbf912020-04-20 17:11:33 +0300104func 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)
111}
112
113func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
114 inventoryName := "name"
115 plmnId := "02f829"
116 nbId := "4a952a0a"
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)
124}
125
126func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
127
128 nodebInfoData, err := proto.Marshal(nodebInfo)
129 if err != nil {
130 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
131 }
132
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}
136
137 for _, v := range servedNrCells {
138
139 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
140 cellData, err := proto.Marshal(&cellEntity)
141
142 if err != nil {
143 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
144 }
145
146 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
147 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
148 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
149 }
150
151 return setExpected
152}
153
154func TestUpdateGnbCellsSdlFailure(t *testing.T) {
155 inventoryName := "name"
156 plmnId := "02f829"
157 nbId := "4a952a0a"
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)
166}
167
168func TestUpdateGnbCellsSuccess(t *testing.T) {
169 inventoryName := "name"
170 plmnId := "02f829"
171 nbId := "4a952a0a"
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)
177 var e error
178 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
179 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
180 assert.Nil(t, rNibErr)
181}
ss412g07ef76d2019-08-12 17:26:40 +0300182
is005q19e72a52019-08-26 17:56:18 +0300183func TestUpdateNodebInfoSuccess(t *testing.T) {
184 inventoryName := "name"
185 plmnId := "02f829"
186 nbId := "4a952a0a"
ss412gefcb4522019-12-02 16:59:19 +0200187 w, sdlInstanceMock := initSdlInstanceMock(namespace)
idanshal08bbf912020-04-20 17:11:33 +0300188 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
is005q19e72a52019-08-26 17:56:18 +0300189 data, err := proto.Marshal(nodebInfo)
190 if err != nil {
191 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
192 }
193 var e error
194 var setExpected []interface{}
195
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)
200
201 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
202
203 rNibErr := w.UpdateNodebInfo(nodebInfo)
204 assert.Nil(t, rNibErr)
205}
206
207func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
208 inventoryName := "name"
209 plmnId := "02f829"
210 nbId := "4a952a0a"
ss412gefcb4522019-12-02 16:59:19 +0200211 w, sdlInstanceMock := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300212 nodebInfo := &entities.NodebInfo{}
213 data, err := proto.Marshal(nodebInfo)
214 if err != nil {
215 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
216 }
217 var e error
218 var setExpected []interface{}
219
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)
224
225 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
226
227 rNibErr := w.UpdateNodebInfo(nodebInfo)
228
229 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300230 assert.IsType(t, &common.ValidationError{}, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300231}
232
is005q26473192019-08-28 17:51:37 +0300233func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
is005q19e72a52019-08-26 17:56:18 +0300234 inventoryName := "name"
ss412gefcb4522019-12-02 16:59:19 +0200235 w, sdlInstanceMock := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300236 nodebInfo := &entities.NodebInfo{}
237 nodebInfo.RanName = inventoryName
238 data, err := proto.Marshal(nodebInfo)
239 if err != nil {
240 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
241 }
242 var e error
243 var setExpected []interface{}
244
245 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
is005q19e72a52019-08-26 17:56:18 +0300246 setExpected = append(setExpected, nodebNameKey, data)
is005q19e72a52019-08-26 17:56:18 +0300247 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
248
249 rNibErr := w.UpdateNodebInfo(nodebInfo)
250
is005q26473192019-08-28 17:51:37 +0300251 assert.Nil(t, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300252}
253
ss412g07ef76d2019-08-12 17:26:40 +0300254func TestSaveEnb(t *testing.T) {
255 name := "name"
256 ranName := "RAN:" + name
ss412gefcb4522019-12-02 16:59:19 +0200257 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300258 nb := entities.NodebInfo{}
259 nb.NodeType = entities.Node_ENB
260 nb.ConnectionStatus = 1
261 nb.Ip = "localhost"
262 nb.Port = 5656
263 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300264 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
265 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
ss412g07ef76d2019-08-12 17:26:40 +0300266 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300267 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300268 data, err := proto.Marshal(&nb)
269 if err != nil {
270 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
271 }
272 var e error
273
274 cellData, err := proto.Marshal(&cellEntity)
275 if err != nil {
276 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
277 }
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)
283
284 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300285
286 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
287 if err != nil {
288 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
289 }
290 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
291
is005q19e72a52019-08-26 17:56:18 +0300292 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ns019t57c3fae2019-08-12 20:08:49 +0300293 nbIdData, err = proto.Marshal(nbIdentity)
ss412g07ef76d2019-08-12 17:26:40 +0300294 if err != nil {
295 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
296 }
297 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300298
ss412g07ef76d2019-08-12 17:26:40 +0300299 rNibErr := w.SaveNodeb(nbIdentity, &nb)
300 assert.Nil(t, rNibErr)
301}
302
303func TestSaveEnbCellIdValidationFailure(t *testing.T) {
304 name := "name"
ss412gefcb4522019-12-02 16:59:19 +0200305 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300306 nb := entities.NodebInfo{}
307 nb.NodeType = entities.Node_ENB
308 nb.ConnectionStatus = 1
309 nb.Ip = "localhost"
310 nb.Port = 5656
311 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300312 cell := &entities.ServedCellInfo{Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300313 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300314 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300315
is005q19e72a52019-08-26 17:56:18 +0300316 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300317 rNibErr := w.SaveNodeb(nbIdentity, &nb)
318 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300319 assert.IsType(t, &common.ValidationError{}, rNibErr)
320 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300321}
322
323func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200324 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300325 nb := entities.NodebInfo{}
326 nb.NodeType = entities.Node_ENB
327 nb.ConnectionStatus = 1
328 nb.Ip = "localhost"
329 nb.Port = 5656
330 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300331 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300332 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300333 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300334
is005q19e72a52019-08-26 17:56:18 +0300335 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300336 rNibErr := w.SaveNodeb(nbIdentity, &nb)
337 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300338 assert.IsType(t, &common.ValidationError{}, rNibErr)
339 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300340}
341
ss412g07ef76d2019-08-12 17:26:40 +0300342func TestSaveGnbCellIdValidationFailure(t *testing.T) {
343 name := "name"
ss412gefcb4522019-12-02 16:59:19 +0200344 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300345 nb := entities.NodebInfo{}
346 nb.NodeType = entities.Node_GNB
347 nb.ConnectionStatus = 1
348 nb.Ip = "localhost"
349 nb.Port = 5656
350 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300351 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
352 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
ss412g07ef76d2019-08-12 17:26:40 +0300353 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
is005q19e72a52019-08-26 17:56:18 +0300354 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
ss412g07ef76d2019-08-12 17:26:40 +0300355
is005q19e72a52019-08-26 17:56:18 +0300356 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300357 rNibErr := w.SaveNodeb(nbIdentity, &nb)
358 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300359 assert.IsType(t, &common.ValidationError{}, rNibErr)
360 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300361}
362
363func TestSaveGnb(t *testing.T) {
364 name := "name"
365 ranName := "RAN:" + name
ss412gefcb4522019-12-02 16:59:19 +0200366 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300367 nb := entities.NodebInfo{}
368 nb.NodeType = entities.Node_GNB
369 nb.ConnectionStatus = 1
370 nb.Ip = "localhost"
371 nb.Port = 5656
372 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300373 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}}
ss412g07ef76d2019-08-12 17:26:40 +0300376 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
is005q19e72a52019-08-26 17:56:18 +0300377 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
ss412g07ef76d2019-08-12 17:26:40 +0300378 data, err := proto.Marshal(&nb)
379 if err != nil {
380 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
381 }
382 var e error
383
ss412g07ef76d2019-08-12 17:26:40 +0300384 cellData, err := proto.Marshal(&cellEntity)
385 if err != nil {
386 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
387 }
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)
393
394 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
is005q19e72a52019-08-26 17:56:18 +0300395 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300396 nbIdData, err := proto.Marshal(nbIdentity)
397 if err != nil {
398 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
399 }
400 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
401
ns019t57c3fae2019-08-12 20:08:49 +0300402 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
403 if err != nil {
404 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
405 }
406 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
407
ss412g07ef76d2019-08-12 17:26:40 +0300408 rNibErr := w.SaveNodeb(nbIdentity, &nb)
409 assert.Nil(t, rNibErr)
410}
411
412func TestSaveRanLoadInformationSuccess(t *testing.T) {
413 inventoryName := "name"
414 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
415
416 if validationErr != nil {
417 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
418 }
419
ss412gefcb4522019-12-02 16:59:19 +0200420 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300421
ss412g07ef76d2019-08-12 17:26:40 +0300422 ranLoadInformation := generateRanLoadInformation()
423 data, err := proto.Marshal(ranLoadInformation)
424
425 if err != nil {
426 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
427 }
428
429 var e error
430 var setExpected []interface{}
431 setExpected = append(setExpected, loadKey, data)
432 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
433
ss412g07ef76d2019-08-12 17:26:40 +0300434 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
435 assert.Nil(t, rNibErr)
436}
437
438func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
439 inventoryName := "name2"
ss412gefcb4522019-12-02 16:59:19 +0200440 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300441
442 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
is005q19e72a52019-08-26 17:56:18 +0300443 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300444 assert.Equal(t, expectedErr, err)
445}
446
447func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
448 inventoryName := ""
ss412gefcb4522019-12-02 16:59:19 +0200449 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300450
is005q19e72a52019-08-26 17:56:18 +0300451 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300452 assert.NotNil(t, err)
irina006fbce2019-09-05 16:11:02 +0300453 assert.IsType(t, &common.ValidationError{}, err)
ss412g07ef76d2019-08-12 17:26:40 +0300454}
455
456func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
457 inventoryName := "name2"
458
459 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
460
461 if validationErr != nil {
462 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
463 }
464
ss412gefcb4522019-12-02 16:59:19 +0200465 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300466
467 ranLoadInformation := generateRanLoadInformation()
468 data, err := proto.Marshal(ranLoadInformation)
469
470 if err != nil {
471 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
472 }
473
ss412g07ef76d2019-08-12 17:26:40 +0300474 expectedErr := errors.New("expected error")
475 var setExpected []interface{}
476 setExpected = append(setExpected, loadKey, data)
477 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
478
ss412g07ef76d2019-08-12 17:26:40 +0300479 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
480 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300481 assert.IsType(t, &common.InternalError{}, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300482}
483
484func generateCellLoadInformation() *entities.CellLoadInformation {
485 cellLoadInformation := entities.CellLoadInformation{}
486
487 cellLoadInformation.CellId = "123"
488
489 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
490 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
491
492 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
is005q19e72a52019-08-26 17:56:18 +0300493 TargetCellId: "456",
494 UlHighInterferenceIndication: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300495 }
496
is005q19e72a52019-08-26 17:56:18 +0300497 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
ss412g07ef76d2019-08-12 17:26:40 +0300498
499 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
is005q19e72a52019-08-26 17:56:18 +0300500 RntpPerPrb: "xxx",
501 RntpThreshold: entities.RntpThreshold_NEG_4,
ss412g07ef76d2019-08-12 17:26:40 +0300502 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
is005q19e72a52019-08-26 17:56:18 +0300503 PB: 1,
504 PdcchInterferenceImpact: 2,
ss412g07ef76d2019-08-12 17:26:40 +0300505 EnhancedRntp: &entities.EnhancedRntp{
is005q19e72a52019-08-26 17:56:18 +0300506 EnhancedRntpBitmap: "xxx",
507 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
508 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
ss412g07ef76d2019-08-12 17:26:40 +0300509 },
510 }
511
512 cellLoadInformation.AbsInformation = &entities.AbsInformation{
is005q19e72a52019-08-26 17:56:18 +0300513 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
514 AbsPatternInfo: "xxx",
515 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
516 MeasurementSubset: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300517 }
518
519 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
520
521 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
is005q19e72a52019-08-26 17:56:18 +0300522 AssociatedSubframes: "xxx",
523 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
ss412g07ef76d2019-08-12 17:26:40 +0300524 }
525
526 compInformationItem := &entities.CompInformationItem{
idanshal08bbf912020-04-20 17:11:33 +0300527 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
is005q19e72a52019-08-26 17:56:18 +0300528 BenefitMetric: 50,
ss412g07ef76d2019-08-12 17:26:40 +0300529 }
530
531 cellLoadInformation.CompInformation = &entities.CompInformation{
is005q19e72a52019-08-26 17:56:18 +0300532 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
533 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
ss412g07ef76d2019-08-12 17:26:40 +0300534 }
535
536 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
is005q19e72a52019-08-26 17:56:18 +0300537 State: entities.NaicsState_NAICS_ACTIVE,
538 TransmissionModes: "xxx",
539 PB: 2,
540 PAList: []entities.PA{entities.PA_DB_NEG_3},
ss412g07ef76d2019-08-12 17:26:40 +0300541 }
542
543 return &cellLoadInformation
544}
545
546func generateRanLoadInformation() *entities.RanLoadInformation {
547 ranLoadInformation := entities.RanLoadInformation{}
548
is005q19bf35e2019-08-12 18:59:29 +0300549 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
ss412g07ef76d2019-08-12 17:26:40 +0300550
551 cellLoadInformation := generateCellLoadInformation()
552 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
553
554 return &ranLoadInformation
555}
556
557func TestSaveNilEntityFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200558 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300559 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)
563}
564
565func TestSaveUnknownTypeEntityFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200566 w, _ := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300567 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300568 nb := &entities.NodebInfo{}
569 nb.Port = 5656
570 nb.Ip = "localhost"
571 actualErr := w.SaveNodeb(nbIdentity, nb)
ss412ga07b8592020-06-16 21:51:33 +0300572 assert.IsType(t, &common.ValidationError{}, actualErr)
ss412g07ef76d2019-08-12 17:26:40 +0300573}
574
575func TestSaveEntityFailure(t *testing.T) {
576 name := "name"
577 plmnId := "02f829"
578 nbId := "4a952a0a"
579
ss412gefcb4522019-12-02 16:59:19 +0200580 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300581 gnb := entities.NodebInfo{}
582 gnb.NodeType = entities.Node_GNB
583 data, err := proto.Marshal(&gnb)
584 if err != nil {
585 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
586 }
is005q19e72a52019-08-26 17:56:18 +0300587 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
ss412g07ef76d2019-08-12 17:26:40 +0300588 setExpected := []interface{}{"RAN:" + name, data}
is005q19e72a52019-08-26 17:56:18 +0300589 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
ss412g07ef76d2019-08-12 17:26:40 +0300590 expectedErr := errors.New("expected error")
591 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
592 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
593 assert.NotEmpty(t, rNibErr)
594}
595
ss412g07ef76d2019-08-12 17:26:40 +0300596func TestGetRNibWriter(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200597 received, _ := initSdlInstanceMock(namespace)
598 assert.NotEmpty(t, received)
ss412g07ef76d2019-08-12 17:26:40 +0300599}
600
ss412gefcb4522019-12-02 16:59:19 +0200601func TestSaveE2TInstanceSuccess(t *testing.T) {
602 address := "10.10.2.15:9800"
603 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
604
605 if validationErr != nil {
606 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
607 }
608
609 w, sdlInstanceMock := initSdlInstanceMock(namespace)
610
611 e2tInstance := generateE2tInstance(address)
612 data, err := json.Marshal(e2tInstance)
613
614 if err != nil {
615 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
616 }
617
ss412g07ef76d2019-08-12 17:26:40 +0300618 var e error
ss412gefcb4522019-12-02 16:59:19 +0200619 var setExpected []interface{}
620 setExpected = append(setExpected, loadKey, data)
621 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
622
623 rNibErr := w.SaveE2TInstance(e2tInstance)
624 assert.Nil(t, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300625}
626
ss412gefcb4522019-12-02 16:59:19 +0200627func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
628 w, _ := initSdlInstanceMock(namespace)
629 var address string
Irina49144462020-04-07 16:37:20 +0300630 e2tInstance := entities.NewE2TInstance(address, "test")
ss412gefcb4522019-12-02 16:59:19 +0200631 err := w.SaveE2TInstance(e2tInstance)
632 assert.NotNil(t, err)
633 assert.IsType(t, &common.ValidationError{}, err)
634}
635
636func TestSaveE2TInstanceSdlFailure(t *testing.T) {
637 address := "10.10.2.15:9800"
638 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
639
640 if validationErr != nil {
641 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
642 }
643
644 w, sdlInstanceMock := initSdlInstanceMock(namespace)
645
646 e2tInstance := generateE2tInstance(address)
647 data, err := json.Marshal(e2tInstance)
648
649 if err != nil {
650 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
651 }
652
653 expectedErr := errors.New("expected error")
654 var setExpected []interface{}
655 setExpected = append(setExpected, loadKey, data)
656 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
657
658 rNibErr := w.SaveE2TInstance(e2tInstance)
659 assert.NotNil(t, rNibErr)
660 assert.IsType(t, &common.InternalError{}, rNibErr)
661}
662
663func generateE2tInstance(address string) *entities.E2TInstance {
Irina49144462020-04-07 16:37:20 +0300664 e2tInstance := entities.NewE2TInstance(address, "pod test")
ss412gefcb4522019-12-02 16:59:19 +0200665
666 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
667
668 return e2tInstance
669}
670
671func TestSaveE2TAddressesSuccess(t *testing.T) {
672 address := "10.10.2.15:9800"
673 w, sdlInstanceMock := initSdlInstanceMock(namespace)
674
675 e2tAddresses := []string{address}
676 data, err := json.Marshal(e2tAddresses)
677
678 if err != nil {
679 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
680 }
681
ss412g07ef76d2019-08-12 17:26:40 +0300682 var e error
ss412gefcb4522019-12-02 16:59:19 +0200683 var setExpected []interface{}
684 setExpected = append(setExpected, E2TAddressesKey, data)
685 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
686
687 rNibErr := w.SaveE2TAddresses(e2tAddresses)
688 assert.Nil(t, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300689}
690
ss412gefcb4522019-12-02 16:59:19 +0200691func TestSaveE2TAddressesSdlFailure(t *testing.T) {
692 address := "10.10.2.15:9800"
693 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300694
ss412gefcb4522019-12-02 16:59:19 +0200695 e2tAddresses := []string{address}
696 data, err := json.Marshal(e2tAddresses)
697
698 if err != nil {
699 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
700 }
701
702 expectedErr := errors.New("expected error")
703 var setExpected []interface{}
704 setExpected = append(setExpected, E2TAddressesKey, data)
705 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
706
707 rNibErr := w.SaveE2TAddresses(e2tAddresses)
708 assert.NotNil(t, rNibErr)
709 assert.IsType(t, &common.InternalError{}, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300710}
711
Amichaif846c592020-01-08 16:45:07 +0200712func TestRemoveE2TInstanceSuccess(t *testing.T) {
713 address := "10.10.2.15:9800"
714 w, sdlInstanceMock := initSdlInstanceMock(namespace)
715
716 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
717 var e error
718 sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
719
720 rNibErr := w.RemoveE2TInstance(address)
721 assert.Nil(t, rNibErr)
722 sdlInstanceMock.AssertExpectations(t)
723}
724
725func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
726 address := "10.10.2.15:9800"
727 w, sdlInstanceMock := initSdlInstanceMock(namespace)
728
729 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
730 expectedErr := errors.New("expected error")
731 sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
732
733 rNibErr := w.RemoveE2TInstance(address)
734 assert.IsType(t, &common.InternalError{}, rNibErr)
735}
736
737func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
738 w, sdlInstanceMock := initSdlInstanceMock(namespace)
739
740 rNibErr := w.RemoveE2TInstance("")
741 assert.IsType(t, &common.ValidationError{}, rNibErr)
742 sdlInstanceMock.AssertExpectations(t)
743}
744
ss412ga07b8592020-06-16 21:51:33 +0300745func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
746 inventoryName := "name"
747 plmnId := "02f829"
748 nbId := "4a952a0a"
749 channelName := "RAN_CONNECT_STATE_CHANGE"
750 eventName := inventoryName + "_" + "CONNECTED"
751 w, sdlInstanceMock := initSdlInstanceMock(namespace)
752 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
753 data, err := proto.Marshal(nodebInfo)
754 if err != nil {
755 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
756 }
757 var e error
758 var setExpected []interface{}
759
760 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
761 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
762 setExpected = append(setExpected, nodebNameKey, data)
763 setExpected = append(setExpected, nodebIdKey, data)
764
idanshal1766b712020-06-22 12:41:02 +0300765 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300766
767 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
768 assert.Nil(t, rNibErr)
769}
770
771func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
772 inventoryName := "name"
773 plmnId := "02f829"
774 nbId := "4a952a0a"
775 channelName := "RAN_CONNECT_STATE_CHANGE"
776 eventName := inventoryName + "_" + "CONNECTED"
777 w, sdlInstanceMock := initSdlInstanceMock(namespace)
778 nodebInfo := &entities.NodebInfo{}
779 data, err := proto.Marshal(nodebInfo)
780 if err != nil {
781 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
782 }
783 var e error
784 var setExpected []interface{}
785
786 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
787 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
788 setExpected = append(setExpected, nodebNameKey, data)
789 setExpected = append(setExpected, nodebIdKey, data)
790
idanshal1766b712020-06-22 12:41:02 +0300791 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300792
793 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
794
795 assert.NotNil(t, rNibErr)
796 assert.IsType(t, &common.ValidationError{}, rNibErr)
797}
798
799func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) {
800 inventoryName := "name"
801 channelName := "RAN_CONNECT_STATE_CHANGE"
802 eventName := inventoryName + "_" + "CONNECTED"
803 w, sdlInstanceMock := initSdlInstanceMock(namespace)
804 nodebInfo := &entities.NodebInfo{}
805 nodebInfo.RanName = inventoryName
806 data, err := proto.Marshal(nodebInfo)
807 if err != nil {
808 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
809 }
810 var e error
811 var setExpected []interface{}
812
813 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
814 setExpected = append(setExpected, nodebNameKey, data)
idanshal1766b712020-06-22 12:41:02 +0300815 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300816
817 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
818
819 assert.Nil(t, rNibErr)
820}
821
822func TestSaveGeneralConfiguration(t *testing.T) {
823 w, sdlInstanceMock := initSdlInstanceMock(namespace)
824
825 key := common.BuildGeneralConfigurationKey()
826 configurationData := "{\"enableRic\":true}"
827 configuration := &entities.GeneralConfiguration{}
828 configuration.EnableRic = true
829
830 sdlInstanceMock.On("Set",[]interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
831 rNibErr := w.SaveGeneralConfiguration(configuration)
832
833 assert.Nil(t, rNibErr)
834 sdlInstanceMock.AssertExpectations(t)
835}
836
837func TestSaveGeneralConfigurationDbError(t *testing.T) {
838 w, sdlInstanceMock := initSdlInstanceMock(namespace)
839
840 key := common.BuildGeneralConfigurationKey()
841 configurationData := "{\"enableRic\":true}"
842 configuration := &entities.GeneralConfiguration{}
843 configuration.EnableRic = true
844
845 expectedErr := errors.New("expected error")
846
847 sdlInstanceMock.On("Set",[]interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
848 rNibErr := w.SaveGeneralConfiguration(configuration)
849
850 assert.NotNil(t, rNibErr)
851}
852
ss412g07ef76d2019-08-12 17:26:40 +0300853//Integration tests
854//
ns019t57c3fae2019-08-12 20:08:49 +0300855//func TestSaveEnbGnbInteg(t *testing.T){
ss412g07ef76d2019-08-12 17:26:40 +0300856// for i := 0; i<10; i++{
857// Init("e2Manager", 1)
858// w := GetRNibWriter()
859// nb := entities.NodebInfo{}
860// nb.NodeType = entities.Node_ENB
861// nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
862// nb.Ip = "localhost"
863// nb.Port = uint32(5656 + i)
864// enb := entities.Enb{}
865// cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
866// cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
867// cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
868// enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
869// nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
870// plmnId := 0x02f828
871// nbId := 0x4a952a0a
ss412ga07b8592020-06-16 21:51:33 +0300872// nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
ss412g07ef76d2019-08-12 17:26:40 +0300873// err := w.SaveNodeb(nbIdentity, &nb)
874// if err != nil{
875// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
876// }
877//
878// nb1 := entities.NodebInfo{}
879// nb1.NodeType = entities.Node_GNB
ns019t57c3fae2019-08-12 20:08:49 +0300880// nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
ss412g07ef76d2019-08-12 17:26:40 +0300881// nb1.Ip = "localhost"
882// nb1.Port = uint32(6565 + i)
883// gnb := entities.Gnb{}
884// gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
885// gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
886// gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
887// gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
888// nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
ss412ga07b8592020-06-16 21:51:33 +0300889// nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
ss412g07ef76d2019-08-12 17:26:40 +0300890// err = w.SaveNodeb(nbIdentity, &nb1)
891// if err != nil{
892// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
893// }
894// }
895//}
ns019t57c3fae2019-08-12 20:08:49 +0300896//
897//func TestSaveNbRanNamesInteg(t *testing.T){
898// for i := 0; i<10; i++{
899// Init("e2Manager", 1)
900// w := GetRNibWriter()
901// nb := entities.NodebInfo{}
902// nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
903// nb.Ip = "localhost"
904// nb.Port = uint32(5656 + i)
905// nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
906// err := w.SaveNodeb(nbIdentity, &nb)
907// if err != nil{
908// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
909// }
910// }
911//}
912//
ss412g07ef76d2019-08-12 17:26:40 +0300913//func TestSaveRanLoadInformationInteg(t *testing.T){
914// Init("e2Manager", 1)
915// w := GetRNibWriter()
916// ranLoadInformation := generateRanLoadInformation()
917// err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
918// if err != nil{
919// t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)
920// }
is005q19e72a52019-08-26 17:56:18 +0300921//}