Search in sources :

Example 11 with ProjectMessage

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

the class ProcessedProviderMessageTest method combineProjectOperationsDontMatchTest.

@Test
public void combineProjectOperationsDontMatchTest() {
    LinkableItem provider = new LinkableItem("Provider", "Provider Config Name");
    ProviderDetails providerDetails = new ProviderDetails(1L, provider);
    LinkableItem commonProject = new LinkableItem("Project", "Project 1");
    ProjectMessage projectMessage1 = ProjectMessage.projectStatusInfo(providerDetails, commonProject, ProjectOperation.CREATE);
    ProjectMessage projectMessage2 = ProjectMessage.projectStatusInfo(providerDetails, commonProject, ProjectOperation.DELETE);
    ProcessedProviderMessage<ProjectMessage> processedProviderMessage1 = ProcessedProviderMessage.singleSource(10L, projectMessage1);
    ProcessedProviderMessage<ProjectMessage> processedProviderMessage2 = ProcessedProviderMessage.singleSource(20L, projectMessage2);
    // Create then delete
    List<ProcessedProviderMessage<ProjectMessage>> combinedProjectMessages1 = processedProviderMessage1.combine(processedProviderMessage2);
    assertEquals(0, combinedProjectMessages1.size());
    // Delete then create
    List<ProcessedProviderMessage<ProjectMessage>> combinedProjectMessages2 = processedProviderMessage2.combine(processedProviderMessage1);
    assertEquals(1, combinedProjectMessages2.size());
    assertEquals(processedProviderMessage1.getProviderMessage(), combinedProjectMessages2.get(0).getProviderMessage());
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) Test(org.junit.jupiter.api.Test)

Example 12 with ProjectMessage

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

the class ProcessedProviderMessageTest method combineProjectVersionOperationsMatchTest.

@Test
public void combineProjectVersionOperationsMatchTest() {
    LinkableItem provider = new LinkableItem("Provider", "Provider Config Name");
    ProviderDetails providerDetails = new ProviderDetails(1L, provider);
    LinkableItem commonProject = new LinkableItem("Project", "Project 1");
    LinkableItem commonProjectVersion = new LinkableItem("Project Version", "Project Version 1");
    ProjectOperation commonOperation = ProjectOperation.CREATE;
    ProjectMessage projectMessage1 = ProjectMessage.projectVersionStatusInfo(providerDetails, commonProject, commonProjectVersion, commonOperation);
    ProjectMessage projectMessage2 = ProjectMessage.projectVersionStatusInfo(providerDetails, commonProject, commonProjectVersion, commonOperation);
    ProcessedProviderMessage<ProjectMessage> processedProviderMessage1 = ProcessedProviderMessage.singleSource(10L, projectMessage1);
    ProcessedProviderMessage<ProjectMessage> processedProviderMessage2 = ProcessedProviderMessage.singleSource(20L, projectMessage2);
    assertCombined(processedProviderMessage1, processedProviderMessage2);
}
Also used : LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) ProjectOperation(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation) Test(org.junit.jupiter.api.Test)

Example 13 with ProjectMessage

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

the class ProjectVersionNotificationMessageExtractorTest 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);
    ProjectVersionNotificationContent projectVersionNotificationContent = createProjectVersionNotificationContent();
    NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(projectVersionNotificationContent);
    ProjectVersionNotificationMessageExtractor extractor = new ProjectVersionNotificationMessageExtractor(providerKey, servicesFactoryCache);
    ProviderMessageHolder providerMessageHolder = extractor.extract(notificationContentWrapper, projectVersionNotificationContent);
    assertEquals(1, providerMessageHolder.getProjectMessages().size());
    assertEquals(0, providerMessageHolder.getSimpleMessages().size());
    ProjectMessage projectMessage = providerMessageHolder.getProjectMessages().get(0);
    assertEquals(MessageReason.PROJECT_VERSION_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());
    assertTrue(projectMessage.getProjectVersion().isPresent());
    LinkableItem projectVersion = projectMessage.getProjectVersion().get();
    assertEquals(PROJECT_VERSION, projectVersion.getValue());
    assertTrue(projectVersion.getUrl().isPresent());
    assertEquals(PROJECT_VERSION_URL, projectVersion.getUrl().get());
}
Also used : ProjectVersionNotificationContent(com.synopsys.integration.blackduck.api.manual.component.ProjectVersionNotificationContent) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) 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 14 with ProjectMessage

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

the class IssueTrackerSearcherTest method findIssuesProject.

@Test
public void findIssuesProject() throws AlertException {
    ProjectMessage projectMessage = ProjectMessage.projectStatusInfo(PROVIDER_DETAILS, PROJECT_ITEM, ProjectOperation.CREATE);
    IssueTrackerSearcher<String> searcher = new IssueTrackerSearcher<>(null, null, null, null, modelTransformer);
    List<ActionableIssueSearchResult<String>> foundIssues = searcher.findIssues(projectMessage);
    assertEquals(0, foundIssues.size());
}
Also used : ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) Test(org.junit.jupiter.api.Test)

Example 15 with ProjectMessage

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

the class IssueTrackerModelExtractorTest method extractProjectMessageIssueModelsCommentTest.

@Test
public void extractProjectMessageIssueModelsCommentTest() throws AlertException {
    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.UPDATE, 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.UPDATE);
    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");
    assertEquals(0, modelHolder.getIssueCreationModels().size());
    assertEquals(0, modelHolder.getIssueTransitionModels().size());
    assertEquals(1, modelHolder.getIssueCommentModels().size());
}
Also used : 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) 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