Search in sources :

Example 31 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.

the class ProjectNotificationMessageExtractorTest method extractTest.

@Test
public void extractTest() throws IntegrationException {
    NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
    Mockito.when(blackDuckHttpClient.getBlackDuckUrl()).thenReturn(new HttpUrl("https://a.blackduck.server.example.com"));
    Mockito.when(blackDuckServicesFactory.getBlackDuckHttpClient()).thenReturn(blackDuckHttpClient);
    Mockito.when(servicesFactoryCache.retrieveBlackDuckServicesFactory(Mockito.anyLong())).thenReturn(blackDuckServicesFactory);
    ProjectNotificationContent projectNotificationContent = createProjectNotificationContent();
    NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectNotificationContent);
    ProjectNotificationMessageExtractor extractor = new ProjectNotificationMessageExtractor(providerKey, servicesFactoryCache);
    ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectNotificationContent);
    assertEquals(1, providerMessageHolder.getProjectMessages().size());
    assertEquals(0, providerMessageHolder.getSimpleMessages().size());
    ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
    assertEquals(MessageReason.PROJECT_STATUS, projectMessage.getMessageReason());
    assertTrue(projectMessage.getOperation().isPresent());
    assertEquals(ProjectOperation.CREATE, projectMessage.getOperation().get());
    assertTrue(projectMessage.getBomComponents().isEmpty());
    assertEquals(PROJECT, projectMessage.getProject().getValue());
    assertTrue(projectMessage.getProject().getUrl().isPresent());
    assertEquals(PROJECT_URL, projectMessage.getProject().getUrl().get());
    assertFalse(projectMessage.getProjectVersion().isPresent());
}
Also used : ProjectNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectNotificationContent) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) HttpUrl(com.synopsys.integration.rest.HttpUrl) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Example 32 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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 33 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage in project hub-alert by blackducksoftware.

the class IssueTrackerSearcherTest method findIssuesComponentUpdate.

@Test
public void findIssuesComponentUpdate() throws AlertException {
    BomComponentDetails bomComponentDetails = Mockito.mock(BomComponentDetails.class);
    ProjectMessage projectMessage = ProjectMessage.componentUpdate(PROVIDER_DETAILS, PROJECT_ITEM, PROJECT_VERSION_ITEM, List.of(bomComponentDetails));
    ProjectIssueModel projectIssueModel = Mockito.mock(ProjectIssueModel.class);
    ProjectIssueSearchResult<String> projectIssueSearchResult = new ProjectIssueSearchResult<>(EXISTING_ISSUE_DETAILS, projectIssueModel);
    ProjectVersionComponentIssueFinder<String> componentIssueFinder = Mockito.mock(ProjectVersionComponentIssueFinder.class);
    Mockito.when(componentIssueFinder.findIssuesByComponent(Mockito.eq(PROVIDER_DETAILS), Mockito.eq(PROJECT_ITEM), Mockito.eq(PROJECT_VERSION_ITEM), Mockito.eq(bomComponentDetails))).thenReturn(List.of(projectIssueSearchResult));
    IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, null, componentIssueFinder, null, modelTransformer);
    List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
    assertEquals(1, foundIssues.size());
    assertSearchResult(foundIssues.get(0), projectIssueModel, ItemOperation.UPDATE);
}
Also used : ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProjectIssueModel(com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 34 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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 35 with ProjectMessage

use of com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage 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)

Aggregations

ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)45 Test (org.junit.jupiter.api.Test)32 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)22 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)14 ProcessedProviderMessage (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessage)13 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)13 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)12 ProjectIssueModel (com.synopsys.integration.alert.api.channel.issue.model.ProjectIssueModel)11 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)9 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)7 IssuePolicyDetails (com.synopsys.integration.alert.api.channel.issue.model.IssuePolicyDetails)6 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)5 IssueBomComponentDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueBomComponentDetails)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)4 LinkedList (java.util.LinkedList)4 MockIssueTrackerMessageFormatter (com.synopsys.integration.alert.api.channel.issue.convert.mock.MockIssueTrackerMessageFormatter)3 IssueVulnerabilityDetails (com.synopsys.integration.alert.api.channel.issue.model.IssueVulnerabilityDetails)3 ActionableIssueSearchResult (com.synopsys.integration.alert.api.channel.issue.search.ActionableIssueSearchResult)3