use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView 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());
}
use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.
the class BlackDuckComponentVulnerabilityDetailsCreatorTest method hasSecurityRiskFalseTest.
@Test
public void hasSecurityRiskFalseTest() {
BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
ProjectVersionComponentVersionView comp1 = createTestComponentView(0L, 0L, 0L, 0L, 0L, 0L);
assertFalse(vulnerabilityDetailsCreator.hasSecurityRisk(comp1), UNEXPECTED_RISK_MESSAGE);
ProjectVersionComponentVersionView comp2 = createTestComponentView(0L, 0L, 0L, 0L, 0L, 1L);
assertFalse(vulnerabilityDetailsCreator.hasSecurityRisk(comp2), UNEXPECTED_RISK_MESSAGE);
ProjectVersionComponentVersionView comp3 = createTestComponentView(0L, 0L, 0L, 0L, 0L, 10L);
assertFalse(vulnerabilityDetailsCreator.hasSecurityRisk(comp3), UNEXPECTED_RISK_MESSAGE);
}
use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.
the class BlackDuckComponentVulnerabilityDetailsCreatorTest method hasSecurityRiskTrueTest.
@Test
public void hasSecurityRiskTrueTest() {
BlackDuckComponentVulnerabilityDetailsCreator vulnerabilityDetailsCreator = new BlackDuckComponentVulnerabilityDetailsCreator();
ProjectVersionComponentVersionView comp1 = createTestComponentView(1L, 0L, 0L, 0L, 0L, 0L);
assertTrue(vulnerabilityDetailsCreator.hasSecurityRisk(comp1), EXPECTED_RISK_MESSAGE);
ProjectVersionComponentVersionView comp2 = createTestComponentView(0L, 5L, 0L, 0L, 0L, 0L);
assertTrue(vulnerabilityDetailsCreator.hasSecurityRisk(comp2), EXPECTED_RISK_MESSAGE);
ProjectVersionComponentVersionView comp3 = createTestComponentView(0L, 0L, 11L, 0L, 0L, 0L);
assertTrue(vulnerabilityDetailsCreator.hasSecurityRisk(comp3), EXPECTED_RISK_MESSAGE);
ProjectVersionComponentVersionView comp4 = createTestComponentView(0L, 0L, 0L, 4L, 0L, 0L);
assertTrue(vulnerabilityDetailsCreator.hasSecurityRisk(comp4), EXPECTED_RISK_MESSAGE);
ProjectVersionComponentVersionView comp5 = createTestComponentView(0L, 0L, 0L, 0L, 2L, 0L);
assertTrue(vulnerabilityDetailsCreator.hasSecurityRisk(comp5), EXPECTED_RISK_MESSAGE);
ProjectVersionComponentVersionView comp6 = createTestComponentView(1L, 0L, 1L, 0L, 1L, 0L);
assertTrue(vulnerabilityDetailsCreator.hasSecurityRisk(comp6), EXPECTED_RISK_MESSAGE);
}
use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.
the class BlackDuckMessageAttributesUtilsTest method testGetUsageLinkableItemsNullUsageIncluded.
@Test
public void testGetUsageLinkableItemsNullUsageIncluded() {
ProjectVersionComponentVersionView projectVersionComponentView = new ProjectVersionComponentVersionView();
List<UsageType> listWithNull = new ArrayList<>();
listWithNull.add(UsageType.PREREQUISITE);
listWithNull.add(null);
projectVersionComponentView.setUsages(listWithNull);
String usage = BlackDuckMessageAttributesUtils.extractUsage(projectVersionComponentView);
assertEquals(UsageType.PREREQUISITE.prettyPrint(), usage);
}
use of com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView in project hub-alert by blackducksoftware.
the class BomEditNotificationMessageExtractorTest 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();
Mockito.when(blackDuckApiClient.getResponse(Mockito.any(), Mockito.any())).thenReturn(projectVersionComponentVersionView);
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());
assertEquals(0, testBomComponentDetails.getComponentConcerns().size());
assertEquals(0, testBomComponentDetails.getAdditionalAttributes().size());
ComponentUpgradeGuidance componentUpgradeGuidance = testBomComponentDetails.getComponentUpgradeGuidance();
assertFalse(componentUpgradeGuidance.getLongTermUpgradeGuidance().isPresent());
assertFalse(componentUpgradeGuidance.getShortTermUpgradeGuidance().isPresent());
}
Aggregations