Search in sources :

Example 1 with NotificationReceivedEvent

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

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

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

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

the class NotificationReceivedEventHandlerTestIT method testHandleEventNotProcessedNotifications.

@Test
void testHandleEventNotProcessedNotifications() {
    List<AlertNotificationModel> notificationContent = new ArrayList<>();
    notificationContent.add(createAlertNotificationModel(false));
    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 5 with NotificationReceivedEvent

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

the class BlackDuckAccumulator method write.

private void write(List<AlertNotificationModel> contentList) {
    logger.info("Writing {} notifications...", contentList.size());
    List<AlertNotificationModel> savedNotifications = notificationAccessor.saveAllNotifications(contentList);
    if (logger.isDebugEnabled()) {
        List<Long> notificationIds = savedNotifications.stream().map(AlertNotificationModel::getId).collect(Collectors.toList());
        String joinedIds = StringUtils.join(notificationIds, ", ");
        notificationLogger.debug("Saved notifications: {}", joinedIds);
    }
    eventManager.sendEvent(new NotificationReceivedEvent());
}
Also used : AlertNotificationModel(com.synopsys.integration.alert.common.rest.model.AlertNotificationModel) NotificationReceivedEvent(com.synopsys.integration.alert.api.event.NotificationReceivedEvent)

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