Search in sources :

Example 1 with MapProcessorCache

use of com.blackducksoftware.integration.hub.notification.MapProcessorCache 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 MapProcessorCache

use of com.blackducksoftware.integration.hub.notification.MapProcessorCache 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 MapProcessorCache

use of com.blackducksoftware.integration.hub.notification.MapProcessorCache in project hub-alert by blackducksoftware.

the class PolicyOverrideProcessorTest method testProcessRemoveEvent.

@Test
public void testProcessRemoveEvent() throws HubIntegrationException, URISyntaxException {
    // Test will break if ListProcessorCache is used because NotificationEvents does not have an equals method defined
    final MapProcessorCache cache = new MapProcessorCache();
    final PolicyOverrideProcessor policyOverrideProcessor = new PolicyOverrideProcessor(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 = "google.com";
    final String componentVersionUrl = "newest";
    final PolicyRuleView policyRuleView = new PolicyRuleView();
    final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
    final String firstName = "B";
    final String lastName = "Dawg";
    final String componentIssueUrl = "broken.edu";
    final PolicyOverrideContentItem notification = new PolicyOverrideContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentUrl, componentVersionUrl, policyRuleList, firstName, lastName, componentIssueUrl);
    assertTrue(cache.getEvents().size() == 0);
    final PolicyOverrideProcessor spyProcessor = Mockito.spy(policyOverrideProcessor);
    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) Date(java.util.Date) PolicyOverrideContentItem(com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache) Test(org.junit.Test)

Example 4 with MapProcessorCache

use of com.blackducksoftware.integration.hub.notification.MapProcessorCache in project hub-alert by blackducksoftware.

the class PolicyViolationProcessorTest method processTestRun.

private void processTestRun(final PolicyViolationContentItem contentItem) throws HubIntegrationException {
    final MapProcessorCache cache = new MapProcessorCache();
    final PolicyViolationProcessor policyViolationProcessor = new PolicyViolationProcessor(cache, new TestLogger());
    assertTrue(cache.getEvents().size() == 0);
    policyViolationProcessor.process(contentItem);
    assertTrue(cache.getEvents().size() == 1);
}
Also used : TestLogger(com.blackducksoftware.integration.test.TestLogger) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache)

Example 5 with MapProcessorCache

use of com.blackducksoftware.integration.hub.notification.MapProcessorCache in project hub-alert by blackducksoftware.

the class NotificationItemProcessor method init.

public void init(final GlobalProperties globalProperties, final IntLogger intLogger) {
    HubServicesFactory hubServicesFactory;
    try {
        hubServicesFactory = globalProperties.createHubServicesFactory(intLogger);
        final ProjectService projectService = hubServicesFactory.createProjectService();
        final MapProcessorCache policyCache = new UserNotificationCache(projectService);
        final VulnerabilityCache vulnerabilityCache = new VulnerabilityCache(projectService, hubServicesFactory);
        getCacheList().add(policyCache);
        getCacheList().add(vulnerabilityCache);
        getProcessorMap().put(PolicyViolationContentItem.class, new PolicyViolationProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyViolationClearedContentItem.class, new PolicyViolationClearedProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyOverrideContentItem.class, new PolicyOverrideProcessor(policyCache, intLogger));
        getProcessorMap().put(VulnerabilityContentItem.class, new VulnerabilityProcessor(vulnerabilityCache, intLogger));
    } catch (final IntegrationException ex) {
        intLogger.error("Error building the notification processor", ex);
    }
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache)

Aggregations

MapProcessorCache (com.blackducksoftware.integration.hub.notification.MapProcessorCache)5 TestLogger (com.blackducksoftware.integration.test.TestLogger)4 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)3 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)3 Date (java.util.Date)3 Test (org.junit.Test)3 PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 VulnerabilitySourceQualifiedId (com.blackducksoftware.integration.hub.api.response.VulnerabilitySourceQualifiedId)1 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)1 PolicyOverrideContentItem (com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem)1 PolicyViolationClearedContentItem (com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem)1 VulnerabilityContentItem (com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem)1 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)1 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)1