blob: 069e509ef9722f37b28fede78fd7e5e1cc3497fa [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 (
Idan Shalom14eb5132020-07-06 09:41:46 +000023 "e2mgr/configuration"
ss412g07ef76d2019-08-12 17:26:40 +030024 "e2mgr/mocks"
ss412gefcb4522019-12-02 16:59:19 +020025 "encoding/json"
ss412g07ef76d2019-08-12 17:26:40 +030026 "errors"
27 "fmt"
is005q19bf35e2019-08-12 18:59:29 +030028 "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"
ss412g07ef76d2019-08-12 17:26:40 +030030 "github.com/golang/protobuf/proto"
ss412g07ef76d2019-08-12 17:26:40 +030031 "github.com/stretchr/testify/assert"
32 "testing"
33 "time"
34)
35
idanshal08bbf912020-04-20 17:11:33 +030036var namespace = "namespace"
Idan Shalom14eb5132020-07-06 09:41:46 +000037
idanshald916e2a2020-04-22 15:56:43 +030038const (
39 RanName = "test"
40)
idanshal08bbf912020-04-20 17:11:33 +030041
ss412gefcb4522019-12-02 16:59:19 +020042func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
43 sdlInstanceMock = new(mocks.MockSdlInstance)
Idan Shalom14eb5132020-07-06 09:41:46 +000044 w = GetRNibWriter(sdlInstanceMock, configuration.RnibWriterConfig{StateChangeMessageChannel: "RAN_CONNECTION_STATUS_CHANGE", RanManipulationMessageChannel: "RAN_MANIPULATION"})
ss412gefcb4522019-12-02 16:59:19 +020045 return
ss412g07ef76d2019-08-12 17:26:40 +030046}
47
idanshal08bbf912020-04-20 17:11:33 +030048func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo {
49 nodebInfo := &entities.NodebInfo{
50 RanName: inventoryName,
51 GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId},
52 NodeType: nodeType,
53 ConnectionStatus: entities.ConnectionStatus_CONNECTED,
54 }
55
56 if nodeType == entities.Node_ENB {
57 nodebInfo.Configuration = &entities.NodebInfo_Enb{
58 Enb: &entities.Enb{},
59 }
60 } else if nodeType == entities.Node_GNB {
61 nodebInfo.Configuration = &entities.NodebInfo_Gnb{
62 Gnb: &entities.Gnb{},
63 }
64 }
65
66 return nodebInfo
67}
68
69func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
70
Irina5830d4d2020-07-08 18:11:04 +000071 var servedNrCells []*entities.ServedNRCell
idanshal08bbf912020-04-20 17:11:33 +030072
idanshald916e2a2020-04-22 15:56:43 +030073 for i, v := range cellIds {
idanshal08bbf912020-04-20 17:11:33 +030074 servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
75 CellId: v,
76 ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
77 Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
78
79 },
80 },
81 NrMode: entities.Nr_FDD,
idanshald916e2a2020-04-22 15:56:43 +030082 NrPci: uint32(i + 1),
idanshal08bbf912020-04-20 17:11:33 +030083 ServedPlmns: []string{"whatever"},
84 }})
85 }
86
87 return servedNrCells
88}
89
Irina5830d4d2020-07-08 18:11:04 +000090func generateServedCells(cellIds ...string) []*entities.ServedCellInfo {
91
92 var servedCells []*entities.ServedCellInfo
93
94 for i, v := range cellIds {
95 servedCells = append(servedCells, &entities.ServedCellInfo{
96 CellId: v,
97 ChoiceEutraMode: &entities.ChoiceEUTRAMode{
98 Fdd: &entities.FddInfo{},
99 },
100 Pci: uint32(i + 1),
101 BroadcastPlmns: []string{"whatever"},
102 })
103 }
104
105 return servedCells
106}
107
idanshald916e2a2020-04-22 15:56:43 +0300108func TestRemoveServedNrCellsSuccess(t *testing.T) {
109 w, sdlInstanceMock := initSdlInstanceMock(namespace)
110 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
Amichai7e2e4932020-07-07 15:49:07 +0000111 sdlInstanceMock.On("Remove", buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil)
Irina5830d4d2020-07-08 18:11:04 +0000112
idanshald916e2a2020-04-22 15:56:43 +0300113 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
114 assert.Nil(t, err)
115}
116
117func TestRemoveServedNrCellsFailure(t *testing.T) {
118 w, sdlInstanceMock := initSdlInstanceMock(namespace)
119 servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
Amichai7e2e4932020-07-07 15:49:07 +0000120 sdlInstanceMock.On("Remove", buildServedNRCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error"))
Irina5830d4d2020-07-08 18:11:04 +0000121
idanshald916e2a2020-04-22 15:56:43 +0300122 err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
123 assert.IsType(t, &common.InternalError{}, err)
124}
125
idanshal08bbf912020-04-20 17:11:33 +0300126func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
127 w, sdlInstanceMock := initSdlInstanceMock(namespace)
128 servedNrCells := generateServedNrCells("test1", "test2")
129 nodebInfo := &entities.NodebInfo{}
130 sdlInstanceMock.AssertNotCalled(t, "Set")
131 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
132 assert.IsType(t, &common.ValidationError{}, rNibErr)
133}
134
135func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
136 inventoryName := "name"
137 plmnId := "02f829"
138 nbId := "4a952a0a"
139 w, sdlInstanceMock := initSdlInstanceMock(namespace)
140 servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
141 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
142 nodebInfo.GetGnb().ServedNrCells = servedNrCells
143 sdlInstanceMock.AssertNotCalled(t, "Set")
144 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
145 assert.IsType(t, &common.ValidationError{}, rNibErr)
146}
147
148func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
149
150 nodebInfoData, err := proto.Marshal(nodebInfo)
151 if err != nil {
152 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
153 }
154
155 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
156 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
157 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
158
159 for _, v := range servedNrCells {
160
161 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
162 cellData, err := proto.Marshal(&cellEntity)
163
164 if err != nil {
165 t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
166 }
167
168 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
169 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
170 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
171 }
172
173 return setExpected
174}
175
176func TestUpdateGnbCellsSdlFailure(t *testing.T) {
177 inventoryName := "name"
178 plmnId := "02f829"
179 nbId := "4a952a0a"
180 w, sdlInstanceMock := initSdlInstanceMock(namespace)
181 servedNrCells := generateServedNrCells("test1", "test2")
182 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
183 nodebInfo.GetGnb().ServedNrCells = servedNrCells
184 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
185 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(errors.New("expected error"))
186 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
187 assert.IsType(t, &common.InternalError{}, rNibErr)
188}
189
190func TestUpdateGnbCellsSuccess(t *testing.T) {
191 inventoryName := "name"
192 plmnId := "02f829"
193 nbId := "4a952a0a"
194 w, sdlInstanceMock := initSdlInstanceMock(namespace)
195 servedNrCells := generateServedNrCells("test1", "test2")
196 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
197 nodebInfo.GetGnb().ServedNrCells = servedNrCells
198 setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
199 var e error
200 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
201 rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
202 assert.Nil(t, rNibErr)
203}
ss412g07ef76d2019-08-12 17:26:40 +0300204
is005q19e72a52019-08-26 17:56:18 +0300205func TestUpdateNodebInfoSuccess(t *testing.T) {
206 inventoryName := "name"
207 plmnId := "02f829"
208 nbId := "4a952a0a"
ss412gefcb4522019-12-02 16:59:19 +0200209 w, sdlInstanceMock := initSdlInstanceMock(namespace)
idanshal08bbf912020-04-20 17:11:33 +0300210 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
is005q19e72a52019-08-26 17:56:18 +0300211 data, err := proto.Marshal(nodebInfo)
212 if err != nil {
213 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
214 }
215 var e error
216 var setExpected []interface{}
217
218 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
219 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
220 setExpected = append(setExpected, nodebNameKey, data)
221 setExpected = append(setExpected, nodebIdKey, data)
222
223 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
224
225 rNibErr := w.UpdateNodebInfo(nodebInfo)
226 assert.Nil(t, rNibErr)
227}
228
229func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
230 inventoryName := "name"
231 plmnId := "02f829"
232 nbId := "4a952a0a"
ss412gefcb4522019-12-02 16:59:19 +0200233 w, sdlInstanceMock := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300234 nodebInfo := &entities.NodebInfo{}
235 data, err := proto.Marshal(nodebInfo)
236 if err != nil {
237 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
238 }
239 var e error
240 var setExpected []interface{}
241
242 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
243 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
244 setExpected = append(setExpected, nodebNameKey, data)
245 setExpected = append(setExpected, nodebIdKey, data)
246
247 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
248
249 rNibErr := w.UpdateNodebInfo(nodebInfo)
250
251 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300252 assert.IsType(t, &common.ValidationError{}, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300253}
254
is005q26473192019-08-28 17:51:37 +0300255func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
is005q19e72a52019-08-26 17:56:18 +0300256 inventoryName := "name"
ss412gefcb4522019-12-02 16:59:19 +0200257 w, sdlInstanceMock := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300258 nodebInfo := &entities.NodebInfo{}
259 nodebInfo.RanName = inventoryName
260 data, err := proto.Marshal(nodebInfo)
261 if err != nil {
262 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
263 }
264 var e error
265 var setExpected []interface{}
266
267 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
is005q19e72a52019-08-26 17:56:18 +0300268 setExpected = append(setExpected, nodebNameKey, data)
is005q19e72a52019-08-26 17:56:18 +0300269 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
270
271 rNibErr := w.UpdateNodebInfo(nodebInfo)
272
is005q26473192019-08-28 17:51:37 +0300273 assert.Nil(t, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300274}
275
ss412g07ef76d2019-08-12 17:26:40 +0300276func TestSaveEnb(t *testing.T) {
277 name := "name"
278 ranName := "RAN:" + name
ss412gefcb4522019-12-02 16:59:19 +0200279 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300280 nb := entities.NodebInfo{}
Idan Shalom14eb5132020-07-06 09:41:46 +0000281 nb.RanName = name
ss412g07ef76d2019-08-12 17:26:40 +0300282 nb.NodeType = entities.Node_ENB
283 nb.ConnectionStatus = 1
284 nb.Ip = "localhost"
285 nb.Port = 5656
286 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300287 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
288 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
ss412g07ef76d2019-08-12 17:26:40 +0300289 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300290 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300291 data, err := proto.Marshal(&nb)
292 if err != nil {
293 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
294 }
295 var e error
296
297 cellData, err := proto.Marshal(&cellEntity)
298 if err != nil {
299 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
300 }
301 var setExpected []interface{}
302 setExpected = append(setExpected, ranName, data)
303 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
304 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
305 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
306
Idan Shalom14eb5132020-07-06 09:41:46 +0000307 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", name + "_" + RanAddedEvent}, []interface{}{setExpected}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300308
309 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
310 if err != nil {
311 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
312 }
313 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
314
is005q19e72a52019-08-26 17:56:18 +0300315 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ns019t57c3fae2019-08-12 20:08:49 +0300316 nbIdData, err = proto.Marshal(nbIdentity)
ss412g07ef76d2019-08-12 17:26:40 +0300317 if err != nil {
318 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
319 }
320 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300321
ss412g07ef76d2019-08-12 17:26:40 +0300322 rNibErr := w.SaveNodeb(nbIdentity, &nb)
323 assert.Nil(t, rNibErr)
324}
325
326func TestSaveEnbCellIdValidationFailure(t *testing.T) {
327 name := "name"
ss412gefcb4522019-12-02 16:59:19 +0200328 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300329 nb := entities.NodebInfo{}
330 nb.NodeType = entities.Node_ENB
331 nb.ConnectionStatus = 1
332 nb.Ip = "localhost"
333 nb.Port = 5656
334 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300335 cell := &entities.ServedCellInfo{Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300336 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300337 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300338
is005q19e72a52019-08-26 17:56:18 +0300339 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300340 rNibErr := w.SaveNodeb(nbIdentity, &nb)
341 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300342 assert.IsType(t, &common.ValidationError{}, rNibErr)
343 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300344}
345
346func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200347 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300348 nb := entities.NodebInfo{}
349 nb.NodeType = entities.Node_ENB
350 nb.ConnectionStatus = 1
351 nb.Ip = "localhost"
352 nb.Port = 5656
353 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300354 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300355 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300356 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300357
is005q19e72a52019-08-26 17:56:18 +0300358 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300359 rNibErr := w.SaveNodeb(nbIdentity, &nb)
360 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300361 assert.IsType(t, &common.ValidationError{}, rNibErr)
362 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300363}
364
ss412g07ef76d2019-08-12 17:26:40 +0300365func TestSaveGnbCellIdValidationFailure(t *testing.T) {
366 name := "name"
ss412gefcb4522019-12-02 16:59:19 +0200367 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300368 nb := entities.NodebInfo{}
369 nb.NodeType = entities.Node_GNB
370 nb.ConnectionStatus = 1
371 nb.Ip = "localhost"
372 nb.Port = 5656
373 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300374 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
375 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
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
is005q19e72a52019-08-26 17:56:18 +0300379 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300380 rNibErr := w.SaveNodeb(nbIdentity, &nb)
381 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300382 assert.IsType(t, &common.ValidationError{}, rNibErr)
383 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300384}
385
386func TestSaveGnb(t *testing.T) {
387 name := "name"
388 ranName := "RAN:" + name
ss412gefcb4522019-12-02 16:59:19 +0200389 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300390 nb := entities.NodebInfo{}
391 nb.NodeType = entities.Node_GNB
392 nb.ConnectionStatus = 1
393 nb.Ip = "localhost"
394 nb.Port = 5656
395 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300396 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
397 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
398 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
ss412g07ef76d2019-08-12 17:26:40 +0300399 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
is005q19e72a52019-08-26 17:56:18 +0300400 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
ss412g07ef76d2019-08-12 17:26:40 +0300401 data, err := proto.Marshal(&nb)
402 if err != nil {
403 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
404 }
405 var e error
406
ss412g07ef76d2019-08-12 17:26:40 +0300407 cellData, err := proto.Marshal(&cellEntity)
408 if err != nil {
409 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
410 }
411 var setExpected []interface{}
412 setExpected = append(setExpected, ranName, data)
413 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
414 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
415 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
416
417 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
is005q19e72a52019-08-26 17:56:18 +0300418 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300419 nbIdData, err := proto.Marshal(nbIdentity)
420 if err != nil {
421 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
422 }
423 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
424
ns019t57c3fae2019-08-12 20:08:49 +0300425 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
426 if err != nil {
427 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
428 }
429 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
430
ss412g07ef76d2019-08-12 17:26:40 +0300431 rNibErr := w.SaveNodeb(nbIdentity, &nb)
432 assert.Nil(t, rNibErr)
433}
434
435func TestSaveRanLoadInformationSuccess(t *testing.T) {
436 inventoryName := "name"
437 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
438
439 if validationErr != nil {
440 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
441 }
442
ss412gefcb4522019-12-02 16:59:19 +0200443 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300444
ss412g07ef76d2019-08-12 17:26:40 +0300445 ranLoadInformation := generateRanLoadInformation()
446 data, err := proto.Marshal(ranLoadInformation)
447
448 if err != nil {
449 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
450 }
451
452 var e error
453 var setExpected []interface{}
454 setExpected = append(setExpected, loadKey, data)
455 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
456
ss412g07ef76d2019-08-12 17:26:40 +0300457 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
458 assert.Nil(t, rNibErr)
459}
460
461func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
462 inventoryName := "name2"
ss412gefcb4522019-12-02 16:59:19 +0200463 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300464
465 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
is005q19e72a52019-08-26 17:56:18 +0300466 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300467 assert.Equal(t, expectedErr, err)
468}
469
470func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
471 inventoryName := ""
ss412gefcb4522019-12-02 16:59:19 +0200472 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300473
is005q19e72a52019-08-26 17:56:18 +0300474 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300475 assert.NotNil(t, err)
irina006fbce2019-09-05 16:11:02 +0300476 assert.IsType(t, &common.ValidationError{}, err)
ss412g07ef76d2019-08-12 17:26:40 +0300477}
478
479func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
480 inventoryName := "name2"
481
482 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
483
484 if validationErr != nil {
485 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
486 }
487
ss412gefcb4522019-12-02 16:59:19 +0200488 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300489
490 ranLoadInformation := generateRanLoadInformation()
491 data, err := proto.Marshal(ranLoadInformation)
492
493 if err != nil {
494 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
495 }
496
ss412g07ef76d2019-08-12 17:26:40 +0300497 expectedErr := errors.New("expected error")
498 var setExpected []interface{}
499 setExpected = append(setExpected, loadKey, data)
500 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
501
ss412g07ef76d2019-08-12 17:26:40 +0300502 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
503 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300504 assert.IsType(t, &common.InternalError{}, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300505}
506
507func generateCellLoadInformation() *entities.CellLoadInformation {
508 cellLoadInformation := entities.CellLoadInformation{}
509
510 cellLoadInformation.CellId = "123"
511
512 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
513 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
514
515 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
is005q19e72a52019-08-26 17:56:18 +0300516 TargetCellId: "456",
517 UlHighInterferenceIndication: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300518 }
519
is005q19e72a52019-08-26 17:56:18 +0300520 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
ss412g07ef76d2019-08-12 17:26:40 +0300521
522 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
is005q19e72a52019-08-26 17:56:18 +0300523 RntpPerPrb: "xxx",
524 RntpThreshold: entities.RntpThreshold_NEG_4,
ss412g07ef76d2019-08-12 17:26:40 +0300525 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
is005q19e72a52019-08-26 17:56:18 +0300526 PB: 1,
527 PdcchInterferenceImpact: 2,
ss412g07ef76d2019-08-12 17:26:40 +0300528 EnhancedRntp: &entities.EnhancedRntp{
is005q19e72a52019-08-26 17:56:18 +0300529 EnhancedRntpBitmap: "xxx",
530 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
531 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
ss412g07ef76d2019-08-12 17:26:40 +0300532 },
533 }
534
535 cellLoadInformation.AbsInformation = &entities.AbsInformation{
is005q19e72a52019-08-26 17:56:18 +0300536 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
537 AbsPatternInfo: "xxx",
538 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
539 MeasurementSubset: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300540 }
541
542 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
543
544 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
is005q19e72a52019-08-26 17:56:18 +0300545 AssociatedSubframes: "xxx",
546 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
ss412g07ef76d2019-08-12 17:26:40 +0300547 }
548
549 compInformationItem := &entities.CompInformationItem{
idanshal08bbf912020-04-20 17:11:33 +0300550 CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
is005q19e72a52019-08-26 17:56:18 +0300551 BenefitMetric: 50,
ss412g07ef76d2019-08-12 17:26:40 +0300552 }
553
554 cellLoadInformation.CompInformation = &entities.CompInformation{
is005q19e72a52019-08-26 17:56:18 +0300555 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
556 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
ss412g07ef76d2019-08-12 17:26:40 +0300557 }
558
559 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
is005q19e72a52019-08-26 17:56:18 +0300560 State: entities.NaicsState_NAICS_ACTIVE,
561 TransmissionModes: "xxx",
562 PB: 2,
563 PAList: []entities.PA{entities.PA_DB_NEG_3},
ss412g07ef76d2019-08-12 17:26:40 +0300564 }
565
566 return &cellLoadInformation
567}
568
569func generateRanLoadInformation() *entities.RanLoadInformation {
570 ranLoadInformation := entities.RanLoadInformation{}
571
is005q19bf35e2019-08-12 18:59:29 +0300572 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
ss412g07ef76d2019-08-12 17:26:40 +0300573
574 cellLoadInformation := generateCellLoadInformation()
575 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
576
577 return &ranLoadInformation
578}
579
580func TestSaveNilEntityFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200581 w, _ := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300582 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
583 nbIdentity := &entities.NbIdentity{}
584 actualErr := w.SaveNodeb(nbIdentity, nil)
585 assert.Equal(t, expectedErr, actualErr)
586}
587
588func TestSaveUnknownTypeEntityFailure(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200589 w, _ := initSdlInstanceMock(namespace)
is005q19e72a52019-08-26 17:56:18 +0300590 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300591 nb := &entities.NodebInfo{}
592 nb.Port = 5656
593 nb.Ip = "localhost"
594 actualErr := w.SaveNodeb(nbIdentity, nb)
ss412ga07b8592020-06-16 21:51:33 +0300595 assert.IsType(t, &common.ValidationError{}, actualErr)
ss412g07ef76d2019-08-12 17:26:40 +0300596}
597
598func TestSaveEntityFailure(t *testing.T) {
599 name := "name"
600 plmnId := "02f829"
601 nbId := "4a952a0a"
602
ss412gefcb4522019-12-02 16:59:19 +0200603 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300604 gnb := entities.NodebInfo{}
605 gnb.NodeType = entities.Node_GNB
606 data, err := proto.Marshal(&gnb)
607 if err != nil {
608 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
609 }
is005q19e72a52019-08-26 17:56:18 +0300610 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
ss412g07ef76d2019-08-12 17:26:40 +0300611 setExpected := []interface{}{"RAN:" + name, data}
is005q19e72a52019-08-26 17:56:18 +0300612 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
ss412g07ef76d2019-08-12 17:26:40 +0300613 expectedErr := errors.New("expected error")
614 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
615 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
616 assert.NotEmpty(t, rNibErr)
617}
618
ss412g07ef76d2019-08-12 17:26:40 +0300619func TestGetRNibWriter(t *testing.T) {
ss412gefcb4522019-12-02 16:59:19 +0200620 received, _ := initSdlInstanceMock(namespace)
621 assert.NotEmpty(t, received)
ss412g07ef76d2019-08-12 17:26:40 +0300622}
623
ss412gefcb4522019-12-02 16:59:19 +0200624func TestSaveE2TInstanceSuccess(t *testing.T) {
625 address := "10.10.2.15:9800"
626 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
627
628 if validationErr != nil {
629 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
630 }
631
632 w, sdlInstanceMock := initSdlInstanceMock(namespace)
633
634 e2tInstance := generateE2tInstance(address)
635 data, err := json.Marshal(e2tInstance)
636
637 if err != nil {
638 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
639 }
640
ss412g07ef76d2019-08-12 17:26:40 +0300641 var e error
ss412gefcb4522019-12-02 16:59:19 +0200642 var setExpected []interface{}
643 setExpected = append(setExpected, loadKey, data)
644 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
645
646 rNibErr := w.SaveE2TInstance(e2tInstance)
647 assert.Nil(t, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300648}
649
ss412gefcb4522019-12-02 16:59:19 +0200650func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
651 w, _ := initSdlInstanceMock(namespace)
652 var address string
Irina49144462020-04-07 16:37:20 +0300653 e2tInstance := entities.NewE2TInstance(address, "test")
ss412gefcb4522019-12-02 16:59:19 +0200654 err := w.SaveE2TInstance(e2tInstance)
655 assert.NotNil(t, err)
656 assert.IsType(t, &common.ValidationError{}, err)
657}
658
659func TestSaveE2TInstanceSdlFailure(t *testing.T) {
660 address := "10.10.2.15:9800"
661 loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
662
663 if validationErr != nil {
664 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
665 }
666
667 w, sdlInstanceMock := initSdlInstanceMock(namespace)
668
669 e2tInstance := generateE2tInstance(address)
670 data, err := json.Marshal(e2tInstance)
671
672 if err != nil {
673 t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
674 }
675
676 expectedErr := errors.New("expected error")
677 var setExpected []interface{}
678 setExpected = append(setExpected, loadKey, data)
679 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
680
681 rNibErr := w.SaveE2TInstance(e2tInstance)
682 assert.NotNil(t, rNibErr)
683 assert.IsType(t, &common.InternalError{}, rNibErr)
684}
685
686func generateE2tInstance(address string) *entities.E2TInstance {
Irina49144462020-04-07 16:37:20 +0300687 e2tInstance := entities.NewE2TInstance(address, "pod test")
ss412gefcb4522019-12-02 16:59:19 +0200688
689 e2tInstance.AssociatedRanList = []string{"test1", "test2"}
690
691 return e2tInstance
692}
693
694func TestSaveE2TAddressesSuccess(t *testing.T) {
695 address := "10.10.2.15:9800"
696 w, sdlInstanceMock := initSdlInstanceMock(namespace)
697
698 e2tAddresses := []string{address}
699 data, err := json.Marshal(e2tAddresses)
700
701 if err != nil {
702 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
703 }
704
ss412g07ef76d2019-08-12 17:26:40 +0300705 var e error
ss412gefcb4522019-12-02 16:59:19 +0200706 var setExpected []interface{}
707 setExpected = append(setExpected, E2TAddressesKey, data)
708 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
709
710 rNibErr := w.SaveE2TAddresses(e2tAddresses)
711 assert.Nil(t, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300712}
713
ss412gefcb4522019-12-02 16:59:19 +0200714func TestSaveE2TAddressesSdlFailure(t *testing.T) {
715 address := "10.10.2.15:9800"
716 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412g07ef76d2019-08-12 17:26:40 +0300717
ss412gefcb4522019-12-02 16:59:19 +0200718 e2tAddresses := []string{address}
719 data, err := json.Marshal(e2tAddresses)
720
721 if err != nil {
722 t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
723 }
724
725 expectedErr := errors.New("expected error")
726 var setExpected []interface{}
727 setExpected = append(setExpected, E2TAddressesKey, data)
728 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
729
730 rNibErr := w.SaveE2TAddresses(e2tAddresses)
731 assert.NotNil(t, rNibErr)
732 assert.IsType(t, &common.InternalError{}, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300733}
734
Amichaif846c592020-01-08 16:45:07 +0200735func TestRemoveE2TInstanceSuccess(t *testing.T) {
736 address := "10.10.2.15:9800"
737 w, sdlInstanceMock := initSdlInstanceMock(namespace)
738
739 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
740 var e error
741 sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
742
743 rNibErr := w.RemoveE2TInstance(address)
744 assert.Nil(t, rNibErr)
745 sdlInstanceMock.AssertExpectations(t)
746}
747
748func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
749 address := "10.10.2.15:9800"
750 w, sdlInstanceMock := initSdlInstanceMock(namespace)
751
752 e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
753 expectedErr := errors.New("expected error")
754 sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
755
756 rNibErr := w.RemoveE2TInstance(address)
757 assert.IsType(t, &common.InternalError{}, rNibErr)
758}
759
760func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
761 w, sdlInstanceMock := initSdlInstanceMock(namespace)
762
763 rNibErr := w.RemoveE2TInstance("")
764 assert.IsType(t, &common.ValidationError{}, rNibErr)
765 sdlInstanceMock.AssertExpectations(t)
766}
767
ss412ga07b8592020-06-16 21:51:33 +0300768func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
769 inventoryName := "name"
770 plmnId := "02f829"
771 nbId := "4a952a0a"
Amichai7e2e4932020-07-07 15:49:07 +0000772 channelName := "RAN_CONNECTION_STATUS_CHANGE"
ss412ga07b8592020-06-16 21:51:33 +0300773 eventName := inventoryName + "_" + "CONNECTED"
Idan Shalom14eb5132020-07-06 09:41:46 +0000774 w, sdlInstanceMock := initSdlInstanceMock(namespace)
ss412ga07b8592020-06-16 21:51:33 +0300775 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
776 data, err := proto.Marshal(nodebInfo)
777 if err != nil {
778 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
779 }
780 var e error
781 var setExpected []interface{}
782
783 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
784 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
785 setExpected = append(setExpected, nodebNameKey, data)
786 setExpected = append(setExpected, nodebIdKey, data)
787
idanshal1766b712020-06-22 12:41:02 +0300788 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300789
Amichai7e2e4932020-07-07 15:49:07 +0000790 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
ss412ga07b8592020-06-16 21:51:33 +0300791 assert.Nil(t, rNibErr)
792}
793
794func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
795 inventoryName := "name"
796 plmnId := "02f829"
797 nbId := "4a952a0a"
Amichai7e2e4932020-07-07 15:49:07 +0000798 channelName := "RAN_CONNECTION_STATUS_CHANGE"
ss412ga07b8592020-06-16 21:51:33 +0300799 eventName := inventoryName + "_" + "CONNECTED"
800 w, sdlInstanceMock := initSdlInstanceMock(namespace)
801 nodebInfo := &entities.NodebInfo{}
802 data, err := proto.Marshal(nodebInfo)
803 if err != nil {
804 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
805 }
806 var e error
807 var setExpected []interface{}
808
809 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
810 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
811 setExpected = append(setExpected, nodebNameKey, data)
812 setExpected = append(setExpected, nodebIdKey, data)
813
idanshal1766b712020-06-22 12:41:02 +0300814 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300815
Amichai7e2e4932020-07-07 15:49:07 +0000816 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
ss412ga07b8592020-06-16 21:51:33 +0300817
818 assert.NotNil(t, rNibErr)
819 assert.IsType(t, &common.ValidationError{}, rNibErr)
820}
821
822func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) {
823 inventoryName := "name"
Amichai7e2e4932020-07-07 15:49:07 +0000824 channelName := "RAN_CONNECTION_STATUS_CHANGE"
ss412ga07b8592020-06-16 21:51:33 +0300825 eventName := inventoryName + "_" + "CONNECTED"
826 w, sdlInstanceMock := initSdlInstanceMock(namespace)
827 nodebInfo := &entities.NodebInfo{}
828 nodebInfo.RanName = inventoryName
829 data, err := proto.Marshal(nodebInfo)
830 if err != nil {
831 t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
832 }
833 var e error
834 var setExpected []interface{}
835
836 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
837 setExpected = append(setExpected, nodebNameKey, data)
idanshal1766b712020-06-22 12:41:02 +0300838 sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
ss412ga07b8592020-06-16 21:51:33 +0300839
Amichai7e2e4932020-07-07 15:49:07 +0000840 rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, eventName)
ss412ga07b8592020-06-16 21:51:33 +0300841
842 assert.Nil(t, rNibErr)
843}
844
845func TestSaveGeneralConfiguration(t *testing.T) {
846 w, sdlInstanceMock := initSdlInstanceMock(namespace)
847
848 key := common.BuildGeneralConfigurationKey()
849 configurationData := "{\"enableRic\":true}"
850 configuration := &entities.GeneralConfiguration{}
851 configuration.EnableRic = true
852
Idan Shalom14eb5132020-07-06 09:41:46 +0000853 sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
ss412ga07b8592020-06-16 21:51:33 +0300854 rNibErr := w.SaveGeneralConfiguration(configuration)
855
856 assert.Nil(t, rNibErr)
857 sdlInstanceMock.AssertExpectations(t)
858}
859
860func TestSaveGeneralConfigurationDbError(t *testing.T) {
861 w, sdlInstanceMock := initSdlInstanceMock(namespace)
862
863 key := common.BuildGeneralConfigurationKey()
864 configurationData := "{\"enableRic\":true}"
865 configuration := &entities.GeneralConfiguration{}
866 configuration.EnableRic = true
867
868 expectedErr := errors.New("expected error")
869
Idan Shalom14eb5132020-07-06 09:41:46 +0000870 sdlInstanceMock.On("Set", []interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
ss412ga07b8592020-06-16 21:51:33 +0300871 rNibErr := w.SaveGeneralConfiguration(configuration)
872
873 assert.NotNil(t, rNibErr)
874}
Irina5830d4d2020-07-08 18:11:04 +0000875func TestRemoveServedCellsSuccess(t *testing.T) {
876 w, sdlInstanceMock := initSdlInstanceMock(namespace)
877 servedCellsToRemove := generateServedCells("whatever1", "whatever2")
878 sdlInstanceMock.On("Remove", buildServedCellInfoKeysToRemove(RanName, servedCellsToRemove)).Return(nil)
879 err := w.RemoveServedCells(RanName, servedCellsToRemove)
880 assert.Nil(t, err)
881}
ss412ga07b8592020-06-16 21:51:33 +0300882
Irina5830d4d2020-07-08 18:11:04 +0000883func TestUpdateEnbInvalidNodebInfoFailure(t *testing.T) {
884 w, sdlInstanceMock := initSdlInstanceMock(namespace)
885 servedCells := generateServedCells("test1", "test2")
886 nodebInfo := &entities.NodebInfo{}
887 sdlInstanceMock.AssertNotCalled(t, "SetAndPublish")
888 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
889 assert.IsType(t, &common.ValidationError{}, rNibErr)
890}
891
892func TestUpdateEnbInvalidCellFailure(t *testing.T) {
893 inventoryName := "name"
894 plmnId := "02f829"
895 nbId := "4a952a0a"
896 w, sdlInstanceMock := initSdlInstanceMock(namespace)
897 servedCells := []*entities.ServedCellInfo{{CellId: ""}}
898 nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
899 nodebInfo.GetEnb().ServedCells = servedCells
900 sdlInstanceMock.AssertNotCalled(t, "SetAndPublish")
901 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
902 assert.IsType(t, &common.ValidationError{}, rNibErr)
903}
904
905/*func TestUpdateEnbSdlFailure(t *testing.T) {
906 inventoryName := "ranName"
907 plmnId := "02f829"
908 nbId := "4a952a0a"
909 w, sdlInstanceMock := initSdlInstanceMock(namespace)
910 servedCells := generateServedCells("test1", "test2")
911 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
912 nodebInfo.GetEnb().ServedCells = servedCells
913 setExpected := getUpdateEnbSetExpected(t, nodebInfo, servedCells)
914 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(errors.New("expected error"))
915 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
916 assert.IsType(t, &common.InternalError{}, rNibErr)
917}*/
918
919/*func TestUpdateEnbSuccess(t *testing.T) {
920 inventoryName := "ranName"
921 plmnId := "02f829"
922 nbId := "4a952a0a"
923 w, sdlInstanceMock := initSdlInstanceMock(namespace)
924 servedCells := generateServedCells("test1", "test2")
925 nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
926 nodebInfo.GetEnb().ServedCells = servedCells
927 setExpected := getUpdateEnbSetExpected(t, nodebInfo, servedCells)
928
929 var e error
930 sdlInstanceMock.On("SetAndPublish", []string{"RAN_MANIPULATION", inventoryName + "_" + RanUpdatedEvent}, []interface{}{setExpected}).Return(e)
931 rNibErr := w.UpdateEnb(nodebInfo, servedCells)
932 assert.Nil(t, rNibErr)
933}*/
934
935func getUpdateEnbSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) []interface{} {
936
937 nodebInfoData, err := proto.Marshal(nodebInfo)
938 if err != nil {
939 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal NodeB entity. Error: %s", err)
940 }
941
942 nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
943 nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
944 setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
945
946 for _, v := range servedCells {
947
948 cellEntity := entities.ServedCellInfo{CellId: "some cell id", EutraMode: entities.Eutra_FDD, CsgId: "some csg id"}
949 cellData, err := proto.Marshal(&cellEntity)
950
951 if err != nil {
952 t.Fatalf("#rNibWriter_test.getUpdateEnbSetExpected - Failed to marshal cell entity. Error: %s", err)
953 }
954
955 nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetCellId())
956 cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetPci())
957 setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
958 }
959 return setExpected
960}