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)
44 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
45 configPath := "../resources/configuration.yaml"
46 configPathTmp := "../resources/configuration.yaml_tmp"
47 err := os.Rename(configPath, configPathTmp)
49 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
52 err = os.Rename(configPathTmp, configPath)
54 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
57 assert.Panics(t, func() { ParseConfiguration() })
60 func TestRmrConfigNotFoundFailure(t *testing.T) {
61 configPath := "../resources/configuration.yaml"
62 configPathTmp := "../resources/configuration.yaml_tmp"
63 err := os.Rename(configPath, configPathTmp)
65 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
68 err = os.Rename(configPathTmp, configPath)
70 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
73 yamlMap := map[string]interface{}{
74 "logging": map[string]interface{}{"logLevel": "info"},
75 "http": map[string]interface{}{"port": 3800},
76 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
78 buf, err := yaml.Marshal(yamlMap)
80 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
82 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
84 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
86 assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
89 func TestLoggingConfigNotFoundFailure(t *testing.T) {
90 configPath := "../resources/configuration.yaml"
91 configPathTmp := "../resources/configuration.yaml_tmp"
92 err := os.Rename(configPath, configPathTmp)
94 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
97 err = os.Rename(configPathTmp, configPath)
99 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
102 yamlMap := map[string]interface{}{
103 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
104 "http": map[string]interface{}{"port": 3800},
105 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
107 buf, err := yaml.Marshal(yamlMap)
109 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
111 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
113 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
115 assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
116 func() { ParseConfiguration() })
119 func TestHttpConfigNotFoundFailure(t *testing.T) {
120 configPath := "../resources/configuration.yaml"
121 configPathTmp := "../resources/configuration.yaml_tmp"
122 err := os.Rename(configPath, configPathTmp)
124 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
127 err = os.Rename(configPathTmp, configPath)
129 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
132 yamlMap := map[string]interface{}{
133 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
134 "logging": map[string]interface{}{"logLevel": "info"},
135 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
137 buf, err := yaml.Marshal(yamlMap)
139 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
141 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
143 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
145 assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
146 func() { ParseConfiguration() })
149 func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
150 configPath := "../resources/configuration.yaml"
151 configPathTmp := "../resources/configuration.yaml_tmp"
152 err := os.Rename(configPath, configPathTmp)
154 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
157 err = os.Rename(configPathTmp, configPath)
159 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
162 yamlMap := map[string]interface{}{
163 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
164 "logging": map[string]interface{}{"logLevel": "info"},
165 "http": map[string]interface{}{"port": 3800},
167 buf, err := yaml.Marshal(yamlMap)
169 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
171 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
173 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
175 assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
176 func() { ParseConfiguration() })