use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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.common.persistence.model.job.DistributionJobModel 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.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method getPageOfJobsTest.
@Test
void getPageOfJobsTest() {
UUID jobId = UUID.randomUUID();
DistributionJobEntity distributionJobEntity = createSlackDistributionJobEntity(jobId);
distributionJobEntity.setBlackDuckJobDetails(new BlackDuckJobDetailsEntity(jobId, 3L, true, "*", "*"));
Page<DistributionJobEntity> page = new PageImpl<>(List.of(distributionJobEntity));
Mockito.when(distributionJobRepository.findAll(Mockito.any(PageRequest.class))).thenReturn(page);
AlertPagedModel<DistributionJobModel> pageOfJobs = jobAccessor.getPageOfJobs(0, 10);
assertEquals(1, pageOfJobs.getTotalPages());
List<DistributionJobModel> models = pageOfJobs.getModels();
assertEquals(1, models.size());
DistributionJobModel distributionJobModel = models.get(0);
assertEquals(jobId, distributionJobModel.getJobId());
assertEquals(jobName, distributionJobModel.getName());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method createJiraServerJobTest.
@Test
void createJiraServerJobTest() {
UUID jobId = UUID.randomUUID();
JiraServerJobDetailsModel jiraServerJobDetailsModel = new JiraServerJobDetailsModel(jobId, false, null, null, null, null, null, List.of(), "issueSummary");
DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.JIRA_SERVER.getUniversalKey(), jiraServerJobDetailsModel);
JiraServerJobDetailsEntity jiraServerJobDetailsEntity = new JiraServerJobDetailsEntity(null, false, null, null, null, null, null, null);
jiraServerJobDetailsEntity.setJobCustomFields(List.of());
DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
distributionJobEntity.setJiraServerJobDetails(jiraServerJobDetailsEntity);
BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
Mockito.when(jiraServerJobDetailsAccessor.saveJobDetails(Mockito.any(), Mockito.any())).thenReturn(jiraServerJobDetailsModel);
Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
assertEquals(jobId, createdJob.getJobId());
assertEquals(jobName, createdJob.getName());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method createJiraCloudJobTest.
@Test
void createJiraCloudJobTest() {
UUID jobId = UUID.randomUUID();
JiraCloudJobDetailsModel jiraCloudJobDetailsModel = new JiraCloudJobDetailsModel(jobId, false, null, null, null, null, null, List.of(), null);
DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.JIRA_CLOUD.getUniversalKey(), jiraCloudJobDetailsModel);
JiraCloudJobDetailsEntity jiraCloudJobDetailsEntity = new JiraCloudJobDetailsEntity(null, false, null, null, null, null, null, null);
jiraCloudJobDetailsEntity.setJobCustomFields(List.of());
DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
distributionJobEntity.setJiraCloudJobDetails(jiraCloudJobDetailsEntity);
BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
Mockito.when(jiraCloudJobDetailsAccessor.saveJiraCloudJobDetails(Mockito.any(), Mockito.any())).thenReturn(jiraCloudJobDetailsEntity);
Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
DistributionJobModel createdJob = jobAccessor.createJob(distributionJobRequestModel);
assertEquals(jobId, createdJob.getJobId());
assertEquals(jobName, createdJob.getName());
}
Aggregations