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.
21 "github.com/stretchr/testify/assert"
28 func TestParseConfigurationSuccess(t *testing.T) {
29 config := ParseConfiguration()
30 assert.Equal(t, 3800, config.Http.Port)
31 assert.Equal(t, 3801, config.Rmr.Port)
32 assert.Equal(t, 65536, config.Rmr.MaxMsgSize)
33 assert.Equal(t, "info", config.Logging.LogLevel)
34 assert.Equal(t, 100, config.NotificationResponseBuffer)
35 assert.Equal(t, 5, config.BigRedButtonTimeoutSec)
36 assert.Equal(t, 1500, config.KeepAliveResponseTimeoutMs)
37 assert.Equal(t, 500, config.KeepAliveDelayMs)
40 func TestParseConfigurationFileNotFoundFailure(t *testing.T) {
41 configPath := "../resources/configuration.yaml"
42 configPathTmp := "../resources/configuration.yaml_tmp"
43 err := os.Rename(configPath, configPathTmp)
45 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
48 err = os.Rename(configPathTmp, configPath)
50 t.Errorf("#TestParseConfigurationFileNotFoundFailure - failed to rename configuration file: %s\n", configPath)
53 assert.Panics(t, func() { ParseConfiguration() })
56 func TestRmrConfigNotFoundFailure(t *testing.T) {
57 configPath := "../resources/configuration.yaml"
58 configPathTmp := "../resources/configuration.yaml_tmp"
59 err := os.Rename(configPath, configPathTmp)
61 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
64 err = os.Rename(configPathTmp, configPath)
66 t.Errorf("#TestRmrConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
69 yamlMap := map[string]interface{}{
70 "logging": map[string]interface{}{"logLevel": "info"},
71 "http": map[string]interface{}{"port": 3800},
72 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
74 buf, err := yaml.Marshal(yamlMap)
76 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
78 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
80 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
82 assert.PanicsWithValue(t, "#configuration.populateRmrConfig - failed to populate RMR configuration: The entry 'rmr' not found\n", func() { ParseConfiguration() })
85 func TestLoggingConfigNotFoundFailure(t *testing.T) {
86 configPath := "../resources/configuration.yaml"
87 configPathTmp := "../resources/configuration.yaml_tmp"
88 err := os.Rename(configPath, configPathTmp)
90 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
93 err = os.Rename(configPathTmp, configPath)
95 t.Errorf("#TestLoggingConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
98 yamlMap := map[string]interface{}{
99 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
100 "http": map[string]interface{}{"port": 3800},
101 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
103 buf, err := yaml.Marshal(yamlMap)
105 t.Errorf("#TestRmrConfigNotFoundFailure - failed to marshal configuration map\n")
107 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
109 t.Errorf("#TestRmrConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
111 assert.PanicsWithValue(t, "#configuration.populateLoggingConfig - failed to populate logging configuration: The entry 'logging' not found\n",
112 func() { ParseConfiguration() })
115 func TestHttpConfigNotFoundFailure(t *testing.T) {
116 configPath := "../resources/configuration.yaml"
117 configPathTmp := "../resources/configuration.yaml_tmp"
118 err := os.Rename(configPath, configPathTmp)
120 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
123 err = os.Rename(configPathTmp, configPath)
125 t.Errorf("#TestHttpConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
128 yamlMap := map[string]interface{}{
129 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
130 "logging": map[string]interface{}{"logLevel": "info"},
131 "routingManager": map[string]interface{}{"baseUrl": "http://iltlv740.intl.att.com:8080/ric/v1/handles/"},
133 buf, err := yaml.Marshal(yamlMap)
135 t.Errorf("#TestHttpConfigNotFoundFailure - failed to marshal configuration map\n")
137 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
139 t.Errorf("#TestHttpConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
141 assert.PanicsWithValue(t, "#configuration.populateHttpConfig - failed to populate HTTP configuration: The entry 'http' not found\n",
142 func() { ParseConfiguration() })
145 func TestRoutingManagerConfigNotFoundFailure(t *testing.T) {
146 configPath := "../resources/configuration.yaml"
147 configPathTmp := "../resources/configuration.yaml_tmp"
148 err := os.Rename(configPath, configPathTmp)
150 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
153 err = os.Rename(configPathTmp, configPath)
155 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to rename configuration file: %s\n", configPath)
158 yamlMap := map[string]interface{}{
159 "rmr": map[string]interface{}{"port": 3801, "maxMsgSize": 4096},
160 "logging": map[string]interface{}{"logLevel": "info"},
161 "http": map[string]interface{}{"port": 3800},
163 buf, err := yaml.Marshal(yamlMap)
165 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to marshal configuration map\n")
167 err = ioutil.WriteFile("../resources/configuration.yaml", buf, 0644)
169 t.Errorf("#TestRoutingManagerConfigNotFoundFailure - failed to write configuration file: %s\n", configPath)
171 assert.PanicsWithValue(t, "#configuration.populateRoutingManagerConfig - failed to populate Routing Manager configuration: The entry 'routingManager' not found\n",
172 func() { ParseConfiguration() })