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