Search in sources :

Example 21 with ProjectVersionComponentVersionView

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());
}
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 22 with ProjectVersionComponentVersionView

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);
}
Also used : ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 23 with ProjectVersionComponentVersionView

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);
}
Also used : ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 24 with ProjectVersionComponentVersionView

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);
}
Also used : ArrayList(java.util.ArrayList) UsageType(com.synopsys.integration.blackduck.api.generated.enumeration.UsageType) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView) Test(org.junit.jupiter.api.Test)

Example 25 with ProjectVersionComponentVersionView

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());
}
Also used : ComponentUpgradeGuidance(com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) 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

ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)34 HttpUrl (com.synopsys.integration.rest.HttpUrl)24 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)17 Test (org.junit.jupiter.api.Test)17 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)11 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)11 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)9 ProjectVersionComponentVersionLicensesView (com.synopsys.integration.blackduck.api.generated.component.ProjectVersionComponentVersionLicensesView)9 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)9 ResourceLink (com.synopsys.integration.blackduck.api.core.ResourceLink)6 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)5 ComponentConcern (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentConcern)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)3 ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)3 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)3 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)3 ArrayList (java.util.ArrayList)3 BlackDuckProviderKey (com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey)2 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)2