Search in sources :

Example 6 with PolicyRuleView

use of com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView 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 7 with PolicyRuleView

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

the class PolicyViolationProcessorTest method testProcess.

@Test
public void testProcess() throws HubIntegrationException, URISyntaxException {
    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 ResourceMetadata metaView = new ResourceMetadata();
    metaView.href = "Meta href";
    policyRuleView._meta = metaView;
    final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
    final String componentIssueUrl = "issueUrl";
    final PolicyViolationContentItem notification = new PolicyViolationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentUrl, componentVersionUrl, policyRuleList, componentIssueUrl);
    processTestRun(notification);
}
Also used : PolicyViolationContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem) 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) ResourceMetadata(com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 8 with PolicyRuleView

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

the class PolicyViolationProcessorTest method testProcessWithoutVersion.

@Test
public void testProcessWithoutVersion() throws URISyntaxException, HubIntegrationException {
    final Date createdAt = new Date();
    final ProjectVersionModel projectVersionModel = new ProjectVersionModel();
    final String componentName = "Content item test";
    final String componentUrl = "url";
    final String componentVersionUrl = "newest";
    final PolicyRuleView policyRuleView = new PolicyRuleView();
    final ResourceMetadata metaView = new ResourceMetadata();
    metaView.href = "Meta href";
    policyRuleView._meta = metaView;
    final List<PolicyRuleView> policyRuleList = Arrays.asList(policyRuleView);
    final String componentIssueUrl = "issueUrl";
    final PolicyViolationContentItem notification = new PolicyViolationContentItem(createdAt, projectVersionModel, componentName, null, componentUrl, componentVersionUrl, policyRuleList, componentIssueUrl);
    processTestRun(notification);
}
Also used : PolicyViolationContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) ResourceMetadata(com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata) Date(java.util.Date) Test(org.junit.Test)

Example 9 with PolicyRuleView

use of com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView 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);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) PolicyRuleView(com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) PolicyViolationClearedContentItem(com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem)

Aggregations

PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)9 PolicyViolationContentItem (com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem)5 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)3 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)3 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)2 MapProcessorCache (com.blackducksoftware.integration.hub.notification.MapProcessorCache)2 PolicyOverrideContentItem (com.blackducksoftware.integration.hub.notification.PolicyOverrideContentItem)2 PolicyViolationClearedContentItem (com.blackducksoftware.integration.hub.notification.PolicyViolationClearedContentItem)2 TestLogger (com.blackducksoftware.integration.test.TestLogger)2