use of com.axibase.tsd.api.model.alert.Alert in project atsd-api-test by axibase.
the class AlertQueryAcknowledgedTest method markAlertAcknowledged.
private void markAlertAcknowledged(final String entityName) {
Map<String, String> alertQuery = new HashMap<>();
alertQuery.put("entity", entityName);
alertQuery.put("startDate", MIN_QUERYABLE_DATE);
alertQuery.put("endDate", MAX_QUERYABLE_DATE);
List<Alert> alertList = queryAlerts(alertQuery).readEntity(ResponseAsList.ofAlerts());
List<Map<String, Object>> updateAlertsCommand = new ArrayList<>();
Map<String, Object> item;
for (final Alert alert : alertList) {
item = new HashMap<>();
item.put("acknowledged", true);
item.put("id", alert.getId());
updateAlertsCommand.add(item);
}
if (Response.Status.Family.SUCCESSFUL != Util.responseFamily(updateAlerts(updateAlertsCommand.toArray()))) {
throw new IllegalStateException("Fail to set alert acknowledged");
}
}
use of com.axibase.tsd.api.model.alert.Alert in project atsd-api-test by axibase.
the class AlertQueryAcknowledgedTest method checkAllAcknowledgedTypesExist.
private void checkAllAcknowledgedTypesExist() {
Map<String, Object> alertQuery = new HashMap<>();
alertQuery.put("entities", Arrays.asList(ENTITY_NAME, ENTITY_NAME_ACK));
alertQuery.put("startDate", MIN_QUERYABLE_DATE);
alertQuery.put("endDate", MAX_QUERYABLE_DATE);
List<Alert> alertList = queryAlerts(alertQuery).readEntity(ResponseAsList.ofAlerts());
Boolean acknowledgedFalseExist = false;
Boolean acknowledgedTrueExist = false;
for (Alert alert : alertList) {
if (!alert.getAcknowledged()) {
acknowledgedFalseExist = true;
} else {
acknowledgedTrueExist = true;
}
}
if (!acknowledgedFalseExist || !acknowledgedTrueExist) {
throw new IllegalStateException("Both acknowledged types should exist to run test.");
}
}
use of com.axibase.tsd.api.model.alert.Alert in project atsd-api-test by axibase.
the class AlertHistoryQueryTest method testUnknownEntityNotAffectProcessingOthers.
@Issue("2993")
@Test(enabled = false)
public void testUnknownEntityNotAffectProcessingOthers() throws Exception {
AlertHistoryQuery qExist = templateQuery().setEntity("alert-historyquery-entity-1");
AlertHistoryQuery qUnknown = templateQuery().setEntity("UNKNOWN");
List<Alert> resultList = AlertMethod.queryHistory(qExist, qUnknown);
assertEquals("Fail to get alert history by queries with unknown entity", 2, resultList.size());
assertEquals("Unexpected warning message", "ENTITY not found for name: 'unknown'", resultList.get(1).getWarning());
}
use of com.axibase.tsd.api.model.alert.Alert in project atsd-api-test by axibase.
the class TokenAlertTest method testUpdateMethod.
@Test(description = "Tests alert update endpoint with tokens.")
@Issue("6052")
public void testUpdateMethod() throws Exception {
String url = "/alerts/update";
String token = TokenRepository.getToken(username, HttpMethod.POST, url);
String entity = Mocks.entity();
generateAlertForEntity(entity);
AlertQuery query = new AlertQuery().setStartDate(Util.MIN_QUERYABLE_DATE).setEndDate(Util.MAX_QUERYABLE_DATE).setMetrics(Collections.singletonList(RULE_METRIC_NAME)).setEntity(entity);
Alert alert = queryAlerts(query).readEntity(ResponseAsList.ofAlerts()).get(0);
// changing data in retrieved alert
alert.setAcknowledged(!alert.getAcknowledged());
AlertUpdateQuery updateQuery = new AlertUpdateQuery(alert.getId(), alert.getAcknowledged());
updateAlerts(Collections.singletonList(updateQuery), token);
Response response = queryAlerts(query);
assertTrue(compareJsonString(Util.prettyPrint(Collections.singletonList(alert)), response.readEntity(String.class)));
}
use of com.axibase.tsd.api.model.alert.Alert in project atsd-api-test by axibase.
the class TokenAlertTest method testDeleteMethod.
@Test(description = "Tests alert update endpoint with tokens.")
@Issue("6052")
public void testDeleteMethod() throws Exception {
String url = "/alerts/delete";
String token = TokenRepository.getToken(username, HttpMethod.POST, url);
String entity = Mocks.entity();
generateAlertForEntity(entity);
AlertQuery query = new AlertQuery().setStartDate(Util.MIN_QUERYABLE_DATE).setEndDate(Util.MAX_QUERYABLE_DATE).setMetrics(Collections.singletonList(RULE_METRIC_NAME)).setEntity(entity);
Alert alert = queryAlerts(query).readEntity(ResponseAsList.ofAlerts()).get(0);
deleteAlerts(Collections.singletonList(new AlertDeleteQuery(alert.getId())), token);
Checker.check(new DeletionCheck(new AlertCheck(query)));
}
Aggregations