func TestSaveUnknownTypeEntityFailure(t *testing.T) {
w, _ := initSdlInstanceMock(namespace)
- 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
nb.Ip = "localhost"
actualErr := w.SaveNodeb(nbIdentity, nb)
- assert.Equal(t, expectedErr, actualErr)
+ assert.IsType(t, &common.ValidationError{}, actualErr)
}
func TestSaveEntityFailure(t *testing.T) {
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
+ 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("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("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("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
//
//func TestSaveEnbGnbInteg(t *testing.T){