use of com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem 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.PolicyViolationClearedContentItem in project hub-alert by blackducksoftware.
the class PolicyViolationClearedProcessor method process.
@Override
public void process(final NotificationContentItem notification) throws HubIntegrationException {
if (notification instanceof PolicyViolationClearedContentItem) {
final PolicyViolationClearedContentItem policyViolationCleared = (PolicyViolationClearedContentItem) notification;
final Map<String, Object> dataMap = new HashMap<>();
for (final PolicyRuleView rule : policyViolationCleared.getPolicyRuleList()) {
dataMap.put(POLICY_CONTENT_ITEM, policyViolationCleared);
dataMap.put(POLICY_RULE, rule);
final String eventKey = generateEventKey(dataMap);
final Map<String, Object> dataSet = generateDataSet(dataMap);
final NotificationEvent event = new NotificationEvent(eventKey, NotificationCategoryEnum.POLICY_VIOLATION, dataSet);
if (getCache().hasEvent(event.getEventKey())) {
getCache().removeEvent(event);
} else {
event.setCategoryType(NotificationCategoryEnum.POLICY_VIOLATION_CLEARED);
getCache().addEvent(event);
}
}
}
}
Aggregations