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 *******************************************************************************/
22 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
23 "github.com/stretchr/testify/assert"
30 func TestSaveRsmRanInfo(t *testing.T) {
31 sdl := &mocks.MockSdlInstance{}
32 writer := GetRsmWriter(sdl)
34 key, _ := common.ValidateAndBuildNodeBNameKey(ranName)
35 infoAsGoType := models.RsmRanInfo{
42 infoAsDbType:= "{\"ranName\":\"test1\",\"enb1MeasurementId\":1,\"enb2MeasurementId\":2,\"action\":\"start\",\"actionStatus\":false}"
43 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(infoAsDbType)}}).Return(nil)
44 err := writer.SaveRsmRanInfo(&infoAsGoType)
46 t.Errorf("want: success, got: error: %v\n", err)
48 sdl.AssertNumberOfCalls(t, "Set",1)
52 func TestSaveRsmRanInfoValidationError(t *testing.T) {
53 sdl := &mocks.MockSdlInstance{}
54 writer := GetRsmWriter(sdl)
56 key, _ := common.ValidateAndBuildNodeBNameKey(ranName)
57 infoAsGoType := models.RsmRanInfo{
64 infoAsDbType:= "{\"ranName\":\"test1\",\"enb1MeasurementId\":1,\"enb2MeasurementId\":2,\"action\":\"start\",\"actionStatus\":false}"
65 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(infoAsDbType)}}).Return(nil)
66 err := writer.SaveRsmRanInfo(&infoAsGoType)
68 assert.Equal(t, err.Error(), "#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received")
72 func TestSaveGeneralConfiguration(t *testing.T) {
73 sdl := &mocks.MockSdlInstance{}
74 writer := GetRsmWriter(sdl)
75 var testCases = []struct {
76 cfgAsGoType models.RsmGeneralConfiguration
80 cfgAsGoType: models.RsmGeneralConfiguration{
81 EnableResourceStatus: true,
82 PartialSuccessAllowed: true,
84 TnlLoadIndPeriodic: true,
85 HwLoadIndPeriodic: true,
86 AbsStatusPeriodic: true,
87 RsrpMeasurementPeriodic: true,
89 PeriodicityMs: enums.ReportingPeriodicity_one_thousand_ms,
90 PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
91 PeriodicityCsiMs: enums.ReportingPeriodicityCSIR_ms20,
94 cfgAsDbType: "{\"enableResourceStatus\":true,\"partialSuccessAllowed\":true,\"prbPeriodic\":true,\"tnlLoadIndPeriodic\":true,\"wwLoadIndPeriodic\":true,\"absStatusPeriodic\":true,\"rsrpMeasurementPeriodic\":true,\"csiPeriodic\":true,\"periodicityMs\":1,\"periodicityRsrpMeasurementMs\":3,\"periodicityCsiMs\":3}",
98 for _, tc := range testCases {
99 t.Run(tc.cfgAsDbType, func(t *testing.T) {
100 key:= buildRsmGeneralConfigurationKey()
101 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(tc.cfgAsDbType)}}).Return(nil)
102 err := writer.SaveRsmGeneralConfiguration(&tc.cfgAsGoType)
104 t.Errorf("want: success, got: error: %v\n", err)
107 sdl.AssertNumberOfCalls(t, "Set",1)
113 func TestSaveGeneralConfigurationDbError(t *testing.T) {
114 sdl := &mocks.MockSdlInstance{}
115 writer := GetRsmWriter(sdl)
117 cfgAsGoType:= models.RsmGeneralConfiguration{
118 EnableResourceStatus: true,
119 PartialSuccessAllowed: true,
121 TnlLoadIndPeriodic: true,
122 HwLoadIndPeriodic: true,
123 AbsStatusPeriodic: true,
124 RsrpMeasurementPeriodic: true,
126 PeriodicityMs: enums.ReportingPeriodicity_one_thousand_ms,
127 PeriodicityRsrpMeasurementMs: enums.ReportingPeriodicityRSRPMR_four_hundred_80_ms,
128 PeriodicityCsiMs: enums.ReportingPeriodicityCSIR_ms20,
130 cfgAsDbTYpe:= "{\"enableResourceStatus\":true,\"partialSuccessAllowed\":true,\"prbPeriodic\":true,\"tnlLoadIndPeriodic\":true,\"wwLoadIndPeriodic\":true,\"absStatusPeriodic\":true,\"rsrpMeasurementPeriodic\":true,\"csiPeriodic\":true,\"periodicityMs\":1,\"periodicityRsrpMeasurementMs\":3,\"periodicityCsiMs\":3}"
131 key:= buildRsmGeneralConfigurationKey()
132 sdl.On("Set",[]interface{}{[]interface{}{key, []byte(cfgAsDbTYpe)}}).Return(fmt.Errorf("db error"))
133 err := writer.SaveRsmGeneralConfiguration(&cfgAsGoType)
134 assert.NotNil(t, err)
135 assert.Equal(t, err.Error(), "db error")