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)
45 assert.NotEmpty(t, config.Kubernetes.KubeNamespace)
46 assert.NotEmpty(t, config.Kubernetes.ConfigPath)
49 func TestStringer(t *testing.T) {
50 config := ParseConfiguration().String()
51 assert.NotEmpty(t, config)
54 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
55 configPath := "../resources/configuration.yaml"
56 configPathTmp := "../resources/configuration.yaml_tmp"
57 err := os.Rename(configPath, configPathTmp)
59 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
62 err = os.Rename(configPathTmp, configPath)
64 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
67 assert.Panics(t, func() { ParseConfiguration() })
70 func TestRmrConfigNotFoundFailure(t *testing.T) {
71 configPath := "../resources/configuration.yaml"
72 configPathTmp := "../resources/configuration.yaml_tmp"
73 err := os.Rename(configPath, configPathTmp)
75 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
78 err = os.Rename(configPathTmp, configPath)
80 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
83 yamlMap := map[string]interface{}{
84 "logging": map[string]interface{}{"logLevel": "info"},
85 "http": map[string]interface{}{"port": 3800},
86 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
87 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
89 buf, err := yaml.Marshal(yamlMap)
91 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
93 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
95 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
97 assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
100 func TestLoggingConfigNotFoundFailure(t *testing.T) {
101 configPath := "../resources/configuration.yaml"
102 configPathTmp := "../resources/configuration.yaml_tmp"
103 err := os.Rename(configPath, configPathTmp)
105 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
108 err = os.Rename(configPathTmp, configPath)
110 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
113 yamlMap := map[string]interface{}{
114 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
115 "http": map[string]interface{}{"port": 3800},
116 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
117 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
119 buf, err := yaml.Marshal(yamlMap)
121 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
123 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
125 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
127 assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
128 func() { ParseConfiguration() })
131 func TestHttpConfigNotFoundFailure(t *testing.T) {
132 configPath := "../resources/configuration.yaml"
133 configPathTmp := "../resources/configuration.yaml_tmp"
134 err := os.Rename(configPath, configPathTmp)
136 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
139 err = os.Rename(configPathTmp, configPath)
141 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
144 yamlMap := map[string]interface{}{
145 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
146 "logging": map[string]interface{}{"logLevel": "info"},
147 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
148 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
150 buf, err := yaml.Marshal(yamlMap)
152 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
154 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
156 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
158 assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
159 func() { ParseConfiguration() })
162 func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
163 configPath := "../resources/configuration.yaml"
164 configPathTmp := "../resources/configuration.yaml_tmp"
165 err := os.Rename(configPath, configPathTmp)
167 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
170 err = os.Rename(configPathTmp, configPath)
172 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
175 yamlMap := map[string]interface{}{
176 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
177 "logging": map[string]interface{}{"logLevel": "info"},
178 "http": map[string]interface{}{"port": 3800},
179 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
181 buf, err := yaml.Marshal(yamlMap)
183 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
185 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
187 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
189 assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
190 func() { ParseConfiguration() })
193 func TestGlobalRicIdConfigNotFoundFailure(t *testing.T) {
194 configPath := "../resources/configuration.yaml"
195 configPathTmp := "../resources/configuration.yaml_tmp"
196 err := os.Rename(configPath, configPathTmp)
198 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
201 err = os.Rename(configPathTmp, configPath)
203 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
206 yamlMap := map[string]interface{}{
207 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
208 "logging": map[string]interface{}{"logLevel": "info"},
209 "http": map[string]interface{}{"port": 3800},
210 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
211 "kubernetes": map[string]interface{}{"kubeNamespace": "test", "ConfigPath": "test"},
213 buf, err := yaml.Marshal(yamlMap)
215 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to marshal configuration map\n")
217 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
219 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
221 assert.PanicsWithValue(t, "#configuration.populateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n",
222 func() { ParseConfiguration() })
225 func TestKubernetesConfigNotFoundFailure(t *testing.T) {
226 configPath := "../resources/configuration.yaml"
227 configPathTmp := "../resources/configuration.yaml_tmp"
228 err := os.Rename(configPath, configPathTmp)
230 t.Errorf("#TestKubernetesConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
233 err = os.Rename(configPathTmp, configPath)
235 t.Errorf("#TestKubernetesConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
238 yamlMap := map[string]interface{}{
239 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
240 "logging": map[string]interface{}{"logLevel": "info"},
241 "http": map[string]interface{}{"port": 3800},
242 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
243 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
245 buf, err := yaml.Marshal(yamlMap)
247 t.Errorf("#TestKubernetesConfigNotFoundFailure - failed to marshal configuration map\n")
249 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
251 t.Errorf("#TestKubernetesConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
253 assert.PanicsWithValue(t, "#configuration.populateKubernetesConfig - failed to populate Kubernetes configuration: The entry 'kubernetes' not found\n",
254 func() { ParseConfiguration() })