use of com.blackducksoftware.integration.hub.notification.NotificationContentItem in project hub-alert by blackducksoftware.
the class VulnerabilityCacheTest method testRemoveEvent.
@Test
public void testRemoveEvent() {
final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
final HubService mockedHubService = Mockito.mock(HubService.class);
final ComponentService mockedComponentService = Mockito.mock(ComponentService.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final VulnerabilityCache vulnerabilityCache = new VulnerabilityCache(mockedProjectService, hubServicesFactory);
Mockito.when(hubServicesFactory.createProjectService()).thenReturn(mockedProjectService);
Mockito.when(hubServicesFactory.createHubService()).thenReturn(mockedHubService);
Mockito.when(hubServicesFactory.createComponentService()).thenReturn(mockedComponentService);
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
projectVersionModel.setProjectLink("New project link");
final String componentName = "notification test";
final ComponentVersionView componentVersionView = new ComponentVersionView();
final String componentVersionUrl = "sss";
final String componentIssueUrl = "ddd";
final Map<String, Object> dataSet = new HashMap<>();
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl));
dataSet.put(VulnerabilityCache.VULNERABILITY_ID_SET, new HashSet<String>());
final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
assumeTrue(vulnerabilityCache.getEventMap().size() == 0);
vulnerabilityCache.removeEvent(notificationEvent);
assumeTrue(vulnerabilityCache.getEventMap().size() == 1);
vulnerabilityCache.removeEvent(notificationEvent);
assumeTrue(vulnerabilityCache.getEventMap().size() == 0);
}
use of com.blackducksoftware.integration.hub.notification.NotificationContentItem in project hub-alert by blackducksoftware.
the class AccumulatorWriter method write.
@Override
public void write(final List<? extends DBStoreEvent> itemList) throws Exception {
try {
if (itemList != null && !itemList.isEmpty()) {
logger.info("Writing {} notifications", itemList.size());
itemList.forEach(item -> {
final List<NotificationEvent> notificationList = item.getNotificationList();
final List<NotificationModel> entityList = new ArrayList<>();
notificationList.forEach(notification -> {
final String eventKey = notification.getEventKey();
final NotificationContentItem content = (NotificationContentItem) notification.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
final Date createdAt = content.getCreatedAt();
final NotificationCategoryEnum notificationType = notification.getCategoryType();
final String projectName = content.getProjectVersion().getProjectName();
final String projectUrl = content.getProjectVersion().getProjectLink();
final String projectVersion = content.getProjectVersion().getProjectVersionName();
final String projectVersionUrl = content.getProjectVersion().getUrl();
final String componentName = content.getComponentName();
final String componentVersion = content.getComponentVersion().versionName;
final String policyRuleName = getPolicyRule(notification);
final String person = getPerson(notification);
final NotificationEntity entity = new NotificationEntity(eventKey, createdAt, notificationType, projectName, projectUrl, projectVersion, projectVersionUrl, componentName, componentVersion, policyRuleName, person);
final Collection<VulnerabilityEntity> vulnerabilityList = getVulnerabilities(notification, entity);
NotificationModel model = new NotificationModel(entity, vulnerabilityList);
model = notificationManager.saveNotification(model);
entityList.add(model);
});
final RealTimeEvent realTimeEvent = new RealTimeEvent(entityList);
channelTemplateManager.sendEvent(realTimeEvent);
});
} else {
logger.info("No notifications to write");
}
} catch (final Exception ex) {
logger.error("Error occurred writing notification data", ex);
}
}
use of com.blackducksoftware.integration.hub.notification.NotificationContentItem in project hub-alert by blackducksoftware.
the class AccumulatorReaderTest method testRead.
@Test
public void testRead() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final NotificationService notificationService = Mockito.mock(NotificationService.class);
final SortedSet<NotificationContentItem> notificationContentItems = new TreeSet<>();
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
projectVersionModel.setProjectLink("New project link");
final String componentName = "notification test";
final ComponentVersionView componentVersionView = new ComponentVersionView();
final String componentVersionUrl = "sss";
final String componentIssueUrl = "ddd";
final NotificationContentItem notificationContentItem = new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl);
notificationContentItems.add(notificationContentItem);
final NotificationResults notificationResults = new NotificationResults(notificationContentItems, null);
Mockito.doReturn(hubServicesFactory).when(globalProperties).createHubServicesFactoryAndLogErrors(Mockito.any());
Mockito.doReturn(notificationService).when(hubServicesFactory).createNotificationService();
Mockito.doReturn(notificationResults).when(notificationService).getAllNotificationResults(Mockito.any(), Mockito.any());
final AccumulatorReader accumulatorReader = new AccumulatorReader(globalProperties);
final NotificationResults actualNotificationResults = accumulatorReader.read();
assertNotNull(actualNotificationResults);
}
use of com.blackducksoftware.integration.hub.notification.NotificationContentItem in project hub-alert by blackducksoftware.
the class AccumulatorWriterTest method generateDataSet.
private Map<String, Object> generateDataSet() {
final Map<String, Object> dataSet = new HashMap<>();
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
projectVersionModel.setProjectLink("New project link");
final String componentName = "notification test";
final ComponentVersionView componentVersionView = new ComponentVersionView();
final String componentVersionUrl = "sss";
final String componentIssueUrl = "ddd";
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl));
dataSet.put(ItemTypeEnum.RULE.name(), "policyRuleName");
dataSet.put(ItemTypeEnum.PERSON.name(), "policyUserName");
dataSet.put(VulnerabilityCache.VULNERABILITY_OPERATION, VulnerabilityOperationEnum.ADD.name());
final Set<String> vulnSet = new HashSet<>();
vulnSet.add("vulnerabilityId");
dataSet.put(VulnerabilityCache.VULNERABILITY_ID_SET, vulnSet);
return dataSet;
}
use of com.blackducksoftware.integration.hub.notification.NotificationContentItem in project hub-alert by blackducksoftware.
the class UserNotificationCacheTest method testAddUserInformation.
@Test
public void testAddUserInformation() throws IntegrationException {
final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
final UserNotificationCache userNotificationCache = new UserNotificationCache(mockedProjectService);
final AssignedUserView assignedUser = new AssignedUserView();
assignedUser.name = "test name";
final List<AssignedUserView> assignedUsersList = Arrays.asList(assignedUser);
Mockito.when(mockedProjectService.getAssignedUsersToProject(Mockito.anyString())).thenReturn(assignedUsersList);
final Date createdAt = new Date();
final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
projectVersionModel.setProjectLink("New project link");
final String componentName = "notification test";
final ComponentVersionView componentVersionView = new ComponentVersionView();
final String componentVersionUrl = "sss";
final String componentIssueUrl = "ddd";
final Map<String, Object> dataSet = new HashMap<>();
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl));
final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
final List<NotificationEvent> notificationEvents = Arrays.asList(notificationEvent);
Collection<NotificationEvent> notEmptyEventList = Arrays.asList();
assertTrue(notEmptyEventList.size() == 0);
notEmptyEventList = userNotificationCache.addUserInformation(notificationEvents);
assertTrue(notEmptyEventList.size() == 1);
}
Aggregations