blob: c887da6d504897e81f539ffb7f13a1a967fd81a0 [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.
16//
17
18package rNibWriter
19
20import (
ss412g07ef76d2019-08-12 17:26:40 +030021 "e2mgr/mocks"
ss412g07ef76d2019-08-12 17:26:40 +030022 "errors"
23 "fmt"
is005q19bf35e2019-08-12 18:59:29 +030024 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
25 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
ss412g07ef76d2019-08-12 17:26:40 +030026 "github.com/golang/protobuf/proto"
ss412g07ef76d2019-08-12 17:26:40 +030027 "github.com/stretchr/testify/assert"
28 "testing"
29 "time"
30)
31
32func TestInitRNibWriter(t *testing.T) {
33 writerPool = nil
34 initSdlInstanceMock(namespace, 1)
35 available, created := writerPool.Stats()
36 assert.Equal(t, available, 0, "number of available objects in the writerPool should be 0")
37 assert.Equal(t, created, 0, "number of created objects in the writerPool should be 0")
38 w := GetRNibWriter()
39 assert.NotNil(t, w)
40}
41
42func TestInitPool(t *testing.T) {
43 writerPool = nil
44 sdlInstanceMock := new(mocks.MockSdlInstance)
45 initPool(1, func() interface{} {
46 sdlI := common.ISdlInstance(sdlInstanceMock)
47 return &rNibWriterInstance{sdl: &sdlI, namespace: namespace}
48 },
49 func(obj interface{}) {
50 },
51 )
52 assert.NotNil(t, writerPool)
53 assert.NotNil(t, writerPool.New)
54 assert.NotNil(t, writerPool.Destroy)
55 available, created := writerPool.Stats()
56 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
57 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
58}
59
60var namespace = "namespace"
61
62func initSdlInstanceMock(namespace string, poolSize int) *mocks.MockSdlInstance {
63 sdlInstanceMock := new(mocks.MockSdlInstance)
64 initPool(poolSize, func() interface{} {
65 sdlI := common.ISdlInstance(sdlInstanceMock)
66 return &rNibWriterInstance{sdl: &sdlI, namespace: namespace}
67 },
68 func(obj interface{}) {
69 },
70 )
71 return sdlInstanceMock
72}
73
is005q19e72a52019-08-26 17:56:18 +030074func TestUpdateNodebInfoSuccess(t *testing.T) {
75 inventoryName := "name"
76 plmnId := "02f829"
77 nbId := "4a952a0a"
78 writerPool = nil
79 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
80 w := GetRNibWriter()
81 nodebInfo := &entities.NodebInfo{}
82 nodebInfo.RanName = inventoryName
83 nodebInfo.GlobalNbId = &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
84 nodebInfo.NodeType = entities.Node_ENB
85 nodebInfo.ConnectionStatus = 1
86 enb := entities.Enb{}
87 nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
88 data, err := proto.Marshal(nodebInfo)
89 if err != nil {
90 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
91 }
92 var e error
93 var setExpected []interface{}
94
95 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
96 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
97 setExpected = append(setExpected, nodebNameKey, data)
98 setExpected = append(setExpected, nodebIdKey, data)
99
100 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
101
102 rNibErr := w.UpdateNodebInfo(nodebInfo)
103 assert.Nil(t, rNibErr)
104}
105
106func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
107 inventoryName := "name"
108 plmnId := "02f829"
109 nbId := "4a952a0a"
110 writerPool = nil
111 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
112 w := GetRNibWriter()
113 nodebInfo := &entities.NodebInfo{}
114 data, err := proto.Marshal(nodebInfo)
115 if err != nil {
116 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
117 }
118 var e error
119 var setExpected []interface{}
120
121 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
122 nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
123 setExpected = append(setExpected, nodebNameKey, data)
124 setExpected = append(setExpected, nodebIdKey, data)
125
126 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
127
128 rNibErr := w.UpdateNodebInfo(nodebInfo)
129
130 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300131 assert.IsType(t, &common.ValidationError{}, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300132}
133
is005q26473192019-08-28 17:51:37 +0300134func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
is005q19e72a52019-08-26 17:56:18 +0300135 inventoryName := "name"
is005q19e72a52019-08-26 17:56:18 +0300136 writerPool = nil
137 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
138 w := GetRNibWriter()
139 nodebInfo := &entities.NodebInfo{}
140 nodebInfo.RanName = inventoryName
141 data, err := proto.Marshal(nodebInfo)
142 if err != nil {
143 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
144 }
145 var e error
146 var setExpected []interface{}
147
148 nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
is005q19e72a52019-08-26 17:56:18 +0300149 setExpected = append(setExpected, nodebNameKey, data)
is005q19e72a52019-08-26 17:56:18 +0300150 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
151
152 rNibErr := w.UpdateNodebInfo(nodebInfo)
153
is005q26473192019-08-28 17:51:37 +0300154 assert.Nil(t, rNibErr)
is005q19e72a52019-08-26 17:56:18 +0300155}
156
ss412g07ef76d2019-08-12 17:26:40 +0300157func TestSaveEnb(t *testing.T) {
158 name := "name"
159 ranName := "RAN:" + name
160 writerPool = nil
161 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
162 w := GetRNibWriter()
163 nb := entities.NodebInfo{}
164 nb.NodeType = entities.Node_ENB
165 nb.ConnectionStatus = 1
166 nb.Ip = "localhost"
167 nb.Port = 5656
168 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300169 cell := &entities.ServedCellInfo{CellId: "aaff", Pci: 3}
170 cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}}
ss412g07ef76d2019-08-12 17:26:40 +0300171 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300172 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300173 data, err := proto.Marshal(&nb)
174 if err != nil {
175 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
176 }
177 var e error
178
179 cellData, err := proto.Marshal(&cellEntity)
180 if err != nil {
181 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
182 }
183 var setExpected []interface{}
184 setExpected = append(setExpected, ranName, data)
185 setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
186 setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
187 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
188
189 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300190
191 nbIdData, err := proto.Marshal(&entities.NbIdentity{InventoryName: name})
192 if err != nil {
193 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
194 }
195 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
196
is005q19e72a52019-08-26 17:56:18 +0300197 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ns019t57c3fae2019-08-12 20:08:49 +0300198 nbIdData, err = proto.Marshal(nbIdentity)
ss412g07ef76d2019-08-12 17:26:40 +0300199 if err != nil {
200 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
201 }
202 sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
ns019t57c3fae2019-08-12 20:08:49 +0300203
ss412g07ef76d2019-08-12 17:26:40 +0300204 rNibErr := w.SaveNodeb(nbIdentity, &nb)
205 assert.Nil(t, rNibErr)
206}
207
208func TestSaveEnbCellIdValidationFailure(t *testing.T) {
209 name := "name"
210 writerPool = nil
211 initSdlInstanceMock(namespace, 1)
212 w := GetRNibWriter()
213 nb := entities.NodebInfo{}
214 nb.NodeType = entities.Node_ENB
215 nb.ConnectionStatus = 1
216 nb.Ip = "localhost"
217 nb.Port = 5656
218 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300219 cell := &entities.ServedCellInfo{Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300220 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300221 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300222
is005q19e72a52019-08-26 17:56:18 +0300223 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300224 rNibErr := w.SaveNodeb(nbIdentity, &nb)
225 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300226 assert.IsType(t, &common.ValidationError{}, rNibErr)
227 assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300228}
229
230func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
231 writerPool = nil
232 initSdlInstanceMock(namespace, 1)
233 w := GetRNibWriter()
234 nb := entities.NodebInfo{}
235 nb.NodeType = entities.Node_ENB
236 nb.ConnectionStatus = 1
237 nb.Ip = "localhost"
238 nb.Port = 5656
239 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300240 cell := &entities.ServedCellInfo{CellId: "aaa", Pci: 3}
ss412g07ef76d2019-08-12 17:26:40 +0300241 enb.ServedCells = []*entities.ServedCellInfo{cell}
is005q19e72a52019-08-26 17:56:18 +0300242 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300243
is005q19e72a52019-08-26 17:56:18 +0300244 nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300245 rNibErr := w.SaveNodeb(nbIdentity, &nb)
246 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300247 assert.IsType(t, &common.ValidationError{}, rNibErr)
248 assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300249}
250
251func TestSaveEnbOnClosedPool(t *testing.T) {
252 name := "name"
253 writerPool = nil
254 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
255 w := GetRNibWriter()
256 nb := entities.NodebInfo{}
257 nb.NodeType = entities.Node_ENB
258 nb.ConnectionStatus = 1
259 nb.Ip = "localhost"
260 nb.Port = 5656
261 enb := entities.Enb{}
is005q19e72a52019-08-26 17:56:18 +0300262 nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
ss412g07ef76d2019-08-12 17:26:40 +0300263 data, err := proto.Marshal(&nb)
264 if err != nil {
265 t.Errorf("#rNibWriter_test.TestSaveEnbOnClosedPool - Failed to marshal NodeB entity. Error: %v", err)
266 }
267 setExpected := []interface{}{name, data}
268 var e error
269 sdlInstanceMock.On("Set", setExpected).Return(e)
270 writerPool.Close()
271 nbIdentity := &entities.NbIdentity{}
is005q19e72a52019-08-26 17:56:18 +0300272 assert.Panics(t, func() { w.SaveNodeb(nbIdentity, &nb) })
ss412g07ef76d2019-08-12 17:26:40 +0300273}
274
275func TestSaveGnbCellIdValidationFailure(t *testing.T) {
276 name := "name"
277 writerPool = nil
278 initSdlInstanceMock(namespace, 1)
279 w := GetRNibWriter()
280 nb := entities.NodebInfo{}
281 nb.NodeType = entities.Node_GNB
282 nb.ConnectionStatus = 1
283 nb.Ip = "localhost"
284 nb.Port = 5656
285 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300286 cellInfo := &entities.ServedNRCellInformation{NrPci: 2}
287 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
ss412g07ef76d2019-08-12 17:26:40 +0300288 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
is005q19e72a52019-08-26 17:56:18 +0300289 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
ss412g07ef76d2019-08-12 17:26:40 +0300290
is005q19e72a52019-08-26 17:56:18 +0300291 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300292 rNibErr := w.SaveNodeb(nbIdentity, &nb)
293 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300294 assert.IsType(t, &common.ValidationError{}, rNibErr)
295 assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
ss412g07ef76d2019-08-12 17:26:40 +0300296}
297
298func TestSaveGnb(t *testing.T) {
299 name := "name"
300 ranName := "RAN:" + name
301 writerPool = nil
302 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
303 w := GetRNibWriter()
304 nb := entities.NodebInfo{}
305 nb.NodeType = entities.Node_GNB
306 nb.ConnectionStatus = 1
307 nb.Ip = "localhost"
308 nb.Port = 5656
309 gnb := entities.Gnb{}
is005q19e72a52019-08-26 17:56:18 +0300310 cellInfo := &entities.ServedNRCellInformation{NrPci: 2, CellId: "ccdd"}
311 cell := &entities.ServedNRCell{ServedNrCellInformation: cellInfo}
312 cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}}
ss412g07ef76d2019-08-12 17:26:40 +0300313 gnb.ServedNrCells = []*entities.ServedNRCell{cell}
is005q19e72a52019-08-26 17:56:18 +0300314 nb.Configuration = &entities.NodebInfo_Gnb{Gnb: &gnb}
ss412g07ef76d2019-08-12 17:26:40 +0300315 data, err := proto.Marshal(&nb)
316 if err != nil {
317 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
318 }
319 var e error
320
ss412g07ef76d2019-08-12 17:26:40 +0300321 cellData, err := proto.Marshal(&cellEntity)
322 if err != nil {
323 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
324 }
325 var setExpected []interface{}
326 setExpected = append(setExpected, ranName, data)
327 setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
328 setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
329 setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
330
331 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
is005q19e72a52019-08-26 17:56:18 +0300332 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300333 nbIdData, err := proto.Marshal(nbIdentity)
334 if err != nil {
335 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
336 }
337 sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
338
ns019t57c3fae2019-08-12 20:08:49 +0300339 nbIdData, err = proto.Marshal(&entities.NbIdentity{InventoryName: name})
340 if err != nil {
341 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal nbIdentity entity. Error: %v", err)
342 }
343 sdlInstanceMock.On("RemoveMember", entities.Node_UNKNOWN.String(), []interface{}{nbIdData}).Return(e)
344
ss412g07ef76d2019-08-12 17:26:40 +0300345 rNibErr := w.SaveNodeb(nbIdentity, &nb)
346 assert.Nil(t, rNibErr)
347}
348
349func TestSaveRanLoadInformationSuccess(t *testing.T) {
350 inventoryName := "name"
351 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
352
353 if validationErr != nil {
354 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
355 }
356
357 writerPool = nil
358 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
359 w := GetRNibWriter()
360
ss412g07ef76d2019-08-12 17:26:40 +0300361 ranLoadInformation := generateRanLoadInformation()
362 data, err := proto.Marshal(ranLoadInformation)
363
364 if err != nil {
365 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
366 }
367
368 var e error
369 var setExpected []interface{}
370 setExpected = append(setExpected, loadKey, data)
371 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
372
ss412g07ef76d2019-08-12 17:26:40 +0300373 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
374 assert.Nil(t, rNibErr)
375}
376
377func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
378 inventoryName := "name2"
379 writerPool = nil
380 initSdlInstanceMock(namespace, 1)
381 w := GetRNibWriter()
382
383 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
is005q19e72a52019-08-26 17:56:18 +0300384 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300385 assert.Equal(t, expectedErr, err)
386}
387
388func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
389 inventoryName := ""
390 writerPool = nil
391 initSdlInstanceMock(namespace, 1)
392 w := GetRNibWriter()
393
is005q19e72a52019-08-26 17:56:18 +0300394 err := w.SaveRanLoadInformation(inventoryName, nil)
ss412g07ef76d2019-08-12 17:26:40 +0300395 assert.NotNil(t, err)
irina006fbce2019-09-05 16:11:02 +0300396 assert.IsType(t, &common.ValidationError{}, err)
ss412g07ef76d2019-08-12 17:26:40 +0300397}
398
399func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
400 inventoryName := "name2"
401
402 loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
403
404 if validationErr != nil {
405 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
406 }
407
ss412g07ef76d2019-08-12 17:26:40 +0300408 writerPool = nil
409 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
410 w := GetRNibWriter()
411
412 ranLoadInformation := generateRanLoadInformation()
413 data, err := proto.Marshal(ranLoadInformation)
414
415 if err != nil {
416 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
417 }
418
ss412g07ef76d2019-08-12 17:26:40 +0300419 expectedErr := errors.New("expected error")
420 var setExpected []interface{}
421 setExpected = append(setExpected, loadKey, data)
422 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
423
ss412g07ef76d2019-08-12 17:26:40 +0300424 rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
425 assert.NotNil(t, rNibErr)
irina006fbce2019-09-05 16:11:02 +0300426 assert.IsType(t, &common.InternalError{}, rNibErr)
ss412g07ef76d2019-08-12 17:26:40 +0300427}
428
429func generateCellLoadInformation() *entities.CellLoadInformation {
430 cellLoadInformation := entities.CellLoadInformation{}
431
432 cellLoadInformation.CellId = "123"
433
434 ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
435 cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
436
437 ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
is005q19e72a52019-08-26 17:56:18 +0300438 TargetCellId: "456",
439 UlHighInterferenceIndication: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300440 }
441
is005q19e72a52019-08-26 17:56:18 +0300442 cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation}
ss412g07ef76d2019-08-12 17:26:40 +0300443
444 cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
is005q19e72a52019-08-26 17:56:18 +0300445 RntpPerPrb: "xxx",
446 RntpThreshold: entities.RntpThreshold_NEG_4,
ss412g07ef76d2019-08-12 17:26:40 +0300447 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
is005q19e72a52019-08-26 17:56:18 +0300448 PB: 1,
449 PdcchInterferenceImpact: 2,
ss412g07ef76d2019-08-12 17:26:40 +0300450 EnhancedRntp: &entities.EnhancedRntp{
is005q19e72a52019-08-26 17:56:18 +0300451 EnhancedRntpBitmap: "xxx",
452 RntpHighPowerThreshold: entities.RntpThreshold_NEG_2,
453 EnhancedRntpStartTime: &entities.StartTime{StartSfn: 500, StartSubframeNumber: 5},
ss412g07ef76d2019-08-12 17:26:40 +0300454 },
455 }
456
457 cellLoadInformation.AbsInformation = &entities.AbsInformation{
is005q19e72a52019-08-26 17:56:18 +0300458 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
459 AbsPatternInfo: "xxx",
460 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
461 MeasurementSubset: "xxx",
ss412g07ef76d2019-08-12 17:26:40 +0300462 }
463
464 cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
465
466 cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
is005q19e72a52019-08-26 17:56:18 +0300467 AssociatedSubframes: "xxx",
468 ExtendedUlInterferenceOverloadIndications: cellLoadInformation.UlInterferenceOverloadIndications,
ss412g07ef76d2019-08-12 17:26:40 +0300469 }
470
471 compInformationItem := &entities.CompInformationItem{
is005q19e72a52019-08-26 17:56:18 +0300472 CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis: "xxx"}},
473 BenefitMetric: 50,
ss412g07ef76d2019-08-12 17:26:40 +0300474 }
475
476 cellLoadInformation.CompInformation = &entities.CompInformation{
is005q19e72a52019-08-26 17:56:18 +0300477 CompInformationItems: []*entities.CompInformationItem{compInformationItem},
478 CompInformationStartTime: &entities.StartTime{StartSfn: 123, StartSubframeNumber: 456},
ss412g07ef76d2019-08-12 17:26:40 +0300479 }
480
481 cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
is005q19e72a52019-08-26 17:56:18 +0300482 State: entities.NaicsState_NAICS_ACTIVE,
483 TransmissionModes: "xxx",
484 PB: 2,
485 PAList: []entities.PA{entities.PA_DB_NEG_3},
ss412g07ef76d2019-08-12 17:26:40 +0300486 }
487
488 return &cellLoadInformation
489}
490
491func generateRanLoadInformation() *entities.RanLoadInformation {
492 ranLoadInformation := entities.RanLoadInformation{}
493
is005q19bf35e2019-08-12 18:59:29 +0300494 ranLoadInformation.LoadTimestamp = uint64(time.Now().UnixNano())
ss412g07ef76d2019-08-12 17:26:40 +0300495
496 cellLoadInformation := generateCellLoadInformation()
497 ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
498
499 return &ranLoadInformation
500}
501
502func TestSaveNilEntityFailure(t *testing.T) {
503 writerPool = nil
504 initSdlInstanceMock(namespace, 1)
505 w := GetRNibWriter()
506 expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
507 nbIdentity := &entities.NbIdentity{}
508 actualErr := w.SaveNodeb(nbIdentity, nil)
509 assert.Equal(t, expectedErr, actualErr)
510}
511
512func TestSaveUnknownTypeEntityFailure(t *testing.T) {
513 writerPool = nil
514 initSdlInstanceMock(namespace, 1)
515 w := GetRNibWriter()
irina006fbce2019-09-05 16:11:02 +0300516 expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")
is005q19e72a52019-08-26 17:56:18 +0300517 nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
ss412g07ef76d2019-08-12 17:26:40 +0300518 nb := &entities.NodebInfo{}
519 nb.Port = 5656
520 nb.Ip = "localhost"
521 actualErr := w.SaveNodeb(nbIdentity, nb)
522 assert.Equal(t, expectedErr, actualErr)
523}
524
525func TestSaveEntityFailure(t *testing.T) {
526 name := "name"
527 plmnId := "02f829"
528 nbId := "4a952a0a"
529
530 writerPool = nil
531 sdlInstanceMock := initSdlInstanceMock(namespace, 1)
532 w := GetRNibWriter()
533 gnb := entities.NodebInfo{}
534 gnb.NodeType = entities.Node_GNB
535 data, err := proto.Marshal(&gnb)
536 if err != nil {
537 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
538 }
is005q19e72a52019-08-26 17:56:18 +0300539 nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}}
ss412g07ef76d2019-08-12 17:26:40 +0300540 setExpected := []interface{}{"RAN:" + name, data}
is005q19e72a52019-08-26 17:56:18 +0300541 setExpected = append(setExpected, "GNB:"+plmnId+":"+nbId, data)
ss412g07ef76d2019-08-12 17:26:40 +0300542 expectedErr := errors.New("expected error")
543 sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
544 rNibErr := w.SaveNodeb(nbIdentity, &gnb)
545 assert.NotEmpty(t, rNibErr)
546}
547
548func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) {
549 writerPool = nil
irina006fbce2019-09-05 16:11:02 +0300550 assert.Panics(t, func() { GetRNibWriter().SaveNodeb(nil,nil) })
ss412g07ef76d2019-08-12 17:26:40 +0300551}
552
553func TestGetRNibWriter(t *testing.T) {
554 writerPool = nil
555 initSdlInstanceMock(namespace, 1)
556 received := GetRNibWriter()
irina006fbce2019-09-05 16:11:02 +0300557 assert.Empty(t, received)
ss412g07ef76d2019-08-12 17:26:40 +0300558 available, created := writerPool.Stats()
559 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
irina006fbce2019-09-05 16:11:02 +0300560 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
ss412g07ef76d2019-08-12 17:26:40 +0300561 writerPool.Close()
562}
563
564func TestClose(t *testing.T) {
565 writerPool = nil
566 instanceMock := initSdlInstanceMock(namespace, 2)
567 w1 := GetRNibWriter()
568 w2 := GetRNibWriter()
569 writerPool.Put(w1)
570 writerPool.Put(w2)
571 available, created := writerPool.Stats()
572 assert.Equal(t, 2, available, "number of available objects in the writerPool should be 2")
irina006fbce2019-09-05 16:11:02 +0300573 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
ss412g07ef76d2019-08-12 17:26:40 +0300574 var e error
575 instanceMock.On("Close").Return(e)
576 Close()
577 available, created = writerPool.Stats()
578 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
ss412g07ef76d2019-08-12 17:26:40 +0300579}
580
581func TestCloseOnClosedPoolFailure(t *testing.T) {
582 writerPool = nil
583 instanceMock := initSdlInstanceMock(namespace, 1)
584 w1 := GetRNibWriter()
585 writerPool.Put(w1)
586 available, created := writerPool.Stats()
587 assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
irina006fbce2019-09-05 16:11:02 +0300588 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
ss412g07ef76d2019-08-12 17:26:40 +0300589 var e error
590 instanceMock.On("Close").Return(e)
591 Close()
is005q19e72a52019-08-26 17:56:18 +0300592 assert.Panics(t, func() { Close() })
ss412g07ef76d2019-08-12 17:26:40 +0300593}
594
595func TestCloseFailure(t *testing.T) {
596 writerPool = nil
597 instanceMock := initSdlInstanceMock(namespace, 2)
598 w1 := GetRNibWriter()
599 writerPool.Put(w1)
600 available, created := writerPool.Stats()
601 assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
irina006fbce2019-09-05 16:11:02 +0300602 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
ss412g07ef76d2019-08-12 17:26:40 +0300603 e := errors.New("expected error")
604 instanceMock.On("Close").Return(e)
605 Close()
606 available, created = writerPool.Stats()
607 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
ss412g07ef76d2019-08-12 17:26:40 +0300608}
609
610func TestInit(t *testing.T) {
611 writerPool = nil
612 Init("", 1)
613 assert.NotNil(t, writerPool)
614 assert.NotNil(t, writerPool.New)
615 assert.NotNil(t, writerPool.Destroy)
616 available, created := writerPool.Stats()
617 assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
618 assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
619}
620
621//Integration tests
622//
ns019t57c3fae2019-08-12 20:08:49 +0300623//func TestSaveEnbGnbInteg(t *testing.T){
ss412g07ef76d2019-08-12 17:26:40 +0300624// for i := 0; i<10; i++{
625// Init("e2Manager", 1)
626// w := GetRNibWriter()
627// nb := entities.NodebInfo{}
628// nb.NodeType = entities.Node_ENB
629// nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
630// nb.Ip = "localhost"
631// nb.Port = uint32(5656 + i)
632// enb := entities.Enb{}
633// cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
634// cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
635// cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
636// enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
637// nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
638// plmnId := 0x02f828
639// nbId := 0x4a952a0a
640// nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
641// err := w.SaveNodeb(nbIdentity, &nb)
642// if err != nil{
643// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
644// }
645//
646// nb1 := entities.NodebInfo{}
647// nb1.NodeType = entities.Node_GNB
ns019t57c3fae2019-08-12 20:08:49 +0300648// nb1.ConnectionStatus = entities.ConnectionStatus_CONNECTED
ss412g07ef76d2019-08-12 17:26:40 +0300649// nb1.Ip = "localhost"
650// nb1.Port = uint32(6565 + i)
651// gnb := entities.Gnb{}
652// gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
653// gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
654// gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
655// gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
656// nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
657// nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
658// err = w.SaveNodeb(nbIdentity, &nb1)
659// if err != nil{
660// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
661// }
662// }
663//}
ns019t57c3fae2019-08-12 20:08:49 +0300664//
665//func TestSaveNbRanNamesInteg(t *testing.T){
666// for i := 0; i<10; i++{
667// Init("e2Manager", 1)
668// w := GetRNibWriter()
669// nb := entities.NodebInfo{}
670// nb.ConnectionStatus = entities.ConnectionStatus_CONNECTING
671// nb.Ip = "localhost"
672// nb.Port = uint32(5656 + i)
673// nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameOnly%d" ,i)}
674// err := w.SaveNodeb(nbIdentity, &nb)
675// if err != nil{
676// t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
677// }
678// }
679//}
680//
ss412g07ef76d2019-08-12 17:26:40 +0300681//func TestSaveRanLoadInformationInteg(t *testing.T){
682// Init("e2Manager", 1)
683// w := GetRNibWriter()
684// ranLoadInformation := generateRanLoadInformation()
685// err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
686// if err != nil{
687// t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)
688// }
is005q19e72a52019-08-26 17:56:18 +0300689//}