use of com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem in project hub-alert by blackducksoftware.
the class VulnerabilityProcessorTest method testProcess.
@Test
public void testProcess() throws URISyntaxException, HubIntegrationException {
final MapProcessorCache cache = new MapProcessorCache();
final VulnerabilityProcessor vulnProcessor = new VulnerabilityProcessor(cache, new TestLogger());
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 List<VulnerabilitySourceQualifiedId> addedVulns = Lists.newArrayList();
final List<VulnerabilitySourceQualifiedId> updatedVulns = Lists.newArrayList();
final List<VulnerabilitySourceQualifiedId> deletedVulns = Lists.newArrayList();
final VulnerabilityContentItem emptyVulnerabilityContentItem = new VulnerabilityContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, addedVulns, updatedVulns, deletedVulns, componentIssueUrl);
vulnProcessor.process(emptyVulnerabilityContentItem);
assertTrue(cache.getEvents().size() == 0);
final VulnerabilitySourceQualifiedId addedQualifiedId = new VulnerabilitySourceQualifiedId();
final VulnerabilitySourceQualifiedId removedQualifiedId = new VulnerabilitySourceQualifiedId();
addedVulns.add(addedQualifiedId);
updatedVulns.add(addedQualifiedId);
deletedVulns.add(removedQualifiedId);
final VulnerabilityContentItem filledAndEmptiedVulnerabilityContentItem = new VulnerabilityContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, addedVulns, updatedVulns, deletedVulns, componentIssueUrl);
vulnProcessor.process(filledAndEmptiedVulnerabilityContentItem);
assertTrue(cache.getEvents().size() == 0);
}
use of com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem in project hub-alert by blackducksoftware.
the class VulnerabilityProcessor method process.
@Override
public void process(final NotificationContentItem notification) {
if (notification instanceof VulnerabilityContentItem) {
final VulnerabilityContentItem vulnerabilityContentItem = (VulnerabilityContentItem) notification;
handleNotification(vulnerabilityContentItem);
}
}
use of com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem in project hub-alert by blackducksoftware.
the class VulnerabilityCacheTest method testGetEvents.
@Test
public void testGetEvents() throws IntegrationException, URISyntaxException {
final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
final HubService mockedHubService = Mockito.mock(HubService.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final ComponentService mockedComponentService = Mockito.mock(ComponentService.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 AssignedUserView assignedUser = new AssignedUserView();
assignedUser.name = "test name";
final List<AssignedUserView> assignedUsersList = Arrays.asList(assignedUser);
Mockito.when(mockedProjectService.getAssignedUsersToProject(Mockito.anyString())).thenReturn(assignedUsersList);
final VulnerabilityV2View vulnView = new VulnerabilityV2View();
vulnView.severity = "HIGH";
vulnView.name = "vulnerable";
Mockito.when(mockedComponentService.getVulnerabilitiesFromComponentVersion(Mockito.any())).thenReturn(Arrays.asList(vulnView));
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";
Mockito.when(mockedHubService.getAllResponses(componentVersionView, ComponentVersionView.VULNERABILITIES_LINK_RESPONSE)).thenReturn(Arrays.asList(vulnView));
final Map<String, Object> dataSet = new HashMap<>();
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new VulnerabilityContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, Arrays.asList(), Arrays.asList(), Arrays.asList(), componentIssueUrl));
dataSet.put(VulnerabilityCache.VULNERABILITY_ID_SET, Collections.singleton("vulnerable"));
final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
final Collection<NotificationEvent> emptyNotifications = vulnerabilityCache.getEvents();
assertTrue(emptyNotifications.size() == 0);
vulnerabilityCache.addEvent(notificationEvent);
final Collection<NotificationEvent> notEmptyNotifications = vulnerabilityCache.getEvents();
assertTrue(notEmptyNotifications.size() == 1);
}
use of com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem in project hub-alert by blackducksoftware.
the class VulnerabilityCache method createVulnerabilityEvents.
private List<NotificationEvent> createVulnerabilityEvents(final NotificationEvent originalEvent) throws IntegrationException {
final List<NotificationEvent> eventList = new LinkedList<>();
final VulnerabilityContentItem vulnerabilityContent = (VulnerabilityContentItem) originalEvent.getDataSet().get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
final List<VulnerabilityV2View> vulnerabilityList = hubServicesFactory.createHubService().getAllResponses(vulnerabilityContent.getComponentVersion(), ComponentVersionView.VULNERABILITIES_LINK_RESPONSE);
addEventsToList(originalEvent, vulnerabilityList, eventList);
addCountsToDataSet(eventList);
return eventList;
}
use of com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem in project hub-alert by blackducksoftware.
the class VulnerabilityProcessor method generateDataSet.
@Override
public Map<String, Object> generateDataSet(final Map<String, Object> inputData) {
final Map<String, Object> dataSet = new HashMap<>();
final VulnerabilityContentItem vulnerabilityContent = (VulnerabilityContentItem) inputData.get(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT);
dataSet.put(ItemTypeEnum.COMPONENT.name(), vulnerabilityContent.getComponentName());
dataSet.put(ItemTypeEnum.VERSION.name(), vulnerabilityContent.getComponentVersion().versionName);
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, vulnerabilityContent);
dataSet.put(VulnerabilityCache.VULNERABILITY_ID_SET, inputData.get(VulnerabilityCache.VULNERABILITY_ID_SET));
return dataSet;
}
Aggregations