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);
}
use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class AlertMapper method convertToUpdate.
public UpdateAlertTriggerEntity convertToUpdate(AlertInput alertInput) {
final UpdateAlertTriggerEntity updating = new UpdateAlertTriggerEntity();
updating.setEnabled(alertInput.getEnabled());
updating.setConditions(convertConditions(alertInput));
return updating;
}
use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertResource method updateAlert.
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Permissions({ @Permission(value = RolePermission.APPLICATION_ALERT, acls = RolePermissionAction.UPDATE) })
public Response updateAlert(@PathParam("applicationId") String applicationId, @PathParam("alertId") String alertId, @Valid @NotNull(message = "Input must not be null.") AlertInput alertInput) {
LOGGER.info("Updating alert {}", alertId);
checkPlugins();
final UpdateAlertTriggerEntity updateAlertTriggerEntity = alertMapper.convertToUpdate(alertInput);
updateAlertTriggerEntity.setId(alertId);
final AlertTriggerEntity updated = applicationAlertService.update(applicationId, updateAlertTriggerEntity);
Alert alert = alertMapper.convert(updated);
return Response.ok(alert).build();
}
use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceImpl method update.
@Override
public AlertTriggerEntity update(String applicationId, UpdateAlertTriggerEntity alert) {
final AlertTriggerEntity alertTrigger = alertService.findById(alert.getId());
alert.setName(alertTrigger.getName());
alert.setReferenceType(AlertReferenceType.APPLICATION);
alert.setReferenceId(alertTrigger.getReferenceId());
alert.setSource("REQUEST");
alert.setSeverity(Trigger.Severity.INFO);
alert.setDampening(Dampening.strictCount(1));
alert.setNotifications(alertTrigger.getNotifications());
alert.setFilters(alertTrigger.getFilters());
return alertService.update(alert);
}
use of io.gravitee.rest.api.model.alert.UpdateAlertTriggerEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationAlertServiceTest method shouldAddMember.
@Test
public void shouldAddMember() 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").put("from", "from").put("subject", "subject").put("body", "body");
when(mapper.readTree(notification.getConfiguration())).thenReturn(emailNode);
when(mapper.readTree(notification2.getConfiguration())).thenReturn(emailNode);
cut.addMemberToApplication(APPLICATION_ID, "add@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,add@mail.gio");
}
Aggregations