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);
}
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());
}
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());
}
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);
}
Aggregations