Search in sources :

Example 1 with AlertTriggerEntity

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

Example 2 with AlertTriggerEntity

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

Example 3 with AlertTriggerEntity

use of io.gravitee.rest.api.model.alert.AlertTriggerEntity 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 4 with AlertTriggerEntity

use of io.gravitee.rest.api.model.alert.AlertTriggerEntity 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)

Example 5 with AlertTriggerEntity

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

Aggregations

AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)15 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)14 UpdateAlertTriggerEntity (io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity)14 Test (org.junit.Test)12 Notification (io.gravitee.notifier.api.Notification)7 ArrayList (java.util.ArrayList)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Alert (io.gravitee.rest.api.portal.rest.model.Alert)4 SimpleEvent (io.gravitee.common.event.impl.SimpleEvent)3 ApplicationAlertEventType (io.gravitee.rest.api.model.alert.ApplicationAlertEventType)3 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)3 NotificationTemplateEntity (io.gravitee.rest.api.model.notification.NotificationTemplateEntity)3 NotificationTemplateEvent (io.gravitee.rest.api.model.notification.NotificationTemplateEvent)3 RateCondition (io.gravitee.alert.api.condition.RateCondition)2 ThresholdRangeCondition (io.gravitee.alert.api.condition.ThresholdRangeCondition)2 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)2 Consumes (javax.ws.rs.Consumes)2 Produces (javax.ws.rs.Produces)2 AggregationCondition (io.gravitee.alert.api.condition.AggregationCondition)1 ApplicationAlertMaximumException (io.gravitee.rest.api.service.exceptions.ApplicationAlertMaximumException)1