Search in sources :

Example 1 with JiraServerJobDetailsEntity

use of com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity in project hub-alert by blackducksoftware.

the class StaticJobAccessorTest method createJiraServerJobTest.

@Test
void createJiraServerJobTest() {
    UUID jobId = UUID.randomUUID();
    JiraServerJobDetailsModel jiraServerJobDetailsModel = new JiraServerJobDetailsModel(jobId, false, null, null, null, null, null, List.of(), "issueSummary");
    DistributionJobRequestModel distributionJobRequestModel = createDistributionJobEntity(ChannelKeys.JIRA_SERVER.getUniversalKey(), jiraServerJobDetailsModel);
    JiraServerJobDetailsEntity jiraServerJobDetailsEntity = new JiraServerJobDetailsEntity(null, false, null, null, null, null, null, null);
    jiraServerJobDetailsEntity.setJobCustomFields(List.of());
    DistributionJobEntity distributionJobEntity = createDistributionJobEntity(jobId, distributionJobRequestModel);
    distributionJobEntity.setJiraServerJobDetails(jiraServerJobDetailsEntity);
    BlackDuckJobDetailsEntity blackDuckJobDetailsEntity = createBlackDuckJobDetailsEntity(jobId, distributionJobRequestModel);
    Mockito.when(jiraServerJobDetailsAccessor.saveJobDetails(Mockito.any(), Mockito.any())).thenReturn(jiraServerJobDetailsModel);
    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) JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) UUID(java.util.UUID) DistributionJobRequestModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel) JiraServerJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel) 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 JiraServerJobDetailsEntity

use of com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity in project hub-alert by blackducksoftware.

the class JiraServerJobDetailsAccessorTest method retrieveDetailsTest.

@Test
void retrieveDetailsTest() {
    UUID jobId = UUID.randomUUID();
    List<JiraServerJobCustomFieldEntity> customFields = createCustomFieldEntities(jobId);
    JiraServerJobDetailsEntity jiraJobDetailsEntity = createDetailsEntity(jobId);
    jiraJobDetailsEntity.setJobCustomFields(customFields);
    Mockito.when(jobDetailsRepository.findById(jobId)).thenReturn(Optional.of(jiraJobDetailsEntity));
    Mockito.when(jiraServerJobCustomFieldRepository.findByJobId(jobId)).thenReturn(customFields);
    JiraServerJobDetailsModel foundJobDetailsModel = jobDetailsAccessor.retrieveDetails(jobId).orElse(null);
    assertNotNull(foundJobDetailsModel);
    assertEquals(jobId, foundJobDetailsModel.getJobId());
}
Also used : JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) JiraServerJobCustomFieldEntity(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldEntity) UUID(java.util.UUID) JiraServerJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel) Test(org.junit.jupiter.api.Test)

Example 3 with JiraServerJobDetailsEntity

use of com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity in project hub-alert by blackducksoftware.

the class DefaultJiraServerJobDetailsAccessor method saveConcreteJobDetails.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public JiraServerJobDetailsModel saveConcreteJobDetails(UUID jobId, JiraServerJobDetailsModel jobDetails) {
    JiraServerJobDetailsEntity jiraServerJobDetailsToSave = new JiraServerJobDetailsEntity(jobId, jobDetails.isAddComments(), jobDetails.getIssueCreatorUsername(), jobDetails.getProjectNameOrKey(), jobDetails.getIssueType(), jobDetails.getResolveTransition(), jobDetails.getReopenTransition(), jobDetails.getIssueSummary());
    JiraServerJobDetailsEntity savedJobDetails = jiraServerJobDetailsRepository.save(jiraServerJobDetailsToSave);
    jiraServerJobCustomFieldRepository.bulkDeleteByJobId(jobId);
    List<JiraServerJobCustomFieldEntity> customFieldsToSave = jobDetails.getCustomFields().stream().map(model -> new JiraServerJobCustomFieldEntity(savedJobDetails.getJobId(), model.getFieldName(), model.getFieldValue())).collect(Collectors.toList());
    List<JiraServerJobCustomFieldEntity> savedJobCustomFields = jiraServerJobCustomFieldRepository.saveAll(customFieldsToSave);
    savedJobDetails.setJobCustomFields(savedJobCustomFields);
    return convertToModel(savedJobDetails);
}
Also used : JiraServerJobCustomFieldRepository(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldRepository) JiraServerChannelKey(com.synopsys.integration.alert.descriptor.api.JiraServerChannelKey) JiraServerJobDetailsRepository(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) UUID(java.util.UUID) DistributionJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel) JiraJobCustomFieldModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel) Collectors(java.util.stream.Collectors) List(java.util.List) Component(org.springframework.stereotype.Component) JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) Propagation(org.springframework.transaction.annotation.Propagation) DescriptorKey(com.synopsys.integration.alert.descriptor.api.model.DescriptorKey) Optional(java.util.Optional) JiraServerJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel) JiraServerJobCustomFieldEntity(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldEntity) JiraServerJobDetailsAccessor(com.synopsys.integration.alert.common.persistence.accessor.JiraServerJobDetailsAccessor) Transactional(org.springframework.transaction.annotation.Transactional) JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) JiraServerJobCustomFieldEntity(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with JiraServerJobDetailsEntity

use of com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity in project hub-alert by blackducksoftware.

the class JiraServerJobDetailsAccessorTest method saveJobDetailsTest.

@Test
void saveJobDetailsTest() {
    UUID jobId = UUID.randomUUID();
    List<JiraServerJobCustomFieldEntity> customFields = createCustomFieldEntities(jobId);
    JiraServerJobDetailsEntity jiraJobDetailsEntity = createDetailsEntity(jobId);
    jiraJobDetailsEntity.setJobCustomFields(customFields);
    JiraServerJobDetailsModel jiraJobDetailsModel = createDetailsModel(jiraJobDetailsEntity);
    Mockito.when(jiraServerJobCustomFieldRepository.saveAll(Mockito.any())).thenReturn(customFields);
    Mockito.when(jiraServerJobCustomFieldRepository.findByJobId(jobId)).thenReturn(customFields);
    Mockito.when(jobDetailsRepository.findById(jobId)).thenReturn(Optional.of(jiraJobDetailsEntity));
    Mockito.when(jobDetailsRepository.save(Mockito.any())).thenReturn(jiraJobDetailsEntity);
    JiraServerJobDetailsModel newJiraJobDetails = jobDetailsAccessor.saveJobDetails(jobId, jiraJobDetailsModel);
    assertEquals(jobId, newJiraJobDetails.getJobId());
    assertNotNull(newJiraJobDetails.getCustomFields());
    assertEquals(1, newJiraJobDetails.getCustomFields().size());
}
Also used : JiraServerJobDetailsEntity(com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity) JiraServerJobCustomFieldEntity(com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldEntity) UUID(java.util.UUID) JiraServerJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel) Test(org.junit.jupiter.api.Test)

Aggregations

JiraServerJobDetailsEntity (com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsEntity)4 JiraServerJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraServerJobDetailsModel)4 UUID (java.util.UUID)4 JiraServerJobCustomFieldEntity (com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldEntity)3 Test (org.junit.jupiter.api.Test)3 JiraServerJobDetailsRepository (com.synopsys.integration.alert.channel.jira.server.database.job.JiraServerJobDetailsRepository)1 JiraServerJobCustomFieldRepository (com.synopsys.integration.alert.channel.jira.server.database.job.custom_field.JiraServerJobCustomFieldRepository)1 JiraServerJobDetailsAccessor (com.synopsys.integration.alert.common.persistence.accessor.JiraServerJobDetailsAccessor)1 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)1 DistributionJobRequestModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobRequestModel)1 DistributionJobDetailsModel (com.synopsys.integration.alert.common.persistence.model.job.details.DistributionJobDetailsModel)1 JiraJobCustomFieldModel (com.synopsys.integration.alert.common.persistence.model.job.details.JiraJobCustomFieldModel)1 DistributionJobEntity (com.synopsys.integration.alert.database.job.DistributionJobEntity)1 BlackDuckJobDetailsEntity (com.synopsys.integration.alert.database.job.blackduck.BlackDuckJobDetailsEntity)1 JiraServerChannelKey (com.synopsys.integration.alert.descriptor.api.JiraServerChannelKey)1 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1