Search in sources :

Example 1 with DBStoreEvent

use of com.blackducksoftware.integration.hub.alert.event.DBStoreEvent in project hub-alert by blackducksoftware.

the class GlobalSchedulingConfigActions method runAccumulator.

public void runAccumulator() throws Exception {
    final AccumulatorReader reader = new AccumulatorReader(globalProperties);
    final AccumulatorProcessor processor = new AccumulatorProcessor(globalProperties);
    final AccumulatorWriter writer = new AccumulatorWriter(notificationManager, channelTemplateManager);
    final NotificationResults results = reader.read();
    final DBStoreEvent event = processor.process(results);
    final List<DBStoreEvent> events = new ArrayList<>();
    if (event != null) {
        events.add(event);
    }
    writer.write(events);
}
Also used : AccumulatorProcessor(com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorProcessor) NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) ArrayList(java.util.ArrayList) AccumulatorReader(com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorReader) AccumulatorWriter(com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorWriter) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)

Example 2 with DBStoreEvent

use of com.blackducksoftware.integration.hub.alert.event.DBStoreEvent in project hub-alert by blackducksoftware.

the class ChannelTemplateManagerTest method testNotAbstractChannelEvent.

@Test
public void testNotAbstractChannelEvent() {
    final ChannelTemplateManager channelTemplateManager = new ChannelTemplateManager(new Gson(), null, null, null) {

        @Override
        public boolean hasTemplate(final String destination) {
            return true;
        }

        @Override
        public AbstractJmsTemplate getTemplate(final String destination) {
            final AbstractJmsTemplate abstractJmsTemplate = Mockito.mock(AbstractJmsTemplate.class);
            Mockito.doNothing().when(abstractJmsTemplate).convertAndSend(Mockito.anyString(), Mockito.any(Object.class));
            return abstractJmsTemplate;
        }
    };
    final DBStoreEvent dbStoreEvent = new DBStoreEvent(null);
    final boolean isTrue = channelTemplateManager.sendEvent(dbStoreEvent);
    assertTrue(isTrue);
}
Also used : AbstractJmsTemplate(com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate) Gson(com.google.gson.Gson) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) Test(org.junit.Test)

Example 3 with DBStoreEvent

use of com.blackducksoftware.integration.hub.alert.event.DBStoreEvent in project hub-alert by blackducksoftware.

the class AccumulatorProcessorTestIT method testProcess.

@Test
public void testProcess() throws Exception {
    final Long timestamp = (new Date()).getTime();
    final String testProjectName = "hub-Alert-NotificationAccumulatorTest-" + timestamp;
    final String testProjectVersionName = "1.0.0";
    final ProjectRequest projectRequest = new ProjectRequest();
    projectRequest.name = testProjectName;
    final String projectUrl = projectService.createHubProject(projectRequest);
    final ProjectView projectItem = hubService.getResponse(projectUrl, ProjectView.class);
    System.out.println("projectUrl: " + projectUrl);
    final ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
    projectVersionRequest.distribution = ProjectVersionDistributionType.INTERNAL;
    projectVersionRequest.phase = ProjectVersionPhaseType.DEVELOPMENT;
    projectVersionRequest.versionName = testProjectVersionName;
    projectService.createHubVersion(projectItem, projectVersionRequest);
    uploadBdio("bdio/component-bdio.jsonld");
    TimeUnit.SECONDS.sleep(60);
    final NotificationResults notificationData = notificationDataService.getAllNotificationResults(new Date(System.currentTimeMillis() - 100000), new Date());
    final AccumulatorProcessor accumulatorProcessor = new AccumulatorProcessor(globalProperties);
    final DBStoreEvent storeEvent = accumulatorProcessor.process(notificationData);
    assertNotNull(storeEvent);
    final List<NotificationEvent> notificationEvents = storeEvent.getNotificationList();
    assertFalse(notificationEvents.isEmpty());
    assertEquals(storeEvent.getEventId().length(), 36);
    NotificationEvent apacheEvent = null;
    for (final NotificationEvent event : notificationEvents) {
        System.out.println(event);
        if ("Apache Commons FileUpload".equals(event.getDataSet().get("COMPONENT"))) {
            apacheEvent = event;
        }
    }
    assertNotNull(apacheEvent);
    final AccumulatorProcessor accumulatorProcessorNull = new AccumulatorProcessor(null);
    final DBStoreEvent storeEventNull = accumulatorProcessorNull.process(notificationData);
    assertNull(storeEventNull);
}
Also used : NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectView(com.blackducksoftware.integration.hub.api.generated.view.ProjectView) Date(java.util.Date) ProjectVersionRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 4 with DBStoreEvent

use of com.blackducksoftware.integration.hub.alert.event.DBStoreEvent in project hub-alert by blackducksoftware.

the class AccumulatorWriterTest method testWrite.

@Test
public void testWrite() throws Exception {
    final NotificationManager notificationManager = Mockito.mock(NotificationManager.class);
    final ChannelTemplateManager channelTemplateManager = Mockito.mock(ChannelTemplateManager.class);
    final AccumulatorWriter accumulatorWriter = new AccumulatorWriter(notificationManager, channelTemplateManager);
    final String eventKey = "_event_key_";
    final NotificationCategoryEnum categoryType = NotificationCategoryEnum.HIGH_VULNERABILITY;
    final NotificationEvent notificationEvent = new NotificationEvent(eventKey, categoryType, generateDataSet());
    final DBStoreEvent storeEvent = new DBStoreEvent(Arrays.asList(notificationEvent));
    accumulatorWriter.write(Arrays.asList(storeEvent));
    Mockito.verify(channelTemplateManager).sendEvent(Mockito.any());
}
Also used : NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) ChannelTemplateManager(com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager) NotificationCategoryEnum(com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) Test(org.junit.Test)

Example 5 with DBStoreEvent

use of com.blackducksoftware.integration.hub.alert.event.DBStoreEvent in project hub-alert by blackducksoftware.

the class NotificationItemProcessorTest method testProcessEvents.

@Test
public void testProcessEvents() throws HubIntegrationException {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final NotificationEvent event1 = new NotificationEvent("event 1", NotificationCategoryEnum.HIGH_VULNERABILITY, null);
    final NotificationEvent event2 = new NotificationEvent("event 2", NotificationCategoryEnum.LOW_VULNERABILITY, null);
    final List<NotificationEvent> eventList = Arrays.asList(event1, event2);
    final NotificationItemProcessor notificationItemProcessor = new NotificationItemProcessor(globalProperties, new TestLogger());
    final DBStoreEvent storeEvent = notificationItemProcessor.processEvents(eventList);
    assertEquals("DB_STORE_EVENT", storeEvent.getTopic());
    assertTrue(storeEvent.getNotificationList().size() == 2);
}
Also used : TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) TestLogger(com.blackducksoftware.integration.test.TestLogger) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Aggregations

DBStoreEvent (com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)6 Test (org.junit.Test)4 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)3 NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)2 AbstractJmsTemplate (com.blackducksoftware.integration.hub.alert.AbstractJmsTemplate)1 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)1 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)1 AccumulatorProcessor (com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorProcessor)1 AccumulatorReader (com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorReader)1 AccumulatorWriter (com.blackducksoftware.integration.hub.alert.accumulator.AccumulatorWriter)1 ChannelTemplateManager (com.blackducksoftware.integration.hub.alert.channel.ChannelTemplateManager)1 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 NotificationItemProcessor (com.blackducksoftware.integration.hub.alert.processor.NotificationItemProcessor)1 ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)1 ProjectVersionRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest)1 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)1 NotificationCategoryEnum (com.blackducksoftware.integration.hub.notification.NotificationCategoryEnum)1 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)1 TestLogger (com.blackducksoftware.integration.test.TestLogger)1 HubConnectionTest (com.blackducksoftware.integration.test.annotation.HubConnectionTest)1