Search in sources :

Example 1 with UrlMultipleResponses

use of com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses in project hub-alert by blackducksoftware.

the class BlackDuckMessageBomComponentDetailsCreator method retrieveComponentVulnerabilities.

private ComponentVulnerabilities retrieveComponentVulnerabilities(ProjectVersionComponentVersionView bomComponent) throws IntegrationException {
    if (!vulnerabilityDetailsCreator.hasSecurityRisk(bomComponent)) {
        return ComponentVulnerabilities.none();
    }
    if (StringUtils.isBlank(bomComponent.getComponentVersion())) {
        return ComponentVulnerabilities.none();
    }
    List<HttpUrl> vulnerabilitiesUrls = createVulnerabilitiesLinks(bomComponent.getHref(), bomComponent.getOrigins());
    List<BlackDuckProjectVersionComponentVulnerabilitiesView> allVulnerabilitiesViews = new ArrayList<>();
    for (HttpUrl vulnerabilitiesUrl : vulnerabilitiesUrls) {
        UrlMultipleResponses<BlackDuckProjectVersionComponentVulnerabilitiesView> urlMultipleResponses = new UrlMultipleResponses<>(vulnerabilitiesUrl, VULNERABILITIES_LINK.getResponseClass());
        BlackDuckMultipleRequest<BlackDuckProjectVersionComponentVulnerabilitiesView> spec = new BlackDuckRequestBuilder().commonGet().addHeader(HttpHeaders.ACCEPT, VULNERABILITIES_MEDIA_TYPE).buildBlackDuckRequest(urlMultipleResponses);
        allVulnerabilitiesViews.addAll(blackDuckApiClient.getAllResponses(spec));
    }
    return vulnerabilityDetailsCreator.toComponentVulnerabilities(allVulnerabilitiesViews);
}
Also used : UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) ArrayList(java.util.ArrayList) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 2 with UrlMultipleResponses

use of com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses in project hub-alert by blackducksoftware.

the class BlackDuckNotificationRetrieverTest method retrievePageOfFilteredNotificationsTest.

@Test
public void retrievePageOfFilteredNotificationsTest() throws IntegrationException {
    ProjectNotificationUserView projectNotificationView = new ProjectNotificationUserView();
    BlackDuckPageResponse<NotificationUserView> pageResponse = new BlackDuckPageResponse<>(1, List.of(projectNotificationView));
    UrlMultipleResponses<NotificationUserView> currentUserNotificationsUrl = new UrlMultipleResponses<>(new HttpUrl(THROWAWAY_SERVER), NotificationUserView.class);
    UserView apiUser = Mockito.mock(UserView.class);
    Mockito.doReturn(currentUserNotificationsUrl).when(apiUser).metaNotificationsLink();
    UrlSingleResponse<UserView> currentUserUrl = new UrlSingleResponse<>(new HttpUrl(THROWAWAY_SERVER), UserView.class);
    ApiDiscovery apiDiscovery = Mockito.mock(ApiDiscovery.class);
    Mockito.doReturn(currentUserUrl).when(apiDiscovery).metaCurrentUserLink();
    BlackDuckApiClient blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
    Mockito.doReturn(pageResponse).when(blackDuckApiClient).getPageResponse(Mockito.any(BlackDuckMultipleRequest.class));
    Mockito.doReturn(apiUser).when(blackDuckApiClient).getResponse(Mockito.eq(currentUserUrl));
    BlackDuckAccumulatorSearchDateManager dateRangeCreator = createDateRangeCreator();
    BlackDuckNotificationRetriever notificationRetriever = new BlackDuckNotificationRetriever(blackDuckApiClient, apiDiscovery);
    StatefulAlertPage<NotificationUserView, IntegrationException> notificationPage = notificationRetriever.retrievePageOfFilteredNotifications(dateRangeCreator.retrieveNextSearchDateRange(), List.of());
    assertEquals(pageResponse.getItems(), notificationPage.getCurrentModels());
}
Also used : UrlSingleResponse(com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) ProjectNotificationUserView(com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView) Test(org.junit.jupiter.api.Test)

Aggregations

UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)1 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)1 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)1 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)1 ProjectNotificationUserView (com.synopsys.integration.blackduck.api.manual.view.ProjectNotificationUserView)1 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)1 BlackDuckRequestBuilder (com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)1 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)1 BlackDuckMultipleRequest (com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest)1 IntegrationException (com.synopsys.integration.exception.IntegrationException)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1