Search in sources :

Example 6 with ProjectVersionModel

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

the class AccumulatorWriterTest method generateDataSet.

private Map<String, Object> generateDataSet() {
    final Map<String, Object> dataSet = new HashMap<>();
    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";
    dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl));
    dataSet.put(ItemTypeEnum.RULE.name(), "policyRuleName");
    dataSet.put(ItemTypeEnum.PERSON.name(), "policyUserName");
    dataSet.put(VulnerabilityCache.VULNERABILITY_OPERATION, VulnerabilityOperationEnum.ADD.name());
    final Set<String> vulnSet = new HashSet<>();
    vulnSet.add("vulnerabilityId");
    dataSet.put(VulnerabilityCache.VULNERABILITY_ID_SET, vulnSet);
    return dataSet;
}
Also used : NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) HashMap(java.util.HashMap) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) HashSet(java.util.HashSet)

Example 7 with ProjectVersionModel

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

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

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

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

the class UserNotificationCacheTest method testAddUserInformation.

@Test
public void testAddUserInformation() throws IntegrationException {
    final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
    final UserNotificationCache userNotificationCache = new UserNotificationCache(mockedProjectService);
    final AssignedUserView assignedUser = new AssignedUserView();
    assignedUser.name = "test name";
    final List<AssignedUserView> assignedUsersList = Arrays.asList(assignedUser);
    Mockito.when(mockedProjectService.getAssignedUsersToProject(Mockito.anyString())).thenReturn(assignedUsersList);
    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 Map<String, Object> dataSet = new HashMap<>();
    dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new NotificationContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, componentIssueUrl));
    final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
    final List<NotificationEvent> notificationEvents = Arrays.asList(notificationEvent);
    Collection<NotificationEvent> notEmptyEventList = Arrays.asList();
    assertTrue(notEmptyEventList.size() == 0);
    notEmptyEventList = userNotificationCache.addUserInformation(notificationEvents);
    assertTrue(notEmptyEventList.size() == 1);
}
Also used : HashMap(java.util.HashMap) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) NotificationContentItem(com.blackducksoftware.integration.hub.notification.NotificationContentItem) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) AssignedUserView(com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView) Test(org.junit.Test)

Aggregations

ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)11 Date (java.util.Date)11 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)10 Test (org.junit.Test)10 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)5 HashMap (java.util.HashMap)5 PolicyRuleView (com.blackducksoftware.integration.hub.api.generated.view.PolicyRuleView)4 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)4 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)4 MapProcessorCache (com.blackducksoftware.integration.hub.notification.MapProcessorCache)3 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)3 TestLogger (com.blackducksoftware.integration.test.TestLogger)3 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)2 AssignedUserView (com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView)2 PolicyViolationContentItem (com.blackducksoftware.integration.hub.notification.PolicyViolationContentItem)2 VulnerabilityContentItem (com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem)2 ComponentService (com.blackducksoftware.integration.hub.service.ComponentService)2 HubService (com.blackducksoftware.integration.hub.service.HubService)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 OutputLogger (com.blackducksoftware.integration.hub.alert.OutputLogger)1