Search in sources :

Example 6 with NotificationTemplateEntity

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());
}
Also used : NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) NotificationTemplate(io.gravitee.repository.management.model.NotificationTemplate) Test(org.junit.Test)

Example 7 with NotificationTemplateEntity

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());
}
Also used : NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) NotificationTemplate(io.gravitee.repository.management.model.NotificationTemplate) Test(org.junit.Test)

Example 8 with NotificationTemplateEntity

use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertServiceTest method shouldHandleNotificationTemplateUpdatedEventEmptyNotification.

@Test
public void shouldHandleNotificationTemplateUpdatedEventEmptyNotification() 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));
    when(alertTrigger.getNotifications()).thenReturn(Collections.emptyList());
    cut.handleEvent(event);
    verify(alertService, times(0)).update(any());
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) NotificationTemplateEvent(io.gravitee.rest.api.model.notification.NotificationTemplateEvent) SimpleEvent(io.gravitee.common.event.impl.SimpleEvent) ApplicationAlertEventType(io.gravitee.rest.api.model.alert.ApplicationAlertEventType) NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) 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 9 with NotificationTemplateEntity

use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity 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");
}
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 10 with NotificationTemplateEntity

use of io.gravitee.rest.api.model.notification.NotificationTemplateEntity in project gravitee-management-rest-api by gravitee-io.

the class NotificationTemplateServiceTest method shouldCreateNotificationTemplate.

@Test
public void shouldCreateNotificationTemplate() throws TechnicalException {
    NotificationTemplateEntity newNotificationTemplateEntity = new NotificationTemplateEntity();
    newNotificationTemplateEntity.setName(NOTIFICATION_TEMPLATE_NAME);
    newNotificationTemplateEntity.setType(io.gravitee.rest.api.model.notification.NotificationTemplateType.valueOf(NOTIFICATION_TEMPLATE_TYPE.name()));
    newNotificationTemplateEntity.setEnabled(NOTIFICATION_TEMPLATE_ENABLED);
    when(notificationTemplateRepository.create(any())).thenReturn(notificationTemplate);
    notificationTemplateService.create(newNotificationTemplateEntity);
    verify(notificationTemplateRepository, times(1)).create(any());
    verify(auditService, times(1)).createOrganizationAuditLog(any(), eq(NotificationTemplate.AuditEvent.NOTIFICATION_TEMPLATE_CREATED), any(), isNull(), any());
}
Also used : NotificationTemplateEntity(io.gravitee.rest.api.model.notification.NotificationTemplateEntity) Test(org.junit.Test)

Aggregations

NotificationTemplateEntity (io.gravitee.rest.api.model.notification.NotificationTemplateEntity)16 Test (org.junit.Test)8 NotificationTemplate (io.gravitee.repository.management.model.NotificationTemplate)5 NotificationTemplateEvent (io.gravitee.rest.api.model.notification.NotificationTemplateEvent)4 SimpleEvent (io.gravitee.common.event.impl.SimpleEvent)3 AlertTriggerEntity (io.gravitee.rest.api.model.alert.AlertTriggerEntity)3 ApplicationAlertEventType (io.gravitee.rest.api.model.alert.ApplicationAlertEventType)3 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)3 UpdateAlertTriggerEntity (io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity)3 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)3 UuidString (io.gravitee.rest.api.service.common.UuidString)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Notification (io.gravitee.notifier.api.Notification)2 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)2 TechnicalManagementException (io.gravitee.rest.api.service.exceptions.TechnicalManagementException)2 EmailTemplate (io.gravitee.rest.api.service.builder.EmailNotificationBuilder.EmailTemplate)1 NotificationTemplateNotFoundException (io.gravitee.rest.api.service.exceptions.NotificationTemplateNotFoundException)1 Async (org.springframework.scheduling.annotation.Async)1 Yaml (org.yaml.snakeyaml.Yaml)1