use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView 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;
}
use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView 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.api.generated.view.ComponentVersionView 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);
}
use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView 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);
}
use of com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView in project hub-alert by blackducksoftware.
the class UserNotificationCacheTest method testAddUserInformationException.
@Test
public void testAddUserInformationException() throws Exception {
try (OutputLogger outputLogger = new OutputLogger()) {
final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
final UserNotificationCache userNotificationCache = new UserNotificationCache(mockedProjectService);
Mockito.doThrow(new IntegrationException()).when(mockedProjectService).getAssignedUsersToProject(Mockito.anyString());
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> emptyEventList = Arrays.asList();
assertEquals(0, emptyEventList.size());
emptyEventList = userNotificationCache.addUserInformation(notificationEvents);
assertEquals(0, emptyEventList.size());
assertTrue(outputLogger.isLineContainingText("Error getting the users for project"));
}
}
Aggregations