Search in sources :

Example 1 with NewAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.

the class AlertMapperTest method convertAlertInputToNewAlertTriggerEntityResponseTime.

@Test
public void convertAlertInputToNewAlertTriggerEntityResponseTime() {
    final AlertInput alertInput = new AlertInput();
    alertInput.setEnabled(true);
    alertInput.setResponseTime(35);
    alertInput.setDuration(10);
    alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
    alertInput.setType(AlertType.RESPONSE_TIME);
    final NewAlertTriggerEntity actual = alertMapper.convert(alertInput);
    assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
    assertThat(actual.getType()).isEqualTo(AlertMapper.RESPONSE_TIME_ALERT);
    final AggregationCondition aggregationCondition = (AggregationCondition) actual.getConditions().get(0);
    assertThat(aggregationCondition.getDuration()).isEqualTo(alertInput.getDuration().longValue());
    assertThat(aggregationCondition.getTimeUnit()).isEqualTo(TimeUnit.MINUTES);
    assertThat(aggregationCondition.getThreshold()).isEqualTo(alertInput.getResponseTime().doubleValue());
}
Also used : AggregationCondition(io.gravitee.alert.api.condition.AggregationCondition) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) Test(org.junit.Test)

Example 2 with NewAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertServiceTest method shouldNotCreateMappingError.

@Test(expected = TechnicalManagementException.class)
public void shouldNotCreateMappingError() throws Exception {
    NewAlertTriggerEntity newAlert = new NewAlertTriggerEntity();
    newAlert.setId(ALERT_ID);
    newAlert.setType("METRICS_RATE");
    ApplicationEntity application = getApplication();
    prepareForCreation(newAlert);
    when(applicationService.findById(APPLICATION_ID)).thenReturn(application);
    when(mapper.writeValueAsString(any())).thenThrow(JsonProcessingException.class);
    cut.create(APPLICATION_ID, newAlert);
}
Also used : NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Test(org.junit.Test)

Example 3 with NewAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertServiceTest method shouldCreateStatusAlert.

@Test
public void shouldCreateStatusAlert() {
    NewAlertTriggerEntity newAlert = new NewAlertTriggerEntity();
    newAlert.setId(ALERT_ID);
    newAlert.setType("METRICS_RATE");
    ApplicationEntity application = getApplication();
    prepareForCreation(newAlert);
    when(applicationService.findById(APPLICATION_ID)).thenReturn(application);
    cut.create(APPLICATION_ID, newAlert);
    verify(alertService, times(1)).create(newAlert);
    verify(notificationTemplateService, times(1)).findByHookAndScope(AlertHook.CONSUMER_HTTP_STATUS.name(), HookScope.TEMPLATES_FOR_ALERT.name());
}
Also used : NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Test(org.junit.Test)

Example 4 with NewAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.

the class AlertMapper method convert.

public NewAlertTriggerEntity convert(AlertInput alertInput) {
    final NewAlertTriggerEntity newAlert = new NewAlertTriggerEntity();
    newAlert.setEnabled(alertInput.getEnabled());
    newAlert.setConditions(convertConditions(alertInput));
    switch(Objects.requireNonNull(alertInput.getType())) {
        case STATUS:
            newAlert.setType(STATUS_ALERT);
            break;
        case RESPONSE_TIME:
            newAlert.setType(RESPONSE_TIME_ALERT);
            break;
    }
    return newAlert;
}
Also used : NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)

Example 5 with NewAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.

the class AlertMapperTest method convertAlertInputToNewAlertTriggerEntityStatus2xx.

@Test
public void convertAlertInputToNewAlertTriggerEntityStatus2xx() {
    final AlertInput alertInput = new AlertInput();
    alertInput.setEnabled(true);
    alertInput.setStatusCode("2xx");
    alertInput.setStatusPercent(20);
    alertInput.setDuration(10);
    alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
    alertInput.setType(AlertType.STATUS);
    final NewAlertTriggerEntity actual = alertMapper.convert(alertInput);
    assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
    assertThat(actual.getType()).isEqualTo(AlertMapper.STATUS_ALERT);
    final RateCondition rateCondition = (RateCondition) actual.getConditions().get(0);
    assertThat(rateCondition.getDuration()).isEqualTo(alertInput.getDuration().longValue());
    assertThat(rateCondition.getTimeUnit()).isEqualTo(TimeUnit.MINUTES);
    assertThat(rateCondition.getThreshold()).isEqualTo(alertInput.getStatusPercent().doubleValue());
    final ThresholdRangeCondition condition = (ThresholdRangeCondition) rateCondition.getComparison();
    assertThat(condition.getProperty()).isEqualTo("response.status");
    assertThat(condition.getThresholdLow()).isEqualTo(200D);
    assertThat(condition.getThresholdHigh()).isEqualTo(299D);
}
Also used : AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) RateCondition(io.gravitee.alert.api.condition.RateCondition) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition) Test(org.junit.Test)

Aggregations

NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)8 Test (org.junit.Test)6 ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)3 AlertInput (io.gravitee.rest.api.portal.rest.model.AlertInput)3 RateCondition (io.gravitee.alert.api.condition.RateCondition)2 ThresholdRangeCondition (io.gravitee.alert.api.condition.ThresholdRangeCondition)2 AggregationCondition (io.gravitee.alert.api.condition.AggregationCondition)1 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)1 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)1 ApplicationAlertMaximumException (io.gravitee.rest.api.service.exceptions.ApplicationAlertMaximumException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1