Search in sources :

Example 16 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails in project hub-alert by blackducksoftware.

the class IssueTrackerSearcherTest method findIssuesProjectIssueModel.

@Test
public void findIssuesProjectIssueModel() throws AlertException {
    BomComponentDetails bomComponentDetails = Mockito.mock(BomComponentDetails.class);
    ProjectMessage projectMessage = ProjectMessage.componentConcern(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, List.of(bomComponentDetails));
    ProjectIssueModel projectIssueModel1 = Mockito.mock(ProjectIssueModel.class);
    ExistingIssueDetails<String> issue1 = new ExistingIssueDetails<>("issue-1", "issue-1", "issue 1", "https://issue-1", IssueStatus.RESOLVABLE, IssueCategory.POLICY);
    IssuePolicyDetails policyDetails = new IssuePolicyDetails("A policy", ItemOperation.DELETE, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel2 = Mockito.mock(ProjectIssueModel.class);
    Mockito.when(projectIssueModel2.getPolicyDetails()).thenReturn(Optional.of(policyDetails));
    IssueVulnerabilityDetails vulnerabilityDetails = new IssueVulnerabilityDetails(true, List.of(), List.of(), List.of());
    ProjectIssueModel projectIssueModel3 = Mockito.mock(ProjectIssueModel.class);
    Mockito.when(projectIssueModel3.getVulnerabilityDetails()).thenReturn(Optional.of(vulnerabilityDetails));
    ExactIssueFinder<String> exactIssueFinder = Mockito.mock(ExactIssueFinder.class);
    Mockito.when(exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel1)).thenReturn(List.of(issue1));
    Mockito.when(exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel2)).thenReturn(List.of());
    ProjectMessageToIssueModelTransformer mockModelTransformer = Mockito.mock(ProjectMessageToIssueModelTransformer.class);
    Mockito.when(mockModelTransformer.convertToIssueModels(Mockito.eq(projectMessage))).thenReturn(List.of(projectIssueModel1, projectIssueModel2, projectIssueModel3));
    IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, null, null, exactIssueFinder, mockModelTransformer);
    List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
    assertEquals(1, foundIssues.size());
    ActionableIssueSearchResult<String> foundIssue = foundIssues.get(0);
    assertEquals(issue1, foundIssue.getExistingIssueDetails().orElse(null));
}
Also used : ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ProjectMessageToIssueModelTransformer(com.synopsys.integration.alert.api.channel.issue.convert.ProjectMessageToIssueModelTransformer) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 17 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails 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));
}
Also used : ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ActionableIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) Test(org.junit.jupiter.api.Test)

Example 18 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails 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());
}
Also used : IssueTransitionModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTransitionModel) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) MockIssueTrackerMessageFormatter(com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ActionableIssueSearchResult(com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ExistingIssueDetails(com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) IssueOperation(com.synopsys.integration.alert.common.channel.issuetracker.enumeration.IssueOperation) Test(org.junit.jupiter.api.Test)

Example 19 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails in project hub-alert by blackducksoftware.

the class IssueTrackerSearcher method findIssueByProjectIssueModel.

private ActionableIssueSearchResult<T> findIssueByProjectIssueModel(ProjectIssueModel projectIssueModel) throws AlertException {
    ExistingIssueDetails<T> existingIssue = null;
    ItemOperation searchResultOperation = ItemOperation.UPDATE;
    List<ExistingIssueDetails<T>> existingIssues = exactIssueFinder.findExistingIssuesByProjectIssueModel(projectIssueModel);
    int foundIssuesCount = existingIssues.size();
    if (foundIssuesCount == 1) {
        existingIssue = existingIssues.get(0);
        Optional<ItemOperation> policyOperation = projectIssueModel.getPolicyDetails().map(IssuePolicyDetails::getOperation);
        Optional<IssueVulnerabilityDetails> optionalVulnerabilityDetails = projectIssueModel.getVulnerabilityDetails();
        Optional<ItemOperation> componentUnknownOperation = projectIssueModel.getComponentUnknownVersionDetails().map(IssueComponentUnknownVersionDetails::getItemOperation);
        if (policyOperation.isPresent()) {
            searchResultOperation = policyOperation.get();
        } else if (optionalVulnerabilityDetails.isPresent()) {
            IssueVulnerabilityDetails issueVulnerabilityDetails = optionalVulnerabilityDetails.get();
            searchResultOperation = findVulnerabilitySearchResultOperation(existingIssue, issueVulnerabilityDetails);
        } else if (componentUnknownOperation.isPresent()) {
            searchResultOperation = componentUnknownOperation.get();
        }
    } else if (foundIssuesCount > 1) {
        Set<String> issueKeys = existingIssues.stream().map(ExistingIssueDetails::getIssueKey).collect(Collectors.toSet());
        String issueKeyString = StringUtils.join(issueKeys, ", ");
        throw new AlertException("Expected to find a unique issue, but more than one was found. " + issueKeyString);
    } else {
        searchResultOperation = ItemOperation.ADD;
    }
    return new ActionableIssueSearchResult<>(existingIssue, projectIssueModel, searchResultOperation);
}
Also used : IssueComponentUnknownVersionDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails) Set(java.util.Set) IssueVulnerabilityDetails(com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ItemOperation(com.synopsys.integration.alert.common.enumeration.ItemOperation) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 20 with IssuePolicyDetails

use of com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails in project hub-alert by blackducksoftware.

the class ProjectIssueModelConverterTest method toIssueCreationModelPolicyTest.

@Test
public void toIssueCreationModelPolicyTest() {
    IssuePolicyDetails testPolicy = new IssuePolicyDetails("Test Policy", ItemOperation.ADD, ComponentConcernSeverity.UNSPECIFIED_UNKNOWN);
    ProjectIssueModel projectIssueModel = ProjectIssueModel.policy(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, ISSUE_BOM_COMPONENT_DETAILS, testPolicy);
    IssueCreationModel issueCreationModel = basicIssueCreationModelTest(projectIssueModel);
    assertTrue(issueCreationModel.getTitle().contains(testPolicy.getName()), "Expected policy name to be present in the title");
    assertTrue(issueCreationModel.getDescription().contains(testPolicy.getName()), "Expected policy name to be present in the description");
}
Also used : IssueCreationModel(com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel) IssuePolicyDetails(com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) Test(org.junit.jupiter.api.Test)

Aggregations

IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)20 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)14 Test (org.junit.jupiter.api.Test)11 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)10 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)8 ExistingIssueDetails (com.synopsys.integration.alert.api.channel.issue.search.ExistingIssueDetails)7 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)5 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)5 IssueComponentUnknownVersionDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueComponentUnknownVersionDetails)4 IssueCategoryRetriever (com.synopsys.integration.alert.api.channel.issue.search.IssueCategoryRetriever)4 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)4 Gson (com.google.gson.Gson)3 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 IssueCreationModel (com.synopsys.integration.alert.api.channel.issue.model.IssueCreationModel)3 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)3 IssueCategory (com.synopsys.integration.alert.api.channel.issue.search.enumeration.IssueCategory)3 AlertRuntimeException (com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException)3 ItemOperation (com.synopsys.integration.alert.common.enumeration.ItemOperation)3 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)3 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)3