Search in sources :

Example 1 with AlarmId

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);
}
Also used : AlarmId(io.imunity.furms.domain.alarms.AlarmId) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with AlarmId

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);
}
Also used : AlarmId(io.imunity.furms.domain.alarms.AlarmId) AlarmWithUserIds(io.imunity.furms.domain.alarms.AlarmWithUserIds) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) AuditLog(io.imunity.furms.domain.audit_log.AuditLog) AuditLogServiceImplTest(io.imunity.furms.core.audit_log.AuditLogServiceImplTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with AlarmId

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));
}
Also used : AlarmId(io.imunity.furms.domain.alarms.AlarmId) AlarmWithUserIds(io.imunity.furms.domain.alarms.AlarmWithUserIds) FenixUserId(io.imunity.furms.domain.users.FenixUserId) AlarmUpdatedEvent(io.imunity.furms.domain.alarms.AlarmUpdatedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with AlarmId

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"));
}
Also used : AlarmId(io.imunity.furms.domain.alarms.AlarmId) AlarmWithUserEmails(io.imunity.furms.domain.alarms.AlarmWithUserEmails) FenixUserId(io.imunity.furms.domain.users.FenixUserId) Test(org.junit.jupiter.api.Test)

Example 5 with AlarmId

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));
}
Also used : AlarmId(io.imunity.furms.domain.alarms.AlarmId) AlarmWithUserIds(io.imunity.furms.domain.alarms.AlarmWithUserIds) AlarmRemovedEvent(io.imunity.furms.domain.alarms.AlarmRemovedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

AlarmId (io.imunity.furms.domain.alarms.AlarmId)26 Test (org.junit.jupiter.api.Test)24 AlarmWithUserIds (io.imunity.furms.domain.alarms.AlarmWithUserIds)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 FenixUserId (io.imunity.furms.domain.users.FenixUserId)12 DBIntegrationTest (io.imunity.furms.db.DBIntegrationTest)10 UUID (java.util.UUID)8 AlarmWithUserEmails (io.imunity.furms.domain.alarms.AlarmWithUserEmails)6 Optional (java.util.Optional)6 Set (java.util.Set)6 FiredAlarm (io.imunity.furms.domain.alarms.FiredAlarm)5 ProjectAllocation (io.imunity.furms.domain.project_allocation.ProjectAllocation)5 List (java.util.List)5 Collectors.toSet (java.util.stream.Collectors.toSet)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Community (io.imunity.furms.domain.communities.Community)4 CommunityAllocation (io.imunity.furms.domain.community_allocation.CommunityAllocation)4 FurmsImage (io.imunity.furms.domain.images.FurmsImage)4 Project (io.imunity.furms.domain.projects.Project)4 ResourceCredit (io.imunity.furms.domain.resource_credits.ResourceCredit)4