Search in sources :

Example 1 with DateRange

use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.

the class SystemMessageAccessorTestIT method testFindBetweenDateRange.

@Test
public void testFindBetweenDateRange() {
    List<SystemMessageEntity> expectedMessages = createSystemMessageList();
    Collections.reverse(expectedMessages);
    OffsetDateTime currentDateTime = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime startTime = currentDateTime.minusMinutes(10);
    List<SystemMessageEntity> savedMessages = new ArrayList<>(expectedMessages);
    savedMessages.add(new SystemMessageEntity(currentDateTime, SEVERITY, "content", TYPE));
    savedMessages.add(new SystemMessageEntity(startTime.minusMinutes(15), SEVERITY, "content", TYPE));
    savedMessages.add(new SystemMessageEntity(currentDateTime.plusMinutes(5), SEVERITY, "content", TYPE));
    systemMessageRepository.saveAll(savedMessages);
    DateRange dateRange = DateRange.of(startTime, currentDateTime);
    List<SystemMessageModel> actualMessageList = defaultSystemMessageUtility.findBetween(dateRange);
    assertNotNull(actualMessageList);
    assertEquals(MESSAGE_COUNT, actualMessageList.size());
    assertEquals(expectedMessages.size(), actualMessageList.size());
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) OffsetDateTime(java.time.OffsetDateTime) SystemMessageModel(com.synopsys.integration.alert.common.persistence.model.SystemMessageModel) ArrayList(java.util.ArrayList) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with DateRange

use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.

the class SystemActions method getSystemMessagesBetween.

private ActionResponse<MultiSystemMessageModel> getSystemMessagesBetween(String startDate, String endDate) throws ParseException {
    DateRange dateRange = DateRange.of(startDate, endDate);
    List<SystemMessageModel> messages = systemMessageAccessor.findBetween(dateRange);
    return new ActionResponse<>(HttpStatus.OK, new MultiSystemMessageModel(messages));
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange) SystemMessageModel(com.synopsys.integration.alert.common.persistence.model.SystemMessageModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 3 with DateRange

use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.

the class BlackDuckAccumulator method accumulateNotifications.

private void accumulateNotifications() {
    Optional<BlackDuckNotificationRetriever> optionalNotificationRetriever = notificationRetrieverFactory.createBlackDuckNotificationRetriever(getProviderProperties());
    if (optionalNotificationRetriever.isPresent()) {
        DateRange dateRange = searchDateManager.retrieveNextSearchDateRange();
        logger.info("Accumulating notifications between {} and {} ", DateUtils.formatDateAsJsonString(dateRange.getStart()), DateUtils.formatDateAsJsonString(dateRange.getEnd()));
        retrieveAndStoreNotificationsSafely(optionalNotificationRetriever.get(), dateRange);
    }
}
Also used : DateRange(com.synopsys.integration.alert.common.message.model.DateRange)

Example 4 with DateRange

use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.

the class ProcessingTaskTest method testReadEmptyList.

@Test
void testReadEmptyList() {
    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(true);
    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);
    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) 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 5 with DateRange

use of com.synopsys.integration.alert.common.message.model.DateRange in project hub-alert by blackducksoftware.

the class ProcessingTaskTest method testPagedRead.

@Test
void testPagedRead() throws IOException {
    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(true);
    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);
    int count = 20;
    List<AlertNotificationModel> allModels = new ArrayList<>(count);
    for (int index = 0; index < count; index++) {
        String notificationJson = TestResourceUtils.readFileToString("json/projectVersionNotification.json");
        AlertNotificationModel model = new AlertNotificationModel(Integer.valueOf(index).longValue(), 1L, "BlackDuck", "BlackDuck_1", "PROJECT_VERSION", notificationJson, DateUtils.createCurrentDateTimestamp(), DateUtils.createCurrentDateTimestamp(), false);
        allModels.add(model);
    }
    notificationManager.saveAllNotifications(allModels);
    DateRange dateRange = task.getDateRange();
    int pageSize = 5;
    int totalPages = count / pageSize;
    List<AlertNotificationModel> testModels = new ArrayList<>(count);
    for (int currentPage = 0; currentPage < totalPages; currentPage++) {
        AlertPagedModel<AlertNotificationModel> pagedModel = task.read(dateRange, currentPage, pageSize);
        assertEquals(totalPages, pagedModel.getTotalPages());
        assertEquals(currentPage, pagedModel.getCurrentPage());
        assertEquals(pageSize, pagedModel.getPageSize());
        testModels.addAll(pagedModel.getModels());
    }
    assertEquals(allModels.size(), testModels.size());
    assertTrue(allModels.containsAll(testModels));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) DefaultNotificationAccessor(com.synopsys.integration.alert.database.api.DefaultNotificationAccessor) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) ArrayList(java.util.ArrayList) TaskScheduler(org.springframework.scheduling.TaskScheduler) DateRange(com.synopsys.integration.alert.common.message.model.DateRange) TaskManager(com.synopsys.integration.alert.api.task.TaskManager) StaticJobAccessor(com.synopsys.integration.alert.database.api.StaticJobAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) 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