Search in sources :

Example 1 with NotificationUserView

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());
}
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 2 with NotificationUserView

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;
}
Also used : NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) UserView(com.synopsys.integration.blackduck.api.generated.view.UserView) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) NotificationEditor(com.synopsys.integration.blackduck.service.request.NotificationEditor) BlackDuckRequestBuilder(com.synopsys.integration.blackduck.http.BlackDuckRequestBuilder)

Example 3 with NotificationUserView

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;
}
Also used : NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) Date(java.util.Date)

Example 4 with NotificationUserView

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());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) IntegrationException(com.synopsys.integration.exception.IntegrationException) EventManager(com.synopsys.integration.alert.api.event.EventManager) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) Test(org.junit.jupiter.api.Test)

Example 5 with NotificationUserView

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);
}
Also used : StatefulAlertPage(com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage) AlertPagedDetails(com.synopsys.integration.alert.common.rest.model.AlertPagedDetails) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)

Aggregations

NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)5 UserView (com.synopsys.integration.blackduck.api.generated.view.UserView)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 Test (org.junit.jupiter.api.Test)2 EventManager (com.synopsys.integration.alert.api.event.EventManager)1 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)1 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)1 ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)1 AlertPagedDetails (com.synopsys.integration.alert.common.rest.model.AlertPagedDetails)1 PageRetriever (com.synopsys.integration.alert.processor.api.filter.PageRetriever)1 StatefulAlertPage (com.synopsys.integration.alert.processor.api.filter.StatefulAlertPage)1 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)1 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)1 UrlMultipleResponses (com.synopsys.integration.blackduck.api.core.response.UrlMultipleResponses)1 UrlSingleResponse (com.synopsys.integration.blackduck.api.core.response.UrlSingleResponse)1 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)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