use of com.synopsys.integration.alert.database.audit.AuditEntryRepository in project hub-alert by blackducksoftware.
the class AuditEntryActionsTest method testGetNull.
@Test
public void testGetNull() {
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasReadPermission(Mockito.any(ConfigContextEnum.class), Mockito.any(DescriptorKey.class))).thenReturn(Boolean.TRUE);
AuditDescriptorKey auditDescriptorKey = new AuditDescriptorKey();
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any())).thenReturn(Optional.empty());
DefaultNotificationAccessor notificationAccessor = Mockito.mock(DefaultNotificationAccessor.class);
Mockito.when(notificationAccessor.findById(Mockito.anyLong())).thenReturn(Optional.empty());
DefaultRestApiAuditAccessor auditEntryUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, notificationAccessor, null);
AuditEntryActions auditEntryActions = new AuditEntryActions(authorizationManager, auditDescriptorKey, auditEntryUtility, notificationAccessor, null, null, null);
ActionResponse<AuditEntryModel> auditEntryModel = auditEntryActions.get(1L);
assertTrue(auditEntryModel.isError());
assertFalse(auditEntryModel.hasContent());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryRepository in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessorTest method setAuditEntryStatusTest.
private AuditEntryEntity setAuditEntryStatusTest(AuditEntryStatus expectedStatus, AuditAccessorStatusSetter statusSetter) {
UUID testJobId = UUID.randomUUID();
Long testNotificationId = 99L;
Set<Long> testNotificationIds = Set.of(testNotificationId);
AuditEntryNotificationView testView = new AuditEntryNotificationView(0L, testJobId, testNotificationId, null, null, null, null, null);
AtomicReference<AuditEntryEntity> savedEntry = new AtomicReference<>();
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
Mockito.when(auditEntryRepository.findByJobIdAndNotificationIds(testJobId, testNotificationIds)).thenReturn(List.of(testView));
Mockito.when(auditEntryRepository.saveAll(Mockito.anyList())).then(invocation -> {
List<AuditEntryEntity> savedEntries = invocation.getArgument(0);
if (!savedEntries.isEmpty()) {
savedEntry.set(savedEntries.get(0));
}
return List.of();
});
DefaultProcessingAuditAccessor processingAuditAccessor = new DefaultProcessingAuditAccessor(auditEntryRepository, null);
statusSetter.setStatus(processingAuditAccessor, testJobId, testNotificationIds);
AuditEntryEntity auditEntryEntity = savedEntry.get();
assertNotNull(auditEntryEntity, "Expected an audit entry to have been saved");
assertEquals(testView.getId(), auditEntryEntity.getId());
assertEquals(testView.getJobId(), auditEntryEntity.getCommonConfigId());
assertEquals(expectedStatus.name(), auditEntryEntity.getStatus());
assertNotNull(auditEntryEntity.getTimeLastSent(), "Expected time last sent to be set");
return auditEntryEntity;
}
use of com.synopsys.integration.alert.database.audit.AuditEntryRepository in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNotNullTest.
@Test
public void findFirstByJobIdNotNullTest() {
OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
OffsetDateTime timeCreated = timeLastSent.minusMinutes(10L);
AuditEntryStatus status = AuditEntryStatus.PENDING;
UUID testUUID = UUID.randomUUID();
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(testUUID, timeCreated, timeLastSent, status.name(), null, null);
Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, null);
AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
String testTimeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
String testTimeLastSent = auditJobStatusModel.getTimeLastSent();
String testStatus = auditJobStatusModel.getStatus();
assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
assertEquals(DateUtils.formatDate(timeCreated, DateUtils.AUDIT_DATE_FORMAT), testTimeAuditCreated);
assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testTimeLastSent);
assertEquals(status.getDisplayName(), testStatus);
}
use of com.synopsys.integration.alert.database.audit.AuditEntryRepository in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method findFirstByJobIdNullTest.
@Test
public void findFirstByJobIdNullTest() {
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
ContentConverter contentConverter = Mockito.mock(ContentConverter.class);
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(null, null, null, null, null, null);
Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, contentConverter);
UUID testUUID = UUID.randomUUID();
AuditJobStatusModel auditJobStatusModel = auditUtility.findFirstByJobId(testUUID).get();
String timeAuditCreated = auditJobStatusModel.getTimeAuditCreated();
String timeLastSent = auditJobStatusModel.getTimeLastSent();
String status = auditJobStatusModel.getStatus();
assertTrue(auditUtility.findFirstByJobId(testUUID).isPresent());
assertNull(timeAuditCreated);
assertNull(timeLastSent);
assertNull(status);
}
use of com.synopsys.integration.alert.database.audit.AuditEntryRepository in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method findFirstByJobIdEmptyTest.
@Test
public void findFirstByJobIdEmptyTest() {
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
ContentConverter contentConverter = Mockito.mock(ContentConverter.class);
Mockito.when(auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(Mockito.any(UUID.class))).thenReturn(Optional.empty());
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, contentConverter);
assertFalse(auditUtility.findFirstByJobId(UUID.randomUUID()).isPresent());
}
Aggregations