Search in sources :

Example 6 with NotificationExtractorBlackDuckServicesFactoryCache

use of com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache in project hub-alert by blackducksoftware.

the class BomEditNotificationDetailExtractorTest method createCache.

private NotificationExtractorBlackDuckServicesFactoryCache createCache(Long blackDuckConfigId, String projectName, String projectVersionName) throws IntegrationException {
    ProjectView projectView = Mockito.mock(ProjectView.class);
    Mockito.when(projectView.getName()).thenReturn(projectName);
    ProjectVersionView projectVersionView = Mockito.mock(ProjectVersionView.class);
    Mockito.when(projectVersionView.getVersionName()).thenReturn(projectVersionName);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectVersionView.class))).thenReturn(projectVersionView);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.eq(projectVersionView.metaProjectLink()))).thenReturn(projectView);
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    NotificationExtractorBlackDuckServicesFactoryCache cache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    Mockito.when(cache.retrieveBlackDuckServicesFactory(Mockito.eq(blackDuckConfigId))).thenReturn(blackDuckServicesFactory);
    return cache;
}
Also used : ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 7 with NotificationExtractorBlackDuckServicesFactoryCache

use of com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache in project hub-alert by blackducksoftware.

the class JobNotificationProcessorTest method createNotificationExtractorBlackDuckServicesFactoryCache.

private NotificationExtractorBlackDuckServicesFactoryCache createNotificationExtractorBlackDuckServicesFactoryCache() {
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    AlertProperties properties = new AlertProperties();
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    BlackDuckPropertiesFactory blackDuckPropertiesFactory = new BlackDuckPropertiesFactory(configurationModelConfigurationAccessor, GSON, properties, proxyManager);
    return new NotificationExtractorBlackDuckServicesFactoryCache(blackDuckPropertiesFactory);
}
Also used : ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) AlertProperties(com.synopsys.integration.alert.common.AlertProperties) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)

Example 8 with NotificationExtractorBlackDuckServicesFactoryCache

use of com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache in project hub-alert by blackducksoftware.

the class BomEditNotificationDetailExtractorTest method extractDetailedContentErrorTest.

@Test
public void extractDetailedContentErrorTest() throws IOException, IntegrationException {
    Long blackDuckConfigId = 0L;
    String notificationString = TestResourceUtils.readFileToString(BOM_EDIT_JSON_PATH);
    BomEditNotificationView notificationView = gson.fromJson(notificationString, BomEditNotificationView.class);
    NotificationExtractorBlackDuckServicesFactoryCache cache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    Mockito.doThrow(new AlertConfigurationException("Expected Exception thrown creating BlackDuckServicesFactory")).when(cache).retrieveBlackDuckServicesFactory(Mockito.anyLong());
    BomEditNotificationDetailExtractor extractor = new BomEditNotificationDetailExtractor(cache);
    AlertNotificationModel notification = new AlertNotificationModel(0L, blackDuckConfigId, "BlackDuck", "Config 1", null, null, null, null, false);
    List<DetailedNotificationContent> detailedNotificationContents = extractor.extractDetailedContent(notification, notificationView);
    assertEquals(0, detailedNotificationContents.size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) BomEditNotificationView(com.synopsys.integration.blackduck.api.manual.view.BomEditNotificationView) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Test(org.junit.jupiter.api.Test)

Example 9 with NotificationExtractorBlackDuckServicesFactoryCache

use of com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache in project hub-alert by blackducksoftware.

the class RuleViolationClearedNotificationMessageExtractorTest method init.

@BeforeEach
public void init() {
    NotificationExtractorBlackDuckServicesFactoryCache servicesFactoryCache = Mockito.mock(NotificationExtractorBlackDuckServicesFactoryCache.class);
    BlackDuckPolicySeverityConverter blackDuckPolicySeverityConverter = new BlackDuckPolicySeverityConverter();
    BlackDuckPolicyComponentConcernCreator blackDuckPolicyComponentConcernCreator = new BlackDuckPolicyComponentConcernCreator(blackDuckPolicySeverityConverter);
    BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
    BlackDuckComponentPolicyDetailsCreatorFactory blackDuckComponentPolicyDetailsCreatorFactory = new BlackDuckComponentPolicyDetailsCreatorFactory(blackDuckPolicySeverityConverter);
    BlackDuckMessageBomComponentDetailsCreatorFactory detailsCreatorFactory = new BlackDuckMessageBomComponentDetailsCreatorFactory(vulnerabilityDetailsCreator, blackDuckComponentPolicyDetailsCreatorFactory);
    BomComponent404Handler bomComponent404Handler = new BomComponent404Handler();
    extractor = new RuleViolationClearedNotificationMessageExtractor(providerKey, servicesFactoryCache, blackDuckPolicyComponentConcernCreator, detailsCreatorFactory, bomComponent404Handler);
}
Also used : BlackDuckComponentVulnerabilityDetailsCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator) BlackDuckPolicySeverityConverter(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicySeverityConverter) BlackDuckPolicyComponentConcernCreator(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicyComponentConcernCreator) BlackDuckComponentPolicyDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory) BomComponent404Handler(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) BlackDuckMessageBomComponentDetailsCreatorFactory(com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with NotificationExtractorBlackDuckServicesFactoryCache

use of com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache 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)

Aggregations

NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)14 BlackDuckComponentVulnerabilityDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckComponentVulnerabilityDetailsCreator)7 BlackDuckMessageBomComponentDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreatorFactory)7 BomComponent404Handler (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BomComponent404Handler)7 BlackDuckComponentPolicyDetailsCreatorFactory (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckComponentPolicyDetailsCreatorFactory)7 BlackDuckPolicySeverityConverter (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicySeverityConverter)7 BlackDuckPolicyComponentConcernCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.policy.BlackDuckPolicyComponentConcernCreator)5 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)5 HttpUrl (com.synopsys.integration.rest.HttpUrl)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Test (org.junit.jupiter.api.Test)5 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)4 BlackDuckHttpClient (com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 RuleViolationNotificationMessageExtractor (com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor)3 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)3 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)2 ProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProviderMessageHolder)2 ProjectMessage (com.synopsys.integration.alert.processor.api.extract.model.project.ProjectMessage)2 NotificationContentWrapper (com.synopsys.integration.alert.processor.api.filter.NotificationContentWrapper)2