Search in sources :

Example 6 with EmailJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel 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);
}
Also used : EmailChannelKey(com.synopsys.integration.alert.descriptor.api.EmailChannelKey) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with EmailJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel 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());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) 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) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) 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 8 with EmailJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.

the class EmailDistributionTestAction method resolveTestDistributionDetails.

@Override
protected EmailJobDetailsModel resolveTestDistributionDetails(DistributionJobModel testJobModel) throws AlertException {
    Set<String> updateEmailAddresses = emailTestActionHelper.createUpdatedEmailAddresses(testJobModel);
    EmailJobDetailsModel originalEmailJobDetails = testJobModel.getDistributionJobDetails().getAs(DistributionJobDetailsModel.EMAIL);
    // For testing configuration, just use additional email addresses field
    List<String> originalAdditionalEmailAddresses = originalEmailJobDetails.getAdditionalEmailAddresses();
    List<String> additionalEmailAddressesToUse = new ArrayList<>(updateEmailAddresses.size() + originalAdditionalEmailAddresses.size());
    additionalEmailAddressesToUse.addAll(originalAdditionalEmailAddresses);
    additionalEmailAddressesToUse.addAll(updateEmailAddresses);
    return new EmailJobDetailsModel(testJobModel.getJobId(), originalEmailJobDetails.getSubjectLine().orElse(null), false, true, originalEmailJobDetails.getAttachmentFileType(), additionalEmailAddressesToUse);
}
Also used : EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) ArrayList(java.util.ArrayList)

Example 9 with EmailJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.

the class EmailTestActionHelper method createUpdatedEmailAddresses.

public Set<String> createUpdatedEmailAddresses(DistributionJobModel distributionJobModel) throws AlertException {
    Set<String> emailAddresses = new HashSet<>();
    DistributionJobDetailsModel distributionJobDetails = distributionJobModel.getDistributionJobDetails();
    EmailJobDetailsModel emailJobDetails = distributionJobDetails.getAs(DistributionJobDetailsModel.EMAIL);
    Long providerConfigId = distributionJobModel.getBlackDuckGlobalConfigId();
    boolean onlyAdditionalEmails = emailJobDetails.isAdditionalEmailAddressesOnly();
    if (null != providerConfigId && !onlyAdditionalEmails) {
        Set<ProviderProject> providerProjects = retrieveProviderProjects(distributionJobModel, providerConfigId);
        if (CollectionUtils.isNotEmpty(providerProjects)) {
            Set<String> providerEmailAddresses = addEmailAddresses(providerConfigId, providerProjects, distributionJobModel, emailJobDetails);
            emailAddresses.addAll(providerEmailAddresses);
        }
    }
    return emailAddresses;
}
Also used : DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) EmailJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) HashSet(java.util.HashSet)

Example 10 with EmailJobDetailsModel

use of com.synopsys.integration.alert.common.persistence.model.job.details.EmailJobDetailsModel in project hub-alert by blackducksoftware.

the class EmailJobDetailsAccessorTest method saveEmailJobDetailsTest.

@Test
void saveEmailJobDetailsTest() {
    UUID jobId = UUID.randomUUID();
    String additionalEmailAddress = "fake@synopsys.com";
    EmailJobDetailsModel emailJobDetailsModel = new EmailJobDetailsModel(null, null, false, false, null, List.of(additionalEmailAddress));
    EmailJobDetailsEntity emailJobDetailsEntity = new EmailJobDetailsEntity(jobId, null, false, false, null);
    EmailJobAdditionalEmailAddressEntity emailJobAdditionalEmailAddressEntity = new EmailJobAdditionalEmailAddressEntity(jobId, additionalEmailAddress);
    Mockito.when(emailJobDetailsRepository.save(Mockito.any())).thenReturn(emailJobDetailsEntity);
    Mockito.when(additionalEmailAddressRepository.saveAll(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
    Mockito.when(additionalEmailAddressRepository.findByJobId(Mockito.any())).thenReturn(List.of(emailJobAdditionalEmailAddressEntity));
    EmailJobDetailsModel newEmailJobDetails = emailJobDetailsAccessor.saveJobDetails(jobId, emailJobDetailsModel);
    Mockito.verify(additionalEmailAddressRepository).bulkDeleteByJobId(Mockito.any());
    assertEquals(jobId, newEmailJobDetails.getJobId());
    assertEquals(1, newEmailJobDetails.getAdditionalEmailAddresses().size());
    assertEquals(additionalEmailAddress, newEmailJobDetails.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)

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