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).
23 "github.com/stretchr/testify/assert"
30 func TestParseConfigurationSuccess(t *testing.T) {
31 config := ParseConfiguration()
32 assert.Equal(t, 3800, config.Http.Port)
33 assert.Equal(t, 3801, config.Rmr.Port)
34 assert.Equal(t, 65536, config.Rmr.MaxMsgSize)
35 assert.Equal(t, "info", config.Logging.LogLevel)
36 assert.Equal(t, 100, config.NotificationResponseBuffer)
37 assert.Equal(t, 5, config.BigRedButtonTimeoutSec)
38 assert.Equal(t, 4500, config.KeepAliveResponseTimeoutMs)
39 assert.Equal(t, 1500, config.KeepAliveDelayMs)
40 assert.Equal(t, 15000, config.E2TInstanceDeletionTimeoutMs)
41 assert.NotNil(t, config.GlobalRicId)
42 assert.Equal(t, "AACCE", config.GlobalRicId.RicId)
43 assert.Equal(t, "310", config.GlobalRicId.Mcc)
44 assert.Equal(t, "411", config.GlobalRicId.Mnc)
45 assert.Equal(t, "RAN_CONNECTION_STATUS_CHANGE", config.RnibWriter.StateChangeMessageChannel)
46 assert.Equal(t, "RAN_MANIPULATION", config.RnibWriter.RanManipulationMessageChannel)
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://localhost: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://localhost: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://localhost: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{}{"mcc": 327, "mnc": 94, "ricId": "AACCE"},
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://localhost:8080/ric/v1/handles/"},
212 buf, err := yaml.Marshal(yamlMap)
214 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to marshal configuration map\n")
216 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
218 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
220 assert.PanicsWithValue(t, "#configuration.validateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n",
221 func() { ParseConfiguration() })
224 func TestRnibWriterConfigNotFoundFailure(t *testing.T) {
225 configPath := "../resources/configuration.yaml"
226 configPathTmp := "../resources/configuration.yaml_tmp"
227 err := os.Rename(configPath, configPathTmp)
229 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
232 err = os.Rename(configPathTmp, configPath)
234 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
237 yamlMap := map[string]interface{}{
238 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
239 "logging": map[string]interface{}{"logLevel": "info"},
240 "http": map[string]interface{}{"port": 3800},
241 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
242 "globalRicId": map[string]interface{}{"mcc": 327, "mnc": 94, "ricId": "AACCE"},
244 buf, err := yaml.Marshal(yamlMap)
246 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to marshal configuration map\n")
248 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
250 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
252 assert.PanicsWithValue(t, "#configuration.populateRnibWriterConfig - failed to populate Rnib Writer configuration: The entry 'rnibWriter' not found\n",
253 func() { ParseConfiguration() })
256 func TestEmptyRicIdFailure(t *testing.T) {
257 configPath := "../resources/configuration.yaml"
258 configPathTmp := "../resources/configuration.yaml_tmp"
259 err := os.Rename(configPath, configPathTmp)
261 t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
264 err = os.Rename(configPathTmp, configPath)
266 t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
269 yamlMap := map[string]interface{}{
270 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
271 "logging": map[string]interface{}{"logLevel": "info"},
272 "http": map[string]interface{}{"port": 3800},
273 "globalRicId": map[string]interface{}{"mcc": "327", "mnc": "94", "ricId": ""},
274 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
276 buf, err := yaml.Marshal(yamlMap)
278 t.Errorf("#TestEmptyRicIdFailure - failed to marshal configuration map\n")
280 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
282 t.Errorf("#TestEmptyRicIdFailure - failed to write configuration file: %s\n", configPath)
284 assert.PanicsWithValue(t, "#configuration.validateRicId - ricId is missing or empty\n",
285 func() { ParseConfiguration() })
288 func TestMissingRicIdFailure(t *testing.T) {
289 configPath := "../resources/configuration.yaml"
290 configPathTmp := "../resources/configuration.yaml_tmp"
291 err := os.Rename(configPath, configPathTmp)
293 t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
296 err = os.Rename(configPathTmp, configPath)
298 t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
301 yamlMap := map[string]interface{}{
302 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
303 "logging": map[string]interface{}{"logLevel": "info"},
304 "http": map[string]interface{}{"port": 3800},
305 "globalRicId": map[string]interface{}{"mcc": "327", "mnc": "94"},
306 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
308 buf, err := yaml.Marshal(yamlMap)
310 t.Errorf("#TestEmptyRicIdFailure - failed to marshal configuration map\n")
312 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
314 t.Errorf("#TestEmptyRicIdFailure - failed to write configuration file: %s\n", configPath)
316 assert.PanicsWithValue(t, "#configuration.validateRicId - ricId is missing or empty\n",
317 func() { ParseConfiguration() })
320 func TestNonHexRicIdFailure(t *testing.T) {
321 configPath := "../resources/configuration.yaml"
322 configPathTmp := "../resources/configuration.yaml_tmp"
323 err := os.Rename(configPath, configPathTmp)
325 t.Errorf("#TestNonHexRicIdFailure - failed to rename configuration file: %s\n", configPath)
328 err = os.Rename(configPathTmp, configPath)
330 t.Errorf("#TestNonHexRicIdFailure - failed to rename configuration file: %s\n", configPath)
333 yamlMap := map[string]interface{}{
334 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
335 "logging": map[string]interface{}{"logLevel": "info"},
336 "http": map[string]interface{}{"port": 3800},
337 "globalRicId": map[string]interface{}{"mcc": "327", "mnc": "94", "ricId": "TEST1"},
338 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
340 buf, err := yaml.Marshal(yamlMap)
342 t.Errorf("#TestNonHexRicIdFailure - failed to marshal configuration map\n")
344 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
346 t.Errorf("#TestNonHexRicIdFailure - failed to write configuration file: %s\n", configPath)
348 assert.PanicsWithValue(t, "#configuration.validateRicId - ricId is not hex number\n",
349 func() { ParseConfiguration() })
352 func TestWrongRicIdLengthFailure(t *testing.T) {
353 configPath := "../resources/configuration.yaml"
354 configPathTmp := "../resources/configuration.yaml_tmp"
355 err := os.Rename(configPath, configPathTmp)
357 t.Errorf("#TestWrongRicIdLengthFailure - failed to rename configuration file: %s\n", configPath)
360 err = os.Rename(configPathTmp, configPath)
362 t.Errorf("#TestWrongRicIdLengthFailure - failed to rename configuration file: %s\n", configPath)
365 yamlMap := map[string]interface{}{
366 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
367 "logging": map[string]interface{}{"logLevel": "info"},
368 "http": map[string]interface{}{"port": 3800},
369 "globalRicId": map[string]interface{}{"mcc": "327", "mnc": "94", "ricId": "AA43"},
370 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
372 buf, err := yaml.Marshal(yamlMap)
374 t.Errorf("#TestWrongRicIdLengthFailure - failed to marshal configuration map\n")
376 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
378 t.Errorf("#TestWrongRicIdLengthFailure - failed to write configuration file: %s\n", configPath)
380 assert.PanicsWithValue(t, "#configuration.validateRicId - ricId length should be 5 hex characters\n",
381 func() { ParseConfiguration() })
384 func TestMccNotThreeDigitsFailure(t *testing.T) {
385 configPath := "../resources/configuration.yaml"
386 configPathTmp := "../resources/configuration.yaml_tmp"
387 err := os.Rename(configPath, configPathTmp)
389 t.Errorf("#TestMccNotThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
392 err = os.Rename(configPathTmp, configPath)
394 t.Errorf("#TestMccNotThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
397 yamlMap := map[string]interface{}{
398 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
399 "logging": map[string]interface{}{"logLevel": "info"},
400 "http": map[string]interface{}{"port": 3800},
401 "globalRicId": map[string]interface{}{"mcc": "31", "mnc": "94", "ricId": "AA443"},
402 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
404 buf, err := yaml.Marshal(yamlMap)
406 t.Errorf("#TestMccNotThreeDigitsFailure - failed to marshal configuration map\n")
408 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
410 t.Errorf("#TestMccNotThreeDigitsFailure - failed to write configuration file: %s\n", configPath)
412 assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is not 3 digits\n",
413 func() { ParseConfiguration() })
416 func TestMncLengthIsGreaterThanThreeDigitsFailure(t *testing.T) {
417 configPath := "../resources/configuration.yaml"
418 configPathTmp := "../resources/configuration.yaml_tmp"
419 err := os.Rename(configPath, configPathTmp)
421 t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
424 err = os.Rename(configPathTmp, configPath)
426 t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
429 yamlMap := map[string]interface{}{
430 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
431 "logging": map[string]interface{}{"logLevel": "info"},
432 "http": map[string]interface{}{"port": 3800},
433 "globalRicId": map[string]interface{}{"mcc": "310", "mnc": "6794", "ricId": "AA443"},
434 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
436 buf, err := yaml.Marshal(yamlMap)
438 t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to marshal configuration map\n")
440 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
442 t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to write configuration file: %s\n", configPath)
444 assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is not 2 or 3 digits\n",
445 func() { ParseConfiguration() })
448 func TestMncLengthIsLessThanTwoDigitsFailure(t *testing.T) {
449 configPath := "../resources/configuration.yaml"
450 configPathTmp := "../resources/configuration.yaml_tmp"
451 err := os.Rename(configPath, configPathTmp)
453 t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to rename configuration file: %s\n", configPath)
456 err = os.Rename(configPathTmp, configPath)
458 t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to rename configuration file: %s\n", configPath)
461 yamlMap := map[string]interface{}{
462 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
463 "logging": map[string]interface{}{"logLevel": "info"},
464 "http": map[string]interface{}{"port": 3800},
465 "globalRicId": map[string]interface{}{"mcc": "310", "mnc": "4", "ricId": "AA443"},
466 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
468 buf, err := yaml.Marshal(yamlMap)
470 t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to marshal configuration map\n")
472 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
474 t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to write configuration file: %s\n", configPath)
476 assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is not 2 or 3 digits\n",
477 func() { ParseConfiguration() })
480 func TestNegativeMncFailure(t *testing.T) {
481 configPath := "../resources/configuration.yaml"
482 configPathTmp := "../resources/configuration.yaml_tmp"
483 err := os.Rename(configPath, configPathTmp)
485 t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
488 err = os.Rename(configPathTmp, configPath)
490 t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
493 yamlMap := map[string]interface{}{
494 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
495 "logging": map[string]interface{}{"logLevel": "info"},
496 "http": map[string]interface{}{"port": 3800},
497 "globalRicId": map[string]interface{}{"mcc": "310", "mnc": "-2", "ricId": "AA443"},
498 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
500 buf, err := yaml.Marshal(yamlMap)
502 t.Errorf("#TestNegativeMncFailure - failed to marshal configuration map\n")
504 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
506 t.Errorf("#TestNegativeMncFailure - failed to write configuration file: %s\n", configPath)
508 assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is negative\n",
509 func() { ParseConfiguration() })
512 func TestNegativeMccFailure(t *testing.T) {
513 configPath := "../resources/configuration.yaml"
514 configPathTmp := "../resources/configuration.yaml_tmp"
515 err := os.Rename(configPath, configPathTmp)
517 t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
520 err = os.Rename(configPathTmp, configPath)
522 t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
525 yamlMap := map[string]interface{}{
526 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
527 "logging": map[string]interface{}{"logLevel": "info"},
528 "http": map[string]interface{}{"port": 3800},
529 "globalRicId": map[string]interface{}{"mcc": "-31", "mnc": "222", "ricId": "AA443"},
530 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
532 buf, err := yaml.Marshal(yamlMap)
534 t.Errorf("#TestNegativeMncFailure - failed to marshal configuration map\n")
536 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
538 t.Errorf("#TestNegativeMncFailure - failed to write configuration file: %s\n", configPath)
540 assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is negative\n",
541 func() { ParseConfiguration() })
544 func TestAlphaNumericMccFailure(t *testing.T) {
545 configPath := "../resources/configuration.yaml"
546 configPathTmp := "../resources/configuration.yaml_tmp"
547 err := os.Rename(configPath, configPathTmp)
549 t.Errorf("#TestAlphaNumericMccFailure - failed to rename configuration file: %s\n", configPath)
552 err = os.Rename(configPathTmp, configPath)
554 t.Errorf("#TestAlphaNumericMccFailure - failed to rename configuration file: %s\n", configPath)
557 yamlMap := map[string]interface{}{
558 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
559 "logging": map[string]interface{}{"logLevel": "info"},
560 "http": map[string]interface{}{"port": 3800},
561 "globalRicId": map[string]interface{}{"mcc": "1W2", "mnc": "222", "ricId": "AA443"},
562 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
564 buf, err := yaml.Marshal(yamlMap)
566 t.Errorf("#TestAlphaNumericMccFailure - failed to marshal configuration map\n")
568 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
570 t.Errorf("#TestAlphaNumericMccFailure - failed to write configuration file: %s\n", configPath)
572 assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is not a number\n",
573 func() { ParseConfiguration() })
576 func TestAlphaNumericMncFailure(t *testing.T) {
577 configPath := "../resources/configuration.yaml"
578 configPathTmp := "../resources/configuration.yaml_tmp"
579 err := os.Rename(configPath, configPathTmp)
581 t.Errorf("#TestAlphaNumericMncFailure - failed to rename configuration file: %s\n", configPath)
584 err = os.Rename(configPathTmp, configPath)
586 t.Errorf("#TestAlphaNumericMncFailure - failed to rename configuration file: %s\n", configPath)
589 yamlMap := map[string]interface{}{
590 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
591 "logging": map[string]interface{}{"logLevel": "info"},
592 "http": map[string]interface{}{"port": 3800},
593 "globalRicId": map[string]interface{}{"mcc": "111", "mnc": "2A8", "ricId": "AA443"},
594 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
596 buf, err := yaml.Marshal(yamlMap)
598 t.Errorf("#TestAlphaNumericMncFailure - failed to marshal configuration map\n")
600 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
602 t.Errorf("#TestAlphaNumericMncFailure - failed to write configuration file: %s\n", configPath)
604 assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is not a number\n",
605 func() { ParseConfiguration() })
608 func TestMissingMmcFailure(t *testing.T) {
609 configPath := "../resources/configuration.yaml"
610 configPathTmp := "../resources/configuration.yaml_tmp"
611 err := os.Rename(configPath, configPathTmp)
613 t.Errorf("#TestMissingMmcFailure - failed to rename configuration file: %s\n", configPath)
616 err = os.Rename(configPathTmp, configPath)
618 t.Errorf("#TestMissingMmcFailure - failed to rename configuration file: %s\n", configPath)
621 yamlMap := map[string]interface{}{
622 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
623 "logging": map[string]interface{}{"logLevel": "info"},
624 "http": map[string]interface{}{"port": 3800},
625 "globalRicId": map[string]interface{}{"mnc": "94", "ricId": "AABB3"},
626 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
628 buf, err := yaml.Marshal(yamlMap)
630 t.Errorf("#TestMissingMmcFailure - failed to marshal configuration map\n")
632 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
634 t.Errorf("#TestMissingMmcFailure - failed to write configuration file: %s\n", configPath)
636 assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is missing or empty\n",
637 func() { ParseConfiguration() })
640 func TestEmptyMmcFailure(t *testing.T) {
641 configPath := "../resources/configuration.yaml"
642 configPathTmp := "../resources/configuration.yaml_tmp"
643 err := os.Rename(configPath, configPathTmp)
645 t.Errorf("#TestEmptyMmcFailure - failed to rename configuration file: %s\n", configPath)
648 err = os.Rename(configPathTmp, configPath)
650 t.Errorf("#TestEmptyMmcFailure - failed to rename configuration file: %s\n", configPath)
653 yamlMap := map[string]interface{}{
654 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
655 "logging": map[string]interface{}{"logLevel": "info"},
656 "http": map[string]interface{}{"port": 3800},
657 "globalRicId": map[string]interface{}{"mcc": "", "mnc": "94", "ricId": "AABB3"},
658 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
660 buf, err := yaml.Marshal(yamlMap)
662 t.Errorf("#TestEmptyMmcFailure - failed to marshal configuration map\n")
664 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
666 t.Errorf("#TestEmptyMmcFailure - failed to write configuration file: %s\n", configPath)
668 assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is missing or empty\n",
669 func() { ParseConfiguration() })
672 func TestEmptyMncFailure(t *testing.T) {
673 configPath := "../resources/configuration.yaml"
674 configPathTmp := "../resources/configuration.yaml_tmp"
675 err := os.Rename(configPath, configPathTmp)
677 t.Errorf("#TestEmptyMncFailure - failed to rename configuration file: %s\n", configPath)
680 err = os.Rename(configPathTmp, configPath)
682 t.Errorf("#TestEmptyMncFailure - failed to rename configuration file: %s\n", configPath)
685 yamlMap := map[string]interface{}{
686 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
687 "logging": map[string]interface{}{"logLevel": "info"},
688 "http": map[string]interface{}{"port": 3800},
689 "globalRicId": map[string]interface{}{"mcc": "111", "mnc": "", "ricId": "AABB3"},
690 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
692 buf, err := yaml.Marshal(yamlMap)
694 t.Errorf("#TestEmptyMncFailure - failed to marshal configuration map\n")
696 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
698 t.Errorf("#TestEmptyMncFailure - failed to write configuration file: %s\n", configPath)
700 assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is missing or empty\n",
701 func() { ParseConfiguration() })
704 func TestMissingMncFailure(t *testing.T) {
705 configPath := "../resources/configuration.yaml"
706 configPathTmp := "../resources/configuration.yaml_tmp"
707 err := os.Rename(configPath, configPathTmp)
709 t.Errorf("#TestMissingMncFailure - failed to rename configuration file: %s\n", configPath)
712 err = os.Rename(configPathTmp, configPath)
714 t.Errorf("#TestMissingMncFailure - failed to rename configuration file: %s\n", configPath)
717 yamlMap := map[string]interface{}{
718 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
719 "logging": map[string]interface{}{"logLevel": "info"},
720 "http": map[string]interface{}{"port": 3800},
721 "globalRicId": map[string]interface{}{"mcc": "111", "ricId": "AABB3"},
722 "routingManager": map[string]interface{}{"baseUrl": "http://localhost:8080/ric/v1/handles/"},
724 buf, err := yaml.Marshal(yamlMap)
726 t.Errorf("#TestMissingMncFailure - failed to marshal configuration map\n")
728 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
730 t.Errorf("#TestMissingMncFailure - failed to write configuration file: %s\n", configPath)
732 assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is missing or empty\n",
733 func() { ParseConfiguration() })