Search in sources :

Example 6 with NotificationReceivedEvent

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

the class NotificationReceivedEventHandler method processNotifications.

private void processNotifications() {
    AlertPagedModel<AlertNotificationModel> pageOfAlertNotificationModels = notificationAccessor.getFirstPageOfNotificationsNotProcessed(PAGE_SIZE);
    if (!CollectionUtils.isEmpty(pageOfAlertNotificationModels.getModels())) {
        List<AlertNotificationModel> notifications = pageOfAlertNotificationModels.getModels();
        logger.info("Starting to process {} notifications.", notifications.size());
        notificationProcessor.processNotifications(notifications, List.of(FrequencyType.REAL_TIME));
        boolean hasMoreNotificationsToProcess = notificationAccessor.hasMoreNotificationsToProcess();
        if (hasMoreNotificationsToProcess) {
            eventManager.sendEvent(new NotificationReceivedEvent());
        }
    }
    logger.info("Finished processing event for notifications.");
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent)

Example 7 with NotificationReceivedEvent

use of com.synopsys.integration.alert.api.event.NotificationReceivedEvent 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 NotificationReceivedEvent

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

the class NotificationReceivedEventHandlerTestIT method testHandleEventProcessedNotifications.

@Test
void testHandleEventProcessedNotifications() {
    List<AlertNotificationModel> notificationContent = new ArrayList<>();
    notificationContent.add(createAlertNotificationModel(true));
    notificationContent.add(createAlertNotificationModel(true));
    List<AlertNotificationModel> savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
    assertNotNull(savedModels);
    assertEquals(0, defaultNotificationAccessor.getFirstPageOfNotificationsNotProcessed(pageSize).getModels().size());
    NotificationProcessor notificationProcessor = createNotificationProcessor();
    NotificationReceivedEventHandler notificationReceivedEventHandler = new NotificationReceivedEventHandler(defaultNotificationAccessor, notificationProcessor, eventManager);
    notificationReceivedEventHandler.handle(new NotificationReceivedEvent());
    testAlertNotificationModels(savedModels);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) 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 9 with NotificationReceivedEvent

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

the class NotificationReceivedEventHandlerTestIT method testHandleEventMixedProcessedNotifications.

@Test
void testHandleEventMixedProcessedNotifications() {
    List<AlertNotificationModel> notificationContent = new ArrayList<>();
    notificationContent.add(createAlertNotificationModel(true));
    notificationContent.add(createAlertNotificationModel(false));
    List<AlertNotificationModel> savedModels = defaultNotificationAccessor.saveAllNotifications(notificationContent);
    assertNotNull(savedModels);
    NotificationProcessor notificationProcessor = createNotificationProcessor();
    NotificationReceivedEventHandler notificationReceivedEventHandler = new NotificationReceivedEventHandler(defaultNotificationAccessor, notificationProcessor, eventManager);
    notificationReceivedEventHandler.handle(new NotificationReceivedEvent());
    testAlertNotificationModels(savedModels);
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) 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 10 with NotificationReceivedEvent

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

the class JmsNotificationReceiverTestIT method testJms.

@Test
@Disabled
void testJms() throws InterruptedException {
    // Set breakpoints throughout this test, there is nothing to assert against here. Suggestions for breakpoints:
    // Registering listeners: EventListenerConfigurer
    // Sending events: EventManager
    // Receiving events: NotificationReceiver or DistributionChannel
    // Processing notifications: NotificationReceiver
    NotificationReceivedEvent notificationReceivedEvent = new NotificationReceivedEvent();
    eventManager.sendEvent(notificationReceivedEvent);
    Thread.sleep(120000);
}
Also used : NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

NotificationReceivedEvent (com.synopsys.integration.alert.api.event.NotificationReceivedEvent)10 Test (org.junit.jupiter.api.Test)8 AlertNotificationModel (com.synopsys.integration.alert.common.rest.model.AlertNotificationModel)7 NotificationProcessor (com.synopsys.integration.alert.processor.api.NotificationProcessor)7 EventManager (com.synopsys.integration.alert.api.event.EventManager)4 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)4 ArrayList (java.util.ArrayList)4 NotificationAccessor (com.synopsys.integration.alert.common.persistence.accessor.NotificationAccessor)3 ExecutionException (java.util.concurrent.ExecutionException)1 Disabled (org.junit.jupiter.api.Disabled)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1