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 TestParseConfigurationFileNotFoundFailure(t *testing.T) {
48 configPath := "../resources/configuration.yaml"
49 configPathTmp := "../resources/configuration.yaml_tmp"
50 err := os.Rename(configPath, configPathTmp)
52 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
55 err = os.Rename(configPathTmp, configPath)
57 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
60 assert.Panics(t, func() { ParseConfiguration() })
63 func TestRmrConfigNotFoundFailure(t *testing.T) {
64 configPath := "../resources/configuration.yaml"
65 configPathTmp := "../resources/configuration.yaml_tmp"
66 err := os.Rename(configPath, configPathTmp)
68 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
71 err = os.Rename(configPathTmp, configPath)
73 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
76 yamlMap := map[string]interface{}{
77 "logging": map[string]interface{}{"logLevel": "info"},
78 "http": map[string]interface{}{"port": 3800},
79 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
80 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
82 buf, err := yaml.Marshal(yamlMap)
84 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
86 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
88 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
90 assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
93 func TestLoggingConfigNotFoundFailure(t *testing.T) {
94 configPath := "../resources/configuration.yaml"
95 configPathTmp := "../resources/configuration.yaml_tmp"
96 err := os.Rename(configPath, configPathTmp)
98 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
101 err = os.Rename(configPathTmp, configPath)
103 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
106 yamlMap := map[string]interface{}{
107 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
108 "http": map[string]interface{}{"port": 3800},
109 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
110 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
112 buf, err := yaml.Marshal(yamlMap)
114 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
116 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
118 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
120 assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
121 func() { ParseConfiguration() })
124 func TestHttpConfigNotFoundFailure(t *testing.T) {
125 configPath := "../resources/configuration.yaml"
126 configPathTmp := "../resources/configuration.yaml_tmp"
127 err := os.Rename(configPath, configPathTmp)
129 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
132 err = os.Rename(configPathTmp, configPath)
134 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
137 yamlMap := map[string]interface{}{
138 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
139 "logging": map[string]interface{}{"logLevel": "info"},
140 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
141 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
143 buf, err := yaml.Marshal(yamlMap)
145 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
147 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
149 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
151 assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
152 func() { ParseConfiguration() })
155 func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
156 configPath := "../resources/configuration.yaml"
157 configPathTmp := "../resources/configuration.yaml_tmp"
158 err := os.Rename(configPath, configPathTmp)
160 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
163 err = os.Rename(configPathTmp, configPath)
165 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
168 yamlMap := map[string]interface{}{
169 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
170 "logging": map[string]interface{}{"logLevel": "info"},
171 "http": map[string]interface{}{"port": 3800},
172 "globalRicId": map[string]interface{}{"plmnId": "131014", "ricNearRtId": "556670"},
174 buf, err := yaml.Marshal(yamlMap)
176 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
178 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
180 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
182 assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
183 func() { ParseConfiguration() })
186 func TestGlobalRicIdConfigNotFoundFailure(t *testing.T) {
187 configPath := "../resources/configuration.yaml"
188 configPathTmp := "../resources/configuration.yaml_tmp"
189 err := os.Rename(configPath, configPathTmp)
191 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
194 err = os.Rename(configPathTmp, configPath)
196 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
199 yamlMap := map[string]interface{}{
200 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
201 "logging": map[string]interface{}{"logLevel": "info"},
202 "http": map[string]interface{}{"port": 3800},
203 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
205 buf, err := yaml.Marshal(yamlMap)
207 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to marshal configuration map\n")
209 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
211 t.Errorf("#TestGlobalRicIdConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
213 assert.PanicsWithValue(t, "#configuration.populateGlobalRicIdConfig - failed to populate Global RicId configuration: The entry 'globalRicId' not found\n",
214 func() { ParseConfiguration() })