use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.
the class AlertMapperTest method convertAlertInputToUpdateAlertTriggerEntityStatus2xx.
@Test
public void convertAlertInputToUpdateAlertTriggerEntityStatus2xx() {
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 UpdateAlertTriggerEntity actual = alertMapper.convertToUpdate(alertInput);
assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
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);
}
use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.
the class AlertMapperTest method convertAlertInputToUpdateAlertTriggerEntityStatus200.
@Test
public void convertAlertInputToUpdateAlertTriggerEntityStatus200() {
final AlertInput alertInput = new AlertInput();
alertInput.setEnabled(true);
alertInput.setStatusCode("200");
alertInput.setStatusPercent(20);
alertInput.setDuration(10);
alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
alertInput.setType(AlertType.STATUS);
final UpdateAlertTriggerEntity actual = alertMapper.convertToUpdate(alertInput);
assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
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(200D);
}
use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.
the class AlertMapperTest method convertAlertTriggerEntityToAlertStatus200.
@Test
public void convertAlertTriggerEntityToAlertStatus200() {
AlertTriggerEntity alertTriggerEntity = mock(AlertTriggerEntity.class);
when(alertTriggerEntity.getType()).thenReturn(AlertMapper.STATUS_ALERT);
final RateCondition rateCondition = mock(RateCondition.class);
when(alertTriggerEntity.getConditions()).thenReturn(Collections.singletonList(rateCondition));
when(rateCondition.getTimeUnit()).thenReturn(TimeUnit.MINUTES);
when(rateCondition.getDuration()).thenReturn(10L);
when(rateCondition.getThreshold()).thenReturn(20D);
final ThresholdRangeCondition thresholdRangeCondition = mock(ThresholdRangeCondition.class);
when(rateCondition.getComparison()).thenReturn(thresholdRangeCondition);
when(thresholdRangeCondition.getThresholdLow()).thenReturn(200D);
when(thresholdRangeCondition.getThresholdHigh()).thenReturn(200D);
final Alert actual = alertMapper.convert(alertTriggerEntity);
assertThat(actual.getType()).isEqualTo(AlertType.STATUS);
assertThat(actual.getStatusCode()).isEqualTo("200");
assertThat(actual.getStatusPercent()).isEqualTo(20);
assertThat(actual.getDuration()).isEqualTo(10);
assertThat(actual.getTimeUnit()).isEqualTo(AlertTimeUnit.MINUTES);
}
use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.
the class AlertMapper method convert.
public Alert convert(AlertTriggerEntity alertTriggerEntity) {
final Alert alert = new Alert();
alert.setId(alertTriggerEntity.getId());
alert.setEnabled(alertTriggerEntity.isEnabled());
if (RESPONSE_TIME_ALERT.equals(alertTriggerEntity.getType())) {
alert.setType(AlertType.RESPONSE_TIME);
final AggregationCondition condition = (AggregationCondition) alertTriggerEntity.getConditions().get(0);
alert.setDuration((int) condition.getDuration());
alert.setTimeUnit(convert(condition.getTimeUnit()));
alert.setResponseTime(condition.getThreshold().intValue());
} else if (STATUS_ALERT.equals(alertTriggerEntity.getType())) {
alert.setType(AlertType.STATUS);
final RateCondition condition = (RateCondition) alertTriggerEntity.getConditions().get(0);
alert.setDuration((int) condition.getDuration());
alert.setTimeUnit(convert(condition.getTimeUnit()));
final ThresholdRangeCondition comparison = (ThresholdRangeCondition) condition.getComparison();
alert.setStatusCode(convertStatusCode(comparison.getThresholdLow(), comparison.getThresholdHigh()));
alert.setStatusPercent((int) condition.getThreshold());
}
return alert;
}
use of io.gravitee.alert.api.condition.ThresholdRangeCondition in project gravitee-management-rest-api by gravitee-io.
the class AlertMapperTest method convertAlertTriggerEntityToAlertStatus2xx.
@Test
public void convertAlertTriggerEntityToAlertStatus2xx() {
AlertTriggerEntity alertTriggerEntity = mock(AlertTriggerEntity.class);
when(alertTriggerEntity.getType()).thenReturn(AlertMapper.STATUS_ALERT);
final RateCondition rateCondition = mock(RateCondition.class);
when(alertTriggerEntity.getConditions()).thenReturn(Collections.singletonList(rateCondition));
when(rateCondition.getTimeUnit()).thenReturn(TimeUnit.MINUTES);
when(rateCondition.getDuration()).thenReturn(10L);
when(rateCondition.getThreshold()).thenReturn(20D);
final ThresholdRangeCondition thresholdRangeCondition = mock(ThresholdRangeCondition.class);
when(rateCondition.getComparison()).thenReturn(thresholdRangeCondition);
when(thresholdRangeCondition.getThresholdLow()).thenReturn(200D);
when(thresholdRangeCondition.getThresholdHigh()).thenReturn(299D);
final Alert actual = alertMapper.convert(alertTriggerEntity);
assertThat(actual.getType()).isEqualTo(AlertType.STATUS);
assertThat(actual.getStatusCode()).isEqualTo("2xx");
assertThat(actual.getStatusPercent()).isEqualTo(20);
assertThat(actual.getDuration()).isEqualTo(10);
assertThat(actual.getTimeUnit()).isEqualTo(AlertTimeUnit.MINUTES);
}
Aggregations