RIC-395: E2M new REST API - E2M Set Parameters 27/4027/1 common/v1.0.42 entities/v1.0.42 reader/v1.0.42 v1.0.42
authorIrina <ib565x@intl.att.com>
Mon, 8 Jun 2020 17:31:31 +0000 (20:31 +0300)
committerIrina <ib565x@intl.att.com>
Mon, 8 Jun 2020 17:32:06 +0000 (20:32 +0300)
Change-Id: I63d21018f1559bb2e5f45d3c2ecfce32e60792cc
Signed-off-by: Irina <ib565x@intl.att.com>
common/utils.go
entities/general_configuration.go [new file with mode: 0644]
reader/go.mod
reader/rNibReader.go
reader/rNibReader_test.go

index d849021..5c3bff9 100644 (file)
@@ -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 (file)
index 0000000..bb044e4
--- /dev/null
@@ -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"`
+}
index 208cf35..64326d5 100644 (file)
@@ -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
index 946a57a..19feefa 100644 (file)
@@ -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})
 
index 1220b1b..73ff176 100644 (file)
@@ -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