Search in sources :

Example 1 with ComponentVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView in project hub-alert by blackducksoftware.

the class PolicyViolationClearedProcessorTest method testProcess.

@Test
public void testProcess() throws URISyntaxException, HubIntegrationException {
    final MapProcessorCache cache = new MapProcessorCache();
    final PolicyViolationClearedProcessor policyViolationClearedProcessor = new PolicyViolationClearedProcessor(cache, new TestLogger());
    final Date createdAt = new Date();
    final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
    final String componentName = "Content item test";
    final ComponentVersionView componentVersionView = new ComponentVersionView();
    final String componentUrl = "url";
    final String componentVersionUrl = "newest";
    final PolicyRuleView policyRuleView = new PolicyRuleView();
    final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
    final String componentIssueUrl = "broken.edu";
    final PolicyViolationClearedContentItem notification = new PolicyViolationClearedContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentUrl, componentVersionUrl, policyRuleList, componentIssueUrl);
    assertTrue(cache.getEvents().size() == 0);
    final PolicyViolationClearedProcessor spyProcessor = Mockito.spy(policyViolationClearedProcessor);
    Mockito.doReturn("key").when(spyProcessor).generateEventKey(Mockito.anyMap());
    spyProcessor.process(notification);
    assertTrue(cache.getEvents().size() == 1);
    spyProcessor.process(notification);
    assertTrue(cache.getEvents().size() == 0);
}
Also used : ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) TestLogger(com.blackducksoftware.integration.test.TestLogger) PolicyViolationClearedContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem) Date(java.util.Date) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache) Test(org.junit.Test)

Example 2 with ComponentVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView 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);
}
Also used : VulnerabilityContentItem(com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem) VulnerabilitySourceQualifiedId(com.blackducksoftware.integration.hub.api.response.VulnerabilitySourceQualifiedId) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) TestLogger(com.blackducksoftware.integration.test.TestLogger) Date(java.util.Date) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache) Test(org.junit.Test)

Example 3 with ComponentVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView 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);
}
Also used : HashMap(java.util.HashMap) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) ComponentService(com.blackducksoftware.integration.hub.service.ComponentService) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 4 with ComponentVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView 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);
}
Also used : HashMap(java.util.HashMap) VulnerabilityV2View(com.blackducksoftware.integration.hub.api.generated.view.VulnerabilityV2View) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) VulnerabilityContentItem(com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) ComponentService(com.blackducksoftware.integration.hub.service.ComponentService) AssignedUserView(com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 5 with ComponentVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView 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);
}
Also used : NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) TreeSet(java.util.TreeSet) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) NotificationService(com.blackducksoftware.integration.hub.service.NotificationService) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)10 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)10 Date (java.util.Date)10 Test (org.junit.Test)9 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)5 HashMap (java.util.HashMap)5 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)4 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)4 PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)3 MapProcessorCache (com.blackducksoftware.integration.hub.notification.MapProcessorCache)3 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)3 TestLogger (com.blackducksoftware.integration.test.TestLogger)3 AssignedUserView (com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView)2 VulnerabilityContentItem (com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem)2 ComponentService (com.blackducksoftware.integration.hub.service.ComponentService)2 HubService (com.blackducksoftware.integration.hub.service.HubService)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 OutputLogger (com.blackducksoftware.integration.hub.alert.OutputLogger)1 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)1