1 /*******************************************************************************
3 * Copyright (c) 2019 AT&T Intellectual Property.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 *******************************************************************************/
20 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
21 * platform project (RICP).
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
29 // "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
30 "github.com/stretchr/testify/assert"
38 func TestGetRsmRanInfo(t *testing.T) {
39 sdl := &mocks.MockSdlInstance{}
40 reader := GetRsmReader(sdl)
42 key, _ := common.ValidateAndBuildNodeBNameKey(ranName)
43 infoAsGoType := models.RsmRanInfo{
50 infoAsDbType:= "{\"ranName\":\"test1\",\"enb1MeasurementId\":1,\"enb2MeasurementId\":2,\"action\":\"start\",\"actionStatus\":false}"
51 sdl.On("Get", []string{key}).Return(map[string]interface{}{key: infoAsDbType}, nil)
52 info, err := reader.GetRsmRanInfo(ranName)
54 t.Errorf("want: success, got: error: %v\n", err)
56 assert.Equal(t, info, &infoAsGoType)
59 func TestGetRsmRanInfoValidationError(t *testing.T) {
60 sdl := &mocks.MockSdlInstance{}
61 reader := GetRsmReader(sdl)
63 key, _ := common.ValidateAndBuildNodeBNameKey(ranName)
64 sdl.On("Get", []string{key}).Return(map[string]interface{}{key: ""}, nil)
65 _, err := reader.GetRsmRanInfo(ranName)
67 assert.Equal(t, err.Error(), "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received")
70 func TestGetRsmRanInfoDbError(t *testing.T) {
71 sdl := &mocks.MockSdlInstance{}
72 reader := GetRsmReader(sdl)
74 key, _ := common.ValidateAndBuildNodeBNameKey(ranName)
75 sdl.On("Get", []string{key}).Return((map[string]interface{})(nil), fmt.Errorf("db error"))
76 _, err := reader.GetRsmRanInfo(ranName)
78 assert.Equal(t, err.Error(), "db error")
81 func TestGetGeneralConfiguration(t *testing.T) {
82 sdl := &mocks.MockSdlInstance{}
83 reader := GetRsmReader(sdl)
84 var testCases = []struct {
85 cfgAsGoType models.RsmGeneralConfiguration
89 cfgAsGoType: models.RsmGeneralConfiguration{
90 EnableResourceStatus: true,
91 PartialSuccessAllowed: true,
93 TnlLoadIndPeriodic: true,
94 HwLoadIndPeriodic: true,
95 AbsStatusPeriodic: true,
96 RsrpMeasurementPeriodic: true,
98 PeriodicityMs: enums.ReportingPeriodicity_one_thousand_ms,
99 PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
100 PeriodicityCsiMs: enums.ReportingPeriodicityCSIR_ms20,
103 cfgAsDbType: "{\"enableResourceStatus\":true,\"partialSuccessAllowed\":true,\"prbPeriodic\":true,\"tnlLoadIndPeriodic\":true,\"wwLoadIndPeriodic\":true,\"absStatusPeriodic\":true,\"rsrpMeasurementPeriodic\":true,\"csiPeriodic\":true,\"periodicityMs\":1,\"periodicityRsrpMeasurementMs\":3,\"periodicityCsiMs\":3}",
107 for _, tc := range testCases {
108 t.Run(tc.cfgAsDbType, func(t *testing.T) {
109 key := buildRsmGeneralConfigurationKey()
110 sdl.On("Get", []string{key}).Return(map[string]interface{}{key: tc.cfgAsDbType}, nil)
111 cfg, err := reader.GetRsmGeneralConfiguration()
113 t.Errorf("want: success, got: error: %v\n", err)
115 assert.Equal(t, cfg, &tc.cfgAsGoType)
120 func TestGetGeneralConfigurationNotFound(t *testing.T) {
121 sdl := &mocks.MockSdlInstance{}
122 reader := GetRsmReader(sdl)
124 key := buildRsmGeneralConfigurationKey()
125 sdl.On("Get", []string{key}).Return((map[string]interface{})(nil), nil)
126 _, err := reader.GetRsmGeneralConfiguration()
127 assert.NotNil(t, err)
128 assert.Equal(t, err.Error(), "#rsmReader.getByKeyAndUnmarshal - entity of type *models.RsmGeneralConfiguration not found. Key: CFG:GENERAL:v1.0.0")
131 func TestGetGeneralConfigurationDbError(t *testing.T) {
132 sdl := &mocks.MockSdlInstance{}
133 reader := GetRsmReader(sdl)
135 key := buildRsmGeneralConfigurationKey()
136 sdl.On("Get", []string{key}).Return((map[string]interface{})(nil), fmt.Errorf("db error"))
137 _, err := reader.GetRsmGeneralConfiguration()
138 assert.NotNil(t, err)
139 assert.Equal(t, err.Error(), "db error")
142 func TestGetGeneralConfigurationUnmarshalError(t *testing.T) {
143 sdl := &mocks.MockSdlInstance{}
144 reader := GetRsmReader(sdl)
145 cfgAsDbTYpe := "{\"enableResourceStatus\":true, partialSuccessAllowed\":true,\"prbPeriodic\":true,\"tnlLoadIndPeriodic\":true,\"wwLoadIndPeriodic\":true,\"absStatusPeriodic\":true,\"rsrpMeasurementPeriodic\":true,\"csiPeriodic\":true,\"periodicityMs\":1,\"periodicityRsrpMeasurementMs\":3,\"periodicityCsiMs\":3}"
146 key := buildRsmGeneralConfigurationKey()
147 sdl.On("Get", []string{key}).Return(map[string]interface{}{key: cfgAsDbTYpe}, nil)
148 _, err := reader.GetRsmGeneralConfiguration()
149 assert.NotNil(t, err)
150 assert.Equal(t, err.Error(), "invalid character 'p' looking for beginning of object key string")
155 Test execution depends on the existence of the environment variable DBAAS_SERVICE_HOST.
158 func TestGetGeneralConfigurationIntegration(t *testing.T) {
159 if len(os.Getenv("DBAAS_SERVICE_HOST")) == 0 {
162 db := sdlgo.NewDatabase()
163 sdl := sdlgo.NewSdlInstance("rsm", db)
164 reader := GetRsmReader(sdl)
165 cfgAsGoType := models.RsmGeneralConfiguration{
166 EnableResourceStatus: true,
167 PartialSuccessAllowed: true,
169 TnlLoadIndPeriodic: true,
170 HwLoadIndPeriodic: true,
171 AbsStatusPeriodic: true,
172 RsrpMeasurementPeriodic: true,
174 PeriodicityMs: enums.ReportingPeriodicity_one_thousand_ms,
175 PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
176 PeriodicityCsiMs: enums.ReportingPeriodicityCSIR_ms20,
178 cfg, err := reader.GetRsmGeneralConfiguration()
180 t.Errorf("want: success, got: error: %v\n", err)
183 assert.Equal(t, &cfgAsGoType, cfg)