use of io.imunity.furms.domain.alarms.AlarmId in project furms by unity-idm.
the class AlarmAuditLogServiceTest method shouldDetectAlarmDeletion.
@Test
void shouldDetectAlarmDeletion() {
// given
AlarmId id = new AlarmId(UUID.randomUUID());
when(alarmRepository.exist("projectId", id)).thenReturn(true);
when(alarmRepository.find(id)).thenReturn(Optional.of(AlarmWithUserIds.builder().id(id).name("userFacingName").build()));
// when
service.remove("projectId", id);
ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
Mockito.verify(auditLogRepository).create(argument.capture());
assertEquals(Operation.ALARM_MANAGEMENT, argument.getValue().operationCategory);
assertEquals(Action.DELETE, argument.getValue().action);
}
use of io.imunity.furms.domain.alarms.AlarmId in project furms by unity-idm.
the class AlarmAuditLogServiceTest method shouldDetectAlarmCreation.
@Test
void shouldDetectAlarmCreation() {
// given
AlarmId id = new AlarmId(UUID.randomUUID());
AlarmWithUserEmails request = AlarmWithUserEmails.builder().id(id).projectId("projectId").name("userFacingName").alarmUser(Set.of()).build();
AlarmWithUserIds response = AlarmWithUserIds.builder().id(id).projectId("projectId").name("userFacingName").alarmUser(Set.of()).build();
when(alarmRepository.find(id)).thenReturn(Optional.of(response));
when(alarmRepository.create(response)).thenReturn(id);
// when
service.create(request);
ArgumentCaptor<AuditLog> argument = ArgumentCaptor.forClass(AuditLog.class);
Mockito.verify(auditLogRepository).create(argument.capture());
assertEquals(Operation.ALARM_MANAGEMENT, argument.getValue().operationCategory);
assertEquals(Action.CREATE, argument.getValue().action);
}
use of io.imunity.furms.domain.alarms.AlarmId in project furms by unity-idm.
the class AlarmServiceImplTest method shouldUpdateWitUnsettingAlarmToFired.
@Test
void shouldUpdateWitUnsettingAlarmToFired() {
String projectId = "projectId";
String projectAllocationId = "projectAllocationId";
int threshold = 50;
AlarmId alarmId = new AlarmId(UUID.randomUUID());
FenixUserId fenixUserId = new FenixUserId("id");
FenixUserId fenixUserId1 = new FenixUserId("id1");
AlarmWithUserIds oldAlarm = AlarmWithUserIds.builder().name("name").fired(true).build();
when(usersDAO.getAllUsers()).thenReturn(List.of(FURMSUser.builder().fenixUserId(fenixUserId).email("email").build(), FURMSUser.builder().fenixUserId(fenixUserId1).email("email1").build()));
when(alarmRepository.exist(projectId, alarmId)).thenReturn(true);
when(alarmRepository.find(alarmId)).thenReturn(Optional.of(oldAlarm));
when(firedAlarmsService.isExceedThreshold(projectAllocationId, threshold)).thenReturn(false);
alarmService.update(AlarmWithUserEmails.builder().id(alarmId).name("name").projectId(projectId).projectAllocationId(projectAllocationId).allUsers(true).threshold(threshold).fired(true).alarmUser(Set.of("email", "email1")).build());
AlarmWithUserIds alarmWithUserIds = AlarmWithUserIds.builder().id(alarmId).name("name").projectId(projectId).projectAllocationId(projectAllocationId).allUsers(true).threshold(threshold).fired(false).alarmUser(Set.of(fenixUserId, fenixUserId1)).build();
verify(alarmRepository).update(alarmWithUserIds);
verify(publisher).publishEvent(new AlarmUpdatedEvent(alarmWithUserIds, oldAlarm));
}
use of io.imunity.furms.domain.alarms.AlarmId in project furms by unity-idm.
the class AlarmServiceImplTest method shouldFind.
@Test
void shouldFind() {
AlarmId alarmId = new AlarmId(UUID.randomUUID());
String projectId = "projectId";
FenixUserId fenixUserId = new FenixUserId("id");
FenixUserId fenixUserId1 = new FenixUserId("id1");
when(usersDAO.getAllUsers()).thenReturn(List.of(FURMSUser.builder().fenixUserId(fenixUserId).email("email").build(), FURMSUser.builder().fenixUserId(fenixUserId1).email("email1").build()));
when(alarmRepository.find(alarmId)).thenReturn(Optional.of(AlarmWithUserIds.builder().id(alarmId).name("name").projectId(projectId).projectAllocationId("projectAllocationId").allUsers(true).alarmUser(Set.of(fenixUserId, fenixUserId1)).build()));
when(alarmRepository.exist(projectId, alarmId)).thenReturn(true);
Optional<AlarmWithUserEmails> alarmWithUserEmails = alarmService.find(projectId, alarmId);
assertThat(alarmWithUserEmails).isPresent();
assertThat(alarmWithUserEmails.get().id).isEqualTo(alarmId);
assertThat(alarmWithUserEmails.get().name).isEqualTo("name");
assertThat(alarmWithUserEmails.get().projectId).isEqualTo(projectId);
assertThat(alarmWithUserEmails.get().projectAllocationId).isEqualTo("projectAllocationId");
assertThat(alarmWithUserEmails.get().allUsers).isEqualTo(true);
assertThat(alarmWithUserEmails.get().alarmUserEmails).isEqualTo(Set.of("email", "email1"));
}
use of io.imunity.furms.domain.alarms.AlarmId in project furms by unity-idm.
the class AlarmServiceImplTest method shouldRemove.
@Test
void shouldRemove() {
AlarmId alarmId = new AlarmId(UUID.randomUUID());
String projectId = "projectId";
AlarmWithUserIds alarmWithUserIds = AlarmWithUserIds.builder().name("name").build();
when(alarmRepository.find(alarmId)).thenReturn(Optional.of(alarmWithUserIds));
when(alarmRepository.exist(projectId, alarmId)).thenReturn(true);
alarmService.remove("projectId", alarmId);
verify(alarmRepository).remove(alarmId);
verify(publisher).publishEvent(new AlarmRemovedEvent(alarmWithUserIds));
}
Aggregations