Search in sources :

Example 1 with TestLogger

use of com.blackducksoftware.integration.test.TestLogger in project hub-alert by blackducksoftware.

the class NotificationItemProcessorTest method testInit.

@Test
public void testInit() {
    final GlobalProperties globalProperties = new TestGlobalProperties();
    final NotificationItemProcessor notificationItemProcessor = new NotificationItemProcessor(globalProperties, new TestLogger());
    assertTrue(notificationItemProcessor.getCacheList().size() == 2);
    assertTrue(notificationItemProcessor.getProcessorMap().size() == 4);
}
Also used : TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) TestLogger(com.blackducksoftware.integration.test.TestLogger) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Test(org.junit.Test)

Example 2 with TestLogger

use of com.blackducksoftware.integration.test.TestLogger 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 3 with TestLogger

use of com.blackducksoftware.integration.test.TestLogger 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 4 with TestLogger

use of com.blackducksoftware.integration.test.TestLogger 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 5 with TestLogger

use of com.blackducksoftware.integration.test.TestLogger 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)

Aggregations

TestLogger (com.blackducksoftware.integration.test.TestLogger)6 Test (org.junit.Test)5 MapProcessorCache (com.blackducksoftware.integration.hub.notification.MapProcessorCache)4 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)3 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)3 Date (java.util.Date)3 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)2 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)2 DBStoreEvent (com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)1 VulnerabilitySourceQualifiedId (com.blackducksoftware.integration.hub.api.response.VulnerabilitySourceQualifiedId)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)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