use of com.synopsys.integration.alert.common.rest.model.JobAuditModel 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.common.rest.model.JobAuditModel in project hub-alert by blackducksoftware.
the class JobAuditModelTest method testModel.
@Test
public void testModel() {
String id = "1";
String configId = "22";
String name = "name";
String eventType = "eventType";
String timeAuditCreated = new Date(400).toString();
String timeLastSent = new Date(500).toString();
String status = AuditEntryStatus.SUCCESS.name();
String errorMessage = "errorMessage";
String errorStackTrace = "errorStackTrace";
AuditJobStatusModel auditJobStatusModel = new AuditJobStatusModel(UUID.randomUUID(), timeAuditCreated, timeLastSent, status);
JobAuditModel restModel = new JobAuditModel(id, configId, name, eventType, auditJobStatusModel, errorMessage, errorStackTrace);
assertEquals(errorMessage, restModel.getErrorMessage());
assertEquals(errorStackTrace, restModel.getErrorStackTrace());
assertEquals(eventType, restModel.getEventType());
assertEquals(name, restModel.getName());
assertEquals(status, restModel.getAuditJobStatusModel().getStatus());
assertEquals(timeAuditCreated, restModel.getAuditJobStatusModel().getTimeAuditCreated());
assertEquals(timeLastSent, restModel.getAuditJobStatusModel().getTimeLastSent());
assertEquals(configId, restModel.getConfigId());
assertEquals(id, restModel.getId());
}
use of com.synopsys.integration.alert.common.rest.model.JobAuditModel in project hub-alert by blackducksoftware.
the class AuditEntryRestModelTest method testRestModel.
@Test
public void testRestModel() {
String id = "1";
String timeLastSent = new Date(500).toString();
String overallStatus = AuditEntryStatus.SUCCESS.name();
NotificationConfig notification = new NotificationConfig();
List<JobAuditModel> jobAuditModels = Collections.singletonList(new JobAuditModel());
AuditEntryModel restModel = new AuditEntryModel(id, notification, jobAuditModels, overallStatus, timeLastSent);
assertEquals(notification, restModel.getNotification());
assertEquals(jobAuditModels, restModel.getJobs());
assertEquals(overallStatus, restModel.getOverallStatus());
assertEquals(timeLastSent, restModel.getLastSent());
assertEquals(id, restModel.getId());
}
use of com.synopsys.integration.alert.common.rest.model.JobAuditModel in project hub-alert by blackducksoftware.
the class DefaultRestApiAuditAccessor method convertToAuditEntryModelFromNotification.
@Override
@Transactional
public AuditEntryModel convertToAuditEntryModelFromNotification(AlertNotificationModel notificationContentEntry) {
List<AuditNotificationRelation> relations = auditNotificationRepository.findByNotificationId(notificationContentEntry.getId());
List<Long> auditEntryIds = relations.stream().map(AuditNotificationRelation::getAuditEntryId).collect(Collectors.toList());
List<AuditEntryEntity> auditEntryEntities = auditEntryRepository.findAllById(auditEntryIds);
AuditEntryStatus overallStatus = null;
String timeLastSent = null;
OffsetDateTime timeLastSentOffsetDateTime = null;
List<JobAuditModel> jobAuditModels = new ArrayList<>();
for (AuditEntryEntity auditEntryEntity : auditEntryEntities) {
UUID jobId = auditEntryEntity.getCommonConfigId();
if (null != auditEntryEntity.getTimeLastSent() && (null == timeLastSentOffsetDateTime || timeLastSentOffsetDateTime.isBefore(auditEntryEntity.getTimeLastSent()))) {
timeLastSentOffsetDateTime = auditEntryEntity.getTimeLastSent();
timeLastSent = formatAuditDate(timeLastSentOffsetDateTime);
}
String id = contentConverter.getStringValue(auditEntryEntity.getId());
String configId = contentConverter.getStringValue(jobId);
String timeCreated = formatAuditDate(auditEntryEntity.getTimeCreated());
AuditEntryStatus status = null;
if (auditEntryEntity.getStatus() != null) {
status = AuditEntryStatus.valueOf(auditEntryEntity.getStatus());
overallStatus = getWorstStatus(overallStatus, status);
}
String errorMessage = auditEntryEntity.getErrorMessage();
String errorStackTrace = auditEntryEntity.getErrorStackTrace();
Optional<DistributionJobModel> distributionJobModel = jobAccessor.getJobById(jobId);
String distributionConfigName = distributionJobModel.map(DistributionJobModelData::getName).orElse(null);
String eventType = distributionJobModel.map(DistributionJobModelData::getChannelDescriptorName).orElse(null);
String statusDisplayName = null;
if (null != status) {
statusDisplayName = status.getDisplayName();
}
AuditJobStatusModel auditJobStatusModel = new AuditJobStatusModel(jobId, timeCreated, timeLastSent, statusDisplayName);
jobAuditModels.add(new JobAuditModel(id, configId, distributionConfigName, eventType, auditJobStatusModel, errorMessage, errorStackTrace));
}
String id = contentConverter.getStringValue(notificationContentEntry.getId());
NotificationConfig notificationConfig = populateConfigFromEntity(notificationContentEntry);
String overallStatusDisplayName = null;
if (null != overallStatus) {
overallStatusDisplayName = overallStatus.getDisplayName();
}
return new AuditEntryModel(id, notificationConfig, jobAuditModels, overallStatusDisplayName, timeLastSent);
}
Aggregations