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, 1500, config.KeepAliveResponseTimeoutMs)
40 assert.Equal(t, 500, config.KeepAliveDelayMs)
43 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
44 configPath := "../resources/configuration.yaml"
45 configPathTmp := "../resources/configuration.yaml_tmp"
46 err := os.Rename(configPath, configPathTmp)
48 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
51 err = os.Rename(configPathTmp, configPath)
53 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
56 assert.Panics(t, func() { ParseConfiguration() })
59 func TestRmrConfigNotFoundFailure(t *testing.T) {
60 configPath := "../resources/configuration.yaml"
61 configPathTmp := "../resources/configuration.yaml_tmp"
62 err := os.Rename(configPath, configPathTmp)
64 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
67 err = os.Rename(configPathTmp, configPath)
69 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
72 yamlMap := map[string]interface{}{
73 "logging": map[string]interface{}{"logLevel": "info"},
74 "http": map[string]interface{}{"port": 3800},
75 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
77 buf, err := yaml.Marshal(yamlMap)
79 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
81 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
83 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
85 assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
88 func TestLoggingConfigNotFoundFailure(t *testing.T) {
89 configPath := "../resources/configuration.yaml"
90 configPathTmp := "../resources/configuration.yaml_tmp"
91 err := os.Rename(configPath, configPathTmp)
93 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
96 err = os.Rename(configPathTmp, configPath)
98 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
101 yamlMap := map[string]interface{}{
102 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
103 "http": map[string]interface{}{"port": 3800},
104 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
106 buf, err := yaml.Marshal(yamlMap)
108 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
110 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
112 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
114 assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
115 func() { ParseConfiguration() })
118 func TestHttpConfigNotFoundFailure(t *testing.T) {
119 configPath := "../resources/configuration.yaml"
120 configPathTmp := "../resources/configuration.yaml_tmp"
121 err := os.Rename(configPath, configPathTmp)
123 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
126 err = os.Rename(configPathTmp, configPath)
128 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
131 yamlMap := map[string]interface{}{
132 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
133 "logging": map[string]interface{}{"logLevel": "info"},
134 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
136 buf, err := yaml.Marshal(yamlMap)
138 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
140 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
142 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
144 assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
145 func() { ParseConfiguration() })
148 func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
149 configPath := "../resources/configuration.yaml"
150 configPathTmp := "../resources/configuration.yaml_tmp"
151 err := os.Rename(configPath, configPathTmp)
153 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
156 err = os.Rename(configPathTmp, configPath)
158 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
161 yamlMap := map[string]interface{}{
162 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
163 "logging": map[string]interface{}{"logLevel": "info"},
164 "http": map[string]interface{}{"port": 3800},
166 buf, err := yaml.Marshal(yamlMap)
168 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
170 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
172 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
174 assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
175 func() { ParseConfiguration() })