Search in sources :

Example 26 with DistributionJobRequestModel

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()));
}
Also used : MockNotificationContent(com.synopsys.integration.alert.mock.entity.MockNotificationContent) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AuditNotificationRelation(com.synopsys.integration.alert.database.audit.AuditNotificationRelation) AuditEntryEntity(com.synopsys.integration.alert.database.audit.AuditEntryEntity) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) NotificationEntity(com.synopsys.integration.alert.database.notification.NotificationEntity) ResponseStatusException(org.springframework.web.server.ResponseStatusException) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) Test(org.junit.jupiter.api.Test) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest)

Example 27 with DistributionJobRequestModel

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;
}
Also used : ArrayList(java.util.ArrayList) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) FilteredDistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobRequestModel)

Example 28 with DistributionJobRequestModel

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);
}
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 29 with DistributionJobRequestModel

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());
}
Also used : DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) SlackJobDetailsEntity(com.synopsys.integration.alert.database.job.slack.SlackJobDetailsEntity) 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 30 with DistributionJobRequestModel

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());
}
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)

Aggregations

DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)34 Test (org.junit.jupiter.api.Test)25 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)18 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)16 UUID (java.util.UUID)10 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)7 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)7 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)6 SlackJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel)6 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)6 ArrayList (java.util.ArrayList)6 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)4 AuditNotificationRelation (com.synopsys.integration.alert.database.audit.AuditNotificationRelation)4 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)3 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)3 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)3 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)3 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)3