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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations