Search in sources :

Example 1 with UpdateAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity 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());
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AggregationCondition(io.gravitee.alert.api.condition.AggregationCondition) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) Test(org.junit.Test)

Example 2 with UpdateAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity 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);
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) RateCondition(io.gravitee.alert.api.condition.RateCondition) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition) Test(org.junit.Test)

Example 3 with UpdateAlertTriggerEntity

use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity 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);
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) AlertInput(io.gravitee.rest.api.portal.rest.model.AlertInput) RateCondition(io.gravitee.alert.api.condition.RateCondition) ThresholdRangeCondition(io.gravitee.alert.api.condition.ThresholdRangeCondition) Test(org.junit.Test)

Example 4 with UpdateAlertTriggerEntity

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

the class ApplicationAlertServiceTest method shouldHandleNotificationTemplateUpdatedEventResponseTimeAlert.

@Test
public void shouldHandleNotificationTemplateUpdatedEventResponseTimeAlert() throws Exception {
    NotificationTemplateEntity notificationTemplate = new NotificationTemplateEntity();
    notificationTemplate.setHook(AlertHook.CONSUMER_RESPONSE_TIME.name());
    notificationTemplate.setTitle("notification-template-title");
    notificationTemplate.setContent("notification-template-content");
    NotificationTemplateEvent notificationTemplateEvent = new NotificationTemplateEvent("org-id", notificationTemplate);
    final SimpleEvent<ApplicationAlertEventType, Object> event = new SimpleEvent<>(ApplicationAlertEventType.NOTIFICATION_TEMPLATE_UPDATE, notificationTemplateEvent);
    ApplicationListItem app1 = new ApplicationListItem();
    app1.setId("app1");
    ApplicationListItem app2 = new ApplicationListItem();
    app2.setId("app2");
    when(applicationService.findByOrganization("org-id")).thenReturn(new HashSet<>(Arrays.asList(app1, app2)));
    final AlertTriggerEntity alertTrigger = mock(AlertTriggerEntity.class);
    when(alertTrigger.getType()).thenReturn("METRICS_AGGREGATION");
    when(alertService.findByReferenceAndReferenceIds(AlertReferenceType.APPLICATION, Arrays.asList("app1", "app2"))).thenReturn(Collections.singletonList(alertTrigger));
    Notification notification = new Notification();
    notification.setType("default-email");
    notification.setConfiguration("");
    when(alertTrigger.getNotifications()).thenReturn(Collections.singletonList(notification));
    JsonNode emailNode = JsonNodeFactory.instance.objectNode().put("to", "to").put("from", "from").put("subject", "subject").put("body", "body");
    when(mapper.readTree(notification.getConfiguration())).thenReturn(emailNode);
    cut.handleEvent(event);
    ArgumentCaptor<UpdateAlertTriggerEntity> updatingCaptor = ArgumentCaptor.forClass(UpdateAlertTriggerEntity.class);
    verify(alertService, times(1)).update(updatingCaptor.capture());
    final UpdateAlertTriggerEntity updating = updatingCaptor.getValue();
    assertThat(updating.getNotifications().get(0).getConfiguration()).contains("notification-template-content");
    assertThat(updating.getNotifications().get(0).getConfiguration()).contains("notification-template-title");
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) SimpleEvent(io.gravitee.common.event.impl.SimpleEvent) NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Notification(io.gravitee.notifier.api.Notification) ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) NotificationTemplateEvent(io.gravitee.rest.api.model.notification.NotificationTemplateEvent) ApplicationAlertEventType(io.gravitee.rest.api.model.alert.ApplicationAlertEventType) Test(org.junit.Test)

Example 5 with UpdateAlertTriggerEntity

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

the class ApplicationAlertServiceTest method shouldUpdate.

@Test
public void shouldUpdate() throws Exception {
    final AlertTriggerEntity alertTrigger = mock(AlertTriggerEntity.class);
    when(alertService.findById(ALERT_ID)).thenReturn(alertTrigger);
    UpdateAlertTriggerEntity updating = new UpdateAlertTriggerEntity();
    updating.setId(ALERT_ID);
    cut.update(APPLICATION_ID, updating);
    verify(alertService, times(1)).update(updating);
}
Also used : UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) UpdateAlertTriggerEntity(io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity) NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) AlertTriggerEntity(io.gravitee.rest.api.model.alert.AlertTriggerEntity) Test(org.junit.Test)

Aggregations

UpdateAlertTriggerEntity (io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity)12 Test (org.junit.Test)8 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)7 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Notification (io.gravitee.notifier.api.Notification)4 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 SimpleEvent (io.gravitee.common.event.impl.SimpleEvent)2 ApplicationAlertEventType (io.gravitee.rest.api.model.alert.ApplicationAlertEventType)2 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)2 NotificationTemplateEntity (io.gravitee.rest.api.model.notification.NotificationTemplateEntity)2 NotificationTemplateEvent (io.gravitee.rest.api.model.notification.NotificationTemplateEvent)2 ArrayList (java.util.ArrayList)2 AggregationCondition (io.gravitee.alert.api.condition.AggregationCondition)1 Alert (io.gravitee.rest.api.portal.rest.model.Alert)1 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1