Search in sources :

Example 1 with EventManager

use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.

the class ProviderMessageDistributorTest method distributeMissingDestinationKeyTest.

@Test
public void distributeMissingDestinationKeyTest() {
    MockProcessingAuditAccessor processingAuditAccessor = new MockProcessingAuditAccessor();
    EventManager eventManager = Mockito.mock(EventManager.class);
    ProcessedNotificationDetails processedNotificationDetails = new ProcessedNotificationDetails(uuid, "bad channel key", "JobName");
    ProcessedProviderMessageHolder processedMessageHolder = createProcessedProviderMessageHolder(1, 0);
    ProviderMessageDistributor providerMessageDistributor = new ProviderMessageDistributor(processingAuditAccessor, eventManager);
    providerMessageDistributor.distribute(processedNotificationDetails, processedMessageHolder);
    Mockito.verify(eventManager, Mockito.times(0)).sendEvent(Mockito.any());
}
Also used : MockProcessingAuditAccessor(com.synopsys.integration.alert.processor.api.MockProcessingAuditAccessor) EventManager(com.synopsys.integration.alert.api.event.EventManager) ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) Test(org.junit.jupiter.api.Test)

Example 2 with EventManager

use of com.synopsys.integration.alert.api.event.EventManager 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);
    }
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) 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) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with EventManager

use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.

the class NotificationReceivedEventHandlerTest method handleEventProcessingInterruptedTest.

@Test
void handleEventProcessingInterruptedTest() throws IOException {
    NotificationAccessor notificationAccessor = Mockito.mock(NotificationAccessor.class);
    Mockito.doAnswer(invocation -> {
        throw new InterruptedException("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) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with EventManager

use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.

the class NotificationReceivedEventHandlerTestIT method testHandleEventProcessedNotificationsWithPages.

@Test
void testHandleEventProcessedNotificationsWithPages() {
    EventManager eventManagerSpy = Mockito.spy(eventManager);
    int totalNotifications = 200;
    List<AlertNotificationModel> notificationContent = new ArrayList<>();
    for (int index = 0; index < totalNotifications; index++) {
        notificationContent.add(createAlertNotificationModel(false));
    }
    List<AlertNotificationModel> savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
    assertNotNull(savedModels);
    NotificationProcessor notificationProcessor = createNotificationProcessor();
    NotificationReceivedEventHandler notificationReceivedEventHandler = new NotificationReceivedEventHandler(defaultNotificationAccessor, notificationProcessor, eventManagerSpy);
    notificationReceivedEventHandler.handle(new NotificationReceivedEvent());
    Mockito.verify(eventManagerSpy, Mockito.atLeastOnce()).sendEvent(Mockito.any());
    assertEquals(100, defaultNotificationAccessor.getFirstPageOfNotificationsNotProcessed(100).getModels().size());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) EventManager(com.synopsys.integration.alert.api.event.EventManager) ArrayList(java.util.ArrayList) NotificationProcessor(com.synopsys.integration.alert.processor.api.NotificationProcessor) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with EventManager

use of com.synopsys.integration.alert.api.event.EventManager in project hub-alert by blackducksoftware.

the class ProviderMessageDistributorTest method distributeTest.

@Test
public void distributeTest() {
    MockProcessingAuditAccessor processingAuditAccessor = new MockProcessingAuditAccessor();
    EventManager eventManager = Mockito.mock(EventManager.class);
    ProcessedNotificationDetails processedNotificationDetails = new ProcessedNotificationDetails(uuid, slackChannelKey.getUniversalKey(), "JobName");
    ProcessedProviderMessageHolder processedMessageHolder = createProcessedProviderMessageHolder(2, 2);
    ProviderMessageDistributor providerMessageDistributor = new ProviderMessageDistributor(processingAuditAccessor, eventManager);
    providerMessageDistributor.distribute(processedNotificationDetails, processedMessageHolder);
    Mockito.verify(eventManager, Mockito.times(4)).sendEvent(Mockito.any());
}
Also used : MockProcessingAuditAccessor(com.synopsys.integration.alert.processor.api.MockProcessingAuditAccessor) EventManager(com.synopsys.integration.alert.api.event.EventManager) ProcessedProviderMessageHolder(com.synopsys.integration.alert.processor.api.extract.model.ProcessedProviderMessageHolder) 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