use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceTest method shouldFindAllNotificationTemplate.
@Test
public void shouldFindAllNotificationTemplate() throws TechnicalException {
NotificationTemplate temp1 = new NotificationTemplate();
temp1.setId("TEMP1");
temp1.setType(NotificationTemplateType.PORTAL);
NotificationTemplate temp2 = new NotificationTemplate();
temp2.setId("TEMP2");
temp2.setType(NotificationTemplateType.EMAIL);
when(notificationTemplateRepository.findAllByReferenceIdAndReferenceType(NOTIFICATION_TEMPLATE_REFERENCE_ID, NOTIFICATION_TEMPLATE_REFERENCE_TYPE)).thenReturn(Sets.newSet(temp1, temp2));
final Set<NotificationTemplateEntity> all = notificationTemplateService.findAll();
assertNotNull(all);
assertEquals(2, all.size());
}
use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceTest method shouldFindNotificationTemplateByType.
@Test
public void shouldFindNotificationTemplateByType() throws TechnicalException {
NotificationTemplate temp1 = new NotificationTemplate();
temp1.setId("TEMP1");
temp1.setType(NotificationTemplateType.PORTAL);
when(notificationTemplateRepository.findByTypeAndReferenceIdAndReferenceType(NotificationTemplateType.PORTAL, NOTIFICATION_TEMPLATE_REFERENCE_ID, NOTIFICATION_TEMPLATE_REFERENCE_TYPE)).thenReturn(Sets.newSet(temp1));
final Set<NotificationTemplateEntity> byType = notificationTemplateService.findByType(io.gravitee.rest.api.model.notification.NotificationTemplateType.PORTAL);
assertNotNull(byType);
assertEquals(1, byType.size());
}
use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity 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");
}
use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceImpl method handleEvent.
@Override
@Async
public void handleEvent(Event<ApplicationAlertEventType, Object> event) {
switch(event.type()) {
case NOTIFICATION_TEMPLATE_UPDATE:
final NotificationTemplateEvent notificationEvent = (NotificationTemplateEvent) event.content();
final NotificationTemplateEntity notificationTemplate = notificationEvent.getNotificationTemplateEntity();
final String organizationId = notificationEvent.getOrganizationId();
if (notificationTemplate.getHook().equals(AlertHook.CONSUMER_HTTP_STATUS.name())) {
updateAllAlertsBody(organizationId, STATUS_ALERT, notificationTemplate.getContent(), notificationTemplate.getTitle());
} else if (notificationTemplate.getHook().equals(AlertHook.CONSUMER_RESPONSE_TIME.name())) {
updateAllAlertsBody(organizationId, RESPONSE_TIME_ALERT, notificationTemplate.getContent(), notificationTemplate.getTitle());
}
break;
case APPLICATION_MEMBERSHIP_UPDATE:
updateAlertsRecipients((ApplicationAlertMembershipEvent) event.content());
break;
}
}
use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity in project gravitee-management-rest-api by gravitee-io.
the class NotificationTemplateServiceImpl method loadNotificationTemplatesFromHook.
private List<NotificationTemplateEntity> loadNotificationTemplatesFromHook(Hook hook) {
List<NotificationTemplateEntity> result = new ArrayList<>();
if (hook.getScope().hasPortalNotification()) {
final NotificationTemplateEntity portalNotificationTemplateEntity = this.loadPortalNotificationTemplateFromHook(hook);
if (portalNotificationTemplateEntity != null) {
result.add(portalNotificationTemplateEntity);
}
}
final NotificationTemplateEntity emailNotificationTemplateEntity = this.loadEmailNotificationTemplateFromHook(hook);
if (emailNotificationTemplateEntity != null) {
result.add(emailNotificationTemplateEntity);
}
return result;
}
Aggregations