[RIC-430] - Update Connection Status on RAN List - release tag 5.4.5
[ric-plt/e2mgr.git] / E2Manager / configuration / configuration_test.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 //
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
8 //
9 //      http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16
17 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20 package configuration
21
22 import (
23         "github.com/stretchr/testify/assert"
24         "gopkg.in/yaml.v2"
25         "io/ioutil"
26         "os"
27         "testing"
28 )
29
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)
47 }
48
49 func TestStringer(t *testing.T) {
50         config := ParseConfiguration().String()
51         assert.NotEmpty(t, config)
52 }
53
54 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
55         configPath := "../resources/configuration.yaml"
56         configPathTmp := "../resources/configuration.yaml_tmp"
57         err := os.Rename(configPath, configPathTmp)
58         if err != nil {
59                 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
60         }
61         defer func() {
62                 err = os.Rename(configPathTmp, configPath)
63                 if err != nil {
64                         t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
65                 }
66         }()
67         assert.Panics(t, func() { ParseConfiguration() })
68 }
69
70 func TestRmrConfigNotFoundFailure(t *testing.T) {
71         configPath := "../resources/configuration.yaml"
72         configPathTmp := "../resources/configuration.yaml_tmp"
73         err := os.Rename(configPath, configPathTmp)
74         if err != nil {
75                 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
76         }
77         defer func() {
78                 err = os.Rename(configPathTmp, configPath)
79                 if err != nil {
80                         t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
81                 }
82         }()
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"},
88         }
89         buf, err := yaml.Marshal(yamlMap)
90         if err != nil {
91                 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
92         }
93         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
94         if err != nil {
95                 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
96         }
97         assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
98 }
99
100 func TestLoggingConfigNotFoundFailure(t *testing.T) {
101         configPath := "../resources/configuration.yaml"
102         configPathTmp := "../resources/configuration.yaml_tmp"
103         err := os.Rename(configPath, configPathTmp)
104         if err != nil {
105                 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
106         }
107         defer func() {
108                 err = os.Rename(configPathTmp, configPath)
109                 if err != nil {
110                         t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
111                 }
112         }()
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"},
118         }
119         buf, err := yaml.Marshal(yamlMap)
120         if err != nil {
121                 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
122         }
123         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
124         if err != nil {
125                 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
126         }
127         assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
128                 func() { ParseConfiguration() })
129 }
130
131 func TestHttpConfigNotFoundFailure(t *testing.T) {
132         configPath := "../resources/configuration.yaml"
133         configPathTmp := "../resources/configuration.yaml_tmp"
134         err := os.Rename(configPath, configPathTmp)
135         if err != nil {
136                 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
137         }
138         defer func() {
139                 err = os.Rename(configPathTmp, configPath)
140                 if err != nil {
141                         t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
142                 }
143         }()
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"},
149         }
150         buf, err := yaml.Marshal(yamlMap)
151         if err != nil {
152                 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
153         }
154         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
155         if err != nil {
156                 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
157         }
158         assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
159                 func() { ParseConfiguration() })
160 }
161
162 func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
163         configPath := "../resources/configuration.yaml"
164         configPathTmp := "../resources/configuration.yaml_tmp"
165         err := os.Rename(configPath, configPathTmp)
166         if err != nil {
167                 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
168         }
169         defer func() {
170                 err = os.Rename(configPathTmp, configPath)
171                 if err != nil {
172                         t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
173                 }
174         }()
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"},
180         }
181         buf, err := yaml.Marshal(yamlMap)
182         if err != nil {
183                 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
184         }
185         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
186         if err != nil {
187                 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
188         }
189         assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
190                 func() { ParseConfiguration() })
191 }
192
193 func TestGlobalRicIdConfigNotFoundFailure(t *testing.T) {
194         configPath := "../resources/configuration.yaml"
195         configPathTmp := "../resources/configuration.yaml_tmp"
196         err := os.Rename(configPath, configPathTmp)
197         if err != nil {
198                 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
199         }
200         defer func() {
201                 err = os.Rename(configPathTmp, configPath)
202                 if err != nil {
203                         t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
204                 }
205         }()
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/"},
211         }
212         buf, err := yaml.Marshal(yamlMap)
213         if err != nil {
214                 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to marshal configuration map\n")
215         }
216         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
217         if err != nil {
218                 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
219         }
220         assert.PanicsWithValue(t, "#configuration.validateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n",
221                 func() { ParseConfiguration() })
222 }
223
224 func TestRnibWriterConfigNotFoundFailure(t *testing.T) {
225         configPath := "../resources/configuration.yaml"
226         configPathTmp := "../resources/configuration.yaml_tmp"
227         err := os.Rename(configPath, configPathTmp)
228         if err != nil {
229                 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
230         }
231         defer func() {
232                 err = os.Rename(configPathTmp, configPath)
233                 if err != nil {
234                         t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
235                 }
236         }()
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"},
243         }
244         buf, err := yaml.Marshal(yamlMap)
245         if err != nil {
246                 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to marshal configuration map\n")
247         }
248         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
249         if err != nil {
250                 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
251         }
252         assert.PanicsWithValue(t, "#configuration.populateRnibWriterConfig - failed to populate Rnib Writer configuration: The entry 'rnibWriter' not found\n",
253                 func() { ParseConfiguration() })
254 }
255
256 func TestEmptyRicIdFailure(t *testing.T) {
257         configPath := "../resources/configuration.yaml"
258         configPathTmp := "../resources/configuration.yaml_tmp"
259         err := os.Rename(configPath, configPathTmp)
260         if err != nil {
261                 t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
262         }
263         defer func() {
264                 err = os.Rename(configPathTmp, configPath)
265                 if err != nil {
266                         t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
267                 }
268         }()
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/"},
275         }
276         buf, err := yaml.Marshal(yamlMap)
277         if err != nil {
278                 t.Errorf("#TestEmptyRicIdFailure - failed to marshal configuration map\n")
279         }
280         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
281         if err != nil {
282                 t.Errorf("#TestEmptyRicIdFailure - failed to write configuration file: %s\n", configPath)
283         }
284         assert.PanicsWithValue(t, "#configuration.validateRicId - ricId is missing or empty\n",
285                 func() { ParseConfiguration() })
286 }
287
288 func TestMissingRicIdFailure(t *testing.T) {
289         configPath := "../resources/configuration.yaml"
290         configPathTmp := "../resources/configuration.yaml_tmp"
291         err := os.Rename(configPath, configPathTmp)
292         if err != nil {
293                 t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
294         }
295         defer func() {
296                 err = os.Rename(configPathTmp, configPath)
297                 if err != nil {
298                         t.Errorf("#TestEmptyRicIdFailure - failed to rename configuration file: %s\n", configPath)
299                 }
300         }()
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/"},
307         }
308         buf, err := yaml.Marshal(yamlMap)
309         if err != nil {
310                 t.Errorf("#TestEmptyRicIdFailure - failed to marshal configuration map\n")
311         }
312         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
313         if err != nil {
314                 t.Errorf("#TestEmptyRicIdFailure - failed to write configuration file: %s\n", configPath)
315         }
316         assert.PanicsWithValue(t, "#configuration.validateRicId - ricId is missing or empty\n",
317                 func() { ParseConfiguration() })
318 }
319
320 func TestNonHexRicIdFailure(t *testing.T) {
321         configPath := "../resources/configuration.yaml"
322         configPathTmp := "../resources/configuration.yaml_tmp"
323         err := os.Rename(configPath, configPathTmp)
324         if err != nil {
325                 t.Errorf("#TestNonHexRicIdFailure - failed to rename configuration file: %s\n", configPath)
326         }
327         defer func() {
328                 err = os.Rename(configPathTmp, configPath)
329                 if err != nil {
330                         t.Errorf("#TestNonHexRicIdFailure - failed to rename configuration file: %s\n", configPath)
331                 }
332         }()
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/"},
339         }
340         buf, err := yaml.Marshal(yamlMap)
341         if err != nil {
342                 t.Errorf("#TestNonHexRicIdFailure - failed to marshal configuration map\n")
343         }
344         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
345         if err != nil {
346                 t.Errorf("#TestNonHexRicIdFailure - failed to write configuration file: %s\n", configPath)
347         }
348         assert.PanicsWithValue(t, "#configuration.validateRicId - ricId is not hex number\n",
349                 func() { ParseConfiguration() })
350 }
351
352 func TestWrongRicIdLengthFailure(t *testing.T) {
353         configPath := "../resources/configuration.yaml"
354         configPathTmp := "../resources/configuration.yaml_tmp"
355         err := os.Rename(configPath, configPathTmp)
356         if err != nil {
357                 t.Errorf("#TestWrongRicIdLengthFailure - failed to rename configuration file: %s\n", configPath)
358         }
359         defer func() {
360                 err = os.Rename(configPathTmp, configPath)
361                 if err != nil {
362                         t.Errorf("#TestWrongRicIdLengthFailure - failed to rename configuration file: %s\n", configPath)
363                 }
364         }()
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/"},
371         }
372         buf, err := yaml.Marshal(yamlMap)
373         if err != nil {
374                 t.Errorf("#TestWrongRicIdLengthFailure - failed to marshal configuration map\n")
375         }
376         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
377         if err != nil {
378                 t.Errorf("#TestWrongRicIdLengthFailure - failed to write configuration file: %s\n", configPath)
379         }
380         assert.PanicsWithValue(t, "#configuration.validateRicId - ricId length should be 5 hex characters\n",
381                 func() { ParseConfiguration() })
382 }
383
384 func TestMccNotThreeDigitsFailure(t *testing.T) {
385         configPath := "../resources/configuration.yaml"
386         configPathTmp := "../resources/configuration.yaml_tmp"
387         err := os.Rename(configPath, configPathTmp)
388         if err != nil {
389                 t.Errorf("#TestMccNotThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
390         }
391         defer func() {
392                 err = os.Rename(configPathTmp, configPath)
393                 if err != nil {
394                         t.Errorf("#TestMccNotThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
395                 }
396         }()
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/"},
403         }
404         buf, err := yaml.Marshal(yamlMap)
405         if err != nil {
406                 t.Errorf("#TestMccNotThreeDigitsFailure - failed to marshal configuration map\n")
407         }
408         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
409         if err != nil {
410                 t.Errorf("#TestMccNotThreeDigitsFailure - failed to write configuration file: %s\n", configPath)
411         }
412         assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is not 3 digits\n",
413                 func() { ParseConfiguration() })
414 }
415
416 func TestMncLengthIsGreaterThanThreeDigitsFailure(t *testing.T) {
417         configPath := "../resources/configuration.yaml"
418         configPathTmp := "../resources/configuration.yaml_tmp"
419         err := os.Rename(configPath, configPathTmp)
420         if err != nil {
421                 t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
422         }
423         defer func() {
424                 err = os.Rename(configPathTmp, configPath)
425                 if err != nil {
426                         t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to rename configuration file: %s\n", configPath)
427                 }
428         }()
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/"},
435         }
436         buf, err := yaml.Marshal(yamlMap)
437         if err != nil {
438                 t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to marshal configuration map\n")
439         }
440         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
441         if err != nil {
442                 t.Errorf("#TestMncLengthIsGreaterThanThreeDigitsFailure - failed to write configuration file: %s\n", configPath)
443         }
444         assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is not 2 or 3 digits\n",
445                 func() { ParseConfiguration() })
446 }
447
448 func TestMncLengthIsLessThanTwoDigitsFailure(t *testing.T) {
449         configPath := "../resources/configuration.yaml"
450         configPathTmp := "../resources/configuration.yaml_tmp"
451         err := os.Rename(configPath, configPathTmp)
452         if err != nil {
453                 t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to rename configuration file: %s\n", configPath)
454         }
455         defer func() {
456                 err = os.Rename(configPathTmp, configPath)
457                 if err != nil {
458                         t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to rename configuration file: %s\n", configPath)
459                 }
460         }()
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/"},
467         }
468         buf, err := yaml.Marshal(yamlMap)
469         if err != nil {
470                 t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to marshal configuration map\n")
471         }
472         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
473         if err != nil {
474                 t.Errorf("#TestMncLengthIsLessThanTwoDigitsFailure - failed to write configuration file: %s\n", configPath)
475         }
476         assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is not 2 or 3 digits\n",
477                 func() { ParseConfiguration() })
478 }
479
480 func TestNegativeMncFailure(t *testing.T) {
481         configPath := "../resources/configuration.yaml"
482         configPathTmp := "../resources/configuration.yaml_tmp"
483         err := os.Rename(configPath, configPathTmp)
484         if err != nil {
485                 t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
486         }
487         defer func() {
488                 err = os.Rename(configPathTmp, configPath)
489                 if err != nil {
490                         t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
491                 }
492         }()
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/"},
499         }
500         buf, err := yaml.Marshal(yamlMap)
501         if err != nil {
502                 t.Errorf("#TestNegativeMncFailure - failed to marshal configuration map\n")
503         }
504         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
505         if err != nil {
506                 t.Errorf("#TestNegativeMncFailure - failed to write configuration file: %s\n", configPath)
507         }
508         assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is negative\n",
509                 func() { ParseConfiguration() })
510 }
511
512 func TestNegativeMccFailure(t *testing.T) {
513         configPath := "../resources/configuration.yaml"
514         configPathTmp := "../resources/configuration.yaml_tmp"
515         err := os.Rename(configPath, configPathTmp)
516         if err != nil {
517                 t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
518         }
519         defer func() {
520                 err = os.Rename(configPathTmp, configPath)
521                 if err != nil {
522                         t.Errorf("#TestNegativeMncFailure - failed to rename configuration file: %s\n", configPath)
523                 }
524         }()
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/"},
531         }
532         buf, err := yaml.Marshal(yamlMap)
533         if err != nil {
534                 t.Errorf("#TestNegativeMncFailure - failed to marshal configuration map\n")
535         }
536         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
537         if err != nil {
538                 t.Errorf("#TestNegativeMncFailure - failed to write configuration file: %s\n", configPath)
539         }
540         assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is negative\n",
541                 func() { ParseConfiguration() })
542 }
543
544 func TestAlphaNumericMccFailure(t *testing.T) {
545         configPath := "../resources/configuration.yaml"
546         configPathTmp := "../resources/configuration.yaml_tmp"
547         err := os.Rename(configPath, configPathTmp)
548         if err != nil {
549                 t.Errorf("#TestAlphaNumericMccFailure - failed to rename configuration file: %s\n", configPath)
550         }
551         defer func() {
552                 err = os.Rename(configPathTmp, configPath)
553                 if err != nil {
554                         t.Errorf("#TestAlphaNumericMccFailure - failed to rename configuration file: %s\n", configPath)
555                 }
556         }()
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/"},
563         }
564         buf, err := yaml.Marshal(yamlMap)
565         if err != nil {
566                 t.Errorf("#TestAlphaNumericMccFailure - failed to marshal configuration map\n")
567         }
568         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
569         if err != nil {
570                 t.Errorf("#TestAlphaNumericMccFailure - failed to write configuration file: %s\n", configPath)
571         }
572         assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is not a number\n",
573                 func() { ParseConfiguration() })
574 }
575
576 func TestAlphaNumericMncFailure(t *testing.T) {
577         configPath := "../resources/configuration.yaml"
578         configPathTmp := "../resources/configuration.yaml_tmp"
579         err := os.Rename(configPath, configPathTmp)
580         if err != nil {
581                 t.Errorf("#TestAlphaNumericMncFailure - failed to rename configuration file: %s\n", configPath)
582         }
583         defer func() {
584                 err = os.Rename(configPathTmp, configPath)
585                 if err != nil {
586                         t.Errorf("#TestAlphaNumericMncFailure - failed to rename configuration file: %s\n", configPath)
587                 }
588         }()
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/"},
595         }
596         buf, err := yaml.Marshal(yamlMap)
597         if err != nil {
598                 t.Errorf("#TestAlphaNumericMncFailure - failed to marshal configuration map\n")
599         }
600         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
601         if err != nil {
602                 t.Errorf("#TestAlphaNumericMncFailure - failed to write configuration file: %s\n", configPath)
603         }
604         assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is not a number\n",
605                 func() { ParseConfiguration() })
606 }
607
608 func TestMissingMmcFailure(t *testing.T) {
609         configPath := "../resources/configuration.yaml"
610         configPathTmp := "../resources/configuration.yaml_tmp"
611         err := os.Rename(configPath, configPathTmp)
612         if err != nil {
613                 t.Errorf("#TestMissingMmcFailure - failed to rename configuration file: %s\n", configPath)
614         }
615         defer func() {
616                 err = os.Rename(configPathTmp, configPath)
617                 if err != nil {
618                         t.Errorf("#TestMissingMmcFailure - failed to rename configuration file: %s\n", configPath)
619                 }
620         }()
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/"},
627         }
628         buf, err := yaml.Marshal(yamlMap)
629         if err != nil {
630                 t.Errorf("#TestMissingMmcFailure - failed to marshal configuration map\n")
631         }
632         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
633         if err != nil {
634                 t.Errorf("#TestMissingMmcFailure - failed to write configuration file: %s\n", configPath)
635         }
636         assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is missing or empty\n",
637                 func() { ParseConfiguration() })
638 }
639
640 func TestEmptyMmcFailure(t *testing.T) {
641         configPath := "../resources/configuration.yaml"
642         configPathTmp := "../resources/configuration.yaml_tmp"
643         err := os.Rename(configPath, configPathTmp)
644         if err != nil {
645                 t.Errorf("#TestEmptyMmcFailure - failed to rename configuration file: %s\n", configPath)
646         }
647         defer func() {
648                 err = os.Rename(configPathTmp, configPath)
649                 if err != nil {
650                         t.Errorf("#TestEmptyMmcFailure - failed to rename configuration file: %s\n", configPath)
651                 }
652         }()
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/"},
659         }
660         buf, err := yaml.Marshal(yamlMap)
661         if err != nil {
662                 t.Errorf("#TestEmptyMmcFailure - failed to marshal configuration map\n")
663         }
664         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
665         if err != nil {
666                 t.Errorf("#TestEmptyMmcFailure - failed to write configuration file: %s\n", configPath)
667         }
668         assert.PanicsWithValue(t, "#configuration.validateMcc - mcc is missing or empty\n",
669                 func() { ParseConfiguration() })
670 }
671
672 func TestEmptyMncFailure(t *testing.T) {
673         configPath := "../resources/configuration.yaml"
674         configPathTmp := "../resources/configuration.yaml_tmp"
675         err := os.Rename(configPath, configPathTmp)
676         if err != nil {
677                 t.Errorf("#TestEmptyMncFailure - failed to rename configuration file: %s\n", configPath)
678         }
679         defer func() {
680                 err = os.Rename(configPathTmp, configPath)
681                 if err != nil {
682                         t.Errorf("#TestEmptyMncFailure - failed to rename configuration file: %s\n", configPath)
683                 }
684         }()
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/"},
691         }
692         buf, err := yaml.Marshal(yamlMap)
693         if err != nil {
694                 t.Errorf("#TestEmptyMncFailure - failed to marshal configuration map\n")
695         }
696         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
697         if err != nil {
698                 t.Errorf("#TestEmptyMncFailure - failed to write configuration file: %s\n", configPath)
699         }
700         assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is missing or empty\n",
701                 func() { ParseConfiguration() })
702 }
703
704 func TestMissingMncFailure(t *testing.T) {
705         configPath := "../resources/configuration.yaml"
706         configPathTmp := "../resources/configuration.yaml_tmp"
707         err := os.Rename(configPath, configPathTmp)
708         if err != nil {
709                 t.Errorf("#TestMissingMncFailure - failed to rename configuration file: %s\n", configPath)
710         }
711         defer func() {
712                 err = os.Rename(configPathTmp, configPath)
713                 if err != nil {
714                         t.Errorf("#TestMissingMncFailure - failed to rename configuration file: %s\n", configPath)
715                 }
716         }()
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/"},
723         }
724         buf, err := yaml.Marshal(yamlMap)
725         if err != nil {
726                 t.Errorf("#TestMissingMncFailure - failed to marshal configuration map\n")
727         }
728         err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
729         if err != nil {
730                 t.Errorf("#TestMissingMncFailure - failed to write configuration file: %s\n", configPath)
731         }
732         assert.PanicsWithValue(t, "#configuration.validateMnc - mnc is missing or empty\n",
733                 func() { ParseConfiguration() })
734 }