--- /dev/null
+//
+// 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"`
+}
GetE2TInstances(addresses []string) ([]*entities.E2TInstance, error)
GetE2TAddresses() ([]string, error)
+
+ GetGeneralConfiguration() (*entities.GeneralConfiguration, 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})
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
//
// rnibReader := GetRNibReader(sdl)
// e2tInstances, _ := rnibReader.GetE2TInstances([]string{"e2t.att.com:38000","whatever"})
// assert.Len(t, e2tInstances, 1)
-//}
+//}
\ No newline at end of file