Search in sources :

Example 1 with BlackDuckPageResponse

use of com.synopsys.integration.blackduck.http.BlackDuckPageResponse in project hub-alert by blackducksoftware.

the class ProviderDataAccessorTest method getProjectVersionsByHrefTest.

@Test
void getProjectVersionsByHrefTest() throws IntegrationException {
    ProjectView projectView = createProjectViewWithVersionsLink();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenReturn(projectView);
    ProjectVersionView projectVersionView = new ProjectVersionView();
    String versionName = "versionName";
    int totalPages = 1;
    projectVersionView.setVersionName(versionName);
    BlackDuckPageResponse blackDuckPageResponse = new BlackDuckPageResponse(totalPages, List.of(projectVersionView));
    Mockito.when(blackDuckApiClient.getPageResponse(Mockito.any())).thenReturn(blackDuckPageResponse);
    BlackDuckProviderDataAccessor blackDuckProviderDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
    AlertPagedModel<String> projectVersionNamesByHref = blackDuckProviderDataAccessor.getProjectVersionNamesByHref(1L, HREF_1, 1);
    assertNotNull(projectVersionNamesByHref);
    assertEquals(totalPages, projectVersionNamesByHref.getTotalPages());
    Optional<String> firstFoundProjectVersion = projectVersionNamesByHref.getModels().stream().findFirst();
    assertTrue(firstFoundProjectVersion.isPresent());
    String foundVersionName = firstFoundProjectVersion.get();
    assertEquals(versionName, foundVersionName);
}
Also used : ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) Test(org.junit.jupiter.api.Test)

Example 2 with BlackDuckPageResponse

use of com.synopsys.integration.blackduck.http.BlackDuckPageResponse in project hub-alert by blackducksoftware.

the class ProviderDataAccessorTest method getProjectVersionsByHrefWithNoConfigTest.

@Test
void getProjectVersionsByHrefWithNoConfigTest() throws IntegrationException {
    ProjectView projectView = createProjectViewWithVersionsLink();
    Mockito.when(blackDuckApiClient.getResponse(Mockito.any(HttpUrl.class), Mockito.eq(ProjectView.class))).thenReturn(projectView);
    ProjectVersionView projectVersionView = new ProjectVersionView();
    String versionName = "versionName";
    int totalPages = 1;
    projectVersionView.setVersionName(versionName);
    BlackDuckPageResponse blackDuckPageResponse = new BlackDuckPageResponse(totalPages, List.of(projectVersionView));
    Mockito.when(blackDuckApiClient.getPageResponse(Mockito.any())).thenReturn(blackDuckPageResponse);
    BlackDuckProviderDataAccessor blackDuckProviderDataAccessor = new BlackDuckProviderDataAccessor(configurationModelConfigurationAccessor, blackDuckPropertiesFactory);
    AlertPagedModel<String> projectVersionNamesByHref = blackDuckProviderDataAccessor.getProjectVersionNamesByHref(999L, HREF_1, 1);
    assertNotNull(projectVersionNamesByHref);
    assertEquals(0, projectVersionNamesByHref.getTotalPages());
}
Also used : ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) HttpUrl(com.synopsys.integration.rest.HttpUrl) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) Test(org.junit.jupiter.api.Test)

Example 3 with BlackDuckPageResponse

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

Example 4 with BlackDuckPageResponse

use of com.synopsys.integration.blackduck.http.BlackDuckPageResponse in project hub-alert by blackducksoftware.

the class BlackDuckProviderDataAccessor method retrieveUsersForProvider.

private AlertPagedModel<ProviderUserModel> retrieveUsersForProvider(ConfigurationModel blackDuckConfigurationModel, int pageNumber, int pageSize, String searchTerm) throws IntegrationException {
    BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(blackDuckConfigurationModel);
    Predicate<UserView> searchFilter = userView -> StringUtils.isNotBlank(userView.getEmail());
    if (StringUtils.isNotBlank(searchTerm)) {
        searchFilter = searchFilter.and(userView -> StringUtils.containsIgnoreCase(userView.getEmail(), searchTerm));
    }
    ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
    BlackDuckPageResponse<UserView> pageOfUsers = retrieveBlackDuckPageResponse(blackDuckServicesFactory, apiDiscovery.metaUsersLink(), pageNumber, pageSize, searchFilter);
    List<ProviderUserModel> foundUsers = pageOfUsers.getItems().stream().map(UserView::getEmail).map(email -> new ProviderUserModel(email, false)).collect(Collectors.toList());
    // Due to a limitation in the blackduck-common library, the totalCount in the BlackDuckPageResponse does not represent the count the matches the searchFilter. It is the totalCount from Black Duck
    int totalPageCount = computeTotalCount(pageOfUsers, pageSize);
    return new AlertPagedModel<>(totalPageCount, pageNumber, pageSize, foundUsers);
}
Also used : ProviderDataAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor) IntegrationException(com.synopsys.integration.exception.IntegrationException) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) BlackDuckResponse(com.synopsys.integration.blackduck.api.core.BlackDuckResponse) BlackDuckPageDefinition(com.synopsys.integration.blackduck.http.BlackDuckPageDefinition) LoggerFactory(org.slf4j.LoggerFactory) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) StringUtils(org.apache.commons.lang3.StringUtils) BlackDuckMultipleRequest(com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest) IntLogger(com.synopsys.integration.log.IntLogger) HttpUrl(com.synopsys.integration.rest.HttpUrl) ArrayList(java.util.ArrayList) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) ProjectService(com.synopsys.integration.blackduck.service.dataservice.ProjectService) Map(java.util.Map) UrlMultipleResponses(com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) BlackDuckPageResponse(com.synopsys.integration.blackduck.http.BlackDuckPageResponse) BlackDuckPropertiesFactory(com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory) BlackDuckQuery(com.synopsys.integration.blackduck.http.BlackDuckQuery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) BlackDuckApiClient(com.synopsys.integration.blackduck.service.BlackDuckApiClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) ProjectVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) BlackDuckResponsesTransformer(com.synopsys.integration.blackduck.http.transform.BlackDuckResponsesTransformer) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) Nullable(org.jetbrains.annotations.Nullable) ProviderProject(com.synopsys.integration.alert.common.persistence.model.ProviderProject) List(java.util.List) Component(org.springframework.stereotype.Component) ProjectUsersService(com.synopsys.integration.blackduck.service.dataservice.ProjectUsersService) ThrowingSupplier(com.synopsys.integration.function.ThrowingSupplier) Optional(java.util.Optional) ProjectView(com.synopsys.integration.blackduck.api.generated.view.ProjectView) UserService(com.synopsys.integration.blackduck.service.dataservice.UserService) ProviderUserModel(com.synopsys.integration.alert.common.persistence.model.ProviderUserModel) ApiDiscovery(com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) AlertPagedModel(com.synopsys.integration.alert.common.rest.model.AlertPagedModel) BlackDuckServicesFactory(com.synopsys.integration.blackduck.service.BlackDuckServicesFactory)

Aggregations

BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)4 HttpUrl (com.synopsys.integration.rest.HttpUrl)4 ProjectVersionView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionView)3 ProjectView (com.synopsys.integration.blackduck.api.generated.view.ProjectView)3 Test (org.junit.jupiter.api.Test)3 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 BlackDuckMultipleRequest (com.synopsys.integration.blackduck.service.request.BlackDuckMultipleRequest)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)1 ProviderDataAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderDataAccessor)1 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)1 ProviderProject (com.synopsys.integration.alert.common.persistence.model.ProviderProject)1 ProviderUserModel (com.synopsys.integration.alert.common.persistence.model.ProviderUserModel)1 AlertPagedModel (com.synopsys.integration.alert.common.rest.model.AlertPagedModel)1 BlackDuckPropertiesFactory (com.synopsys.integration.alert.provider.blackduck.factory.BlackDuckPropertiesFactory)1