use of com.synopsys.integration.blackduck.api.manual.view.NotificationUserView 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.api.manual.view.NotificationUserView in project hub-alert by blackducksoftware.
the class BlackDuckNotificationRetriever method createNotificationsRequest.
private BlackDuckMultipleRequest<NotificationUserView> createNotificationsRequest(DateRange dateRange, List<String> notificationTypesToInclude) throws IntegrationException {
UserView currentUser = blackDuckApiClient.getResponse(apiDiscovery.metaCurrentUserLink());
UrlMultipleResponses<NotificationUserView> currentUserNotificationsUrl = currentUser.metaNotificationsLink();
NotificationEditor notificationEditor = new NotificationEditor(dateRange.getStart(), dateRange.getEnd(), notificationTypesToInclude);
BlackDuckMultipleRequest<NotificationUserView> spec = new BlackDuckRequestBuilder().commonGet().apply(notificationEditor).addQueryParameter("sort", String.format("%s asc", PAGE_SORT_FIELD)).buildBlackDuckRequest(currentUserNotificationsUrl);
return spec;
}
use of com.synopsys.integration.blackduck.api.manual.view.NotificationUserView in project hub-alert by blackducksoftware.
the class BlackDuckAccumulatorTest method createMockNotificationView.
private NotificationUserView createMockNotificationView() {
NotificationUserView notificationView = Mockito.mock(NotificationUserView.class);
Mockito.when(notificationView.getCreatedAt()).thenReturn(new Date());
Mockito.when(notificationView.getType()).thenReturn(NotificationType.PROJECT);
Mockito.when(notificationView.getJson()).thenReturn("{}");
return notificationView;
}
use of com.synopsys.integration.blackduck.api.manual.view.NotificationUserView in project hub-alert by blackducksoftware.
the class BlackDuckAccumulatorTest method runTest.
/**
* This test should simulate a normal run of the accumulator with notifications present.
*/
@Test
public void runTest() throws Exception {
ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
BlackDuckSystemValidator validator = createBlackDuckValidator(blackDuckProperties, true);
PageRetriever pageRetriever = Mockito.mock(PageRetriever.class);
StatefulAlertPage<NotificationUserView, IntegrationException> notificationPage = createMockNotificationPage(pageRetriever);
BlackDuckNotificationRetriever notificationRetriever = Mockito.mock(BlackDuckNotificationRetriever.class);
Mockito.when(notificationRetriever.retrievePageOfFilteredNotifications(Mockito.any(), Mockito.anyList())).thenReturn(notificationPage);
Mockito.when(pageRetriever.retrieveNextPage(Mockito.anyInt(), Mockito.anyInt())).thenReturn(AlertPagedDetails.emptyPage());
BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = createBlackDuckNotificationRetrieverFactory(blackDuckProperties, notificationRetriever);
NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
Mockito.when(notificationAccessor.saveAllNotifications(Mockito.anyList())).thenAnswer(invocation -> invocation.getArgument(0));
EventManager eventManager = Mockito.mock(EventManager.class);
Mockito.doNothing().when(eventManager).sendEvent(Mockito.any(NotificationReceivedEvent.class));
BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, notificationAccessor, taskPropertiesAccessor, blackDuckProperties, validator, eventManager, notificationRetrieverFactory);
accumulator.run();
Mockito.verify(notificationAccessor, Mockito.times(1)).saveAllNotifications(Mockito.anyList());
}
use of com.synopsys.integration.blackduck.api.manual.view.NotificationUserView in project hub-alert by blackducksoftware.
the class BlackDuckAccumulatorTest method createMockNotificationPage.
private StatefulAlertPage<NotificationUserView, IntegrationException> createMockNotificationPage(PageRetriever pageRetriever) throws IntegrationException {
NotificationUserView notificationView = createMockNotificationView();
AlertPagedDetails<NotificationUserView> alertPagedDetails = new AlertPagedDetails<>(1, 0, 1, List.of(notificationView));
return new StatefulAlertPage<>(alertPagedDetails, pageRetriever, BlackDuckNotificationRetriever.HAS_NEXT_PAGE);
}
Aggregations