Search in sources :

Example 1 with EmailJobDetailsModel

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());
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) PageRequest(org.springframework.data.domain.PageRequest) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) UUID(java.util.UUID) BlackDuckJobDetailsEntity(com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test)

Example 2 with EmailJobDetailsModel

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);
}
Also used : EmailJobAdditionalEmailAddressRepository(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) EmailChannelKey(com.synopsys.integration.alert.descriptor.api.EmailChannelKey) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) Collectors(java.util.stream.Collectors) EmailJobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.EmailJobDetailsAccessor) List(java.util.List) Component(org.springframework.stereotype.Component) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) Propagation(org.springframework.transaction.annotation.Propagation) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Optional(java.util.Optional) EmailJobDetailsRepository(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsRepository) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) Transactional(org.springframework.transaction.annotation.Transactional) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with EmailJobDetailsModel

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());
}
Also used : EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) UUID(java.util.UUID) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Test(org.junit.jupiter.api.Test)

Example 4 with EmailJobDetailsModel

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));
}
Also used : EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) EmailJobDetailsEntity(com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity) UUID(java.util.UUID) EmailJobAdditionalEmailAddressEntity(com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity) Test(org.junit.jupiter.api.Test)

Example 5 with EmailJobDetailsModel

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);
}
Also used : MessageContentGroupCsvCreator(com.synopsys.integration.alert.channel.email.attachment.MessageContentGroupCsvCreator) EmailGlobalConfigModel(com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel) EmailMessagingService(com.synopsys.integration.alert.service.email.EmailMessagingService) EmailAttachmentFileCreator(com.synopsys.integration.alert.channel.email.attachment.EmailAttachmentFileCreator) EmailAddressGatherer(com.synopsys.integration.alert.channel.email.distribution.address.EmailAddressGatherer) FreemarkerTemplatingService(com.synopsys.integration.alert.service.email.template.FreemarkerTemplatingService) JobEmailAddressValidator(com.synopsys.integration.alert.channel.email.distribution.address.JobEmailAddressValidator) EmailGlobalConfigAccessor(com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) JavamailPropertiesFactory(com.synopsys.integration.alert.service.email.JavamailPropertiesFactory) ValidatedEmailAddresses(com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Aggregations

EmailJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel)12 Test (org.junit.jupiter.api.Test)8 UUID (java.util.UUID)7 EmailJobDetailsEntity (com.synopsys.integration.alert.channel.email.database.job.EmailJobDetailsEntity)5 EmailJobAdditionalEmailAddressEntity (com.synopsys.integration.alert.channel.email.database.job.additional.EmailJobAdditionalEmailAddressEntity)4 ValidatedEmailAddresses (com.synopsys.integration.alert.channel.email.distribution.address.ValidatedEmailAddresses)3 EmailGlobalConfigAccessor (com.synopsys.integration.alert.channel.email.database.accessor.EmailGlobalConfigAccessor)2 EmailAddressGatherer (com.synopsys.integration.alert.channel.email.distribution.address.EmailAddressGatherer)2 JobEmailAddressValidator (com.synopsys.integration.alert.channel.email.distribution.address.JobEmailAddressValidator)2 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)2 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)2 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)2 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)2 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)2 EmailChannelKey (com.synopsys.integration.alert.descriptor.api.EmailChannelKey)2 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1