merge of Natalia - change rnib errors
[ric-plt/e2mgr.git] / E2Manager / rNibWriter / rNibWriter_test.go
index 14abb1a..c887da6 100644 (file)
@@ -128,13 +128,11 @@ func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
        rNibErr := w.UpdateNodebInfo(nodebInfo)
 
        assert.NotNil(t, rNibErr)
-       assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
 }
 
-func TestUpdateNodebInfoMissingGlobalNbIdFailure(t *testing.T) {
+func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
        inventoryName := "name"
-       plmnId := "02f829"
-       nbId := "4a952a0a"
        writerPool = nil
        sdlInstanceMock := initSdlInstanceMock(namespace, 1)
        w := GetRNibWriter()
@@ -148,16 +146,12 @@ func TestUpdateNodebInfoMissingGlobalNbIdFailure(t *testing.T) {
        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)
 
        rNibErr := w.UpdateNodebInfo(nodebInfo)
 
-       assert.NotNil(t, rNibErr)
-       assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
+       assert.Nil(t, rNibErr)
 }
 
 func TestSaveEnb(t *testing.T) {
@@ -229,8 +223,8 @@ func TestSaveEnbCellIdValidationFailure(t *testing.T) {
        nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
        rNibErr := w.SaveNodeb(nbIdentity, &nb)
        assert.NotNil(t, rNibErr)
-       assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
-       assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+       assert.Equal(t, "#utils.ValidateAndBuildCellIdKey - an empty cell id received", rNibErr.Error())
 }
 
 func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
@@ -250,8 +244,8 @@ func TestSaveEnbInventoryNameValidationFailure(t *testing.T) {
        nbIdentity := &entities.NbIdentity{InventoryName: "", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
        rNibErr := w.SaveNodeb(nbIdentity, &nb)
        assert.NotNil(t, rNibErr)
-       assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
-       assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+       assert.Equal(t, "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received", rNibErr.Error())
 }
 
 func TestSaveEnbOnClosedPool(t *testing.T) {
@@ -297,8 +291,8 @@ func TestSaveGnbCellIdValidationFailure(t *testing.T) {
        nbIdentity := &entities.NbIdentity{InventoryName: name, GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
        rNibErr := w.SaveNodeb(nbIdentity, &nb)
        assert.NotNil(t, rNibErr)
-       assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
-       assert.Equal(t, "3 VALIDATION_ERROR - #utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
+       assert.IsType(t, &common.ValidationError{}, rNibErr)
+       assert.Equal(t, "#utils.ValidateAndBuildNrCellIdKey - an empty cell id received", rNibErr.Error())
 }
 
 func TestSaveGnb(t *testing.T) {
@@ -399,7 +393,7 @@ func TestSaveRanLoadInformationEmptyInventoryNameFailure(t *testing.T) {
 
        err := w.SaveRanLoadInformation(inventoryName, nil)
        assert.NotNil(t, err)
-       assert.Equal(t, common.VALIDATION_ERROR, err.GetCode())
+       assert.IsType(t, &common.ValidationError{}, err)
 }
 
 func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
@@ -429,8 +423,7 @@ func TestSaveRanLoadInformationSdlFailure(t *testing.T) {
 
        rNibErr := w.SaveRanLoadInformation(inventoryName, ranLoadInformation)
        assert.NotNil(t, rNibErr)
-       assert.Equal(t, common.INTERNAL_ERROR, rNibErr.GetCode())
-       assert.Equal(t, expectedErr, rNibErr.GetError())
+       assert.IsType(t, &common.InternalError{}, rNibErr)
 }
 
 func generateCellLoadInformation() *entities.CellLoadInformation {
@@ -520,7 +513,7 @@ func TestSaveUnknownTypeEntityFailure(t *testing.T) {
        writerPool = nil
        initSdlInstanceMock(namespace, 1)
        w := GetRNibWriter()
-       expectedErr := common.NewValidationError(errors.New("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 "))
+       expectedErr := common.NewValidationError("#rNibWriter.saveNodeB - Unknown responding node type, entity: ip:\"localhost\" port:5656 ")
        nbIdentity := &entities.NbIdentity{InventoryName: "name", GlobalNbId: &entities.GlobalNbId{PlmnId: "02f829", NbId: "4a952a0a"}}
        nb := &entities.NodebInfo{}
        nb.Port = 5656
@@ -554,17 +547,17 @@ func TestSaveEntityFailure(t *testing.T) {
 
 func TestGetRNibWriterPoolNotInitializedFailure(t *testing.T) {
        writerPool = nil
-       assert.Panics(t, func() { GetRNibWriter() })
+       assert.Panics(t, func() { GetRNibWriter().SaveNodeb(nil,nil) })
 }
 
 func TestGetRNibWriter(t *testing.T) {
        writerPool = nil
        initSdlInstanceMock(namespace, 1)
        received := GetRNibWriter()
-       assert.NotEmpty(t, received)
+       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, 1, created, "number of created objects in the writerPool should be 1")
+       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
        writerPool.Close()
 }
 
@@ -577,13 +570,12 @@ func TestClose(t *testing.T) {
        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, 2, created, "number of created objects in the writerPool should be 2")
+       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
        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")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
 }
 
 func TestCloseOnClosedPoolFailure(t *testing.T) {
@@ -593,7 +585,7 @@ func TestCloseOnClosedPoolFailure(t *testing.T) {
        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, 1, created, "number of created objects in the writerPool should be 1")
+       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
        var e error
        instanceMock.On("Close").Return(e)
        Close()
@@ -607,13 +599,12 @@ func TestCloseFailure(t *testing.T) {
        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, 1, created, "number of created 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")
-       assert.Equal(t, 0, created, "number of created objects in the writerPool should be 0")
 }
 
 func TestInit(t *testing.T) {