Search in sources :

Example 1 with BlackDuckJobProjectEntity

use of com.synopsys.integration.alert.database.job.blackduck.projects.BlackDuckJobProjectEntity in project hub-alert by blackducksoftware.

the class BlackDuckJobDetailsAccessorTest method saveBlackDuckJobDetailsTest.

@Test
public void saveBlackDuckJobDetailsTest() {
    UUID jobId = UUID.randomUUID();
    DistributionJobRequestModel distributionJobRequestModel = new DistributionJobRequestModel(true, jobName, FrequencyType.DAILY, ProcessingType.DEFAULT, null, UUID.randomUUID(), 3L, true, "*", "*", Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), null);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = new BlackDuckJobDetailsEntity(jobId, distributionJobRequestModel.getBlackDuckGlobalConfigId(), distributionJobRequestModel.isFilterByProject(), distributionJobRequestModel.getProjectNamePattern().orElse(null), distributionJobRequestModel.getProjectVersionNamePattern().orElse(null));
    BlackDuckJobNotificationTypeEntity blackDuckJobNotificationTypeEntity = new BlackDuckJobNotificationTypeEntity(jobId, "testNotificationType");
    BlackDuckJobProjectEntity blackDuckJobProjectEntity = new BlackDuckJobProjectEntity();
    BlackDuckJobPolicyFilterEntity blackDuckJobPolicyFilterEntity = new BlackDuckJobPolicyFilterEntity();
    BlackDuckJobVulnerabilitySeverityFilterEntity blackDuckJobVulnerabilitySeverityFilterEntity = new BlackDuckJobVulnerabilitySeverityFilterEntity();
    Mockito.when(blackDuckJobDetailsRepository.save(Mockito.any())).thenReturn(blackDuckJobDetailsEntity);
    Mockito.when(blackDuckJobNotificationTypeRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobNotificationTypeEntity));
    Mockito.when(blackDuckJobProjectRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobProjectEntity));
    Mockito.when(blackDuckJobPolicyFilterRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobPolicyFilterEntity));
    Mockito.when(blackDuckJobVulnerabilitySeverityFilterRepository.saveAll(Mockito.any())).thenReturn(List.of(blackDuckJobVulnerabilitySeverityFilterEntity));
    BlackDuckJobDetailsEntity createdBlackDuckJobDetailsEntity = blackDuckJobDetailsAccessor.saveBlackDuckJobDetails(jobId, distributionJobRequestModel);
    Mockito.verify(blackDuckJobNotificationTypeRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    Mockito.verify(blackDuckJobProjectRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    Mockito.verify(blackDuckJobPolicyFilterRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    Mockito.verify(blackDuckJobVulnerabilitySeverityFilterRepository).bulkDeleteAllByJobId(Mockito.eq(jobId));
    assertEquals(jobId, createdBlackDuckJobDetailsEntity.getJobId());
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobNotificationTypes().size());
    assertEquals(blackDuckJobNotificationTypeEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobNotificationTypes().get(0));
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobProjects().size());
    assertEquals(blackDuckJobProjectEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobProjects().get(0));
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobPolicyFilters().size());
    assertEquals(blackDuckJobPolicyFilterEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobPolicyFilters().get(0));
    assertEquals(1, createdBlackDuckJobDetailsEntity.getBlackDuckJobVulnerabilitySeverityFilters().size());
    assertEquals(blackDuckJobVulnerabilitySeverityFilterEntity, createdBlackDuckJobDetailsEntity.getBlackDuckJobVulnerabilitySeverityFilters().get(0));
}
Also used : BlackDuckJobVulnerabilitySeverityFilterEntity(com.synopsys.integration.alert.database.job.blackduck.vulnerability.BlackDuckJobVulnerabilitySeverityFilterEntity) BlackDuckJobProjectEntity(com.synopsys.integration.alert.database.job.blackduck.projects.BlackDuckJobProjectEntity) BlackDuckJobNotificationTypeEntity(com.synopsys.integration.alert.database.job.blackduck.notification.BlackDuckJobNotificationTypeEntity) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) BlackDuckJobPolicyFilterEntity(com.synopsys.integration.alert.database.job.blackduck.policy.BlackDuckJobPolicyFilterEntity) Test(org.junit.jupiter.api.Test)

Example 2 with BlackDuckJobProjectEntity

use of com.synopsys.integration.alert.database.job.blackduck.projects.BlackDuckJobProjectEntity in project hub-alert by blackducksoftware.

the class BlackDuckJobDetailsAccessorTest method retrieveProjectDetailsForJobTest.

@Test
public void retrieveProjectDetailsForJobTest() {
    UUID jobId = UUID.randomUUID();
    String projectName = "projectName";
    String href = "href";
    BlackDuckJobProjectEntity blackDuckJobProjectEntity = new BlackDuckJobProjectEntity(jobId, projectName, href);
    Mockito.when(blackDuckJobProjectRepository.findByJobId(Mockito.eq(jobId))).thenReturn(List.of(blackDuckJobProjectEntity));
    List<BlackDuckProjectDetailsModel> blackDuckProjectDetailsModels = blackDuckJobDetailsAccessor.retrieveProjectDetailsForJob(jobId);
    assertEquals(1, blackDuckProjectDetailsModels.size());
    BlackDuckProjectDetailsModel blackDuckProjectDetailsModel = blackDuckProjectDetailsModels.get(0);
    assertEquals(projectName, blackDuckProjectDetailsModel.getName());
    assertEquals(href, blackDuckProjectDetailsModel.getHref());
}
Also used : BlackDuckProjectDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel) BlackDuckJobProjectEntity(com.synopsys.integration.alert.database.job.blackduck.projects.BlackDuckJobProjectEntity) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

BlackDuckJobProjectEntity (com.synopsys.integration.alert.database.job.blackduck.projects.BlackDuckJobProjectEntity)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2 BlackDuckProjectDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.BlackDuckProjectDetailsModel)1 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)1 BlackDuckJobNotificationTypeEntity (com.synopsys.integration.alert.database.job.blackduck.notification.BlackDuckJobNotificationTypeEntity)1 BlackDuckJobPolicyFilterEntity (com.synopsys.integration.alert.database.job.blackduck.policy.BlackDuckJobPolicyFilterEntity)1 BlackDuckJobVulnerabilitySeverityFilterEntity (com.synopsys.integration.alert.database.job.blackduck.vulnerability.BlackDuckJobVulnerabilitySeverityFilterEntity)1