From: Irina Date: Mon, 8 Jun 2020 17:31:31 +0000 (+0300) Subject: RIC-395: E2M new REST API - E2M Set Parameters X-Git-Tag: common/v1.0.42 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=b40736378083076d377b245b30f60bc5dbdc3ae0;p=ric-plt%2Fnodeb-rnib.git RIC-395: E2M new REST API - E2M Set Parameters Change-Id: I63d21018f1559bb2e5f45d3c2ecfce32e60792cc Signed-off-by: Irina --- diff --git a/common/utils.go b/common/utils.go index d849021..5c3bff9 100644 --- a/common/utils.go +++ b/common/utils.go @@ -97,6 +97,10 @@ func ValidateAndBuildE2TInstanceKey(address string) (string, error) { return fmt.Sprintf("E2TInstance:%s", address), nil } +func BuildGeneralConfigurationKey() string { + return "GENERAL" +} + func MapE2TAddressesToKeys(addresses []string) []string { keys := []string{} diff --git a/entities/general_configuration.go b/entities/general_configuration.go new file mode 100644 index 0000000..bb044e4 --- /dev/null +++ b/entities/general_configuration.go @@ -0,0 +1,24 @@ +// +// Copyright 2019 AT&T Intellectual Property +// Copyright 2019 Nokia +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This source code is part of the near-RT RIC (RAN Intelligent Controller) +// platform project (RICP). + +package entities + +type GeneralConfiguration struct { + EnableRic bool `json:"enableRic"` +} diff --git a/reader/go.mod b/reader/go.mod index 208cf35..64326d5 100644 --- a/reader/go.mod +++ b/reader/go.mod @@ -3,8 +3,8 @@ module gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader go 1.12 require ( - gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.41 - gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.41 + gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common v1.0.42 + gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities v1.0.42 github.com/golang/protobuf v1.4.2 github.com/google/go-cmp v0.4.1 // indirect github.com/pkg/errors v0.8.1 diff --git a/reader/rNibReader.go b/reader/rNibReader.go index 946a57a..19feefa 100644 --- a/reader/rNibReader.go +++ b/reader/rNibReader.go @@ -63,6 +63,8 @@ type RNibReader interface { GetE2TInstances(addresses []string) ([]*entities.E2TInstance, error) GetE2TAddresses() ([]string, error) + + GetGeneralConfiguration() (*entities.GeneralConfiguration, error) } /* @@ -252,6 +254,15 @@ func (w *rNibReaderInstance) GetE2TAddresses() ([]string, error) { return e2tAddresses, err } +func (w *rNibReaderInstance) GetGeneralConfiguration() (*entities.GeneralConfiguration, error) { + config := &entities.GeneralConfiguration{} + key := common.BuildGeneralConfigurationKey() + + err := w.getByKeyAndUnmarshalJson(key, config) + + return config, err +} + func (w *rNibReaderInstance) getByKeyAndUnmarshalJson(key string, entity interface{}) error { data, err := w.sdl.Get([]string{key}) diff --git a/reader/rNibReader_test.go b/reader/rNibReader_test.go index 1220b1b..73ff176 100644 --- a/reader/rNibReader_test.go +++ b/reader/rNibReader_test.go @@ -1179,6 +1179,59 @@ func TestGetE2TInstancesEmptyData(t *testing.T) { assert.IsType(t, &common.ResourceNotFoundError{}, err) } +func TestGetGeneralConfiguration(t *testing.T) { + + key := common.BuildGeneralConfigurationKey() + w, sdlInstanceMock := initSdlInstanceMock() + + configurationData := "{\"enableRic\":true}" + sdlInstanceMock.On("Get", []string{key}).Return(map[string]interface{}{key: configurationData}, nil) + + res, rNibErr := w.GetGeneralConfiguration() + assert.Nil(t, rNibErr) + assert.Equal(t, true, res.EnableRic) +} + +func TestGetGeneralConfigurationNotFound(t *testing.T) { + + key := common.BuildGeneralConfigurationKey() + w, sdlInstanceMock := initSdlInstanceMock() + + sdlInstanceMock.On("Get", []string{key}).Return(map[string]interface{}{}, nil) + + _, rNibErr := w.GetGeneralConfiguration() + + assert.NotNil(t, rNibErr) + assert.Equal(t, "#rNibReader.getByKeyAndUnmarshalJson - entity of type *entities.GeneralConfiguration not found. Key: GENERAL", rNibErr.Error()) +} + +func TestGetGeneralConfigurationSdlFailure(t *testing.T) { + + key := common.BuildGeneralConfigurationKey() + w, sdlInstanceMock := initSdlInstanceMock() + + sdlInstanceMock.On("Get", []string{key}).Return(map[string]interface{}{}, fmt.Errorf("sdl error")) + + _, rNibErr := w.GetGeneralConfiguration() + + assert.NotNil(t, rNibErr) + + assert.Equal(t, "sdl error", rNibErr.Error()) +} + +func TestGetGeneralConfigurationUnmarshalError(t *testing.T) { + + key := common.BuildGeneralConfigurationKey() + w, sdlInstanceMock := initSdlInstanceMock() + + configurationData := "{\"enableRic :true}" + sdlInstanceMock.On("Get", []string{key}).Return(map[string]interface{}{key: configurationData}, nil) + + _, rNibErr := w.GetGeneralConfiguration() + + assert.NotNil(t, rNibErr) + assert.Equal(t, rNibErr.Error(), "unexpected end of JSON input") +} //integration tests // @@ -1338,4 +1391,4 @@ func TestGetE2TInstancesEmptyData(t *testing.T) { // rnibReader := GetRNibReader(sdl) // e2tInstances, _ := rnibReader.GetE2TInstances([]string{"e2t.att.com:38000","whatever"}) // assert.Len(t, e2tInstances, 1) -//} +//} \ No newline at end of file