use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class IssueTrackerModelExtractorTest method extractProjectMessageIssueModelsCreateTest.
@Test
public void extractProjectMessageIssueModelsCreateTest() throws AlertException {
ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, ISSUE_BOM_COMPONENT_DETAILS, policyDetails);
ActionableIssueSearchResult<String> searchResult = new ActionableIssueSearchResult<>(null, projectIssueModel, ItemOperation.ADD);
MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
IssueTrackerSearcher<String> searcher = Mockito.mock(IssueTrackerSearcher.class);
Mockito.when(searcher.findIssues(Mockito.eq(projectMessage))).thenReturn(List.of(searchResult));
IssueTrackerModelExtractor<String> extractor = new IssueTrackerModelExtractor<>(formatter, searcher);
IssueTrackerModelHolder<String> modelHolder = extractor.extractProjectMessageIssueModels(projectMessage, "jobName");
List<IssueCreationModel> issueCreationModels = modelHolder.getIssueCreationModels();
assertEquals(1, issueCreationModels.size());
assertEquals(0, modelHolder.getIssueTransitionModels().size());
assertEquals(0, modelHolder.getIssueCommentModels().size());
IssueCreationModel issueCreationModel = issueCreationModels.get(0);
assertEquals(projectIssueModel, issueCreationModel.getSource().orElse(null));
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class IssueTrackerModelExtractorTest method extractProjectMessageIssueModelsTransitionTest.
@Test
public void extractProjectMessageIssueModelsTransitionTest() throws AlertException {
ItemOperation itemOperation = ItemOperation.DELETE;
IssueOperation issueOperation = IssueOperation.RESOLVE;
ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
ExistingIssueDetails<String> existingIssueDetails = new ExistingIssueDetails<>("issue-id", "issue-key", "issue summary", "https://ui-link", IssueStatus.UNKNOWN, IssueCategory.POLICY);
IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", itemOperation, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, ISSUE_BOM_COMPONENT_DETAILS, policyDetails);
ActionableIssueSearchResult<String> searchResult = new ActionableIssueSearchResult<>(existingIssueDetails, projectIssueModel, itemOperation);
MockIssueTrackerMessageFormatter formatter = MockIssueTrackerMessageFormatter.withIntegerMaxValueLength();
IssueTrackerSearcher<String> searcher = Mockito.mock(IssueTrackerSearcher.class);
Mockito.when(searcher.findIssues(Mockito.eq(projectMessage))).thenReturn(List.of(searchResult));
IssueTrackerModelExtractor<String> extractor = new IssueTrackerModelExtractor<>(formatter, searcher);
IssueTrackerModelHolder<String> modelHolder = extractor.extractProjectMessageIssueModels(projectMessage, "jobName");
List<IssueTransitionModel<String>> issueTransitionModels = modelHolder.getIssueTransitionModels();
assertEquals(0, modelHolder.getIssueCreationModels().size());
assertEquals(1, issueTransitionModels.size());
assertEquals(0, modelHolder.getIssueCommentModels().size());
IssueTransitionModel<String> transitionModel = issueTransitionModels.get(0);
assertEquals(issueOperation, transitionModel.getIssueOperation());
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class ProjectMessageToIssueModelTransformerTest method convertToIssueModelsForVulnerabilitiesTest.
@Test
public void convertToIssueModelsForVulnerabilitiesTest() {
LinkableItem vulnerabilityItem0 = createVulnerabilityItem("CVE-000");
LinkableItem vulnerabilityItem7 = createVulnerabilityItem("CVE-007");
ComponentConcern vulnConcern0 = ComponentConcern.vulnerability(ItemOperation.ADD, vulnerabilityItem0.getValue(), ComponentConcernSeverity.CRITICAL, vulnerabilityItem0.getUrl().orElse(null));
ComponentConcern vulnConcern7 = ComponentConcern.vulnerability(ItemOperation.DELETE, vulnerabilityItem7.getValue(), ComponentConcernSeverity.MINOR_MEDIUM, vulnerabilityItem7.getUrl().orElse(null));
BomComponentDetails bomComponentDetails = createBomComponentDetails(List.of(vulnConcern0, ComponentConcern.vulnerability(ItemOperation.UPDATE, VULNERABILITY_2.getValue(), ComponentConcernSeverity.MINOR_MEDIUM, VULNERABILITY_2.getUrl().orElse(null)), vulnConcern7));
ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT, PROJECT_VERSION, List.of(bomComponentDetails));
ProjectMessageToIssueModelTransformer modelTransformer = new ProjectMessageToIssueModelTransformer();
List<ProjectIssueModel> vulnerabilityIssueModels = modelTransformer.convertToIssueModels(projectMessage);
assertEquals(1, vulnerabilityIssueModels.size());
ProjectIssueModel policyIssueModel = vulnerabilityIssueModels.get(0);
assertRequiredDetails(policyIssueModel);
Optional<IssueVulnerabilityDetails> optionalIssueVulnerabilityDetails = policyIssueModel.getVulnerabilityDetails();
assertTrue(optionalIssueVulnerabilityDetails.isPresent(), "Expected vulnerability details to be present");
IssueVulnerabilityDetails issueVulnerabilityDetails = optionalIssueVulnerabilityDetails.get();
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesAdded().size());
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesUpdated().size());
assertEquals(1, issueVulnerabilityDetails.getVulnerabilitiesDeleted().size());
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class IssueTrackerSearcherTest method findIssuesProjectBomDeleted.
@Test
public void findIssuesProjectBomDeleted() throws AlertException {
ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(PROVIDER_DETAILS, PROJECT_ITEM, ProjectOperation.DELETE);
ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
ProjectIssueSearchResult<String> projectIssueSearchResult = new ProjectIssueSearchResult<>(EXISTING_ISSUE_DETAILS, projectIssueModel);
ProjectIssueFinder<String> projectIssueFinder = Mockito.mock(ProjectIssueFinder.class);
Mockito.when(projectIssueFinder.findProjectIssues(Mockito.eq(PROVIDER_DETAILS), Mockito.eq(PROJECT_ITEM))).thenReturn(List.of(projectIssueSearchResult));
IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(projectIssueFinder, null, null, null, modelTransformer);
List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
assertEquals(1, foundIssues.size());
assertSearchResult(foundIssues.get(0), projectIssueModel, ItemOperation.DELETE);
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class IssueTrackerCallbackInfoCreatorTest method createCallbackInfoNoProjectVersionUrlTest.
@Test
public void createCallbackInfoNoProjectVersionUrlTest() {
LinkableItem projectVersionNoUrl = new LinkableItem("Project Version", "A Project Version", null);
ProjectIssueModel projectIssueModel = ProjectIssueModel.bom(PROVIDER_DETAILS, TEST_ITEM, projectVersionNoUrl, ISSUE_BOM_COMPONENT_DETAILS);
IssueTrackerCallbackInfoCreator callbackInfoCreator = new IssueTrackerCallbackInfoCreator();
Optional<IssueTrackerCallbackInfo> callbackInfo = callbackInfoCreator.createCallbackInfo(projectIssueModel);
assertTrue(callbackInfo.isEmpty(), "Expected no callback info to be present because no project-version url was present");
}
Aggregations