use of com.synopsys.integration.alert.database.audit.AuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryRepositoryTestIT method findFirstByCommonConfigIdOrderByTimeLastSentDescTestIT.
@Test
@Transactional
public void findFirstByCommonConfigIdOrderByTimeLastSentDescTestIT() {
UUID commonConfigId = UUID.randomUUID();
OffsetDateTime leastRecent = OffsetDateTime.ofInstant(Instant.ofEpochMilli(100), ZoneOffset.UTC);
OffsetDateTime middleDate = OffsetDateTime.ofInstant(Instant.ofEpochMilli(200), ZoneOffset.UTC);
OffsetDateTime mostRecent = OffsetDateTime.ofInstant(Instant.ofEpochMilli(300), ZoneOffset.UTC);
AuditEntryEntity leastRecentEntity = new AuditEntryEntity(commonConfigId, null, leastRecent, null, null, null);
AuditEntryEntity middleEntity = new AuditEntryEntity(commonConfigId, null, middleDate, null, null, null);
AuditEntryEntity mostRecentEntity = new AuditEntryEntity(commonConfigId, null, mostRecent, null, null, null);
auditEntryRepository.save(leastRecentEntity);
auditEntryRepository.save(middleEntity);
auditEntryRepository.save(mostRecentEntity);
Optional<AuditEntryEntity> foundEntity = auditEntryRepository.findFirstByCommonConfigIdOrderByTimeLastSentDesc(commonConfigId);
assertNotNull(foundEntity);
assertTrue(foundEntity.isPresent());
assertEquals(mostRecentEntity, foundEntity.get());
}
use of com.synopsys.integration.alert.database.audit.AuditEntryEntity 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.AuditEntryEntity 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.AuditEntryEntity 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.AuditEntryEntity in project hub-alert by blackducksoftware.
the class AuditEntryHandlerTestIT method resendNotificationTestIT.
@Test
public void resendNotificationTestIT() throws Exception {
String content = ResourceUtil.getResourceAsString(getClass(), "/json/policyOverrideNotification.json", StandardCharsets.UTF_8);
MockNotificationContent mockNotification = new MockNotificationContent(DateUtils.createCurrentDateTimestamp(), blackDuckProviderKey.getUniversalKey(), DateUtils.createCurrentDateTimestamp(), "POLICY_OVERRIDE", content, 1L, providerConfigModel.getConfigurationId());
ConfigurationFieldModel providerConfigId = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
providerConfigId.setFieldValue(String.valueOf(providerConfigModel.getConfigurationId()));
DistributionJobRequestModel jobRequestModel = createJobRequestModel();
DistributionJobModel jobModel = jobAccessor.createJob(jobRequestModel);
NotificationEntity savedNotificationEntity = notificationContentRepository.save(mockNotification.createEntity());
AuditEntryEntity savedAuditEntryEntity = auditEntryRepository.save(new AuditEntryEntity(jobModel.getJobId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), AuditEntryStatus.SUCCESS.toString(), null, null));
auditNotificationRepository.save(new AuditNotificationRelation(savedAuditEntryEntity.getId(), savedNotificationEntity.getId()));
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasExecutePermission(Mockito.eq(ConfigContextEnum.GLOBAL.name()), Mockito.eq(AuditDescriptor.AUDIT_COMPONENT))).thenReturn(true);
AuditEntryActions auditEntryActions = createAuditActions(authorizationManager);
try {
auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
auditEntryActions.resendNotification(savedNotificationEntity.getId(), null);
auditEntryActions.resendNotification(savedNotificationEntity.getId(), jobModel.getJobId());
} catch (Exception e) {
logger.error(e.getMessage(), e);
fail("Expected the Audit POST request(s) not to throw an exception");
}
assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(-1L, null));
assertResponseStatusException(HttpStatus.GONE, () -> auditEntryActions.resendNotification(savedNotificationEntity.getId(), UUID.randomUUID()));
}
Aggregations