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());
}
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;
}
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;
}
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());
}
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());
}
Aggregations