Search in sources :

Example 6 with DateRange

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();
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DateRange(com.synopsys.integration.alert.common.message.model.DateRange)

Example 7 with DateRange

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);
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) OffsetDateTime(java.time.OffsetDateTime) Test(org.junit.jupiter.api.Test)

Example 8 with DateRange

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();
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) TaskScheduler(org.springframework.scheduling.TaskScheduler) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) Test(org.junit.jupiter.api.Test)

Example 9 with DateRange

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);
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) OffsetDateTime(java.time.OffsetDateTime) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.jupiter.api.Test)

Example 10 with DateRange

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);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DateRange(com.synopsys.integration.alert.common.message.model.DateRange) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) TaskScheduler(org.springframework.scheduling.TaskScheduler) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) Test(org.junit.jupiter.api.Test)

Aggregations

DateRange (com.synopsys.integration.alert.common.message.model.DateRange)13 Test (org.junit.jupiter.api.Test)10 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)4 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)4 StaticJobAccessor (com.synopsys.integration.alert.database.api.StaticJobAccessor)4 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)4 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)4 OffsetDateTime (java.time.OffsetDateTime)4 TaskScheduler (org.springframework.scheduling.TaskScheduler)4 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)3 SystemMessageModel (com.synopsys.integration.alert.common.persistence.model.SystemMessageModel)2 ZonedDateTime (java.time.ZonedDateTime)2 ArrayList (java.util.ArrayList)2 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)1 ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)1 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)1