Search in sources :

Example 1 with ProviderTaskPropertiesAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor in project hub-alert by blackducksoftware.

the class BlackDuckNotificationRetrieverTest method createDateRangeCreator.

private BlackDuckAccumulatorSearchDateManager createDateRangeCreator() {
    ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
    Mockito.when(taskPropertiesAccessor.getTaskProperty(Mockito.anyString(), Mockito.anyString())).thenReturn(Optional.empty());
    return new BlackDuckAccumulatorSearchDateManager(taskPropertiesAccessor, 0L, "Task");
}
Also used : ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)

Example 2 with ProviderTaskPropertiesAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor in project hub-alert by blackducksoftware.

the class BlackDuckAccumulatorTest method runCreateNotificationRetrieverEmptyTest.

@Test
public void runCreateNotificationRetrieverEmptyTest() {
    ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
    BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
    BlackDuckSystemValidator validator = createBlackDuckValidator(blackDuckProperties, true);
    BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = createBlackDuckNotificationRetrieverFactory(blackDuckProperties, null);
    BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, null, taskPropertiesAccessor, blackDuckProperties, validator, null, notificationRetrieverFactory);
    accumulator.run();
    Mockito.verify(taskPropertiesAccessor, Mockito.times(0)).getTaskProperty(Mockito.anyString(), Mockito.anyString());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) Test(org.junit.jupiter.api.Test)

Example 3 with ProviderTaskPropertiesAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor in project hub-alert by blackducksoftware.

the class BlackDuckAccumulatorSearchDateManagerTest method formatDateTest.

@Test
public void formatDateTest() throws ParseException {
    ProviderTaskPropertiesAccessor mockTaskPropsAccessor = createMockTaskPropertiesAccessor();
    BlackDuckAccumulatorSearchDateManager dateManager = new BlackDuckAccumulatorSearchDateManager(mockTaskPropsAccessor, 0L, "Task");
    OffsetDateTime currentDate = DateUtils.createCurrentDateTimestamp();
    dateManager.saveNextSearchStart(currentDate);
    String currentDateString = DateUtils.formatDateAsJsonString(currentDate);
    OffsetDateTime currentDateDeserialized = DateUtils.parseDateFromJsonString(currentDateString);
    DateRange dateRange = dateManager.retrieveNextSearchDateRange();
    OffsetDateTime nextSearchStart = dateRange.getStart();
    assertEquals(currentDateDeserialized, nextSearchStart);
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) OffsetDateTime(java.time.OffsetDateTime) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) Test(org.junit.jupiter.api.Test)

Example 4 with ProviderTaskPropertiesAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor in project hub-alert by blackducksoftware.

the class BlackDuckAccumulatorSearchDateManagerTest method createDateManager.

private BlackDuckAccumulatorSearchDateManager createDateManager(String expectedDate) {
    ProviderTaskPropertiesAccessor mockTaskPropsAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
    Mockito.when(mockTaskPropsAccessor.getTaskProperty(Mockito.anyString(), Mockito.anyString())).thenReturn(Optional.ofNullable(expectedDate));
    return new BlackDuckAccumulatorSearchDateManager(mockTaskPropsAccessor, 0L, "Task");
}
Also used : ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)

Example 5 with ProviderTaskPropertiesAccessor

use of com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor 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)

Aggregations

ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)6 Test (org.junit.jupiter.api.Test)4 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)3 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)3 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 EventManager (com.synopsys.integration.alert.api.event.EventManager)1 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)1 DateRange (com.synopsys.integration.alert.common.message.model.DateRange)1 PageRetriever (com.synopsys.integration.alert.processor.api.filter.PageRetriever)1 NotificationUserView (com.synopsys.integration.blackduck.api.manual.view.NotificationUserView)1 OffsetDateTime (java.time.OffsetDateTime)1