use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.
the class ProcessingTask method process.
private void process() {
DateRange dateRange = getDateRange();
AlertPagedModel<AlertNotificationModel> page = read(dateRange, AlertPagedModel.DEFAULT_PAGE_NUMBER, PAGE_SIZE);
int currentPage = page.getCurrentPage();
int totalPages = page.getTotalPages();
while (!page.getModels().isEmpty() || currentPage < totalPages) {
List<AlertNotificationModel> notificationList = page.getModels();
logger.info("Processing page {} of {}. {} notifications to process.", currentPage, totalPages, notificationList.size());
notificationProcessor.processNotifications(notificationList, List.of(frequencyType));
page = read(dateRange, currentPage + 1, PAGE_SIZE);
currentPage = page.getCurrentPage();
totalPages = page.getTotalPages();
}
}
use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.
the class BlackDuckAccumulatorSearchDateManagerTest method retrieveDateRangeWithExistingFileTest.
@Test
public void retrieveDateRangeWithExistingFileTest() {
OffsetDateTime expectedStartDate = ZonedDateTime.now(ZoneOffset.UTC).withSecond(0).withNano(0).minusMinutes(5).toOffsetDateTime();
String expectedStartDateString = DateUtils.formatDateAsJsonString(expectedStartDate);
BlackDuckAccumulatorSearchDateManager dateRangeCreator = createDateManager(expectedStartDateString);
DateRange dateRange = dateRangeCreator.retrieveNextSearchDateRange();
assertNotNull(dateRange);
OffsetDateTime actualStartDate = dateRange.getStart();
OffsetDateTime actualEndDate = dateRange.getEnd();
assertEquals(expectedStartDate, actualStartDate);
assertNotEquals(actualStartDate, actualEndDate);
}
use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.
the class ProcessingTaskTest method testJobCountZero.
@Test
void testJobCountZero() {
TaskManager taskManager = Mockito.mock(TaskManager.class);
TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
NotificationAccessor notificationManager = new MockProcessingNotificationAccessor(List.of());
StaticJobAccessor jobAccessor = Mockito.mock(StaticJobAccessor.class);
Mockito.when(jobAccessor.hasJobsByFrequency(Mockito.any())).thenReturn(false);
NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
NotificationProcessor notificationProcessor = new NotificationProcessor(extractionDelegator, null, null, null, null, null);
ProcessingTask task = createTask(taskScheduler, notificationManager, notificationProcessor, taskManager, jobAccessor);
DateRange dateRange = task.getDateRange();
ProcessingTask processingTask = Mockito.spy(task);
processingTask.runTask();
Mockito.verify(processingTask, Mockito.times(0)).getDateRange();
}
use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.
the class ProcessingTaskTest method testDateRange.
@Test
void testDateRange() {
ProcessingTask task = createTask(null, null, null, null, null);
DateRange dateRange = task.getDateRange();
OffsetDateTime expectedEndDay = DateUtils.createCurrentDateTimestamp();
OffsetDateTime expectedStartDay = task.getLastRunTime();
ZonedDateTime actualStartDay = ZonedDateTime.ofInstant(dateRange.getStart().toInstant(), ZoneId.of(ZoneOffset.UTC.getId()));
ZonedDateTime actualEndDay = ZonedDateTime.ofInstant(dateRange.getEnd().toInstant(), ZoneId.of(ZoneOffset.UTC.getId()));
assertDateIsEqual(expectedStartDay, actualStartDay);
assertDateIsEqual(expectedEndDay, actualEndDay);
}
use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.
the class ProcessingTaskTest method testReadException.
@Test
void testReadException() {
TaskManager taskManager = Mockito.mock(TaskManager.class);
TaskScheduler taskScheduler = Mockito.mock(TaskScheduler.class);
DefaultNotificationAccessor notificationManager = Mockito.mock(DefaultNotificationAccessor.class);
StaticJobAccessor jobAccessor = Mockito.mock(StaticJobAccessor.class);
NotificationDetailExtractionDelegator extractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
NotificationProcessor notificationProcessor = new NotificationProcessor(extractionDelegator, null, null, null, null, null);
ProcessingTask task = createTask(taskScheduler, notificationManager, notificationProcessor, taskManager, jobAccessor);
DateRange dateRange = task.getDateRange();
Mockito.doThrow(new RuntimeException("Exception reading data")).when(notificationManager).findByCreatedAtBetween(dateRange.getStart(), dateRange.getEnd(), AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE);
ProcessingTask processingTask = Mockito.spy(task);
List<AlertNotificationModel> actualModelList = processingTask.read(dateRange, AlertPagedModel.DEFAULT_PAGE_NUMBER, AlertPagedModel.DEFAULT_PAGE_SIZE).getModels();
assertEquals(Collections.emptyList(), actualModelList);
}
Aggregations