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