Search in sources :

Example 6 with EventManager

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));
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) ProviderMessageDistributor(com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor) ProjectMessageDigester(com.synopsys.integration.alert.processor.api.digest.ProjectMessageDigester) EventManager(com.synopsys.integration.alert.api.event.EventManager) RuleViolationNotificationDetailExtractor(com.synopsys.integration.alert.provider.blackduck.processor.detail.RuleViolationNotificationDetailExtractor) NotificationExtractorBlackDuckServicesFactoryCache(com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache) ProviderMessageExtractionDelegator(com.synopsys.integration.alert.processor.api.extract.ProviderMessageExtractionDelegator) ProjectMessageSummarizer(com.synopsys.integration.alert.processor.api.summarize.ProjectMessageSummarizer) RuleViolationNotificationMessageExtractor(com.synopsys.integration.alert.provider.blackduck.processor.message.RuleViolationNotificationMessageExtractor) ProcessedNotificationDetails(com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails) NotificationDetailExtractionDelegator(com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator) Test(org.junit.jupiter.api.Test)

Example 7 with EventManager

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);
    }
}
Also used : EventManager(com.synopsys.integration.alert.api.event.EventManager) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) ExecutionException(java.util.concurrent.ExecutionException) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) Test(org.junit.jupiter.api.Test)

Example 8 with EventManager

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);
}
Also used : EventManager(com.synopsys.integration.alert.api.event.EventManager) JmsTemplate(org.springframework.jms.core.JmsTemplate) Gson(com.google.gson.Gson)

Example 9 with EventManager

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());
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) IntegrationException(com.synopsys.integration.exception.IntegrationException) EventManager(com.synopsys.integration.alert.api.event.EventManager) NotificationAccessor(com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) ProviderTaskPropertiesAccessor(com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor) PageRetriever(com.synopsys.integration.alert.processor.api.filter.PageRetriever) NotificationUserView(com.synopsys.integration.blackduck.api.manual.view.NotificationUserView) Test(org.junit.jupiter.api.Test)

Aggregations

EventManager (com.synopsys.integration.alert.api.event.EventManager)9 Test (org.junit.jupiter.api.Test)8 NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)5 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)4 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)4 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)3 MockProcessingAuditAccessor (com.synopsys.integration.alert.processor.api.MockProcessingAuditAccessor)2 ProcessedProviderMessageHolder (com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder)2 Gson (com.google.gson.Gson)1 ProviderTaskPropertiesAccessor (com.synopsys.integration.alert.common.persistence.accessor.ProviderTaskPropertiesAccessor)1 NotificationDetailExtractionDelegator (com.synopsys.integration.alert.processor.api.detail.NotificationDetailExtractionDelegator)1 ProjectMessageDigester (com.synopsys.integration.alert.processor.api.digest.ProjectMessageDigester)1 ProcessedNotificationDetails (com.synopsys.integration.alert.processor.api.distribute.ProcessedNotificationDetails)1 ProviderMessageDistributor (com.synopsys.integration.alert.processor.api.distribute.ProviderMessageDistributor)1 ProviderMessageExtractionDelegator (com.synopsys.integration.alert.processor.api.extract.ProviderMessageExtractionDelegator)1 PageRetriever (com.synopsys.integration.alert.processor.api.filter.PageRetriever)1 ProjectMessageSummarizer (com.synopsys.integration.alert.processor.api.summarize.ProjectMessageSummarizer)1 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)1 NotificationExtractorBlackDuckServicesFactoryCache (com.synopsys.integration.alert.provider.blackduck.processor.NotificationExtractorBlackDuckServicesFactoryCache)1 RuleViolationNotificationDetailExtractor (com.synopsys.integration.alert.provider.blackduck.processor.detail.RuleViolationNotificationDetailExtractor)1