Search in sources :

Example 6 with ComponentVersionUpgradeGuidanceView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationMessageExtractorTest method createBomComponentDetailsMissingOriginTest.

@Test
public void createBomComponentDetailsMissingOriginTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    ProjectVersionComponentVersionView projectVersionComponentVersionView = createProjectVersionComponentVersionView(false);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
    ComponentVersionUpgradeGuidanceView componentVersionUpgradeGuidanceView = createComponentVersionUpgradeGuidanceView();
    // A UrlSingleResponse is needed to Mock the blackDuckApiClient in BlackDuckMessageComponentVersionUpgradeGuidanceService::requestUpgradeGuidanceItems
    UrlSingleResponse<ComponentVersionUpgradeGuidanceView> urlSingleResponse = new UrlSingleResponse<>(new HttpUrl(UPGRADE_GUIDANCE_URL), ComponentVersionUpgradeGuidanceView.class);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.eq(urlSingleResponse))).thenReturn(componentVersionUpgradeGuidanceView);
    VulnerabilityUniqueProjectNotificationContent notificationContent = createVulnerabilityUniqueProjectNotificationContent();
    List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    assertEquals(1, bomComponentDetailsList.size());
    BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
    assertEquals(COMPONENT, testBomComponentDetails.getComponent());
    assertTrue(testBomComponentDetails.getComponentVersion().isPresent());
    assertEquals(COMPONENT_VERSION.getValue(), testBomComponentDetails.getComponentVersion().get().getValue());
    assertEquals(LICENSE_DISPLAY, testBomComponentDetails.getLicense().getValue());
    assertEquals(UsageType.DYNAMICALLY_LINKED.prettyPrint(), testBomComponentDetails.getUsage());
    assertTrue(testBomComponentDetails.getAdditionalAttributes().isEmpty());
    assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
    assertNotNull(testBomComponentDetails.getComponentVulnerabilities());
    assertEquals(3, testBomComponentDetails.getComponentConcerns().size());
    ComponentUpgradeGuidance componentUpgradeGuidance = testBomComponentDetails.getComponentUpgradeGuidance();
    assertTrue(componentUpgradeGuidance.getLongTermUpgradeGuidance().isEmpty());
    assertTrue(componentUpgradeGuidance.getShortTermUpgradeGuidance().isEmpty());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 7 with ComponentVersionUpgradeGuidanceView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView in project hub-alert by blackducksoftware.

the class BlackDuckMessageComponentVersionUpgradeGuidanceService method createUpgradeGuidanceItems.

private ComponentUpgradeGuidance createUpgradeGuidanceItems(ComponentVersionUpgradeGuidanceView upgradeGuidanceView) {
    LinkableItem shortTermGuidance = Optional.ofNullable(upgradeGuidanceView.getShortTerm()).map(CommonUpgradeGuidanceModel::fromShortTermGuidance).map(guidanceModel -> createUpgradeGuidanceItem(BlackDuckMessageLabels.LABEL_GUIDANCE_SHORT_TERM, guidanceModel)).orElse(null);
    LinkableItem longTermGuidance = Optional.ofNullable(upgradeGuidanceView.getLongTerm()).map(CommonUpgradeGuidanceModel::fromLongTermGuidance).map(guidanceModel -> createUpgradeGuidanceItem(BlackDuckMessageLabels.LABEL_GUIDANCE_LONG_TERM, guidanceModel)).orElse(null);
    return new ComponentUpgradeGuidance(shortTermGuidance, longTermGuidance);
}
Also used : ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) LinkSingleResponse(com.synopsys.integration.blackduck.api.core.response.LinkSingleResponse) UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) IntegrationException(com.synopsys.integration.exception.IntegrationException) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) StringUtils(org.apache.commons.lang3.StringUtils) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) HttpUrl(com.synopsys.integration.rest.HttpUrl) ArrayList(java.util.ArrayList) List(java.util.List) ResourceMetadata(com.synopsys.integration.blackduck.api.core.ResourceMetadata) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) Optional(java.util.Optional) BlackDuckMessageLabels(com.synopsys.integration.alert.provider.blackduck.processor.message.BlackDuckMessageLabels) ResourceLink(com.synopsys.integration.blackduck.api.core.ResourceLink) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) LinkableItem(com.synopsys.integration.alert.common.message.model.LinkableItem) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)

Example 8 with ComponentVersionUpgradeGuidanceView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationMessageExtractorTest method createBomComponentDetailsTest.

@Test
public void createBomComponentDetailsTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    ProjectVersionComponentVersionView projectVersionComponentVersionView = createProjectVersionComponentVersionView(true);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class))).thenReturn(projectVersionComponentVersionView);
    ComponentVersionUpgradeGuidanceView componentVersionUpgradeGuidanceView = createComponentVersionUpgradeGuidanceView();
    // A UrlSingleResponse is needed to Mock the blackDuckApiClient in BlackDuckMessageComponentVersionUpgradeGuidanceService::requestUpgradeGuidanceItems
    UrlSingleResponse<ComponentVersionUpgradeGuidanceView> urlSingleResponse = new UrlSingleResponse<>(new HttpUrl(UPGRADE_GUIDANCE_URL), ComponentVersionUpgradeGuidanceView.class);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.eq(urlSingleResponse))).thenReturn(componentVersionUpgradeGuidanceView);
    VulnerabilityUniqueProjectNotificationContent notificationContent = createVulnerabilityUniqueProjectNotificationContent();
    List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    assertEquals(1, bomComponentDetailsList.size());
    BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
    assertEquals(COMPONENT, testBomComponentDetails.getComponent());
    assertTrue(testBomComponentDetails.getComponentVersion().isPresent());
    assertEquals(COMPONENT_VERSION.getValue(), testBomComponentDetails.getComponentVersion().get().getValue());
    assertEquals(LICENSE_DISPLAY, testBomComponentDetails.getLicense().getValue());
    assertEquals(UsageType.DYNAMICALLY_LINKED.prettyPrint(), testBomComponentDetails.getUsage());
    assertTrue(testBomComponentDetails.getAdditionalAttributes().isEmpty());
    assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
    assertNotNull(testBomComponentDetails.getComponentVulnerabilities());
    assertEquals(3, testBomComponentDetails.getComponentConcerns().size());
    ComponentUpgradeGuidance componentUpgradeGuidance = testBomComponentDetails.getComponentUpgradeGuidance();
    assertTrue(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
    assertTrue(componentUpgradeGuidance.getShortTermUpgradeGuidance().isPresent());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) HttpUrl(com.synopsys.integration.rest.HttpUrl) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) BomComponentDetails(com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails) Test(org.junit.jupiter.api.Test)

Example 9 with ComponentVersionUpgradeGuidanceView

use of com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView in project hub-alert by blackducksoftware.

the class BlackDuckMessageComponentVersionUpgradeGuidanceServiceTest method requestUpgradeGuidanceItemsBomTest.

@Test
public void requestUpgradeGuidanceItemsBomTest() throws IntegrationException {
    HttpUrl httpUrl = new HttpUrl("https://fake-url");
    UrlSingleResponse<ComponentVersionUpgradeGuidanceView> expectedUrl = new UrlSingleResponse<>(httpUrl, ComponentVersionUpgradeGuidanceView.class);
    ComponentVersionUpgradeGuidanceView upgradeGuidanceView = createUpgradeGuidance(true);
    BlackDuckApiClient blackDuckApiClient = createBlackDuckApiClient(expectedUrl, upgradeGuidanceView);
    LinkSingleResponse<ComponentVersionUpgradeGuidanceView> upgradeGuidanceLink = new LinkSingleResponse<>("upgrade-guidance", ComponentVersionUpgradeGuidanceView.class);
    ProjectVersionComponentVersionView bomComponent = createBomComponent(upgradeGuidanceLink, expectedUrl);
    BlackDuckMessageComponentVersionUpgradeGuidanceService upgradeGuidanceService = new BlackDuckMessageComponentVersionUpgradeGuidanceService(blackDuckApiClient);
    ComponentUpgradeGuidance componentUpgradeGuidance = upgradeGuidanceService.requestUpgradeGuidanceItems(bomComponent);
    assertTrue(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
    assertTrue(componentUpgradeGuidance.getShortTermUpgradeGuidance().isPresent());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) LinkSingleResponse(com.synopsys.integration.blackduck.api.core.response.LinkSingleResponse) HttpUrl(com.synopsys.integration.rest.HttpUrl) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Aggregations

ComponentVersionUpgradeGuidanceView (com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)9 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)7 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)7 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)7 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)7 HttpUrl (com.synopsys.integration.rest.HttpUrl)7 Test (org.junit.jupiter.api.Test)6 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)4 VulnerabilityUniqueProjectNotificationContent (com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent)4 ComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView)4 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)4 LinkSingleResponse (com.synopsys.integration.blackduck.api.core.response.LinkSingleResponse)2 ComponentVersionUpgradeGuidanceLongTermView (com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceLongTermView)2 ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView (com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView)2 ComponentVersionUpgradeGuidanceShortTermView (com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceShortTermView)2 ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView (com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView)2 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)2 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)1 BlackDuckMessageLabels (com.synopsys.integration.alert.provider.blackduck.processor.message.BlackDuckMessageLabels)1 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)1