use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.
the class JobNotificationProcessorTest method processNotificationForJobTest.
@Test
public void processNotificationForJobTest() throws IntegrationException {
// Set up dependencies for JobNotificationProcessor
RuleViolationNotificationDetailExtractor ruleViolationNotificationDetailExtractor = new RuleViolationNotificationDetailExtractor();
NotificationDetailExtractionDelegator notificationDetailExtractionDelegator = new NotificationDetailExtractionDelegator(RESPONSE_RESOLVER, List.of(ruleViolationNotificationDetailExtractor));
RuleViolationNotificationMessageExtractor ruleViolationNotificationMessageExtractor = createRuleViolationNotificationMessageExtractor();
ProviderMessageExtractionDelegator providerMessageExtractionDelegator = new ProviderMessageExtractionDelegator(List.of(ruleViolationNotificationMessageExtractor));
ProjectMessageDigester projectMessageDigester = new ProjectMessageDigester();
ProjectMessageSummarizer projectMessageSummarizer = new ProjectMessageSummarizer();
NotificationContentProcessor notificationContentProcessor = new NotificationContentProcessor(providerMessageExtractionDelegator, projectMessageDigester, projectMessageSummarizer);
MockProcessingAuditAccessor processingAuditAccessor = new MockProcessingAuditAccessor();
EventManager eventManager = Mockito.mock(EventManager.class);
ProviderMessageDistributor providerMessageDistributor = new ProviderMessageDistributor(processingAuditAccessor, eventManager);
NotificationExtractorBlackDuckServicesFactoryCache lifecycleCaches = createNotificationExtractorBlackDuckServicesFactoryCache();
// Create Requirements for processNotificationForJob
ProcessedNotificationDetails processedNotificationDetails = new ProcessedNotificationDetails(uuid, CHANNEL_KEY, "JobName");
AlertNotificationModel notificationModel = createNotification(NotificationType.RULE_VIOLATION.name());
// Run test and verify notification saved by ProcessingAuditAccessor
JobNotificationProcessor jobNotificationProcessor = new JobNotificationProcessor(notificationDetailExtractionDelegator, notificationContentProcessor, providerMessageDistributor, List.of(lifecycleCaches));
jobNotificationProcessor.processNotificationForJob(processedNotificationDetails, ProcessingType.DEFAULT, List.of(notificationModel));
Set<Long> auditNotificationIds = processingAuditAccessor.getNotificationIds(uuid);
Mockito.verify(eventManager, Mockito.times(1)).sendEvent(Mockito.any());
assertEquals(1, auditNotificationIds.size());
assertTrue(auditNotificationIds.contains(notificationId));
}
use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method handleEventProcessingExceptionTest.
@Test
void handleEventProcessingExceptionTest() throws IOException {
NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
Mockito.doAnswer((invocation) -> {
throw new ExecutionException(new RuntimeException("Test: exception for thread"));
}).when(notificationAccessor).getFirstPageOfNotificationsNotProcessed(Mockito.anyInt());
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);
}
}
use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.
the class NotificationReceivedEventHandlerTest method mockEventManager.
private EventManager mockEventManager() {
JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);
Mockito.doNothing().when(jmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
Gson gson = new Gson();
return new EventManager(gson, jmsTemplate);
}
use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.
the class BlackDuckAccumulatorTest method runTest.
/**
* This test should simulate a normal run of the accumulator with notifications present.
*/
@Test
public void runTest() throws Exception {
ProviderTaskPropertiesAccessor taskPropertiesAccessor = Mockito.mock(ProviderTaskPropertiesAccessor.class);
BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
BlackDuckSystemValidator validator = createBlackDuckValidator(blackDuckProperties, true);
PageRetriever pageRetriever = Mockito.mock(PageRetriever.class);
StatefulAlertPage<NotificationUserView, IntegrationException> notificationPage = createMockNotificationPage(pageRetriever);
BlackDuckNotificationRetriever notificationRetriever = Mockito.mock(BlackDuckNotificationRetriever.class);
Mockito.when(notificationRetriever.retrievePageOfFilteredNotifications(Mockito.any(), Mockito.anyList())).thenReturn(notificationPage);
Mockito.when(pageRetriever.retrieveNextPage(Mockito.anyInt(), Mockito.anyInt())).thenReturn(AlertPagedDetails.emptyPage());
BlackDuckNotificationRetrieverFactory notificationRetrieverFactory = createBlackDuckNotificationRetrieverFactory(blackDuckProperties, notificationRetriever);
NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
Mockito.when(notificationAccessor.saveAllNotifications(Mockito.anyList())).thenAnswer(invocation -> invocation.getArgument(0));
EventManager eventManager = Mockito.mock(EventManager.class);
Mockito.doNothing().when(eventManager).sendEvent(Mockito.any(NotificationReceivedEvent.class));
BlackDuckAccumulator accumulator = new BlackDuckAccumulator(BLACK_DUCK_PROVIDER_KEY, null, notificationAccessor, taskPropertiesAccessor, blackDuckProperties, validator, eventManager, notificationRetrieverFactory);
accumulator.run();
Mockito.verify(notificationAccessor, Mockito.times(1)).saveAllNotifications(Mockito.anyList());
}
Aggregations