use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor 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.persistence.accessor.NotificationAccessor 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));
}
use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor in project hub-alert by blackducksoftware.
the class ComponentUnknownVersionNotificationSerializationTest method testNotificationSerialization.
@Test
@Ignore
@Disabled
public void testNotificationSerialization() throws IntegrationException, InterruptedException {
LocalDateTime searchStartTime = LocalDateTime.now().minusMinutes(1);
AlertRequestUtility alertRequestUtility = IntegrationPerformanceTestRunner.createAlertRequestUtility(webApplicationContext);
BlackDuckProviderService blackDuckProviderService = new BlackDuckProviderService(alertRequestUtility, gson);
configureJob(alertRequestUtility, blackDuckProviderService);
ExternalId externalId = new ExternalId(Forge.MAVEN);
externalId.setGroup("commons-fileupload");
externalId.setName("commons-fileupload");
Predicate<ProjectVersionComponentVersionView> componentFilter = (component) -> component.getComponentName().equals("Apache Commons FileUpload");
blackDuckProviderService.triggerBlackDuckNotification(() -> externalId, componentFilter);
try {
WaitJobConfig waitJobConfig = new WaitJobConfig(intLogger, "notification serialization test notification wait", 300, searchStartTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli(), 20);
NotificationReceivedWaitJobTask notificationWaitJobTask = new NotificationReceivedWaitJobTask(notificationAccessor, searchStartTime, "Apache Commons FileUpload", null, NotificationType.COMPONENT_UNKNOWN_VERSION);
WaitJob<Boolean> waitForNotificationToBeProcessed = WaitJob.createSimpleWait(waitJobConfig, notificationWaitJobTask);
boolean isComplete = waitForNotificationToBeProcessed.waitFor();
if (isComplete) {
String notificationContent = notificationWaitJobTask.getNotificationContent().orElseThrow(() -> new IllegalStateException("Expected notification is missing."));
BlackDuckResponseResolver resolver = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckResponseResolver();
ComponentUnknownVersionNotificationView notificationView = resolver.resolve(notificationContent, ComponentUnknownVersionNotificationView.class);
assertNotNull(notificationView.getContent());
assertTrue(StringUtils.isNotBlank(notificationView.getContent().getComponentName()));
BlackDuckApiClient apiClient = blackDuckProviderService.getBlackDuckServicesFactory().getBlackDuckApiClient();
Optional<HttpUrl> componentUrl = HttpUrl.createSafely(notificationView.getContent().getBomComponent());
if (componentUrl.isPresent()) {
apiClient.delete(componentUrl.get());
}
}
} catch (InterruptedException ex) {
// if a timeout happens that's ok we are trying to ensure deserialization is correct.
}
}
use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method mockNotificationProcessor.
private NotificationProcessor mockNotificationProcessor(NotificationAccessor notificationAccessor) {
NotificationDetailExtractionDelegator detailExtractionDelegator = new NotificationDetailExtractionDelegator(blackDuckResponseResolver, List.of());
JobNotificationMapper jobNotificationMapper = Mockito.mock(JobNotificationMapper.class);
Predicate<AlertPagedDetails> hasNextPage = page -> page.getCurrentPage() < (page.getTotalPages() - 1);
StatefulAlertPage<FilteredJobNotificationWrapper, RuntimeException> statefulAlertPage = new StatefulAlertPage(AlertPagedDetails.emptyPage(), Mockito.mock(PageRetriever.class), hasNextPage);
Mockito.when(jobNotificationMapper.mapJobsToNotifications(Mockito.anyList(), Mockito.anyList())).thenReturn(statefulAlertPage);
return new NotificationProcessor(detailExtractionDelegator, jobNotificationMapper, null, null, List.of(), notificationAccessor);
}
use of com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method handleEventTest.
@Test
void handleEventTest() throws IOException {
AlertNotificationModel alertNotificationModel = createAlertNotificationModel(1L, false);
List<AlertNotificationModel> alertNotificationModels = List.of(alertNotificationModel);
NotificationAccessor notificationAccessor = new MockNotificationAccessor(alertNotificationModels);
NotificationProcessor notificationProcessor = mockNotificationProcessor(notificationAccessor);
EventManager eventManager = mockEventManager();
NotificationReceivedEventHandler eventHandler = new NotificationReceivedEventHandler(notificationAccessor, notificationProcessor, eventManager);
try {
eventHandler.handle(new NotificationReceivedEvent());
} catch (RuntimeException e) {
fail("Unable to handle event", e);
}
}
Aggregations