+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 TestPersistentStorage(t *testing.T) {
+ xapp.Logger.Info("TestPersistentStorage")
+ alarmManager.alarmInfoPvFile = "../../definitions/sample.json"
+ alarmManager.ReadAlarmInfoFromPersistentVolume()
+}
+
+func TestReadAlarmDefinitionFromJsonWrongFilename(t *testing.T) {
+ // use to set wrong file name os.Setenv("SITE_TITLE", "Test Site")
+ xapp.Logger.Info("TestReadAlarmDefinitionFromJsonWrongFilename")
+ os.Setenv("DEF_FILE","test.json")
+ alarmManager.ReadAlarmDefinitionFromJson()
+ // correct the filename
+}
+
+func TestReadAlarmDefinitionFromJsonInvalidFilename(t *testing.T) {
+ // use to set wrong file name os.Setenv("SITE_TITLE", "Test Site")
+ xapp.Logger.Info("TestReadAlarmDefinitionFromJsonInvalidFilename")
+ os.Setenv("DEF_FILE","../../definitions/test.json")
+ alarmManager.ReadAlarmDefinitionFromJson()
+ // correct the filename
+}
+
+func TestPostAlarm(t *testing.T) {
+ xapp.Logger.Info("TestPostAlarm")
+ var activeAlarms []AlarmNotification
+ activeAlarms = make([]AlarmNotification, 1)
+ alarmManager.PostAlarm(&activeAlarms[0])
+}
+
+func TestPostAlarm1(t *testing.T) {
+ xapp.Logger.Info("TestPostAlarm")
+ var activeAlarms []AlarmNotification
+ activeAlarms = make([]AlarmNotification, 2)
+ alarmManager.PostAlarm(&activeAlarms[0])
+}
+
+func TestNewAlarmManagerOther(t *testing.T){
+ NewAlarmManager("", 0, true)
+}
+
+func TestStatusCallbackFailure(t *testing.T) {
+ xapp.Logger.Info("TestStatusCallbackFailure")
+ alarmManager.rmrReady = false
+ assert.Equal(t, false, alarmManager.StatusCB())
+}
+
+func TestConfigChangeCBFailure(t *testing.T) {
+ xapp.Logger.Info("TestConfigChangeCBFailure")
+ alarmManager.maxActiveAlarms = 0
+ alarmManager.maxAlarmHistory = 0
+ alarmManager.ConfigChangeCB("AlarmManager")
+}
+
+