UT coverage improvements
Change-Id: Iea71cb0e2d6d9ca8789385e4770672932873ee04
Signed-off-by: vipin <vipin.mavila@nokia.com>
diff --git a/manager/cmd/manager_test.go b/manager/cmd/manager_test.go
index 0457c58..0e2cef4 100755
--- a/manager/cmd/manager_test.go
+++ b/manager/cmd/manager_test.go
@@ -221,6 +221,34 @@
assert.Nil(t, alarmer.Raise(a), "raise failed")
VerifyAlarm(t, a, 1)
+
+ var activeAlarms []AlarmNotification
+ activeAlarms = make([]AlarmNotification, 1)
+ req, _ := http.NewRequest("GET", "/ric/v1/alarms/active", nil)
+ req = mux.SetURLVars(req, nil)
+ handleFunc := http.HandlerFunc(alarmManager.GetActiveAlarms)
+ response := executeRequest(req, handleFunc)
+ checkResponseCode(t, http.StatusOK, response.Code)
+
+ // Decode the json output from handler
+ json.NewDecoder(response.Body).Decode(activeAlarms)
+ if len(activeAlarms) != 1 {
+ t.Errorf("Incorrect alarm alarm count")
+ }
+
+ var alarmHistory []AlarmNotification
+ alarmHistory = make([]AlarmNotification, 1)
+ req, _ = http.NewRequest("GET", "/ric/v1/alarms/history", nil)
+ req = mux.SetURLVars(req, nil)
+ handleFunc = http.HandlerFunc(alarmManager.GetAlarmHistory)
+ response = executeRequest(req, handleFunc)
+ checkResponseCode(t, http.StatusOK, response.Code)
+
+ // Decode the json output from handler
+ json.NewDecoder(response.Body).Decode(alarmHistory)
+ if len(alarmHistory) != 1 {
+ t.Errorf("Incorrect alarm history count")
+ }
}
func TestAlarmClearedSucess(t *testing.T) {
@@ -523,6 +551,60 @@
assert.Equal(t, len(alarmManager.activeAlarms), 0)
}
+func TestSetAlarmConfig(t *testing.T) {
+ xapp.Logger.Info("TestSetAlarmConfig")
+
+ var setAlarmConfig alarm.AlarmConfigParams
+ setAlarmConfig.MaxActiveAlarms = 500
+ setAlarmConfig.MaxAlarmHistory = 2000
+
+ pbodyEn, _ := json.Marshal(setAlarmConfig)
+ req, _ := http.NewRequest("POST", "/ric/v1/alarms/config", bytes.NewBuffer(pbodyEn))
+ handleFunc := http.HandlerFunc(alarmManager.SetAlarmConfig)
+ response := executeRequest(req, handleFunc)
+ checkResponseCode(t, http.StatusOK, response.Code)
+
+ var getAlarmConfig alarm.AlarmConfigParams
+ req, _ = http.NewRequest("GET", "/ric/v1/alarms/config", nil)
+ req = mux.SetURLVars(req, nil)
+ handleFunc = http.HandlerFunc(alarmManager.GetAlarmConfig)
+ response = executeRequest(req, handleFunc)
+ checkResponseCode(t, http.StatusOK, response.Code)
+
+ // Decode the json output from handler
+ json.NewDecoder(response.Body).Decode(&getAlarmConfig)
+ if getAlarmConfig.MaxActiveAlarms != 500 || getAlarmConfig.MaxAlarmHistory != 2000 {
+ t.Errorf("Incorrect alarm thresholds")
+ }
+
+ // Revert ot default
+ setAlarmConfig.MaxActiveAlarms = 5000
+ setAlarmConfig.MaxAlarmHistory = 20000
+
+ pbodyEn, _ = json.Marshal(setAlarmConfig)
+ req, _ = http.NewRequest("POST", "/ric/v1/alarms/config", bytes.NewBuffer(pbodyEn))
+ handleFunc = http.HandlerFunc(alarmManager.SetAlarmConfig)
+ response = executeRequest(req, handleFunc)
+ checkResponseCode(t, http.StatusOK, response.Code)
+
+ req, _ = http.NewRequest("GET", "/ric/v1/alarms/config", nil)
+ req = mux.SetURLVars(req, nil)
+ handleFunc = http.HandlerFunc(alarmManager.GetAlarmConfig)
+ response = executeRequest(req, handleFunc)
+ checkResponseCode(t, http.StatusOK, response.Code)
+
+ // Decode the json output from handler
+ json.NewDecoder(response.Body).Decode(&getAlarmConfig)
+ if getAlarmConfig.MaxActiveAlarms != 5000 || getAlarmConfig.MaxAlarmHistory != 20000 {
+ t.Errorf("Incorrect alarm thresholds")
+ }
+}
+
+func TestConfigChangeCB(t *testing.T) {
+ xapp.Logger.Info("TestConfigChangeCB")
+ alarmManager.ConfigChangeCB("AlarmManager")
+}
+
func VerifyAlarm(t *testing.T, a alarm.Alarm, expectedCount int) string {
receivedAlert := waitForEvent()
@@ -641,3 +723,4 @@
}
return file, nil
}
+