Search in sources :

Example 6 with BlackDuckApiClient

use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.

the class BlackDuckMessageComponentVersionUpgradeGuidanceServiceTest method createBlackDuckApiClient.

private BlackDuckApiClient createBlackDuckApiClient(UrlSingleResponse<ComponentVersionUpgradeGuidanceView> expectedArg, ComponentVersionUpgradeGuidanceView expectedReturn) throws IntegrationException {
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.when(blackDuckApiClient.getResponse(Mockito.eq(expectedArg))).thenReturn(expectedReturn);
    return blackDuckApiClient;
}
Also used : BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient)

Example 7 with BlackDuckApiClient

use of com.synopsys.integration.blackduck.service.BlackDuckApiClient in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationMessageExtractorTest method retrieveComponentVersionViewEmptyTest.

@Test
public void retrieveComponentVersionViewEmptyTest() 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));
    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(ComponentVersionView.class));
    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 : IntegrationRestException(com.synopsys.integration.rest.exception.IntegrationRestException) 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) VulnerabilityUniqueProjectNotificationContent(com.synopsys.integration.alert.provider.blackduck.processor.model.VulnerabilityUniqueProjectNotificationContent) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) 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 8 with BlackDuckApiClient

use of com.synopsys.integration.blackduck.service.BlackDuckApiClient 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 9 with BlackDuckApiClient

use of com.synopsys.integration.blackduck.service.BlackDuckApiClient 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)

Example 10 with BlackDuckApiClient

use of com.synopsys.integration.blackduck.service.BlackDuckApiClient 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());
}
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)

Aggregations

BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)47 HttpUrl (com.synopsys.integration.rest.HttpUrl)36 BlackDuckServicesFactory (com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)28 Test (org.junit.jupiter.api.Test)24 ProjectVersionComponentVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)21 BomComponentDetails (com.synopsys.integration.alert.processor.api.extract.model.project.BomComponentDetails)19 ComponentUpgradeGuidance (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentUpgradeGuidance)14 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)13 IntegrationException (com.synopsys.integration.exception.IntegrationException)10 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)9 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)9 ResourceMetadata (com.synopsys.integration.blackduck.api.core.ResourceMetadata)7 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)7 PolicyRuleView (com.synopsys.integration.blackduck.api.generated.view.PolicyRuleView)7 ComponentPolicy (com.synopsys.integration.alert.processor.api.extract.model.project.ComponentPolicy)6 ComponentVersionUpgradeGuidanceView (com.synopsys.integration.blackduck.api.generated.response.ComponentVersionUpgradeGuidanceView)6 ComponentPolicyRulesView (com.synopsys.integration.blackduck.api.generated.view.ComponentPolicyRulesView)6 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)5 BlackDuckMessageBomComponentDetailsCreator (com.synopsys.integration.alert.provider.blackduck.processor.message.service.BlackDuckMessageBomComponentDetailsCreator)5 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)5