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 "github.com/stretchr/testify/assert"
36 func TestSaveRsmRanInfo(t *testing.T) {
37 sdl := &mocks.MockSdlInstance{}
38 writer := GetRsmWriter(sdl)
40 key, _ := common.ValidateAndBuildNodeBNameKey(ranName)
41 infoAsGoType := models.RsmRanInfo{
48 infoAsDbType:= "{\"ranName\":\"test1\",\"enb1MeasurementId\":1,\"enb2MeasurementId\":2,\"action\":\"start\",\"actionStatus\":false}"
49 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(infoAsDbType)}}).Return(nil)
50 err := writer.SaveRsmRanInfo(&infoAsGoType)
52 t.Errorf("want: success, got: error: %v\n", err)
54 sdl.AssertNumberOfCalls(t, "Set",1)
58 func TestSaveRsmRanInfoValidationError(t *testing.T) {
59 sdl := &mocks.MockSdlInstance{}
60 writer := GetRsmWriter(sdl)
62 key, _ := common.ValidateAndBuildNodeBNameKey(ranName)
63 infoAsGoType := models.RsmRanInfo{
70 infoAsDbType:= "{\"ranName\":\"test1\",\"enb1MeasurementId\":1,\"enb2MeasurementId\":2,\"action\":\"start\",\"actionStatus\":false}"
71 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(infoAsDbType)}}).Return(nil)
72 err := writer.SaveRsmRanInfo(&infoAsGoType)
74 assert.Equal(t, err.Error(), "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received")
78 func TestSaveGeneralConfiguration(t *testing.T) {
79 sdl := &mocks.MockSdlInstance{}
80 writer := GetRsmWriter(sdl)
81 var testCases = []struct {
82 cfgAsGoType models.RsmGeneralConfiguration
86 cfgAsGoType: models.RsmGeneralConfiguration{
87 EnableResourceStatus: true,
88 PartialSuccessAllowed: true,
90 TnlLoadIndPeriodic: true,
91 HwLoadIndPeriodic: true,
92 AbsStatusPeriodic: true,
93 RsrpMeasurementPeriodic: true,
95 PeriodicityMs: enums.ReportingPeriodicity_one_thousand_ms,
96 PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
97 PeriodicityCsiMs: enums.ReportingPeriodicityCSIR_ms20,
100 cfgAsDbType: "{\"enableResourceStatus\":true,\"partialSuccessAllowed\":true,\"prbPeriodic\":true,\"tnlLoadIndPeriodic\":true,\"wwLoadIndPeriodic\":true,\"absStatusPeriodic\":true,\"rsrpMeasurementPeriodic\":true,\"csiPeriodic\":true,\"periodicityMs\":1,\"periodicityRsrpMeasurementMs\":3,\"periodicityCsiMs\":3}",
104 for _, tc := range testCases {
105 t.Run(tc.cfgAsDbType, func(t *testing.T) {
106 key:= buildRsmGeneralConfigurationKey()
107 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(tc.cfgAsDbType)}}).Return(nil)
108 err := writer.SaveRsmGeneralConfiguration(&tc.cfgAsGoType)
110 t.Errorf("want: success, got: error: %v\n", err)
113 sdl.AssertNumberOfCalls(t, "Set",1)
119 func TestSaveGeneralConfigurationDbError(t *testing.T) {
120 sdl := &mocks.MockSdlInstance{}
121 writer := GetRsmWriter(sdl)
123 cfgAsGoType:= models.RsmGeneralConfiguration{
124 EnableResourceStatus: true,
125 PartialSuccessAllowed: true,
127 TnlLoadIndPeriodic: true,
128 HwLoadIndPeriodic: true,
129 AbsStatusPeriodic: true,
130 RsrpMeasurementPeriodic: true,
132 PeriodicityMs: enums.ReportingPeriodicity_one_thousand_ms,
133 PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
134 PeriodicityCsiMs: enums.ReportingPeriodicityCSIR_ms20,
136 cfgAsDbTYpe:= "{\"enableResourceStatus\":true,\"partialSuccessAllowed\":true,\"prbPeriodic\":true,\"tnlLoadIndPeriodic\":true,\"wwLoadIndPeriodic\":true,\"absStatusPeriodic\":true,\"rsrpMeasurementPeriodic\":true,\"csiPeriodic\":true,\"periodicityMs\":1,\"periodicityRsrpMeasurementMs\":3,\"periodicityCsiMs\":3}"
137 key:= buildRsmGeneralConfigurationKey()
138 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(cfgAsDbTYpe)}}).Return(fmt.Errorf("db error"))
139 err := writer.SaveRsmGeneralConfiguration(&cfgAsGoType)
140 assert.NotNil(t, err)
141 assert.Equal(t, err.Error(), "db error")