use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class AlertMapperTest method convertAlertInputToNewAlertTriggerEntityStatus200.
@Test
public void convertAlertInputToNewAlertTriggerEntityStatus200() {
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 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(200D);
}
use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertsResource method createApplicationAlert.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_ALERT, acls = RolePermissionAction.CREATE) })
public Response createApplicationAlert(@PathParam("applicationId") String applicationId, @Valid @NotNull(message = "Input must not be null.") AlertInput alertInput) {
checkPlugins();
if (applicationAlertService.findByApplication(applicationId).size() == 10) {
throw new ApplicationAlertMaximumException(applicationId, 10);
}
final NewAlertTriggerEntity newAlertTriggerEntity = alertMapper.convert(alertInput);
final AlertTriggerEntity alert = applicationAlertService.create(applicationId, newAlertTriggerEntity);
return Response.created(this.getLocationHeader(alert.getId())).entity(alertMapper.convert(alert)).build();
}
use of io.gravitee.rest.api.model.alert.NewAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldCreateResponseTimeAlert.
@Test
public void shouldCreateResponseTimeAlert() {
NewAlertTriggerEntity newAlert = new NewAlertTriggerEntity();
newAlert.setId(ALERT_ID);
newAlert.setType("METRICS_AGGREGATION");
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_RESPONSE_TIME.name(), HookScope.TEMPLATES_FOR_ALERT.name());
}
Aggregations