use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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.processor.api.extract.model.project.ProjectMessage 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.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class IssueTrackerProcessorTest method processMessagesTest.
@Test
public void processMessagesTest() throws AlertException {
IssueTrackerModelExtractor<String> extractor = Mockito.mock(IssueTrackerModelExtractor.class);
IssueTrackerModelHolder<String> simpleMessageResponses = new IssueTrackerModelHolder<>(List.of(), List.of(), List.of());
Mockito.when(extractor.extractSimpleMessageIssueModels(Mockito.anyList(), Mockito.any())).thenReturn(simpleMessageResponses);
IssueTrackerIssueResponseModel<String> response1 = Mockito.mock(IssueTrackerIssueResponseModel.class);
IssueTrackerIssueResponseModel<String> response2 = Mockito.mock(IssueTrackerIssueResponseModel.class);
IssueTrackerIssueResponseModel<String> response3 = Mockito.mock(IssueTrackerIssueResponseModel.class);
List<IssueTrackerIssueResponseModel<String>> simpleMessageResponse = List.of(response1, response2, response3);
IssueTrackerIssueResponseModel<String> response4 = Mockito.mock(IssueTrackerIssueResponseModel.class);
IssueTrackerIssueResponseModel<String> response5 = Mockito.mock(IssueTrackerIssueResponseModel.class);
List<IssueTrackerIssueResponseModel<String>> projectMessageResponses = List.of(response4, response5);
IssueTrackerMessageSender<String> sender = Mockito.mock(IssueTrackerMessageSender.class);
Mockito.when(sender.sendMessages(Mockito.any())).thenReturn(simpleMessageResponse, projectMessageResponses);
IssueTrackerProcessor<String> processor = new IssueTrackerProcessor<>(extractor, sender);
ProjectMessage projectMessage = Mockito.mock(ProjectMessage.class);
ProviderMessageHolder providerMessageHolder = new ProviderMessageHolder(List.of(projectMessage), List.of());
IssueTrackerResponse<String> issueTrackerResponse = processor.processMessages(providerMessageHolder, "jobName");
assertEquals(simpleMessageResponse.size() + projectMessageResponses.size(), issueTrackerResponse.getUpdatedIssues().size());
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class ProjectMessageSummarizer method constructMessageDetails.
private List<LinkableItem> constructMessageDetails(ProjectMessage projectMessage) {
List<LinkableItem> details = new LinkedList<>();
details.add(projectMessage.getProject());
projectMessage.getProjectVersion().ifPresent(details::add);
Map<ComponentConcernSummaryGrouping, Integer> groupedConcernCounts = new LinkedHashMap<>();
for (BomComponentDetails bomComponent : projectMessage.getBomComponents()) {
for (ComponentConcern concern : bomComponent.getComponentConcerns()) {
ComponentConcernSummaryGrouping concernKey = new ComponentConcernSummaryGrouping(concern.getType(), concern.getOperation(), concern.getSeverity());
int currentCount = groupedConcernCounts.getOrDefault(concernKey, 0);
Number concernNumericValue = concern.getNumericValue();
int concernCount = (concernNumericValue != null) ? concernNumericValue.intValue() : 1;
groupedConcernCounts.put(concernKey, currentCount + concernCount);
}
}
Map<ComponentConcernSummaryGrouping, Integer> sortedGroupedConcernCountsBySeverity = groupedConcernCounts.entrySet().stream().sorted(Map.Entry.comparingByKey(ComponentConcernSummaryGrouping.getComparator())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, // Merge operation is equivalent to Map::putIfAbsent
(old, newIgnored) -> old, LinkedHashMap::new));
for (Map.Entry<ComponentConcernSummaryGrouping, Integer> groupedConcernCount : sortedGroupedConcernCountsBySeverity.entrySet()) {
ComponentConcernSummaryGrouping concernGrouping = groupedConcernCount.getKey();
String severityLabel = ComponentConcernType.POLICY.equals(concernGrouping.type) ? concernGrouping.severity.getPolicyLabel() : concernGrouping.severity.getVulnerabilityLabel();
String stateTypeString = convertToUppercasePlural(concernGrouping.type);
String stateAdjective = convertToAdjective(concernGrouping.type, concernGrouping.operation);
String label = String.format("(%s) %s %s count", severityLabel, stateTypeString, stateAdjective);
LinkableItem concernDetail = new LinkableItem(label, groupedConcernCount.getValue().toString());
concernDetail.setNumericValueFlag(true);
details.add(concernDetail);
}
return details;
}
use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.
the class ProjectMessageSummarizer method summarize.
public ProcessedProviderMessage<SimpleMessage> summarize(ProcessedProviderMessage<ProjectMessage> digestedProjectMessage) {
ProjectMessage projectMessage = digestedProjectMessage.getProviderMessage();
Pair<String, String> summaryAndDescription = constructSummaryAndDescription(projectMessage);
List<LinkableItem> details = constructMessageDetails(projectMessage);
SimpleMessage derivedSimpleMessage = SimpleMessage.derived(summaryAndDescription.getLeft(), summaryAndDescription.getRight(), details, projectMessage);
return new ProcessedProviderMessage<>(digestedProjectMessage.getNotificationIds(), derivedSimpleMessage);
}
Aggregations