use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultDistributionAccessorTestIT method assertValidQueryFunctionality.
private AlertPagedModel<DistributionWithAuditInfo> assertValidQueryFunctionality(int expectedNumberOfResults, Supplier<AlertPagedModel<DistributionWithAuditInfo>> dBQuery) throws ParseException {
Map<UUID, Pair<DistributionJobModel, List<AuditEntryEntity>>> jobAndAuditData = createAndSave6JobAndAudit();
assertEquals(TOTAL_NUMBER_OF_RECORDS, jobAndAuditData.keySet().size());
jobAndAuditData.keySet().stream().forEach(uuid -> {
Optional<DistributionJobModel> job = jobAccessor.getJobById(uuid);
assertTrue(job.isPresent());
});
AlertPagedModel<DistributionWithAuditInfo> queryResult = dBQuery.get();
assertNotNull(queryResult);
assertEquals(expectedNumberOfResults, queryResult.getModels().size());
for (DistributionWithAuditInfo distributionWithAuditInfo : queryResult.getModels()) {
Pair<DistributionJobModel, List<AuditEntryEntity>> distributionJobModelListPair = jobAndAuditData.get(distributionWithAuditInfo.getJobId());
DistributionJobModel distributionJobModel = distributionJobModelListPair.getLeft();
assertEquals(distributionJobModel.getName(), distributionWithAuditInfo.getJobName());
assertNotEquals(AuditEntryStatus.PENDING.name(), distributionWithAuditInfo.getAuditStatus());
List<AuditEntryEntity> audits = distributionJobModelListPair.getRight();
if (!audits.isEmpty()) {
OffsetDateTime mostRecentAuditEntryTime = audits.stream().filter(auditEntryEntity -> auditEntryEntity.getTimeLastSent() != null).max(Comparator.comparing(AuditEntryEntity::getTimeLastSent)).map(AuditEntryEntity::getTimeLastSent).orElse(null);
String formattedTime = null;
if (null != mostRecentAuditEntryTime) {
formattedTime = DateUtils.formatDate(mostRecentAuditEntryTime, DateUtils.AUDIT_DATE_FORMAT);
}
assertEquals(formattedTime, distributionWithAuditInfo.getAuditTimeLastSent());
}
}
return queryResult;
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultDistributionAccessorTestIT method createAndSave6JobAndAudit.
private Map<UUID, Pair<DistributionJobModel, List<AuditEntryEntity>>> createAndSave6JobAndAudit() {
DistributionJobRequestModel firstJob = createSlackJob(true);
DistributionJobRequestModel secondJob = createSlackJob(false);
DistributionJobRequestModel thirdJob = createSlackJob(true);
DistributionJobRequestModel fourthJob = createSlackJob(false);
DistributionJobRequestModel fifthJob = createMSTeamsJob(true);
DistributionJobRequestModel sixthJob = createMSTeamsJob(false);
DistributionJobModel firstJobSaved = jobAccessor.createJob(firstJob);
DistributionJobModel secondJobSaved = jobAccessor.createJob(secondJob);
DistributionJobModel thirdJobSaved = jobAccessor.createJob(thirdJob);
DistributionJobModel fourthJobSaved = jobAccessor.createJob(fourthJob);
DistributionJobModel fifthJobSaved = jobAccessor.createJob(fifthJob);
DistributionJobModel sixthJobSaved = jobAccessor.createJob(sixthJob);
createdJobs.add(firstJobSaved.getJobId());
createdJobs.add(secondJobSaved.getJobId());
createdJobs.add(thirdJobSaved.getJobId());
createdJobs.add(fourthJobSaved.getJobId());
createdJobs.add(fifthJobSaved.getJobId());
createdJobs.add(sixthJobSaved.getJobId());
AuditEntryEntity firstAudit = createAuditEntryEntity(firstJobSaved.getJobId(), OffsetDateTime.now(), AuditEntryStatus.SUCCESS);
AuditEntryEntity secondAudit = createAuditEntryEntity(firstJobSaved.getJobId(), OffsetDateTime.now().minusDays(1), AuditEntryStatus.PENDING);
AuditEntryEntity thirdAudit = createAuditEntryEntity(secondJobSaved.getJobId(), OffsetDateTime.now().minusMinutes(1), AuditEntryStatus.FAILURE);
AuditEntryEntity fourthAudit = createAuditEntryEntity(fourthJobSaved.getJobId(), OffsetDateTime.now().minusHours(1), AuditEntryStatus.SUCCESS);
AuditEntryEntity fifthAudit = createAuditEntryEntity(fifthJobSaved.getJobId(), OffsetDateTime.now().minusHours(2), AuditEntryStatus.SUCCESS);
AuditEntryEntity sixthAudit = createAuditEntryEntity(fifthJobSaved.getJobId(), OffsetDateTime.now().minusMinutes(2), AuditEntryStatus.FAILURE);
AuditEntryEntity seventhAudit = createAuditEntryEntity(sixthJobSaved.getJobId(), null, AuditEntryStatus.SUCCESS);
AuditEntryEntity eighthAudit = createAuditEntryEntity(sixthJobSaved.getJobId(), OffsetDateTime.now(), AuditEntryStatus.FAILURE);
AuditEntryEntity ninthAudit = createAuditEntryEntity(sixthJobSaved.getJobId(), null, AuditEntryStatus.PENDING);
saveAllAudits(List.of(firstAudit, secondAudit, thirdAudit, fourthAudit, fifthAudit, sixthAudit, seventhAudit, eighthAudit, ninthAudit));
return Map.of(firstJobSaved.getJobId(), Pair.of(firstJobSaved, List.of(firstAudit, secondAudit)), secondJobSaved.getJobId(), Pair.of(secondJobSaved, List.of(thirdAudit)), thirdJobSaved.getJobId(), Pair.of(thirdJobSaved, List.of()), fourthJobSaved.getJobId(), Pair.of(fourthJobSaved, List.of(fourthAudit)), fifthJobSaved.getJobId(), Pair.of(fifthJobSaved, List.of(fifthAudit, sixthAudit)), sixthJobSaved.getJobId(), Pair.of(sixthJobSaved, List.of(seventhAudit, eighthAudit, ninthAudit)));
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class NotificationContentRepositoryIT method initializeNotificationRepo.
private Long initializeNotificationRepo(String searchTerm, int numberToCreate) throws ParseException {
List<NotificationEntity> notifications = new ArrayList<>(numberToCreate);
long searchableCount = 0;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(RestConstants.JSON_DATE_FORMAT);
for (int i = 0; i < numberToCreate; i++) {
Date newDate = new Date();
String dateString = simpleDateFormat.format(newDate);
NotificationEntity entity;
if (i % 31 == 0) {
entity = createEntity(dateString, searchTerm);
searchableCount++;
} else {
entity = createEntity(dateString);
}
notifications.add(entity);
}
List<NotificationEntity> savedNotifications = notificationContentRepository.saveAll(notifications);
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
UUID jobId = jobModel.getJobId();
// more investigation is needed
for (NotificationEntity savedNotification : savedNotifications) {
AuditEntryEntity newEntry = new AuditEntryEntity(jobId, OffsetDateTime.now(), null, AuditEntryStatus.PENDING.name(), null, null);
AuditEntryEntity savedEntry = auditEntryRepository.save(newEntry);
AuditNotificationRelation notifAudit = new AuditNotificationRelation(savedEntry.getId(), savedNotification.getId());
auditNotificationRepository.save(notifAudit);
}
auditEntryRepository.flush();
return searchableCount;
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessorTest method createOrUpdatePendingAuditEntryForJobTest.
@Test
public void createOrUpdatePendingAuditEntryForJobTest() {
UUID testJobId = UUID.randomUUID();
Set<Long> testNotificationIds = Set.of(1L, 2L, 10L);
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
Mockito.when(auditEntryRepository.findByJobIdAndNotificationIds(Mockito.eq(testJobId), Mockito.eq(testNotificationIds))).thenReturn(List.of());
Mockito.when(auditEntryRepository.save(Mockito.any())).then(invocation -> {
AuditEntryEntity auditEntry = invocation.getArgument(0);
auditEntry.setId(RANDOM.nextLong());
return auditEntry;
});
AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
Mockito.when(auditNotificationRepository.saveAll(Mockito.anyCollection())).thenReturn(List.of());
DefaultProcessingAuditAccessor processingAuditAccessor = new DefaultProcessingAuditAccessor(auditEntryRepository, auditNotificationRepository);
processingAuditAccessor.createOrUpdatePendingAuditEntryForJob(testJobId, testNotificationIds);
Mockito.verify(auditEntryRepository, Mockito.times(testNotificationIds.size())).save(Mockito.any());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessorTest method setAuditEntryFailureTest.
@Test
public void setAuditEntryFailureTest() {
String testErrorMessage = "Uh oh, an error occurred!";
String testExceptionMessage = "Something bad happened. Yikes...";
Throwable testThrowable = new AlertException(testExceptionMessage);
AuditEntryEntity testResultEntry = setAuditEntryStatusTest(AuditEntryStatus.FAILURE, (accessor, jobId, notificationIds) -> accessor.setAuditEntryFailure(jobId, notificationIds, testErrorMessage, testThrowable));
assertEquals(testErrorMessage, testResultEntry.getErrorMessage());
assertNotNull(testResultEntry.getErrorStackTrace(), "Expected the audit entry to contain an error stack trace");
assertTrue(testResultEntry.getErrorStackTrace().contains(testExceptionMessage), "Expected the error stack trace to contain a specific message, but that message was missing");
}
Aggregations