Search in sources :

Example 1 with Alert

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");
    }
}
Also used : Alert(com.axibase.tsd.api.model.alert.Alert)

Example 2 with Alert

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.");
    }
}
Also used : Alert(com.axibase.tsd.api.model.alert.Alert)

Example 3 with Alert

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());
}
Also used : AlertHistoryQuery(com.axibase.tsd.api.model.alert.AlertHistoryQuery) Alert(com.axibase.tsd.api.model.alert.Alert) Issue(io.qameta.allure.Issue) Test(org.testng.annotations.Test)

Example 4 with Alert

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)));
}
Also used : Response(javax.ws.rs.core.Response) AlertQuery(com.axibase.tsd.api.model.alert.AlertQuery) Alert(com.axibase.tsd.api.model.alert.Alert) AlertUpdateQuery(com.axibase.tsd.api.model.alert.AlertUpdateQuery) Issue(io.qameta.allure.Issue) Test(org.testng.annotations.Test) AlertTest(com.axibase.tsd.api.method.alert.AlertTest)

Example 5 with Alert

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)));
}
Also used : AlertQuery(com.axibase.tsd.api.model.alert.AlertQuery) AlertDeleteQuery(com.axibase.tsd.api.model.alert.AlertDeleteQuery) AlertCheck(com.axibase.tsd.api.method.checks.AlertCheck) Alert(com.axibase.tsd.api.model.alert.Alert) DeletionCheck(com.axibase.tsd.api.method.checks.DeletionCheck) Issue(io.qameta.allure.Issue) Test(org.testng.annotations.Test) AlertTest(com.axibase.tsd.api.method.alert.AlertTest)

Aggregations

Alert (com.axibase.tsd.api.model.alert.Alert)8 Issue (io.qameta.allure.Issue)6 Test (org.testng.annotations.Test)6 AlertTest (com.axibase.tsd.api.method.alert.AlertTest)3 AlertQuery (com.axibase.tsd.api.model.alert.AlertQuery)3 Response (javax.ws.rs.core.Response)2 AlertCheck (com.axibase.tsd.api.method.checks.AlertCheck)1 DeletionCheck (com.axibase.tsd.api.method.checks.DeletionCheck)1 AlertDeleteQuery (com.axibase.tsd.api.model.alert.AlertDeleteQuery)1 AlertHistoryQuery (com.axibase.tsd.api.model.alert.AlertHistoryQuery)1 AlertUpdateQuery (com.axibase.tsd.api.model.alert.AlertUpdateQuery)1