use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class AzureBoardsComponentIssueFinderTest method findExistingIssuesByProjectIssueModelForUnknownVersionTest.
@Test
public void findExistingIssuesByProjectIssueModelForUnknownVersionTest() throws AlertException {
Gson gson = new Gson();
String organizationName = "orgName";
AzureBoardsIssueTrackerQueryManager queryManager = Mockito.mock(AzureBoardsIssueTrackerQueryManager.class);
IssueCategoryRetriever issueCategoryRetriever = new IssueCategoryRetriever();
AzureBoardsExistingIssueDetailsCreator issueDetailsCreator = new AzureBoardsExistingIssueDetailsCreator(organizationName, issueCategoryRetriever, azureBoardsIssueStatusResolver);
AzureBoardsWorkItemFinder workItemFinder = new AzureBoardsWorkItemFinder(queryManager, "test proj");
AzureBoardsComponentIssueFinder componentIssueFinder = new AzureBoardsComponentIssueFinder(gson, workItemFinder, issueDetailsCreator);
IssueComponentUnknownVersionDetails componentUnknownVersionDetails = new IssueComponentUnknownVersionDetails(ItemOperation.ADD, createRiskModels());
IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
ProjectIssueModel projectIssueModel = ProjectIssueModel.componentUnknownVersion(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, componentUnknownVersionDetails);
WorkItemResponseModel workItemResponseModel = createWorkItemResponseModel(workItemReopenState);
Mockito.when(queryManager.executeQueryAndRetrieveWorkItems(Mockito.any())).thenReturn(List.of(workItemResponseModel));
List<ExistingIssueDetails<Integer>> existingIssueDetailsList = componentIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
assertEquals(1, existingIssueDetailsList.size());
ExistingIssueDetails<Integer> existingIssueDetails = existingIssueDetailsList.get(0);
assertEquals(IssueStatus.RESOLVABLE, existingIssueDetails.getIssueStatus());
assertEquals(IssueCategory.BOM, existingIssueDetails.getIssueCategory());
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class AzureBoardsAlertIssuePropertiesManagerTest method verifyValidVulnIssuesAreCreated.
@Test
public void verifyValidVulnIssuesAreCreated() {
AzureBoardsAlertIssuePropertiesManager azureBoardsAlertIssuePropertiesManager = new AzureBoardsAlertIssuePropertiesManager();
LinkableItem providerConfig = new LinkableItem("providerConfigLabel", "providerConfigValue");
ProviderDetails providerDetails = new ProviderDetails(1L, providerConfig);
LinkableItem project = new LinkableItem("projectLabel", "projectValue");
LinkableItem projectVersion = new LinkableItem("projectVersionLabel", "projectVersionValue");
LinkableItem component = new LinkableItem("componentLabel", "componentValue");
LinkableItem componentVersion = new LinkableItem("componentVersionLabel", "componentVersionValue");
IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromSearchResults(component, componentVersion);
IssueVulnerabilityDetails issueVulnerabilityDetails = new IssueVulnerabilityDetails(false, List.of(IssueVulnerabilityModel.fromComponentConcern(ComponentConcern.vulnerability(ItemOperation.ADD, "vulnerabilityId", ComponentConcernSeverity.CRITICAL, "vulnerabilityUrl"))), List.of(), List.of());
ProjectIssueModel vulnerability = ProjectIssueModel.vulnerability(providerDetails, project, projectVersion, issueBomComponentDetails, issueVulnerabilityDetails);
List<WorkItemElementOperationModel> workItemRequestCustomFieldOperations = azureBoardsAlertIssuePropertiesManager.createWorkItemRequestCustomFieldOperations(vulnerability);
LinkableItem provider = providerDetails.getProvider();
String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, providerKey);
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_CATEGORY_KEY_FIELD_REFERENCE_NAME, AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_VULNERABILITY_COMPATIBILITY_LABEL);
String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(vulnerability.getProjectVersion().orElse(null));
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class AzureBoardsAlertIssuePropertiesManagerTest method verifyPolicyIssuesAreCreatedWithTruncatedPropertyValues.
@Test
public void verifyPolicyIssuesAreCreatedWithTruncatedPropertyValues() {
AzureBoardsAlertIssuePropertiesManager azureBoardsAlertIssuePropertiesManager = new AzureBoardsAlertIssuePropertiesManager();
LinkableItem providerConfig = new LinkableItem("providerConfigLabel", "providerConfigValue");
ProviderDetails providerDetails = new ProviderDetails(1L, providerConfig);
LinkableItem project = new LinkableItem("projectLabel", "projectValue");
LinkableItem projectVersion = new LinkableItem("projectVersionLabel", StringUtils.repeat("projectVersionValue", 100));
LinkableItem component = new LinkableItem("componentLabel", "componentValue");
LinkableItem componentVersion = new LinkableItem("componentVersionLabel", "componentVersionValue");
IssueBomComponentDetails issueBomComponentDetails = IssueBomComponentDetails.fromSearchResults(component, componentVersion);
IssuePolicyDetails issuePolicyDetails = new IssuePolicyDetails("policy", ItemOperation.ADD, ComponentConcernSeverity.CRITICAL);
ProjectIssueModel policy = ProjectIssueModel.policy(providerDetails, project, projectVersion, issueBomComponentDetails, issuePolicyDetails);
List<WorkItemElementOperationModel> workItemRequestCustomFieldOperations = azureBoardsAlertIssuePropertiesManager.createWorkItemRequestCustomFieldOperations(policy);
LinkableItem provider = providerDetails.getProvider();
String providerKey = AzureBoardsSearchPropertiesUtils.createProviderKey(provider.getLabel(), provider.getUrl().orElse(null));
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_PROVIDER_KEY_FIELD_REFERENCE_NAME, providerKey);
String additionalInfo = AzureBoardsAlertIssuePropertiesManager.POLICY_ADDITIONAL_KEY_COMPATIBILITY_LABEL + issuePolicyDetails.getName();
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_ADDITIONAL_INFO_KEY_FIELD_REFERENCE_NAME, additionalInfo);
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_CATEGORY_KEY_FIELD_REFERENCE_NAME, AzureBoardsAlertIssuePropertiesManager.CATEGORY_TYPE_POLICY_COMPATIBILITY_LABEL);
// This should trim the contents of the linkableitem
String subTopicKey = AzureBoardsSearchPropertiesUtils.createNullableLinkableItemKey(policy.getProjectVersion().orElse(null));
assertValidContents(workItemRequestCustomFieldOperations, AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME, subTopicKey);
WorkItemElementOperationModel workItem = workItemRequestCustomFieldOperations.stream().filter(workItemElementOperationModel -> StringUtils.endsWith(workItemElementOperationModel.getPath(), AzureCustomFieldManager.ALERT_SUB_TOPIC_KEY_FIELD_REFERENCE_NAME)).findFirst().orElse(null);
assertNotNull(workItem);
Object workItemValue = workItem.getValue();
assertEquals(subTopicKey, workItemValue);
// Ensures that we don't push values that are larger than azure allows for custom fields
assertEquals(256, workItemValue.toString().length());
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class IssueTrackerModelExtractor method convertSearchResult.
private IssueTrackerModelHolder<T> convertSearchResult(ActionableIssueSearchResult<T> searchResult, String jobName) {
Optional<ExistingIssueDetails<T>> existingIssueDetails = searchResult.getExistingIssueDetails();
ProjectIssueModel projectIssueModel = searchResult.getProjectIssueModel();
if (existingIssueDetails.isPresent()) {
return convertExistingIssue(existingIssueDetails.get(), projectIssueModel, searchResult.getRequiredOperation());
} else {
IssueCreationModel issueCreationModel = projectIssueModelConverter.toIssueCreationModel(projectIssueModel, jobName);
return new IssueTrackerModelHolder<>(List.of(issueCreationModel), List.of(), List.of());
}
}
use of com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel in project hub-alert by blackducksoftware.
the class IssueTrackerIssueCreatorTest method createIssueTrackerIssueWithSourceTest.
@Test
public void createIssueTrackerIssueWithSourceTest() throws AlertException {
TestIssueCreator issueCreator = new TestIssueCreator(commenter, callbackInfoCreator);
ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
IssueCreationModel issueCreationModel = IssueCreationModel.project("Test title", null, List.of("example comment"), projectIssueModel);
IssueTrackerIssueResponseModel<String> responseModel = issueCreator.createIssueTrackerIssue(issueCreationModel);
assertEquals(issueCreationModel.getTitle(), responseModel.getIssueTitle());
}
Aggregations