use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldHandleNotificationTemplateUpdatedEventStatusAlert.
@Test
public void shouldHandleNotificationTemplateUpdatedEventStatusAlert() throws Exception {
NotificationTemplateEntity notificationTemplate = new NotificationTemplateEntity();
notificationTemplate.setHook(AlertHook.CONSUMER_HTTP_STATUS.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_RATE");
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");
}
use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldDeleteMember.
@Test
public void shouldDeleteMember() throws Exception {
AlertTriggerEntity trigger1 = mock(AlertTriggerEntity.class);
Notification notification = new Notification();
notification.setType("default-email");
notification.setConfiguration("");
Notification notification2 = new Notification();
notification2.setType("default-email");
notification2.setConfiguration("");
when(trigger1.getNotifications()).thenReturn(Collections.singletonList(notification));
AlertTriggerEntity trigger2 = mock(AlertTriggerEntity.class);
when(trigger2.getNotifications()).thenReturn(Collections.singletonList(notification2));
List<AlertTriggerEntity> triggers = new ArrayList<>();
triggers.add(trigger1);
triggers.add(trigger2);
when(alertService.findByReference(AlertReferenceType.APPLICATION, APPLICATION_ID)).thenReturn(triggers);
JsonNode emailNode = JsonNodeFactory.instance.objectNode().put("to", "to,delete@mail.gio").put("from", "from").put("subject", "subject").put("body", "body");
when(mapper.readTree(notification.getConfiguration())).thenReturn(emailNode);
when(mapper.readTree(notification2.getConfiguration())).thenReturn(emailNode);
cut.deleteMemberFromApplication(APPLICATION_ID, "delete@mail.gio");
ArgumentCaptor<UpdateAlertTriggerEntity> updatingCaptor = ArgumentCaptor.forClass(UpdateAlertTriggerEntity.class);
verify(alertService, times(2)).update(updatingCaptor.capture());
final UpdateAlertTriggerEntity updating = updatingCaptor.getValue();
assertThat(updating.getNotifications().get(0).getConfiguration()).contains("to");
assertThat(updating.getNotifications().get(0).getConfiguration()).doesNotContain("delete@mail.gio");
}
Aggregations