use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method convertToAuditEntryModelFromNotificationTest.
@Test
public void convertToAuditEntryModelFromNotificationTest() throws Exception {
Long id = 1L;
Long providerConfigId = 2L;
String provider = "provider-test";
String providerConfigName = "providerConfigName-test";
String notificationType = "notificationType-test";
String content = "content-test";
OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
OffsetDateTime timeCreated = timeLastSent.minusSeconds(10);
Long auditEntryId = 3L;
String channelName = "test-channel.common.name-value";
String eventType = "test-channel.common.channel.name-value";
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
JobAccessor jobAccessor = Mockito.mock(JobAccessor.class);
ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
ContentConverter contentConverter = new ContentConverter(new DefaultConversionService());
AlertNotificationModel alertNotificationModel = new AlertNotificationModel(id, providerConfigId, provider, providerConfigName, notificationType, content, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryId, alertNotificationModel.getId());
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), timeCreated, timeLastSent, AuditEntryStatus.SUCCESS.name(), null, null);
Mockito.when(auditNotificationRepository.findByNotificationId(Mockito.any())).thenReturn(List.of(auditNotificationRelation));
Mockito.when(auditEntryRepository.findAllById(Mockito.any())).thenReturn(List.of(auditEntryEntity));
DistributionJobModel distributionJob = DistributionJobModel.builder().jobId(UUID.randomUUID()).enabled(true).blackDuckGlobalConfigId(2L).channelDescriptorName("test-channel.common.channel.name-value").name("test-channel.common.name-value").distributionFrequency(FrequencyType.REAL_TIME).filterByProject(false).notificationTypes(List.of(NotificationType.LICENSE_LIMIT.name())).processingType(ProcessingType.DEFAULT).createdAt(DateUtils.createCurrentDateTimestamp()).build();
Mockito.when(jobAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(distributionJob));
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, auditNotificationRepository, jobAccessor, configurationModelConfigurationAccessor, null, contentConverter);
AuditEntryModel testAuditEntryModel = auditUtility.convertToAuditEntryModelFromNotification(alertNotificationModel);
assertEquals(id, Long.valueOf(testAuditEntryModel.getId()));
assertNotNull(testAuditEntryModel.getNotification());
assertFalse(testAuditEntryModel.getJobs().isEmpty());
assertEquals(1, testAuditEntryModel.getJobs().size());
JobAuditModel testJob = testAuditEntryModel.getJobs().get(0);
assertEquals(channelName, testJob.getName());
assertEquals(eventType, testJob.getEventType());
assertEquals(AuditEntryStatus.SUCCESS.getDisplayName(), testAuditEntryModel.getOverallStatus());
assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testAuditEntryModel.getLastSent());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessorTest method findMatchingAuditIdTest.
@Test
public void findMatchingAuditIdTest() {
AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
Mockito.when(auditEntryRepository.findMatchingAudit(Mockito.anyLong(), Mockito.any(UUID.class))).thenReturn(Optional.empty());
DefaultRestApiAuditAccessor auditUtility = new DefaultRestApiAuditAccessor(auditEntryRepository, null, null, null, null, null);
Optional<Long> nullValue = auditUtility.findMatchingAuditId(1L, UUID.randomUUID());
assertFalse(nullValue.isPresent());
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(null, null, null, null, null, null);
Long expectedLong = 2L;
auditEntryEntity.setId(expectedLong);
Mockito.when(auditEntryRepository.findMatchingAudit(Mockito.anyLong(), Mockito.any(UUID.class))).thenReturn(Optional.of(auditEntryEntity));
Optional<Long> actualValue = auditUtility.findMatchingAuditId(expectedLong, UUID.randomUUID());
assertTrue(actualValue.isPresent());
assertEquals(expectedLong, actualValue.get());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessor method fromView.
private AuditEntryEntity fromView(AuditEntryNotificationView view) {
AuditEntryEntity auditEntry = new AuditEntryEntity(view.getJobId(), view.getTimeCreated(), view.getTimeLastSent(), view.getStatus(), view.getErrorMessage(), view.getErrorStackTrace());
auditEntry.setId(view.getId());
return auditEntry;
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class DefaultProcessingAuditAccessor method updateAuditEntries.
private void updateAuditEntries(UUID jobId, Set<Long> notificationIds, Consumer<AuditEntryEntity> auditFieldSetter) {
if (notificationIds.isEmpty()) {
return;
}
List<AuditEntryNotificationView> auditEntryNotificationViews = auditEntryRepository.findByJobIdAndNotificationIds(jobId, notificationIds);
List<AuditEntryEntity> updatedAuditEntries = new ArrayList<>(auditEntryNotificationViews.size());
for (AuditEntryNotificationView view : auditEntryNotificationViews) {
AuditEntryEntity auditEntryToSave = fromView(view);
auditEntryToSave.setTimeLastSent(DateUtils.createCurrentDateTimestamp());
auditFieldSetter.accept(auditEntryToSave);
updatedAuditEntries.add(auditEntryToSave);
logger.trace("Updated audit entry: {}.", auditEntryToSave.getId());
}
auditEntryRepository.saveAll(updatedAuditEntries);
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class NotificationAccessorTestIT method testFindAll.
@Test
public void testFindAll() {
NotificationEntity notificationContent = createNotificationContent();
notificationContent = notificationContentRepository.save(notificationContent);
PageRequest pageRequest = PageRequest.of(0, 10);
Page<AlertNotificationModel> all = notificationManager.findAll(pageRequest, false);
assertFalse(all.isEmpty());
all = notificationManager.findAll(pageRequest, true);
assertTrue(all.isEmpty());
OffsetDateTime now = DateUtils.createCurrentDateTimestamp();
AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), now, now, AuditEntryStatus.PENDING.name(), null, null);
AuditEntryEntity saveAuditEntry = auditEntryRepository.save(auditEntryEntity);
AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(saveAuditEntry.getId(), notificationContent.getId());
auditNotificationRepository.save(auditNotificationRelation);
all = notificationManager.findAll(pageRequest, true);
assertFalse(all.isEmpty());
}
Aggregations