Search in sources :

Example 11 with ProviderMessageHolder

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

the class ProviderMessageExtractor method extract.

public final ProcessedProviderMessageHolder extract(NotificationContentWrapper notificationContentWrapper) {
    if (!notificationContentClass.isAssignableFrom(notificationContentWrapper.getNotificationContentClass())) {
        logger.error("The notification type provided is incompatible with this extractor: {}", notificationContentWrapper.extractNotificationType());
        return ProcessedProviderMessageHolder.empty();
    }
    T stronglyTypedContent = notificationContentClass.cast(notificationContentWrapper.getNotificationContent());
    ProviderMessageHolder extractedMessages = extract(notificationContentWrapper, stronglyTypedContent);
    return toProcessedProviderMessageHolder(notificationContentWrapper.getNotificationId(), extractedMessages);
}
Also used : ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)

Example 12 with ProviderMessageHolder

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

the class LicenseLimitNotificationMessageExtractorTest method extractTest.

@Test
public void extractTest() {
    LicenseLimitNotificationContent notificationContentComponent = createLicenseLimitNotificationContent();
    NotificationContentWrapper notificationContentWrapper = createNotificationContentWrapper(notificationContentComponent);
    LicenseLimitNotificationMessageExtractor licenseLimitNotificationMessageExtractor = new LicenseLimitNotificationMessageExtractor(blackDuckProviderKey);
    ProviderMessageHolder providerMessageHolder = licenseLimitNotificationMessageExtractor.extract(notificationContentWrapper, notificationContentComponent);
    assertEquals(0, providerMessageHolder.getProjectMessages().size());
    assertEquals(1, providerMessageHolder.getSimpleMessages().size());
    SimpleMessage simpleMessage = providerMessageHolder.getSimpleMessages().get(0);
    assertEquals(summary, simpleMessage.getSummary());
    assertEquals(description, simpleMessage.getDescription());
    assertEquals(4, simpleMessage.getDetails().size());
}
Also used : LicenseLimitNotificationContent(com.synopsys.integration.blackduck.api.manual.component.LicenseLimitNotificationContent) SimpleMessage(com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) NotificationContentWrapper(com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper) Test(org.junit.jupiter.api.Test)

Example 13 with ProviderMessageHolder

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

use of com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder 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());
}
Also used : IssueTrackerIssueResponseModel(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel) ProjectMessage(com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage) IssueTrackerModelHolder(com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder) ProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder) Test(org.junit.jupiter.api.Test)

Aggregations

ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)14 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)9 ProviderDetails (com.synopsys.integration.alert.processor.api.extract.model.ProviderDetails)8 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)7 SimpleMessage (com.synopsys.integration.alert.processor.api.extract.model.SimpleMessage)6 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 Test (org.junit.jupiter.api.Test)5 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)3 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)3 ProjectOperation (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectOperation)2 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)2 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 MockChannelMessageFormatter (com.synopsys.integration.alert.api.channel.convert.mock.MockChannelMessageFormatter)1 IssueTrackerIssueResponseModel (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerIssueResponseModel)1 IssueTrackerModelHolder (com.synopsys.integration.alert.api.channel.issue.model.IssueTrackerModelHolder)1 ProcessedProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder)1 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)1 LicenseLimitNotificationContent (com.synopsys.integration.blackduck.api.manual.component.LicenseLimitNotificationContent)1