Search in sources :

Example 1 with ComponentVersionUpgradeGuidanceView

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

the class BlackDuckMessageComponentVersionUpgradeGuidanceServiceTest method requestUpgradeGuidanceItemsComponentTest.

@Test
public void requestUpgradeGuidanceItemsComponentTest() throws IntegrationException {
    HttpUrl httpUrl = new HttpUrl("https://fake-url");
    UrlSingleResponse<ComponentVersionUpgradeGuidanceView> expectedUrl = new UrlSingleResponse<>(httpUrl, ComponentVersionUpgradeGuidanceView.class);
    ComponentVersionUpgradeGuidanceView upgradeGuidanceView = createUpgradeGuidance(false);
    BlackDuckApiClient blackDuckApiClient = createBlackDuckApiClient(expectedUrl, upgradeGuidanceView);
    ComponentVersionView componentVersion = createComponentVersion(expectedUrl);
    BlackDuckMessageComponentVersionUpgradeGuidanceService upgradeGuidanceService = new BlackDuckMessageComponentVersionUpgradeGuidanceService(blackDuckApiClient);
    ComponentUpgradeGuidance componentUpgradeGuidance = upgradeGuidanceService.requestUpgradeGuidanceItems(componentVersion);
    assertTrue(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
    assertFalse(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) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) HttpUrl(com.synopsys.integration.rest.HttpUrl) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) Test(org.junit.jupiter.api.Test)

Example 2 with ComponentVersionUpgradeGuidanceView

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

the class BlackDuckMessageComponentVersionUpgradeGuidanceServiceTest method createUpgradeGuidance.

private ComponentVersionUpgradeGuidanceView createUpgradeGuidance(boolean includeShortTerm) {
    ComponentVersionUpgradeGuidanceView upgradeGuidanceView = new ComponentVersionUpgradeGuidanceView();
    if (includeShortTerm) {
        ComponentVersionUpgradeGuidanceShortTermView shortTermView = new ComponentVersionUpgradeGuidanceShortTermView();
        ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView shortTermRiskView = new ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView();
        shortTermRiskView.setCritical(BigDecimal.ZERO);
        shortTermRiskView.setHigh(BigDecimal.ZERO);
        shortTermRiskView.setMedium(BigDecimal.ZERO);
        shortTermRiskView.setLow(BigDecimal.ZERO);
        shortTermView.setVulnerabilityRisk(shortTermRiskView);
        upgradeGuidanceView.setShortTerm(shortTermView);
    }
    ComponentVersionUpgradeGuidanceLongTermView longTermView = new ComponentVersionUpgradeGuidanceLongTermView();
    ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView longTermRiskView = new ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView();
    longTermRiskView.setCritical(BigDecimal.TEN);
    longTermRiskView.setHigh(BigDecimal.valueOf(20L));
    longTermRiskView.setMedium(BigDecimal.valueOf(30L));
    longTermRiskView.setLow(BigDecimal.valueOf(40L));
    longTermView.setVulnerabilityRisk(longTermRiskView);
    upgradeGuidanceView.setLongTerm(longTermView);
    return upgradeGuidanceView;
}
Also used : ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView) ComponentVersionUpgradeGuidanceShortTermView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceShortTermView) ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView) ComponentVersionUpgradeGuidanceLongTermView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceLongTermView) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)

Example 3 with ComponentVersionUpgradeGuidanceView

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

the class VulnerabilityNotificationMessageExtractorTest method createComponentVersionUpgradeGuidanceView.

private ComponentVersionUpgradeGuidanceView createComponentVersionUpgradeGuidanceView() {
    ComponentVersionUpgradeGuidanceView componentVersionUpgradeGuidanceView = new ComponentVersionUpgradeGuidanceView();
    ComponentVersionUpgradeGuidanceShortTermView shortTermView = new ComponentVersionUpgradeGuidanceShortTermView();
    shortTermView.setOrigin("http://upgradeGuidanceOriginUrlShortTerm");
    shortTermView.setOriginExternalId("upgradeGuidanceExternalIdShortTerm");
    shortTermView.setOriginExternalNamespace("upgradeGuidanceExternalNamespaceShortTerm");
    shortTermView.setOriginName("upgradeGuidanceOriginNameShortTerm");
    shortTermView.setVersion("http://upgradeGuidanceVersionShorTerm");
    shortTermView.setVersionName("upgradeGuidanceVersionNameShortTerm");
    ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView shortTermRiskView = new ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView();
    shortTermRiskView.setCritical(BigDecimal.ZERO);
    shortTermRiskView.setHigh(BigDecimal.ZERO);
    shortTermRiskView.setMedium(BigDecimal.ZERO);
    shortTermRiskView.setLow(BigDecimal.ZERO);
    shortTermView.setVulnerabilityRisk(shortTermRiskView);
    componentVersionUpgradeGuidanceView.setShortTerm(shortTermView);
    ComponentVersionUpgradeGuidanceLongTermView longTermView = new ComponentVersionUpgradeGuidanceLongTermView();
    longTermView.setOrigin("http://upgradeGuidanceOriginUrlLongTerm");
    longTermView.setOriginExternalId("upgradeGuidanceExternalIdLongTerm");
    longTermView.setOriginExternalNamespace("upgradeGuidanceExternalNamespaceLongTerm");
    longTermView.setOriginName("upgradeGuidanceOriginNameLongTerm");
    longTermView.setVersion("http://upgradeGuidanceVersionLongTerm");
    longTermView.setVersionName("upgradeGuidanceVersionNameLongTerm");
    ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView longTermRiskView = new ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView();
    longTermRiskView.setCritical(BigDecimal.ZERO);
    longTermRiskView.setHigh(BigDecimal.ZERO);
    longTermRiskView.setMedium(BigDecimal.ZERO);
    longTermRiskView.setLow(BigDecimal.ZERO);
    longTermView.setVulnerabilityRisk(longTermRiskView);
    componentVersionUpgradeGuidanceView.setLongTerm(longTermView);
    return componentVersionUpgradeGuidanceView;
}
Also used : ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceLongTermVulnerabilityRiskView) ComponentVersionUpgradeGuidanceShortTermView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceShortTermView) ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceShortTermVulnerabilityRiskView) ComponentVersionUpgradeGuidanceLongTermView(com.synopsys.integration.blackduck.api.generated.component.ComponentVersionUpgradeGuidanceLongTermView) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)

Example 4 with ComponentVersionUpgradeGuidanceView

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

the class VulnerabilityNotificationMessageExtractorTest method createBomComponentDetailsMissingBomComponentTest.

@Test
public void createBomComponentDetailsMissingBomComponentTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    Mockito.doThrow(new IntegrationRestException(HttpMethod.GET, new HttpUrl("https://google.com"), HttpStatus.NOT_FOUND.value(), "httpStatusMessageTest", "httpResponseContentTest", "IntegrationRestExceptionForAlertTest")).when(blackDuckApiClient).getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class));
    ComponentVersionView componentVersionView = createComponentVersionView();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ComponentVersionView.class))).thenReturn(componentVersionView);
    ComponentVersionUpgradeGuidanceView componentVersionUpgradeGuidanceView = createComponentVersionUpgradeGuidanceView();
    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());
    assertTrue(testBomComponentDetails.getRelevantPolicies().isEmpty());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_LICENSE, testBomComponentDetails.getLicense().getValue());
    assertEquals(BlackDuckMessageLabels.VALUE_UNKNOWN_USAGE, testBomComponentDetails.getUsage());
    assertTrue(testBomComponentDetails.getAdditionalAttributes().isEmpty());
    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) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) 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 5 with ComponentVersionUpgradeGuidanceView

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

the class VulnerabilityNotificationMessageExtractorTest method safelyRetrieveItemsEmptyTest.

@Test
public void safelyRetrieveItemsEmptyTest() throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
    Mockito.doThrow(new IntegrationRestException(HttpMethod.GET, new HttpUrl("https://google.com"), HttpStatus.NOT_FOUND.value(), "httpStatusMessageTest", "httpResponseContentTest", "IntegrationRestExceptionForAlertTest")).when(blackDuckApiClient).getResponse(Mockito.any(), Mockito.eq(ProjectVersionComponentVersionView.class));
    ComponentVersionView componentVersionView = createComponentVersionView();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.eq(ComponentVersionView.class))).thenReturn(componentVersionView);
    UrlSingleResponse<ComponentVersionUpgradeGuidanceView> urlSingleResponse = new UrlSingleResponse<>(new HttpUrl(UPGRADE_GUIDANCE_URL), ComponentVersionUpgradeGuidanceView.class);
    Mockito.doThrow(new IntegrationRestException(HttpMethod.GET, new HttpUrl("https://google.com"), HttpStatus.NOT_FOUND.value(), "httpStatusMessageTest", "httpResponseContentTest", "IntegrationRestExceptionForAlertTest")).when(blackDuckApiClient).getResponse(Mockito.eq(urlSingleResponse));
    VulnerabilityUniqueProjectNotificationContent notificationContent = createVulnerabilityUniqueProjectNotificationContent();
    List<BomComponentDetails> bomComponentDetailsList = extractor.createBomComponentDetails(notificationContent, blackDuckServicesFactory);
    assertEquals(1, bomComponentDetailsList.size());
    BomComponentDetails testBomComponentDetails = bomComponentDetailsList.get(0);
    ComponentUpgradeGuidance componentUpgradeGuidance = testBomComponentDetails.getComponentUpgradeGuidance();
    assertFalse(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
    assertFalse(componentUpgradeGuidance.getShortTermUpgradeGuidance().isPresent());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) HttpUrl(com.synopsys.integration.rest.HttpUrl) ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) ComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ComponentVersionView) ComponentVersionUpgradeGuidanceView(com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView) 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)

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