Search in sources :

Example 36 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class VulnerabilityNotificationDetailExtractorTest method allSeverityTypesApplyTest.

@Test
public void allSeverityTypesApplyTest() throws IOException {
    VulnerabilityNotificationView vulnerabilityNotificationView = getVulnerabilityNotificationView(VULNERABILITY_SIMPLE_ALL_SEVERITY_JSON_PATH);
    VulnerabilityNotificationDetailExtractor vulnerabilityNotificationDetailExtractor = new VulnerabilityNotificationDetailExtractor();
    AlertNotificationModel alertNotificationModel = createAlertNotificationModel();
    List<DetailedNotificationContent> filterableNotificationWrappers = vulnerabilityNotificationDetailExtractor.extractDetailedContent(alertNotificationModel, vulnerabilityNotificationView);
    assertEquals(1, filterableNotificationWrappers.size());
    DetailedNotificationContent detailedNotificationContent = filterableNotificationWrappers.get(0);
    assertEquals(4, detailedNotificationContent.getVulnerabilitySeverities().size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) VulnerabilityNotificationView(com.synopsys.integration.blackduck.api.manual.view.VulnerabilityNotificationView) DetailedNotificationContent(com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent) Test(org.junit.jupiter.api.Test)

Example 37 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class BlackDuckAccumulator method storeNotifications.

private void storeNotifications(List<NotificationUserView> notifications) {
    List<AlertNotificationModel> alertNotifications = convertToAlertNotificationModels(notifications);
    write(alertNotifications);
    Optional<OffsetDateTime> optionalNextSearchTime = computeLatestNotificationCreatedAtDate(alertNotifications).map(latestNotification -> latestNotification.plusNanos(1000000));
    if (optionalNextSearchTime.isPresent()) {
        OffsetDateTime nextSearchTime = optionalNextSearchTime.get();
        logger.info("Notifications found; the next search time will be: {}", nextSearchTime);
        searchDateManager.saveNextSearchStart(nextSearchTime);
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) OffsetDateTime(java.time.OffsetDateTime)

Example 38 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel in project hub-alert by blackducksoftware.

the class BlackDuckAccumulator method convertToAlertNotificationModel.

private AlertNotificationModel convertToAlertNotificationModel(NotificationView notification) {
    OffsetDateTime createdAt = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime providerCreationTime = DateUtils.fromDateUTC(notification.getCreatedAt());
    String provider = blackDuckProviderKey.getUniversalKey();
    String notificationType = notification.getType().name();
    String jsonContent = notification.getJson();
    return new AlertNotificationModel(null, getProviderProperties().getConfigId(), provider, getProviderProperties().getConfigName(), notificationType, jsonContent, createdAt, providerCreationTime, false);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) OffsetDateTime(java.time.OffsetDateTime)

Example 39 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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 40 with AlertNotificationModel

use of com.synopsys.integration.alert.common.rest.model.AlertNotificationModel 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

AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)94 Test (org.junit.jupiter.api.Test)62 DetailedNotificationContent (com.synopsys.integration.alert.processor.api.detail.DetailedNotificationContent)21 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)20 NotificationEntity (com.synopsys.integration.alert.database.notification.NotificationEntity)16 PageRequest (org.springframework.data.domain.PageRequest)16 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)14 NotificationContentRepository (com.synopsys.integration.alert.database.notification.NotificationContentRepository)14 OffsetDateTime (java.time.OffsetDateTime)13 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)11 ArrayList (java.util.ArrayList)10 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)9 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)7 FilteredDistributionJobResponseModel (com.synopsys.integration.alert.common.persistence.model.job.FilteredDistributionJobResponseModel)7 DefaultNotificationAccessor (com.synopsys.integration.alert.database.api.DefaultNotificationAccessor)6 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)6 NotificationContentComponent (com.synopsys.integration.blackduck.api.manual.component.NotificationContentComponent)5 PageImpl (org.springframework.data.domain.PageImpl)5 TaskManager (com.synopsys.integration.alert.api.task.TaskManager)4 LinkableItem (com.synopsys.integration.alert.common.message.model.LinkableItem)4