[RIC-475] [RIC-507] Inject RanStatusChangeManager | Enhance E2 Setup flow | Remove...
[ric-plt/e2mgr.git] / E2Manager / rNibWriter / rNibWriter_test.go
index f16228b..ab67b80 100644 (file)
 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
 //  platform project (RICP).
 
-
 package rNibWriter
 
 import (
        "e2mgr/mocks"
+       "encoding/json"
        "errors"
        "fmt"
        "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
@@ -32,62 +32,160 @@ import (
        "time"
 )
 
-func TestInitRNibWriter(t *testing.T) {
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       available, created := writerPool.Stats()
-       assert.Equal(t, available, 0, "number of available objects in the writerPool should be 0")
-       assert.Equal(t, created, 0, "number of created objects in the writerPool should be 0")
-       w := GetRNibWriter()
-       assert.NotNil(t, w)
-}
-
-func TestInitPool(t *testing.T) {
-       writerPool = nil
-       sdlInstanceMock := new(mocks.MockSdlInstance)
-       initPool(1, func() interface{} {
-               sdlI := common.ISdlInstance(sdlInstanceMock)
-               return &rNibWriterInstance{sdl: &sdlI, namespace: namespace}
-       },
-               func(obj interface{}) {
-               },
-       )
-       assert.NotNil(t, writerPool)
-       assert.NotNil(t, writerPool.New)
-       assert.NotNil(t, writerPool.Destroy)
-       available, created := writerPool.Stats()
-       assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
+var namespace = "namespace"
+const (
+       RanName = "test"
+)
+
+func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) {
+       sdlInstanceMock = new(mocks.MockSdlInstance)
+       w = GetRNibWriter(sdlInstanceMock)
+       return
 }
 
-var namespace = "namespace"
+func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo {
+       nodebInfo := &entities.NodebInfo{
+               RanName:          inventoryName,
+               GlobalNbId:       &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId},
+               NodeType:         nodeType,
+               ConnectionStatus: entities.ConnectionStatus_CONNECTED,
+       }
 
-func initSdlInstanceMock(namespace string, poolSize int) *mocks.MockSdlInstance {
-       sdlInstanceMock := new(mocks.MockSdlInstance)
-       initPool(poolSize, func() interface{} {
-               sdlI := common.ISdlInstance(sdlInstanceMock)
-               return &rNibWriterInstance{sdl: &sdlI, namespace: namespace}
-       },
-               func(obj interface{}) {
-               },
-       )
-       return sdlInstanceMock
+       if nodeType == entities.Node_ENB {
+               nodebInfo.Configuration = &entities.NodebInfo_Enb{
+                       Enb: &entities.Enb{},
+               }
+       } else if nodeType == entities.Node_GNB {
+               nodebInfo.Configuration = &entities.NodebInfo_Gnb{
+                       Gnb: &entities.Gnb{},
+               }
+       }
+
+       return nodebInfo
+}
+
+func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell {
+
+       servedNrCells := []*entities.ServedNRCell{}
+
+       for i, v := range cellIds {
+               servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{
+                       CellId: v,
+                       ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{
+                               Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{
+
+                               },
+                       },
+                       NrMode:      entities.Nr_FDD,
+                       NrPci:       uint32(i + 1),
+                       ServedPlmns: []string{"whatever"},
+               }})
+       }
+
+       return servedNrCells
+}
+
+func TestRemoveServedNrCellsSuccess(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
+       sdlInstanceMock.On("Remove", buildCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(nil)
+       err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
+       assert.Nil(t, err)
+}
+
+func TestRemoveServedNrCellsFailure(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       servedNrCellsToRemove := generateServedNrCells("whatever1", "whatever2")
+       sdlInstanceMock.On("Remove", buildCellKeysToRemove(RanName, servedNrCellsToRemove)).Return(errors.New("expected error"))
+       err := w.RemoveServedNrCells(RanName, servedNrCellsToRemove)
+       assert.IsType(t, &common.InternalError{}, err)
+}
+
+func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       servedNrCells := generateServedNrCells("test1", "test2")
+       nodebInfo := &entities.NodebInfo{}
+       sdlInstanceMock.AssertNotCalled(t, "Set")
+       rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+}
+
+func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}}
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
+       nodebInfo.GetGnb().ServedNrCells = servedNrCells
+       sdlInstanceMock.AssertNotCalled(t, "Set")
+       rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+}
+
+func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} {
+
+       nodebInfoData, err := proto.Marshal(nodebInfo)
+       if err != nil {
+               t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err)
+       }
+
+       nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName)
+       nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId)
+       setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData}
+
+       for _, v := range servedNrCells {
+
+               cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}}
+               cellData, err := proto.Marshal(&cellEntity)
+
+               if err != nil {
+                       t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err)
+               }
+
+               nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId())
+               cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci())
+               setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData)
+       }
+
+       return setExpected
+}
+
+func TestUpdateGnbCellsSdlFailure(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       servedNrCells := generateServedNrCells("test1", "test2")
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
+       nodebInfo.GetGnb().ServedNrCells = servedNrCells
+       setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(errors.New("expected error"))
+       rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
+       assert.IsType(t, &common.InternalError{}, rNibErr)
+}
+
+func TestUpdateGnbCellsSuccess(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       servedNrCells := generateServedNrCells("test1", "test2")
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId)
+       nodebInfo.GetGnb().ServedNrCells = servedNrCells
+       setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells)
+       var e error
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+       rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells)
+       assert.Nil(t, rNibErr)
 }
 
 func TestUpdateNodebInfoSuccess(t *testing.T) {
        inventoryName := "name"
        plmnId := "02f829"
        nbId := "4a952a0a"
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
-       nodebInfo := &entities.NodebInfo{}
-       nodebInfo.RanName = inventoryName
-       nodebInfo.GlobalNbId = &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}
-       nodebInfo.NodeType = entities.Node_ENB
-       nodebInfo.ConnectionStatus = 1
-       enb := entities.Enb{}
-       nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
        data, err := proto.Marshal(nodebInfo)
        if err != nil {
                t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err)
@@ -110,9 +208,7 @@ func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
        inventoryName := "name"
        plmnId := "02f829"
        nbId := "4a952a0a"
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
        nodebInfo := &entities.NodebInfo{}
        data, err := proto.Marshal(nodebInfo)
        if err != nil {
@@ -136,9 +232,7 @@ func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
 
 func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
        inventoryName := "name"
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
        nodebInfo := &entities.NodebInfo{}
        nodebInfo.RanName = inventoryName
        data, err := proto.Marshal(nodebInfo)
@@ -160,9 +254,7 @@ func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
 func TestSaveEnb(t *testing.T) {
        name := "name"
        ranName := "RAN:" + name
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{}
        nb.NodeType = entities.Node_ENB
        nb.ConnectionStatus = 1
@@ -210,9 +302,7 @@ func TestSaveEnb(t *testing.T) {
 
 func TestSaveEnbCellIdValidationFailure(t *testing.T) {
        name := "name"
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, _ := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{}
        nb.NodeType = entities.Node_ENB
        nb.ConnectionStatus = 1
@@ -231,9 +321,7 @@ func TestSaveEnbCellIdValidationFailure(t *testing.T) {
 }
 
 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, _ := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{}
        nb.NodeType = entities.Node_ENB
        nb.ConnectionStatus = 1
@@ -251,35 +339,9 @@ func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
        assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
 }
 
-func TestSaveEnbOnClosedPool(t *testing.T) {
-       name := "name"
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
-       nb := entities.NodebInfo{}
-       nb.NodeType = entities.Node_ENB
-       nb.ConnectionStatus = 1
-       nb.Ip = "localhost"
-       nb.Port = 5656
-       enb := entities.Enb{}
-       nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
-       data, err := proto.Marshal(&nb)
-       if err != nil {
-               t.Errorf("#rNibWriter_test.TestSaveEnbOnClosedPool - Failed to marshal NodeB entity. Error: %v", err)
-       }
-       setExpected := []interface{}{name, data}
-       var e error
-       sdlInstanceMock.On("Set", setExpected).Return(e)
-       writerPool.Close()
-       nbIdentity := &entities.NbIdentity{}
-       assert.Panics(t, func() { w.SaveNodeb(nbIdentity, &nb) })
-}
-
 func TestSaveGnbCellIdValidationFailure(t *testing.T) {
        name := "name"
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, _ := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{}
        nb.NodeType = entities.Node_GNB
        nb.ConnectionStatus = 1
@@ -301,9 +363,7 @@ func TestSaveGnbCellIdValidationFailure(t *testing.T) {
 func TestSaveGnb(t *testing.T) {
        name := "name"
        ranName := "RAN:" + name
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
        nb := entities.NodebInfo{}
        nb.NodeType = entities.Node_GNB
        nb.ConnectionStatus = 1
@@ -357,9 +417,7 @@ func TestSaveRanLoadInformationSuccess(t *testing.T) {
                t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
        }
 
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
 
        ranLoadInformation := generateRanLoadInformation()
        data, err := proto.Marshal(ranLoadInformation)
@@ -379,9 +437,7 @@ func TestSaveRanLoadInformationSuccess(t *testing.T) {
 
 func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
        inventoryName := "name2"
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, _ := initSdlInstanceMock(namespace)
 
        expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
        err := w.SaveRanLoadInformation(inventoryName, nil)
@@ -390,9 +446,7 @@ func TestSaveRanLoadInformationMarshalNilFailure(t *testing.T) {
 
 func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
        inventoryName := ""
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, _ := initSdlInstanceMock(namespace)
 
        err := w.SaveRanLoadInformation(inventoryName, nil)
        assert.NotNil(t, err)
@@ -408,9 +462,7 @@ func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
                t.Errorf("#rNibWriter_test.TestSaveRanLoadInformationSuccess - Failed to build ran load infromation key. Error: %v", validationErr)
        }
 
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
 
        ranLoadInformation := generateRanLoadInformation()
        data, err := proto.Marshal(ranLoadInformation)
@@ -472,7 +524,7 @@ func generateCellLoadInformation() *entities.CellLoadInformation {
        }
 
        compInformationItem := &entities.CompInformationItem{
-               CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis: "xxx"}},
+               CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}},
                BenefitMetric:      50,
        }
 
@@ -503,9 +555,7 @@ func generateRanLoadInformation() *entities.RanLoadInformation {
 }
 
 func TestSaveNilEntityFailure(t *testing.T) {
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, _ := initSdlInstanceMock(namespace)
        expectedErr := common.NewInternalError(errors.New("proto: Marshal called with nil"))
        nbIdentity := &entities.NbIdentity{}
        actualErr := w.SaveNodeb(nbIdentity, nil)
@@ -513,16 +563,13 @@ func TestSaveNilEntityFailure(t *testing.T) {
 }
 
 func TestSaveUnknownTypeEntityFailure(t *testing.T) {
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
-       expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")
+       w, _ := initSdlInstanceMock(namespace)
        nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
        nb := &entities.NodebInfo{}
        nb.Port = 5656
        nb.Ip = "localhost"
        actualErr := w.SaveNodeb(nbIdentity, nb)
-       assert.Equal(t, expectedErr, actualErr)
+       assert.IsType(t, &common.ValidationError{}, actualErr)
 }
 
 func TestSaveEntityFailure(t *testing.T) {
@@ -530,9 +577,7 @@ func TestSaveEntityFailure(t *testing.T) {
        plmnId := "02f829"
        nbId := "4a952a0a"
 
-       writerPool = nil
-       sdlInstanceMock := initSdlInstanceMock(namespace, 1)
-       w := GetRNibWriter()
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
        gnb := entities.NodebInfo{}
        gnb.NodeType = entities.Node_GNB
        data, err := proto.Marshal(&gnb)
@@ -548,77 +593,267 @@ func TestSaveEntityFailure(t *testing.T) {
        assert.NotEmpty(t, rNibErr)
 }
 
-func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) {
-       writerPool = nil
-       assert.Panics(t, func() { GetRNibWriter().SaveNodeb(nil,nil) })
+func TestGetRNibWriter(t *testing.T) {
+       received, _ := initSdlInstanceMock(namespace)
+       assert.NotEmpty(t, received)
 }
 
-func TestGetRNibWriter(t *testing.T) {
-       writerPool = nil
-       initSdlInstanceMock(namespace, 1)
-       received := GetRNibWriter()
-       assert.Empty(t, received)
-       available, created := writerPool.Stats()
-       assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
-       writerPool.Close()
-}
-
-func TestClose(t *testing.T) {
-       writerPool = nil
-       instanceMock := initSdlInstanceMock(namespace, 2)
-       w1 := GetRNibWriter()
-       w2 := GetRNibWriter()
-       writerPool.Put(w1)
-       writerPool.Put(w2)
-       available, created := writerPool.Stats()
-       assert.Equal(t, 2, available, "number of available objects in the writerPool should be 2")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
+func TestSaveE2TInstanceSuccess(t *testing.T) {
+       address := "10.10.2.15:9800"
+       loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
+
+       if validationErr != nil {
+               t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to build E2T Instance key. Error: %v", validationErr)
+       }
+
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       e2tInstance := generateE2tInstance(address)
+       data, err := json.Marshal(e2tInstance)
+
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSuccess - Failed to marshal E2tInstance entity. Error: %v", err)
+       }
+
+       var e error
+       var setExpected []interface{}
+       setExpected = append(setExpected, loadKey, data)
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.SaveE2TInstance(e2tInstance)
+       assert.Nil(t, rNibErr)
+}
+
+func TestSaveE2TInstanceNullE2tInstanceFailure(t *testing.T) {
+       w, _ := initSdlInstanceMock(namespace)
+       var address string
+       e2tInstance := entities.NewE2TInstance(address, "test")
+       err := w.SaveE2TInstance(e2tInstance)
+       assert.NotNil(t, err)
+       assert.IsType(t, &common.ValidationError{}, err)
+}
+
+func TestSaveE2TInstanceSdlFailure(t *testing.T) {
+       address := "10.10.2.15:9800"
+       loadKey, validationErr := common.ValidateAndBuildE2TInstanceKey(address)
+
+       if validationErr != nil {
+               t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to build E2T Instance key. Error: %v", validationErr)
+       }
+
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       e2tInstance := generateE2tInstance(address)
+       data, err := json.Marshal(e2tInstance)
+
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestSaveE2TInstanceSdlFailure - Failed to marshal E2tInstance entity. Error: %v", err)
+       }
+
+       expectedErr := errors.New("expected error")
+       var setExpected []interface{}
+       setExpected = append(setExpected, loadKey, data)
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
+
+       rNibErr := w.SaveE2TInstance(e2tInstance)
+       assert.NotNil(t, rNibErr)
+       assert.IsType(t, &common.InternalError{}, rNibErr)
+}
+
+func generateE2tInstance(address string) *entities.E2TInstance {
+       e2tInstance := entities.NewE2TInstance(address, "pod test")
+
+       e2tInstance.AssociatedRanList = []string{"test1", "test2"}
+
+       return e2tInstance
+}
+
+func TestSaveE2TAddressesSuccess(t *testing.T) {
+       address := "10.10.2.15:9800"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       e2tAddresses := []string{address}
+       data, err := json.Marshal(e2tAddresses)
+
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSuccess - Failed to marshal E2TInfoList. Error: %v", err)
+       }
+
+       var e error
+       var setExpected []interface{}
+       setExpected = append(setExpected, E2TAddressesKey, data)
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.SaveE2TAddresses(e2tAddresses)
+       assert.Nil(t, rNibErr)
+}
+
+func TestSaveE2TAddressesSdlFailure(t *testing.T) {
+       address := "10.10.2.15:9800"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       e2tAddresses := []string{address}
+       data, err := json.Marshal(e2tAddresses)
+
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestSaveE2TInfoListSdlFailure - Failed to marshal E2TInfoList. Error: %v", err)
+       }
+
+       expectedErr := errors.New("expected error")
+       var setExpected []interface{}
+       setExpected = append(setExpected, E2TAddressesKey, data)
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(expectedErr)
+
+       rNibErr := w.SaveE2TAddresses(e2tAddresses)
+       assert.NotNil(t, rNibErr)
+       assert.IsType(t, &common.InternalError{}, rNibErr)
+}
+
+func TestRemoveE2TInstanceSuccess(t *testing.T) {
+       address := "10.10.2.15:9800"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
        var e error
-       instanceMock.On("Close").Return(e)
-       Close()
-       available, created = writerPool.Stats()
-       assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
-}
-
-func TestCloseOnClosedPoolFailure(t *testing.T) {
-       writerPool = nil
-       instanceMock := initSdlInstanceMock(namespace, 1)
-       w1 := GetRNibWriter()
-       writerPool.Put(w1)
-       available, created := writerPool.Stats()
-       assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
+       sdlInstanceMock.On("Remove", e2tAddresses).Return(e)
+
+       rNibErr := w.RemoveE2TInstance(address)
+       assert.Nil(t, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestRemoveE2TInstanceSdlFailure(t *testing.T) {
+       address := "10.10.2.15:9800"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       e2tAddresses := []string{fmt.Sprintf("E2TInstance:%s", address)}
+       expectedErr := errors.New("expected error")
+       sdlInstanceMock.On("Remove", e2tAddresses).Return(expectedErr)
+
+       rNibErr := w.RemoveE2TInstance(address)
+       assert.IsType(t, &common.InternalError{}, rNibErr)
+}
+
+func TestRemoveE2TInstanceEmptyAddressFailure(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       rNibErr := w.RemoveE2TInstance("")
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestUpdateNodebInfoOnConnectionStatusInversionSuccess(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       channelName := "RAN_CONNECT_STATE_CHANGE"
+       eventName := inventoryName + "_" + "CONNECTED"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId)
+       data, err := proto.Marshal(nodebInfo)
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionSuccess - Failed to marshal NodeB entity. Error: %v", err)
+       }
        var e error
-       instanceMock.On("Close").Return(e)
-       Close()
-       assert.Panics(t, func() { Close() })
-}
-
-func TestCloseFailure(t *testing.T) {
-       writerPool = nil
-       instanceMock := initSdlInstanceMock(namespace, 2)
-       w1 := GetRNibWriter()
-       writerPool.Put(w1)
-       available, created := writerPool.Stats()
-       assert.Equal(t, 1, available, "number of available objects in the writerPool should be 1")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
-       e := errors.New("expected error")
-       instanceMock.On("Close").Return(e)
-       Close()
-       available, created = writerPool.Stats()
-       assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
-}
-
-func TestInit(t *testing.T) {
-       writerPool = nil
-       Init("", 1)
-       assert.NotNil(t, writerPool)
-       assert.NotNil(t, writerPool.New)
-       assert.NotNil(t, writerPool.Destroy)
-       available, created := writerPool.Stats()
-       assert.Equal(t, 0, available, "number of available objects in the writerPool should be 0")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
+       var setExpected []interface{}
+
+       nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+       nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
+       setExpected = append(setExpected, nodebNameKey, data)
+       setExpected = append(setExpected, nodebIdKey, data)
+
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+       // TODO: after SetAndPublish problem is solved, bring back this line
+       // sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
+       assert.Nil(t, rNibErr)
+}
+
+func TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure(t *testing.T) {
+       inventoryName := "name"
+       plmnId := "02f829"
+       nbId := "4a952a0a"
+       channelName := "RAN_CONNECT_STATE_CHANGE"
+       eventName := inventoryName + "_" + "CONNECTED"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       nodebInfo := &entities.NodebInfo{}
+       data, err := proto.Marshal(nodebInfo)
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
+       }
+       var e error
+       var setExpected []interface{}
+
+       nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+       nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
+       setExpected = append(setExpected, nodebNameKey, data)
+       setExpected = append(setExpected, nodebIdKey, data)
+
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+       // TODO: after SetAndPublish problem is solved, bring back this line
+       //sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
+
+       assert.NotNil(t, rNibErr)
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+}
+
+func TestUpdateNodebInfoOnConnectionStatusInversionMissingGlobalNbId(t *testing.T) {
+       inventoryName := "name"
+       channelName := "RAN_CONNECT_STATE_CHANGE"
+       eventName := inventoryName + "_" + "CONNECTED"
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+       nodebInfo := &entities.NodebInfo{}
+       nodebInfo.RanName = inventoryName
+       data, err := proto.Marshal(nodebInfo)
+       if err != nil {
+               t.Errorf("#rNibWriter_test.TestUpdateNodebInfoOnConnectionStatusInversionMissingInventoryNameFailure - Failed to marshal NodeB entity. Error: %v", err)
+       }
+       var e error
+       var setExpected []interface{}
+
+       nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
+       setExpected = append(setExpected, nodebNameKey, data)
+       sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
+       // TODO: after SetAndPublish problem is solved, bring back this line
+       //sdlInstanceMock.On("SetAndPublish", []string{channelName, eventName}, []interface{}{setExpected}).Return(e)
+
+       rNibErr := w.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, channelName, eventName)
+
+       assert.Nil(t, rNibErr)
+}
+
+func TestSaveGeneralConfiguration(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       key := common.BuildGeneralConfigurationKey()
+       configurationData := "{\"enableRic\":true}"
+       configuration := &entities.GeneralConfiguration{}
+       configuration.EnableRic = true
+
+       sdlInstanceMock.On("Set",[]interface{}{[]interface{}{key, []byte(configurationData)}}).Return(nil)
+       rNibErr := w.SaveGeneralConfiguration(configuration)
+
+       assert.Nil(t, rNibErr)
+       sdlInstanceMock.AssertExpectations(t)
+}
+
+func TestSaveGeneralConfigurationDbError(t *testing.T) {
+       w, sdlInstanceMock := initSdlInstanceMock(namespace)
+
+       key := common.BuildGeneralConfigurationKey()
+       configurationData := "{\"enableRic\":true}"
+       configuration := &entities.GeneralConfiguration{}
+       configuration.EnableRic = true
+
+       expectedErr := errors.New("expected error")
+
+       sdlInstanceMock.On("Set",[]interface{}{[]interface{}{key, []byte(configurationData)}}).Return(expectedErr)
+       rNibErr := w.SaveGeneralConfiguration(configuration)
+
+       assert.NotNil(t, rNibErr)
 }
 
 //Integration tests
@@ -640,7 +875,7 @@ func TestInit(t *testing.T) {
 //             nb.Configuration = &entities.NodebInfo_Enb{Enb:&enb}
 //             plmnId := 0x02f828
 //             nbId := 0x4a952a0a
-//             nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
+//             nbIdentity := &entities.NbIdentity{InventoryName: fmt.Sprintf("nameEnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId + i), NbId:fmt.Sprintf("%02x", nbId + i)}}
 //             err := w.SaveNodeb(nbIdentity, &nb)
 //             if err != nil{
 //                     t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)
@@ -657,7 +892,7 @@ func TestInit(t *testing.T) {
 //             gCell3 := &entities.ServedNRCell{ServedNrCellInformation:&entities.ServedNRCellInformation{CellId:fmt.Sprintf("%02x",3333 + i), NrPci:uint32(3 + i)}}
 //             gnb.ServedNrCells = []*entities.ServedNRCell{gCell1, gCell2, gCell3,}
 //             nb1.Configuration = &entities.NodebInfo_Gnb{Gnb:&gnb}
-//             nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{PlmnId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
+//             nbIdentity = &entities.NbIdentity{InventoryName: fmt.Sprintf("nameGnb%d" ,i), GlobalNbId:&entities.GlobalNbId{RicId:fmt.Sprintf("%02x", plmnId - i), NbId:fmt.Sprintf("%02x", nbId - i)}}
 //             err = w.SaveNodeb(nbIdentity, &nb1)
 //             if err != nil{
 //                     t.Errorf("#rNibWriter_test.TestSaveEnbInteg - Failed to save NodeB entity. Error: %v", err)