use of com.blackducksoftware.integration.hub.service.HubService in project hub-alert by blackducksoftware.
the class HubDataActionsTest method testGetHubGroupsNoGroups.
@Test
public void testGetHubGroupsNoGroups() throws Exception {
final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final HubService hubService = Mockito.mock(HubService.class);
Mockito.when(hubService.getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE)).thenReturn(Collections.emptyList());
Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(hubServicesFactory);
final HubDataActions hubDataActions = new HubDataActions(globalProperties);
final List<HubGroup> hubGroups = hubDataActions.getHubGroups();
assertEquals(0, hubGroups.size());
}
use of com.blackducksoftware.integration.hub.service.HubService in project hub-alert by blackducksoftware.
the class VulnerabilityCacheTest method testRemoveEvent.
@Test
public void testRemoveEvent() {
final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
final HubService mockedHubService = Mockito.mock(HubService.class);
final ComponentService mockedComponentService = Mockito.mock(ComponentService.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final VulnerabilityCache vulnerabilityCache = new VulnerabilityCache(mockedProjectService, hubServicesFactory);
Mockito.when(hubServicesFactory.createProjectService()).thenReturn(mockedProjectService);
Mockito.when(hubServicesFactory.createHubService()).thenReturn(mockedHubService);
Mockito.when(hubServicesFactory.createComponentService()).thenReturn(mockedComponentService);
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));
dataSet.put(VulnerabilityCache.VULNERABILITY_ID_SET, new HashSet<String>());
final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
assumeTrue(vulnerabilityCache.getEventMap().size() == 0);
vulnerabilityCache.removeEvent(notificationEvent);
assumeTrue(vulnerabilityCache.getEventMap().size() == 1);
vulnerabilityCache.removeEvent(notificationEvent);
assumeTrue(vulnerabilityCache.getEventMap().size() == 0);
}
use of com.blackducksoftware.integration.hub.service.HubService in project hub-alert by blackducksoftware.
the class VulnerabilityCacheTest method testGetEvents.
@Test
public void testGetEvents() throws IntegrationException, URISyntaxException {
final ProjectService mockedProjectService = Mockito.mock(ProjectService.class);
final HubService mockedHubService = Mockito.mock(HubService.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final ComponentService mockedComponentService = Mockito.mock(ComponentService.class);
final VulnerabilityCache vulnerabilityCache = new VulnerabilityCache(mockedProjectService, hubServicesFactory);
Mockito.when(hubServicesFactory.createProjectService()).thenReturn(mockedProjectService);
Mockito.when(hubServicesFactory.createHubService()).thenReturn(mockedHubService);
Mockito.when(hubServicesFactory.createComponentService()).thenReturn(mockedComponentService);
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 VulnerabilityV2View vulnView = new VulnerabilityV2View();
vulnView.severity = "HIGH";
vulnView.name = "vulnerable";
Mockito.when(mockedComponentService.getVulnerabilitiesFromComponentVersion(Mockito.any())).thenReturn(Arrays.asList(vulnView));
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";
Mockito.when(mockedHubService.getAllResponses(componentVersionView, ComponentVersionView.VULNERABILITIES_LINK_RESPONSE)).thenReturn(Arrays.asList(vulnView));
final Map<String, Object> dataSet = new HashMap<>();
dataSet.put(NotificationEvent.DATA_SET_KEY_NOTIFICATION_CONTENT, new VulnerabilityContentItem(createdAt, projectVersionModel, componentName, componentVersionView, componentVersionUrl, Arrays.asList(), Arrays.asList(), Arrays.asList(), componentIssueUrl));
dataSet.put(VulnerabilityCache.VULNERABILITY_ID_SET, Collections.singleton("vulnerable"));
final NotificationEvent notificationEvent = new NotificationEvent("key", NotificationCategoryEnum.HIGH_VULNERABILITY, dataSet);
final Collection<NotificationEvent> emptyNotifications = vulnerabilityCache.getEvents();
assertTrue(emptyNotifications.size() == 0);
vulnerabilityCache.addEvent(notificationEvent);
final Collection<NotificationEvent> notEmptyNotifications = vulnerabilityCache.getEvents();
assertTrue(notEmptyNotifications.size() == 1);
}
use of com.blackducksoftware.integration.hub.service.HubService in project hub-alert by blackducksoftware.
the class HubDataActionsTest method testGetHubGroups.
@Test
public void testGetHubGroups() throws Exception {
final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final HubService hubService = Mockito.mock(HubService.class);
final List<UserGroupView> userGroups = new ArrayList<>();
final Boolean active = true;
final String username = "User";
final String href = "href";
final UserGroupView userGroup = new UserGroupView();
final ResourceMetadata metaView = new ResourceMetadata();
metaView.href = href;
userGroup._meta = metaView;
userGroup.active = active;
userGroup.name = username;
userGroups.add(userGroup);
Mockito.when(hubService.getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE)).thenReturn(userGroups);
Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(hubServicesFactory);
final HubDataActions hubDataActions = new HubDataActions(globalProperties);
final List<HubGroup> hubGroups = hubDataActions.getHubGroups();
assertEquals(1, hubGroups.size());
final HubGroup hubGroup = hubGroups.get(0);
assertEquals(active, hubGroup.getActive());
assertEquals(username, hubGroup.getName());
assertEquals(href, hubGroup.getUrl());
}
use of com.blackducksoftware.integration.hub.service.HubService in project hub-alert by blackducksoftware.
the class HubDataActionsTest method testGetHubProjectsNoProjects.
@Test
public void testGetHubProjectsNoProjects() throws Exception {
final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final ProjectService projectRequestService = Mockito.mock(ProjectService.class);
final HubService hubService = Mockito.mock(HubService.class);
Mockito.when(hubService.getAllResponses(ApiDiscovery.PROJECTS_LINK_RESPONSE)).thenReturn(Collections.emptyList());
Mockito.when(hubServicesFactory.createProjectService()).thenReturn(projectRequestService);
Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
Mockito.when(globalProperties.createHubServicesFactory(Mockito.any(Logger.class))).thenReturn(hubServicesFactory);
final HubDataActions hubDataActions = new HubDataActions(globalProperties);
final List<HubProject> hubProjects = hubDataActions.getHubProjects();
assertEquals(0, hubProjects.size());
}
Aggregations