use of com.synopsys.integration.rest.HttpUrl 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.rest.HttpUrl in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationMessageExtractorTest method createProjectVersionComponentVersionView.
private ProjectVersionComponentVersionView createProjectVersionComponentVersionView(boolean withOrigin) throws IntegrationException {
ProjectVersionComponentVersionView projectVersionComponentVersionView = new ProjectVersionComponentVersionView();
projectVersionComponentVersionView.setComponentName(COMPONENT.getValue());
projectVersionComponentVersionView.setComponentVersion(COMPONENT_VERSION_URL);
projectVersionComponentVersionView.setComponentVersionName(COMPONENT_VERSION.getValue());
projectVersionComponentVersionView.setPolicyStatus(ProjectVersionComponentPolicyStatusType.IN_VIOLATION);
projectVersionComponentVersionView.setUsages(List.of(UsageType.DYNAMICALLY_LINKED));
ProjectVersionComponentVersionLicensesView projectVersionComponentVersionLicensesView = new ProjectVersionComponentVersionLicensesView();
projectVersionComponentVersionLicensesView.setLicense("http://licenseLink");
projectVersionComponentVersionLicensesView.setLicenseDisplay(LICENSE_DISPLAY);
projectVersionComponentVersionView.setLicenses(List.of(projectVersionComponentVersionLicensesView));
ResourceLink resourceLink = new ResourceLink();
resourceLink.setHref(new HttpUrl("https://policyRulesLink"));
resourceLink.setRel("policy-rules");
ResourceMetadata meta = new ResourceMetadata();
meta.setHref(new HttpUrl("https://bomComponentHref"));
meta.setLinks(List.of(resourceLink));
projectVersionComponentVersionView.setMeta(meta);
ResourceLink resourceLinkUpgradeGuidance = new ResourceLink();
resourceLinkUpgradeGuidance.setHref(new HttpUrl(UPGRADE_GUIDANCE_URL));
resourceLinkUpgradeGuidance.setRel("upgrade-guidance");
ResourceMetadata metaUpgradeGuidance = new ResourceMetadata();
metaUpgradeGuidance.setHref(new HttpUrl("https://upgradeGuidance"));
metaUpgradeGuidance.setLinks(List.of(resourceLinkUpgradeGuidance));
RiskProfileView riskProfileView = new RiskProfileView();
RiskProfileCountsView riskProfileCountsView = new RiskProfileCountsView();
riskProfileCountsView.setCount(BigDecimal.ONE);
riskProfileCountsView.setCountType(RiskPriorityType.HIGH);
riskProfileView.setCounts(List.of(riskProfileCountsView));
projectVersionComponentVersionView.setSecurityRiskProfile(riskProfileView);
if (withOrigin) {
VersionBomOriginView versionBomOriginView = new VersionBomOriginView();
versionBomOriginView.setMeta(metaUpgradeGuidance);
projectVersionComponentVersionView.setOrigins(List.of(versionBomOriginView));
} else {
projectVersionComponentVersionView.setOrigins(List.of());
}
return projectVersionComponentVersionView;
}
use of com.synopsys.integration.rest.HttpUrl 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());
}
use of com.synopsys.integration.rest.HttpUrl in project hub-alert by blackducksoftware.
the class VulnerabilityNotificationMessageExtractorTest method createComponentVersionView.
private ComponentVersionView createComponentVersionView() throws IntegrationException {
ComponentVersionView componentVersionView = new ComponentVersionView();
ResourceLink resourceLinkUpgradeGuidance = new ResourceLink();
resourceLinkUpgradeGuidance.setHref(new HttpUrl(UPGRADE_GUIDANCE_URL));
resourceLinkUpgradeGuidance.setRel("upgrade-guidance");
ResourceMetadata metaUpgradeGuidance = new ResourceMetadata();
metaUpgradeGuidance.setHref(new HttpUrl("https://upgradeGuidance"));
metaUpgradeGuidance.setLinks(List.of(resourceLinkUpgradeGuidance));
componentVersionView.setMeta(metaUpgradeGuidance);
return componentVersionView;
}
use of com.synopsys.integration.rest.HttpUrl 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());
}
Aggregations