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());
}
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);
}
}
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);
}
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);
}
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));
}
Aggregations