use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel 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()));
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class ProcessingJobAccessorTestIT method createDistributionJobModels.
private List<DistributionJobRequestModel> createDistributionJobModels(List<String> vulnTypes, int numberOfJobs) {
List<DistributionJobRequestModel> jobModels = new ArrayList<>();
for (int i = 0; i < numberOfJobs; i++) {
DistributionJobRequestModel distributionJobRequestModel = createJobRequestModel(FrequencyType.REAL_TIME, ProcessingType.DIGEST, List.of(), List.of(NotificationType.VULNERABILITY.name()), vulnTypes, List.of());
jobModels.add(distributionJobRequestModel);
}
return jobModels;
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTestIT method verifyEmailSavesTest.
@Test
public void verifyEmailSavesTest() {
EmailJobDetailsModel emailJobDetailsModel = new EmailJobDetailsModel(UUID.randomUUID(), "subjectLine", false, false, "attachmentFileType", List.of());
DistributionJobRequestModel jobRequestModel = createJobRequestModel(emailJobDetailsModel, new EmailChannelKey());
createAndAssertJob(jobRequestModel);
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method updateJobTest.
@Test
void updateJobTest() throws Exception {
UUID jobId = UUID.randomUUID();
SlackJobDetailsModel slackJobDetailsModel = new SlackJobDetailsModel(jobId, null, null, null);
DistributionJobRequestModel distributionJobRequestModel = new DistributionJobRequestModel(true, jobName, FrequencyType.DAILY, ProcessingType.DEFAULT, ChannelKeys.SLACK.getUniversalKey(), UUID.randomUUID(), 3L, true, "*", "*", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), slackJobDetailsModel);
SlackJobDetailsEntity slackJobDetailsEntity = new SlackJobDetailsEntity();
DistributionJobEntity distributionJobEntity = new DistributionJobEntity(jobId, distributionJobRequestModel.getName(), distributionJobRequestModel.isEnabled(), distributionJobRequestModel.getDistributionFrequency().name(), distributionJobRequestModel.getProcessingType().name(), distributionJobRequestModel.getChannelDescriptorName(), distributionJobRequestModel.getChannelGlobalConfigId(), DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp());
distributionJobEntity.setSlackJobDetails(slackJobDetailsEntity);
BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = new BlackDuckJobDetailsEntity(jobId, distributionJobRequestModel.getBlackDuckGlobalConfigId(), distributionJobRequestModel.isFilterByProject(), distributionJobRequestModel.getProjectNamePattern().orElse(null), distributionJobRequestModel.getProjectVersionNamePattern().orElse(null));
Mockito.when(slackJobDetailsAccessor.saveSlackJobDetails(Mockito.any(), Mockito.any())).thenReturn(slackJobDetailsEntity);
Mockito.when(blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(Mockito.any(), Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
Mockito.when(distributionJobRepository.findById(Mockito.any())).thenReturn(Optional.of(distributionJobEntity));
Mockito.when(distributionJobRepository.save(Mockito.any())).thenReturn(distributionJobEntity);
DistributionJobModel updatedJob = jobAccessor.updateJob(jobId, distributionJobRequestModel);
Mockito.verify(distributionJobRepository).findById(jobId);
Mockito.verify(distributionJobRepository).save(Mockito.any());
assertEquals(jobId, updatedJob.getJobId());
assertEquals(jobName, updatedJob.getName());
}
use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method createEmailJobTest.
@Test
void createEmailJobTest() {
UUID jobId = UUID.randomUUID();
EmailJobDetailsModel emailJobDetailsModel = new EmailJobDetailsModel(jobId, null, false, false, null, List.of());
DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.EMAIL.getUniversalKey(), emailJobDetailsModel);
EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(null, null, false, false, null);
emailJobDetailsEntity.setEmailJobAdditionalEmailAddresses(List.of());
DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
distributionJobEntity.setEmailJobDetails(emailJobDetailsEntity);
BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
Mockito.when(emailJobDetailsAccessor.saveJobDetails(Mockito.any(), Mockito.any())).thenReturn(emailJobDetailsModel);
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