Search in sources :

Example 36 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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 37 with DistributionJobModel

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

the class StaticJobAccessorTest method getPageOfJobsSearchTest.

@Test
void getPageOfJobsSearchTest() {
    ProviderKey providerKey = new BlackDuckProviderKey();
    UUID jobId = UUID.randomUUID();
    DistributionJobEntity distributionJobEntity = createSlackDistributionJobEntity(jobId);
    distributionJobEntity.setBlackDuckJobDetails(new BlackDuckJobDetailsEntity(jobId, 3L, true, "*", "*"));
    Page<DistributionJobEntity> page = new PageImpl<>(List.of(distributionJobEntity));
    Mockito.when(distributionJobRepository.findByChannelDescriptorNamesAndSearchTerm(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(page);
    AlertPagedModel<DistributionJobModel> pageOfJobs = jobAccessor.getPageOfJobs(0, 10, "test-search-term", List.of(providerKey.getUniversalKey()));
    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) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ProviderKey(com.synopsys.integration.alert.descriptor.api.model.ProviderKey) 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 38 with DistributionJobModel

use of com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel 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 39 with DistributionJobModel

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

the class StaticJobAccessorTest method getPageOfJobsBlankSearchTest.

@Test
void getPageOfJobsBlankSearchTest() {
    ProviderKey providerKey = new BlackDuckProviderKey();
    UUID jobId = UUID.randomUUID();
    DistributionJobEntity distributionJobEntity = createSlackDistributionJobEntity(jobId);
    distributionJobEntity.setBlackDuckJobDetails(new BlackDuckJobDetailsEntity(jobId, 3L, true, "*", "*"));
    Page<DistributionJobEntity> page = new PageImpl<>(List.of(distributionJobEntity));
    Mockito.when(distributionJobRepository.findByChannelDescriptorNameIn(Mockito.any(), Mockito.any())).thenReturn(page);
    AlertPagedModel<DistributionJobModel> pageOfJobs = jobAccessor.getPageOfJobs(0, 10, " ", List.of(providerKey.getUniversalKey()));
    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) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) DistributionJobEntity(com.synopsys.integration.alert.database.job.DistributionJobEntity) BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ProviderKey(com.synopsys.integration.alert.descriptor.api.model.ProviderKey) 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 40 with DistributionJobModel

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

the class JobConfigActions method readPageWithoutChecks.

@Override
public final ActionResponse<JobPagedModel> readPageWithoutChecks(Integer pageNumber, Integer pageSize, String searchTerm, Collection<String> permittedDescriptorsForSession) {
    AlertPagedModel<DistributionJobModel> pageOfJobs = jobAccessor.getPageOfJobs(pageNumber, pageSize, searchTerm, permittedDescriptorsForSession);
    List<DistributionJobModel> distributionJobModels = pageOfJobs.getModels();
    List<JobFieldModel> jobFieldModels = new ArrayList<>(distributionJobModels.size());
    for (DistributionJobModel distributionJobModel : distributionJobModels) {
        JobFieldModel jobFieldModel = JobFieldModelPopulationUtils.createJobFieldModelWithDefaultProviderProjectState(distributionJobModel);
        jobFieldModels.add(jobFieldModel);
    }
    JobPagedModel jobPagedModel = new JobPagedModel(pageOfJobs.getTotalPages(), pageOfJobs.getCurrentPage(), pageOfJobs.getPageSize(), jobFieldModels);
    return new ActionResponse<>(HttpStatus.OK, jobPagedModel);
}
Also used : ArrayList(java.util.ArrayList) JobPagedModel(com.synopsys.integration.alert.common.rest.model.JobPagedModel) JobFieldModel(com.synopsys.integration.alert.common.rest.model.JobFieldModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)

Aggregations

DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)52 Test (org.junit.jupiter.api.Test)35 UUID (java.util.UUID)24 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)20 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)15 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)14 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)10 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)9 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)8 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)8 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)8 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)8 AuditEntryEntity (com.synopsys.integration.alert.database.audit.AuditEntryEntity)8 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)7 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)7 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)7 OffsetDateTime (java.time.OffsetDateTime)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)6