2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
24 "github.com/stretchr/testify/assert"
31 func TestParseConfigurationSuccess(t *testing.T) {
32 config := ParseConfiguration()
33 assert.Equal(t, 3800, config.Http.Port)
34 assert.Equal(t, 3801, config.Rmr.Port)
35 assert.Equal(t, 65536, config.Rmr.MaxMsgSize)
36 assert.Equal(t, "info", config.Logging.LogLevel)
37 assert.Equal(t, 100, config.NotificationResponseBuffer)
38 assert.Equal(t, 5, config.BigRedButtonTimeoutSec)
39 assert.Equal(t, 4500, config.KeepAliveResponseTimeoutMs)
40 assert.Equal(t, 1500, config.KeepAliveDelayMs)
41 assert.Equal(t, 15000, config.E2TInstanceDeletionTimeoutMs)
42 assert.NotNil(t, config.GlobalRicId)
43 assert.NotEmpty(t, config.GlobalRicId.PlmnId)
44 assert.NotEmpty(t, config.GlobalRicId.RicNearRtId)
47 func TestStringer(t *testing.T) {
48 config := ParseConfiguration().String()
49 assert.NotEmpty(t, config)
52 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
53 configPath := "../resources/configuration.yaml"
54 configPathTmp := "../resources/configuration.yaml_tmp"
55 err := os.Rename(configPath, configPathTmp)
57 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
60 err = os.Rename(configPathTmp, configPath)
62 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
65 assert.Panics(t, func() { ParseConfiguration() })
68 func TestRmrConfigNotFoundFailure(t *testing.T) {
69 configPath := "../resources/configuration.yaml"
70 configPathTmp := "../resources/configuration.yaml_tmp"
71 err := os.Rename(configPath, configPathTmp)
73 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
76 err = os.Rename(configPathTmp, configPath)
78 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
81 yamlMap := map[string]interface{}{
82 "logging": map[string]interface{}{"logLevel": "info"},
83 "http": map[string]interface{}{"port": 3800},
84 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
85 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
87 buf, err := yaml.Marshal(yamlMap)
89 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
91 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
93 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
95 assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
98 func TestLoggingConfigNotFoundFailure(t *testing.T) {
99 configPath := "../resources/configuration.yaml"
100 configPathTmp := "../resources/configuration.yaml_tmp"
101 err := os.Rename(configPath, configPathTmp)
103 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
106 err = os.Rename(configPathTmp, configPath)
108 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
111 yamlMap := map[string]interface{}{
112 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
113 "http": map[string]interface{}{"port": 3800},
114 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
115 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
117 buf, err := yaml.Marshal(yamlMap)
119 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
121 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
123 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
125 assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
126 func() { ParseConfiguration() })
129 func TestHttpConfigNotFoundFailure(t *testing.T) {
130 configPath := "../resources/configuration.yaml"
131 configPathTmp := "../resources/configuration.yaml_tmp"
132 err := os.Rename(configPath, configPathTmp)
134 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
137 err = os.Rename(configPathTmp, configPath)
139 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
142 yamlMap := map[string]interface{}{
143 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
144 "logging": map[string]interface{}{"logLevel": "info"},
145 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
146 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
148 buf, err := yaml.Marshal(yamlMap)
150 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
152 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
154 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
156 assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
157 func() { ParseConfiguration() })
160 func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
161 configPath := "../resources/configuration.yaml"
162 configPathTmp := "../resources/configuration.yaml_tmp"
163 err := os.Rename(configPath, configPathTmp)
165 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
168 err = os.Rename(configPathTmp, configPath)
170 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
173 yamlMap := map[string]interface{}{
174 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
175 "logging": map[string]interface{}{"logLevel": "info"},
176 "http": map[string]interface{}{"port": 3800},
177 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
179 buf, err := yaml.Marshal(yamlMap)
181 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
183 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
185 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
187 assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
188 func() { ParseConfiguration() })
191 func TestGlobalRicIdConfigNotFoundFailure(t *testing.T) {
192 configPath := "../resources/configuration.yaml"
193 configPathTmp := "../resources/configuration.yaml_tmp"
194 err := os.Rename(configPath, configPathTmp)
196 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
199 err = os.Rename(configPathTmp, configPath)
201 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
204 yamlMap := map[string]interface{}{
205 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
206 "logging": map[string]interface{}{"logLevel": "info"},
207 "http": map[string]interface{}{"port": 3800},
208 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
210 buf, err := yaml.Marshal(yamlMap)
212 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to marshal configuration map\n")
214 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
216 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
218 assert.PanicsWithValue(t, "#configuration.populateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n",
219 func() { ParseConfiguration() })