97535cc546e73c783b286943c4669df5d33b6b62
[ric-plt/e2mgr.git] / E2Manager / rNibWriter / rNibWriter_test.go
1 //
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
18 package rNibWriter
19
20 import (
21         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
22         "e2mgr/mocks"
23         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
24         "errors"
25         "fmt"
26         "github.com/golang/protobuf/proto"
27         "github.com/golang/protobuf/ptypes/timestamp"
28         "github.com/stretchr/testify/assert"
29         "testing"
30         "time"
31 )
32
33 func TestInitRNibWriter(t *testing.T) {
34         writerPool = nil
35         initSdlInstanceMock(namespace, 1)
36         available, created := writerPool.Stats()
37         assert.Equal(t, available, 0, "number of available objects in the writerPool should be 0")
38         assert.Equal(t, created, 0, "number of created objects in the writerPool should be 0")
39         w := GetRNibWriter()
40         assert.NotNil(t, w)
41 }
42
43 func TestInitPool(t *testing.T) {
44         writerPool = nil
45         sdlInstanceMock := new(mocks.MockSdlInstance)
46         initPool(1, func() interface{} {
47                 sdlI := common.ISdlInstance(sdlInstanceMock)
48                 return &rNibWriterInstance{sdl: &sdlI, namespace: namespace}
49         },
50                 func(obj interface{}) {
51                 },
52         )
53         assert.NotNil(t, writerPool)
54         assert.NotNil(t, writerPool.New)
55         assert.NotNil(t, writerPool.Destroy)
56         available, created := writerPool.Stats()
57         assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
58         assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
59 }
60
61 var namespace = "namespace"
62
63 func initSdlInstanceMock(namespace string, poolSize int) *mocks.MockSdlInstance {
64         sdlInstanceMock := new(mocks.MockSdlInstance)
65         initPool(poolSize, func() interface{} {
66                 sdlI := common.ISdlInstance(sdlInstanceMock)
67                 return &rNibWriterInstance{sdl: &sdlI, namespace: namespace}
68         },
69                 func(obj interface{}) {
70                 },
71         )
72         return sdlInstanceMock
73 }
74
75 func TestSaveEnb(t *testing.T) {
76         name := "name"
77         ranName := "RAN:" + name
78         writerPool = nil
79         sdlInstanceMock := initSdlInstanceMock(namespace, 1)
80         w := GetRNibWriter()
81         nb := entities.NodebInfo{}
82         nb.NodeType = entities.Node_ENB
83         nb.ConnectionStatus = 1
84         nb.Ip = "localhost"
85         nb.Port = 5656
86         enb := entities.Enb{}
87         cell := &entities.ServedCellInfo{CellId:"aaff", Pci:3}
88         cellEntity := entities.Cell{Type:entities.Cell_LTE_CELL, Cell:&entities.Cell_ServedCellInfo{ServedCellInfo:cell}}
89         enb.ServedCells = []*entities.ServedCellInfo{cell}
90         nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
91         data, err := proto.Marshal(&nb)
92         if err != nil {
93                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
94         }
95         var e error
96
97         cellData, err := proto.Marshal(&cellEntity)
98         if err != nil {
99                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal Cell entity. Error: %v", err)
100         }
101         var setExpected []interface{}
102         setExpected = append(setExpected, ranName, data)
103         setExpected = append(setExpected, "ENB:02f829:4a952a0a", data)
104         setExpected = append(setExpected, fmt.Sprintf("CELL:%s", cell.GetCellId()), cellData)
105         setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetPci()), cellData)
106
107         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
108         nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}}
109         nbIdData, err := proto.Marshal(nbIdentity)
110         if err != nil {
111                 t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB Identity entity. Error: %v", err)
112         }
113         sdlInstanceMock.On("AddMember", "ENB", []interface{}{nbIdData}).Return(e)
114         rNibErr := w.SaveNodeb(nbIdentity, &nb)
115         assert.Nil(t, rNibErr)
116 }
117
118 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
119         name := "name"
120         writerPool = nil
121         initSdlInstanceMock(namespace, 1)
122         w := GetRNibWriter()
123         nb := entities.NodebInfo{}
124         nb.NodeType = entities.Node_ENB
125         nb.ConnectionStatus = 1
126         nb.Ip = "localhost"
127         nb.Port = 5656
128         enb := entities.Enb{}
129         cell := &entities.ServedCellInfo{Pci:3}
130         enb.ServedCells = []*entities.ServedCellInfo{cell}
131         nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
132
133         nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}}
134         rNibErr := w.SaveNodeb(nbIdentity, &nb)
135         assert.NotNil(t, rNibErr)
136         assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
137         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
138 }
139
140 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
141         writerPool = nil
142         initSdlInstanceMock(namespace, 1)
143         w := GetRNibWriter()
144         nb := entities.NodebInfo{}
145         nb.NodeType = entities.Node_ENB
146         nb.ConnectionStatus = 1
147         nb.Ip = "localhost"
148         nb.Port = 5656
149         enb := entities.Enb{}
150         cell := &entities.ServedCellInfo{CellId:"aaa",Pci:3}
151         enb.ServedCells = []*entities.ServedCellInfo{cell}
152         nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
153
154         nbIdentity := &entities.NbIdentity{InventoryName:"", GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}}
155         rNibErr := w.SaveNodeb(nbIdentity, &nb)
156         assert.NotNil(t, rNibErr)
157         assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
158         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
159 }
160
161 func TestSaveEnbOnClosedPool(t *testing.T) {
162         name := "name"
163         writerPool = nil
164         sdlInstanceMock := initSdlInstanceMock(namespace, 1)
165         w := GetRNibWriter()
166         nb := entities.NodebInfo{}
167         nb.NodeType = entities.Node_ENB
168         nb.ConnectionStatus = 1
169         nb.Ip = "localhost"
170         nb.Port = 5656
171         enb := entities.Enb{}
172         nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
173         data, err := proto.Marshal(&nb)
174         if err != nil {
175                 t.Errorf("#rNibWriter_test.TestSaveEnbOnClosedPool - Failed to marshal NodeB entity. Error: %v", err)
176         }
177         setExpected := []interface{}{name, data}
178         var e error
179         sdlInstanceMock.On("Set", setExpected).Return(e)
180         writerPool.Close()
181         nbIdentity := &entities.NbIdentity{}
182         assert.Panics(t, func(){w.SaveNodeb(nbIdentity, &nb)})
183 }
184
185 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
186         name := "name"
187         writerPool = nil
188         initSdlInstanceMock(namespace, 1)
189         w := GetRNibWriter()
190         nb := entities.NodebInfo{}
191         nb.NodeType = entities.Node_GNB
192         nb.ConnectionStatus = 1
193         nb.Ip = "localhost"
194         nb.Port = 5656
195         gnb := entities.Gnb{}
196         cellInfo:= &entities.ServedNRCellInformation{NrPci:2}
197         cell := &entities.ServedNRCell{ServedNrCellInformation:cellInfo}
198         gnb.ServedNrCells = []*entities.ServedNRCell{cell}
199         nb.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
200
201         nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}}
202         rNibErr := w.SaveNodeb(nbIdentity, &nb)
203         assert.NotNil(t, rNibErr)
204         assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
205         assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
206 }
207
208 func TestSaveGnb(t *testing.T) {
209         name := "name"
210         ranName := "RAN:" + name
211         writerPool = nil
212         sdlInstanceMock := initSdlInstanceMock(namespace, 1)
213         w := GetRNibWriter()
214         nb := entities.NodebInfo{}
215         nb.NodeType = entities.Node_GNB
216         nb.ConnectionStatus = 1
217         nb.Ip = "localhost"
218         nb.Port = 5656
219         gnb := entities.Gnb{}
220         cellInfo:= &entities.ServedNRCellInformation{NrPci:2,CellId:"ccdd"}
221         cell := &entities.ServedNRCell{ServedNrCellInformation:cellInfo}
222         cellEntity := entities.Cell{Type:entities.Cell_NR_CELL, Cell:&entities.Cell_ServedNrCell{ServedNrCell:cell}}
223         gnb.ServedNrCells = []*entities.ServedNRCell{cell}
224         nb.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
225         data, err := proto.Marshal(&nb)
226         if err != nil {
227                 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB entity. Error: %v", err)
228         }
229         var e error
230
231
232         cellData, err := proto.Marshal(&cellEntity)
233         if err != nil {
234                 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal Cell entity. Error: %v", err)
235         }
236         var setExpected []interface{}
237         setExpected = append(setExpected, ranName, data)
238         setExpected = append(setExpected, "GNB:02f829:4a952a0a", data)
239         setExpected = append(setExpected, fmt.Sprintf("NRCELL:%s", cell.GetServedNrCellInformation().GetCellId()), cellData)
240         setExpected = append(setExpected, fmt.Sprintf("PCI:%s:%02x", name, cell.GetServedNrCellInformation().GetNrPci()), cellData)
241
242         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
243         nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}}
244         nbIdData, err := proto.Marshal(nbIdentity)
245         if err != nil {
246                 t.Errorf("#rNibWriter_test.TestSaveGnb - Failed to marshal NodeB Identity entity. Error: %v", err)
247         }
248         sdlInstanceMock.On("AddMember", "GNB", []interface{}{nbIdData}).Return(e)
249
250         rNibErr := w.SaveNodeb(nbIdentity, &nb)
251         assert.Nil(t, rNibErr)
252 }
253
254 func TestSaveRanLoadInformationSuccess(t *testing.T) {
255         inventoryName := "name"
256         loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
257
258         if validationErr != nil {
259                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
260         }
261
262         writerPool = nil
263         sdlInstanceMock := initSdlInstanceMock(namespace, 1)
264         w := GetRNibWriter()
265
266
267         ranLoadInformation := generateRanLoadInformation()
268         data, err := proto.Marshal(ranLoadInformation)
269
270         if err != nil {
271                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
272         }
273
274         var e error
275         var setExpected []interface{}
276         setExpected = append(setExpected, loadKey, data)
277         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
278
279
280         rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
281         assert.Nil(t, rNibErr)
282 }
283
284 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
285         inventoryName := "name2"
286         writerPool = nil
287         initSdlInstanceMock(namespace, 1)
288         w := GetRNibWriter()
289
290         expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
291         err:= w.SaveRanLoadInformation(inventoryName, nil)
292         assert.Equal(t, expectedErr, err)
293 }
294
295 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
296         inventoryName := ""
297         writerPool = nil
298         initSdlInstanceMock(namespace, 1)
299         w := GetRNibWriter()
300
301         err:= w.SaveRanLoadInformation(inventoryName, nil)
302         assert.NotNil(t, err)
303         assert.Equal(t, common.VALIDATION_ERROR, err.GetCode())
304 }
305
306 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
307         inventoryName := "name2"
308
309         loadKey, validationErr := common.ValidateAndBuildRanLoadInformationKey(inventoryName)
310
311         if validationErr != nil {
312                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
313         }
314
315
316         writerPool = nil
317         sdlInstanceMock := initSdlInstanceMock(namespace, 1)
318         w := GetRNibWriter()
319
320         ranLoadInformation := generateRanLoadInformation()
321         data, err := proto.Marshal(ranLoadInformation)
322
323         if err != nil {
324                 t.Errorf("#rNibWriter_test.TestSaveRanLoadInformation - Failed to marshal RanLoadInformation entity. Error: %v", err)
325         }
326
327
328         expectedErr := errors.New("expected error")
329         var setExpected []interface{}
330         setExpected = append(setExpected, loadKey, data)
331         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
332
333
334         rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
335         assert.NotNil(t, rNibErr)
336         assert.Equal(t, common.INTERNAL_ERROR, rNibErr.GetCode())
337         assert.Equal(t, expectedErr, rNibErr.GetError())
338 }
339
340 func generateCellLoadInformation() *entities.CellLoadInformation {
341         cellLoadInformation := entities.CellLoadInformation{}
342
343         cellLoadInformation.CellId = "123"
344
345         ulInterferenceOverloadIndication := entities.UlInterferenceOverloadIndication_HIGH_INTERFERENCE
346         cellLoadInformation.UlInterferenceOverloadIndications = []entities.UlInterferenceOverloadIndication{ulInterferenceOverloadIndication}
347
348         ulHighInterferenceInformation := entities.UlHighInterferenceInformation{
349                 TargetCellId:"456",
350                 UlHighInterferenceIndication:"xxx",
351         }
352
353         cellLoadInformation.UlHighInterferenceInfos = []*entities.UlHighInterferenceInformation{&ulHighInterferenceInformation }
354
355         cellLoadInformation.RelativeNarrowbandTxPower = &entities.RelativeNarrowbandTxPower{
356                 RntpPerPrb:"xxx",
357                 RntpThreshold:entities.RntpThreshold_NEG_4,
358                 NumberOfCellSpecificAntennaPorts: entities.NumberOfCellSpecificAntennaPorts_V1_ANT_PRT,
359                 PB: 1,
360                 PdcchInterferenceImpact:2,
361                 EnhancedRntp: &entities.EnhancedRntp{
362                         EnhancedRntpBitmap:"xxx",
363                         RntpHighPowerThreshold:entities.RntpThreshold_NEG_2,
364                         EnhancedRntpStartTimes: []*entities.StartTime{&entities.StartTime{StartSfn:500,StartSubframeNumber:5}},
365                 },
366         }
367
368         cellLoadInformation.AbsInformation = &entities.AbsInformation{
369                 Mode: entities.AbsInformationMode_ABS_INFO_FDD,
370                 AbsPatternInfo:"xxx",
371                 NumberOfCellSpecificAntennaPorts:entities.NumberOfCellSpecificAntennaPorts_V2_ANT_PRT,
372                 MeasurementSubset:"xxx",
373         }
374
375         cellLoadInformation.InvokeIndication = entities.InvokeIndication_ABS_INFORMATION
376
377         cellLoadInformation.ExtendedUlInterferenceOverloadInfo = &entities.ExtendedUlInterferenceOverloadInfo{
378                 AssociatedSubframes:"xxx",
379                 ExtendedUlInterferenceOverloadIndications:cellLoadInformation.UlInterferenceOverloadIndications,
380         }
381
382         compInformationItem := &entities.CompInformationItem{
383                 CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis:"xxx"}},
384                 BenefitMetric:50,
385         }
386
387         cellLoadInformation.CompInformation = &entities.CompInformation{
388                 CompInformationItems:[]*entities.CompInformationItem{compInformationItem},
389                 CompInformationStartTime:[]*entities.StartTime{&entities.StartTime{StartSfn:123,StartSubframeNumber:456}},
390         }
391
392         cellLoadInformation.DynamicDlTransmissionInformation = &entities.DynamicDlTransmissionInformation{
393                 State: entities.NaicsState_NAICS_ACTIVE,
394                 TransmissionModes:"xxx",
395                 PB: 2,
396                 PAList:[]entities.PA{entities.PA_DB_NEG_3},
397         }
398
399         return &cellLoadInformation
400 }
401
402 func generateRanLoadInformation() *entities.RanLoadInformation {
403         ranLoadInformation := entities.RanLoadInformation{}
404
405         ranLoadInformation.LoadTimestamp = &timestamp.Timestamp{Seconds:time.Now().Unix(),Nanos: int32(time.Now().UnixNano())}
406
407
408         cellLoadInformation := generateCellLoadInformation()
409         ranLoadInformation.CellLoadInfos = []*entities.CellLoadInformation{cellLoadInformation}
410
411         return &ranLoadInformation
412 }
413
414 func TestSaveNilEntityFailure(t *testing.T) {
415         writerPool = nil
416         initSdlInstanceMock(namespace, 1)
417         w := GetRNibWriter()
418         expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
419         nbIdentity := &entities.NbIdentity{}
420         actualErr := w.SaveNodeb(nbIdentity, nil)
421         assert.Equal(t, expectedErr, actualErr)
422 }
423
424 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
425         writerPool = nil
426         initSdlInstanceMock(namespace, 1)
427         w := GetRNibWriter()
428         expectedErr := common.NewValidationError(errors.New("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 "))
429         nbIdentity := &entities.NbIdentity{InventoryName:"name", GlobalNbId:&entities.GlobalNbId{PlmnId:"02f829", NbId:"4a952a0a"}}
430         nb := &entities.NodebInfo{}
431         nb.Port = 5656
432         nb.Ip = "localhost"
433         actualErr := w.SaveNodeb(nbIdentity, nb)
434         assert.Equal(t, expectedErr, actualErr)
435 }
436
437 func TestSaveEntityFailure(t *testing.T) {
438         name := "name"
439         plmnId := "02f829"
440         nbId := "4a952a0a"
441
442         writerPool = nil
443         sdlInstanceMock := initSdlInstanceMock(namespace, 1)
444         w := GetRNibWriter()
445         gnb := entities.NodebInfo{}
446         gnb.NodeType = entities.Node_GNB
447         data, err := proto.Marshal(&gnb)
448         if err != nil {
449                 t.Errorf("#rNibWriter_test.TestSaveEntityFailure - Failed to marshal NodeB entity. Error: %v", err)
450         }
451         nbIdentity := &entities.NbIdentity{InventoryName:name, GlobalNbId:&entities.GlobalNbId{PlmnId:plmnId, NbId:nbId}}
452         setExpected := []interface{}{"RAN:" + name, data}
453         setExpected = append(setExpected,"GNB:" + plmnId + ":" + nbId, data)
454         expectedErr := errors.New("expected error")
455         sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
456         rNibErr := w.SaveNodeb(nbIdentity, &gnb)
457         assert.NotEmpty(t, rNibErr)
458 }
459
460 func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) {
461         writerPool = nil
462         assert.Panics(t, func(){GetRNibWriter()})
463 }
464
465 func TestGetRNibWriter(t *testing.T) {
466         writerPool = nil
467         initSdlInstanceMock(namespace, 1)
468         received := GetRNibWriter()
469         assert.NotEmpty(t, received)
470         available, created := writerPool.Stats()
471         assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
472         assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
473         writerPool.Close()
474 }
475
476 func TestClose(t *testing.T) {
477         writerPool = nil
478         instanceMock := initSdlInstanceMock(namespace, 2)
479         w1 := GetRNibWriter()
480         w2 := GetRNibWriter()
481         writerPool.Put(w1)
482         writerPool.Put(w2)
483         available, created := writerPool.Stats()
484         assert.Equal(t, 2, available, "number of available objects in the writerPool should be 2")
485         assert.Equal(t, 2, created, "number of created objects in the writerPool should be 2")
486         var e error
487         instanceMock.On("Close").Return(e)
488         Close()
489         available, created = writerPool.Stats()
490         assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
491         assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
492 }
493
494 func TestCloseOnClosedPoolFailure(t *testing.T) {
495         writerPool = nil
496         instanceMock := initSdlInstanceMock(namespace, 1)
497         w1 := GetRNibWriter()
498         writerPool.Put(w1)
499         available, created := writerPool.Stats()
500         assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
501         assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
502         var e error
503         instanceMock.On("Close").Return(e)
504         Close()
505         assert.Panics(t, func(){Close()})
506 }
507
508 func TestCloseFailure(t *testing.T) {
509         writerPool = nil
510         instanceMock := initSdlInstanceMock(namespace, 2)
511         w1 := GetRNibWriter()
512         writerPool.Put(w1)
513         available, created := writerPool.Stats()
514         assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
515         assert.Equal(t, 1, created, "number of created objects in the writerPool should be 1")
516         e := errors.New("expected error")
517         instanceMock.On("Close").Return(e)
518         Close()
519         available, created = writerPool.Stats()
520         assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
521         assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
522 }
523
524 func TestInit(t *testing.T) {
525         writerPool = nil
526         Init("", 1)
527         assert.NotNil(t, writerPool)
528         assert.NotNil(t, writerPool.New)
529         assert.NotNil(t, writerPool.Destroy)
530         available, created := writerPool.Stats()
531         assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
532         assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
533 }
534
535 //Integration tests
536 //
537 //func TestSaveEnbInteg(t *testing.T){
538 //      for i := 0; i<10; i++{
539 //              Init("e2Manager", 1)
540 //              w := GetRNibWriter()
541 //              nb := entities.NodebInfo{}
542 //              nb.NodeType = entities.Node_ENB
543 //              nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
544 //              nb.Ip = "localhost"
545 //              nb.Port = uint32(5656 + i)
546 //              enb := entities.Enb{}
547 //              cell1 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",111 + i), Pci:uint32(11 + i)}
548 //              cell2 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",222 + i), Pci:uint32(22 + i)}
549 //              cell3 := &entities.ServedCellInfo{CellId:fmt.Sprintf("%02x",333 + i), Pci:uint32(33 + i)}
550 //              enb.ServedCells = []*entities.ServedCellInfo{cell1, cell2, cell3}
551 //              nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
552 //              plmnId := 0x02f828
553 //              nbId := 0x4a952a0a
554 //              nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
555 //              err := w.SaveNodeb(nbIdentity, &nb)
556 //              if err != nil{
557 //                      t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
558 //              }
559 //
560 //              nb1 := entities.NodebInfo{}
561 //              nb1.NodeType = entities.Node_GNB
562 //              nb.ConnectionStatus = entities.ConnectionStatus_CONNECTED
563 //              nb1.Ip = "localhost"
564 //              nb1.Port =  uint32(6565 + i)
565 //              gnb := entities.Gnb{}
566 //              gCell1 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",1111 + i), NrPci:uint32(1 + i)}}
567 //              gCell2 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",2222 + i), NrPci:uint32(2 + i)}}
568 //              gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
569 //              gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
570 //              nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
571 //              nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
572 //              err = w.SaveNodeb(nbIdentity, &nb1)
573 //              if err != nil{
574 //                      t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
575 //              }
576 //      }
577 //}
578
579 //func TestSaveRanLoadInformationInteg(t *testing.T){
580 //              Init("e2Manager", 1)
581 //              w := GetRNibWriter()
582 //              ranLoadInformation := generateRanLoadInformation()
583 //              err := w.SaveRanLoadInformation("ran_integ", ranLoadInformation)
584 //              if err != nil{
585 //                      t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationInteg - Failed to save RanLoadInformation entity. Error: %v", err)
586 //              }
587 //}