use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.
the class StaticJobAccessorTest method getPageOfJobsEmailTest.
@Test
void getPageOfJobsEmailTest() {
UUID jobId = UUID.randomUUID();
DistributionJobEntity distributionJobEntity = createEmailDistributionJobEntity(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);
Mockito.when(emailJobDetailsAccessor.retrieveDetails(Mockito.any())).thenReturn(Optional.of(new EmailJobDetailsModel(jobId, null, false, false, "NONE", List.of())));
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.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.
the class DefaultEmailJobDetailsAccessor method saveConcreteJobDetails.
@Override
@Transactional(propagation = Propagation.REQUIRED)
public EmailJobDetailsModel saveConcreteJobDetails(UUID jobId, EmailJobDetailsModel jobDetails) {
EmailJobDetailsEntity jobDetailsToSave = new EmailJobDetailsEntity(jobId, jobDetails.getSubjectLine().orElse(null), jobDetails.isProjectOwnerOnly(), jobDetails.isAdditionalEmailAddressesOnly(), jobDetails.getAttachmentFileType());
EmailJobDetailsEntity savedJobDetails = emailJobDetailsRepository.save(jobDetailsToSave);
additionalEmailAddressRepository.bulkDeleteByJobId(jobId);
List<EmailJobAdditionalEmailAddressEntity> additionalEmailAddressEntitiesToSave = jobDetails.getAdditionalEmailAddresses().stream().map(emailAddress -> new EmailJobAdditionalEmailAddressEntity(jobId, emailAddress)).collect(Collectors.toList());
List<EmailJobAdditionalEmailAddressEntity> savedAdditionalEmailAddressEntities = additionalEmailAddressRepository.saveAll(additionalEmailAddressEntitiesToSave);
savedJobDetails.setEmailJobAdditionalEmailAddresses(savedAdditionalEmailAddressEntities);
return convertToModel(savedJobDetails);
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.
the class EmailJobDetailsAccessorTest method retrieveDetailsUnknownIdTest.
@Test
void retrieveDetailsUnknownIdTest() {
UUID jobId = UUID.randomUUID();
String additionalEmailAddress = "fake@synopsys.com";
EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(jobId, null, false, false, null);
EmailJobAdditionalEmailAddressEntity emailJobAdditionalEmailAddressEntity = new EmailJobAdditionalEmailAddressEntity(jobId, additionalEmailAddress);
Mockito.when(emailJobDetailsRepository.findById(Mockito.any())).thenReturn(Optional.empty());
Mockito.when(additionalEmailAddressRepository.findByJobId(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
Optional<EmailJobDetailsModel> foundJobDetailsModel = emailJobDetailsAccessor.retrieveDetails(jobId);
assertTrue(foundJobDetailsModel.isEmpty());
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.
the class EmailJobDetailsAccessorTest method retrieveDetailsTest.
@Test
void retrieveDetailsTest() {
UUID jobId = UUID.randomUUID();
String additionalEmailAddress = "fake@synopsys.com";
EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(jobId, null, false, false, null);
EmailJobAdditionalEmailAddressEntity emailJobAdditionalEmailAddressEntity = new EmailJobAdditionalEmailAddressEntity(jobId, additionalEmailAddress);
Mockito.when(emailJobDetailsRepository.findById(Mockito.any())).thenReturn(Optional.of(emailJobDetailsEntity));
Mockito.when(additionalEmailAddressRepository.findByJobId(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
EmailJobDetailsModel foundJobDetailsModel = emailJobDetailsAccessor.retrieveDetails(jobId).orElse(null);
assertNotNull(foundJobDetailsModel);
assertEquals(jobId, foundJobDetailsModel.getJobId());
assertEquals(1, foundJobDetailsModel.getAdditionalEmailAddresses().size());
assertEquals(additionalEmailAddress, foundJobDetailsModel.getAdditionalEmailAddresses().get(0));
}
use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.
the class EmailChannelTestIT method sendEmailTest.
@Test
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void sendEmailTest() {
MockAlertProperties testAlertProperties = new MockAlertProperties();
String testEmailRecipient = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_RECIPIENT);
EmailAttachmentFileCreator emailAttachmentFileCreator = new EmailAttachmentFileCreator(testAlertProperties, new MessageContentGroupCsvCreator(), gson);
FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
EmailMessagingService emailMessagingService = new EmailMessagingService(freemarkerTemplatingService);
JavamailPropertiesFactory javamailPropertiesFactory = new JavamailPropertiesFactory();
EmailChannelMessagingService emailChannelMessagingService = new EmailChannelMessagingService(testAlertProperties, emailMessagingService, emailAttachmentFileCreator);
EmailGlobalConfigModel emailGlobalConfig = createEmailGlobalConfig();
EmailGlobalConfigAccessor emailConfigurationAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
Mockito.when(emailConfigurationAccessor.getConfiguration()).thenReturn(Optional.of(emailGlobalConfig));
JobEmailAddressValidator emailAddressValidator = Mockito.mock(JobEmailAddressValidator.class);
Mockito.when(emailAddressValidator.validate(Mockito.any(), Mockito.anyCollection())).thenReturn(new ValidatedEmailAddresses(Set.of(testEmailRecipient), Set.of()));
EmailAddressGatherer emailAddressGatherer = new EmailAddressGatherer(null, null);
EmailChannelMessageConverter emailChannelMessageConverter = new EmailChannelMessageConverter(new EmailChannelMessageFormatter());
EmailChannelMessageSender emailChannelMessageSender = new EmailChannelMessageSender(emailConfigurationAccessor, emailAddressGatherer, emailChannelMessagingService, emailAddressValidator, javamailPropertiesFactory);
EmailChannel emailChannel = new EmailChannel(emailChannelMessageConverter, emailChannelMessageSender);
List<String> emailAddresses = List.of(testEmailRecipient);
EmailJobDetailsModel emailJobDetails = new EmailJobDetailsModel(null, EmailChannelTestIT.class.getSimpleName(), false, true, EmailAttachmentFormat.NONE.name(), emailAddresses);
EmailITTestAssertions.assertSendSimpleMessageSuccess(emailChannel, emailJobDetails);
}
Aggregations