use of io.gravitee.alert.api.condition.AggregationCondition in project gravitee-management-rest-api by gravitee-io.
the class AlertMapperTest method convertAlertInputToUpdateAlertTriggerEntityResponseTime.
@Test
public void convertAlertInputToUpdateAlertTriggerEntityResponseTime() {
final AlertInput alertInput = new AlertInput();
alertInput.setEnabled(true);
alertInput.setResponseTime(35);
alertInput.setDuration(10);
alertInput.setTimeUnit(AlertTimeUnit.MINUTES);
alertInput.setType(AlertType.RESPONSE_TIME);
final UpdateAlertTriggerEntity actual = alertMapper.convertToUpdate(alertInput);
assertThat(actual.isEnabled()).isEqualTo(alertInput.getEnabled());
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());
}
use of io.gravitee.alert.api.condition.AggregationCondition in project gravitee-management-rest-api by gravitee-io.
the class AlertMapperTest method convertAlertTriggerEntityToAlertResponseTime.
@Test
public void convertAlertTriggerEntityToAlertResponseTime() {
AlertTriggerEntity alertTriggerEntity = mock(AlertTriggerEntity.class);
when(alertTriggerEntity.getType()).thenReturn(AlertMapper.RESPONSE_TIME_ALERT);
final AggregationCondition aggregationCondition = mock(AggregationCondition.class);
when(alertTriggerEntity.getConditions()).thenReturn(Collections.singletonList(aggregationCondition));
when(aggregationCondition.getTimeUnit()).thenReturn(TimeUnit.MINUTES);
when(aggregationCondition.getDuration()).thenReturn(10L);
when(aggregationCondition.getThreshold()).thenReturn(200D);
final Alert actual = alertMapper.convert(alertTriggerEntity);
assertThat(actual.getType()).isEqualTo(AlertType.RESPONSE_TIME);
assertThat(actual.getResponseTime()).isEqualTo(200);
assertThat(actual.getDuration()).isEqualTo(10);
assertThat(actual.getTimeUnit()).isEqualTo(AlertTimeUnit.MINUTES);
}
use of io.gravitee.alert.api.condition.AggregationCondition 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());
}
use of io.gravitee.alert.api.condition.AggregationCondition 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;
}
Aggregations