Search in sources :

Example 1 with ProjectService

use of com.blackducksoftware.integration.hub.service.ProjectService 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);
}
Also used : HashMap(java.util.HashMap) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) 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) ComponentService(com.blackducksoftware.integration.hub.service.ComponentService) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 2 with ProjectService

use of com.blackducksoftware.integration.hub.service.ProjectService 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);
}
Also used : HashMap(java.util.HashMap) VulnerabilityV2View(com.blackducksoftware.integration.hub.api.generated.view.VulnerabilityV2View) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectVersionModel(com.blackducksoftware.integration.hub.notification.ProjectVersionModel) Date(java.util.Date) VulnerabilityContentItem(com.blackducksoftware.integration.hub.notification.VulnerabilityContentItem) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) ComponentService(com.blackducksoftware.integration.hub.service.ComponentService) AssignedUserView(com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 3 with ProjectService

use of com.blackducksoftware.integration.hub.service.ProjectService 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());
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) Logger(org.slf4j.Logger) HubService(com.blackducksoftware.integration.hub.service.HubService) HubProject(com.blackducksoftware.integration.hub.alert.hub.model.HubProject) Test(org.junit.Test)

Example 4 with ProjectService

use of com.blackducksoftware.integration.hub.service.ProjectService in project hub-alert by blackducksoftware.

the class HubDataActionsTest method testGetHubProjects.

@Test
public void testGetHubProjects() 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);
    final List<ProjectView> projectViews = new ArrayList<>();
    final String projectName = "projectName";
    final ProjectView projectView = new ProjectView();
    projectView.name = projectName;
    projectViews.add(projectView);
    Mockito.when(hubService.getAllResponses(ApiDiscovery.PROJECTS_LINK_RESPONSE)).thenReturn(projectViews);
    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(1, hubProjects.size());
    final HubProject hubProject = hubProjects.get(0);
    assertEquals(projectName, hubProject.getName());
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) ProjectView(com.blackducksoftware.integration.hub.api.generated.view.ProjectView) Logger(org.slf4j.Logger) HubService(com.blackducksoftware.integration.hub.service.HubService) HubProject(com.blackducksoftware.integration.hub.alert.hub.model.HubProject) Test(org.junit.Test)

Example 5 with ProjectService

use of com.blackducksoftware.integration.hub.service.ProjectService 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

ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)7 Test (org.junit.Test)6 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)5 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)4 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)4 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)4 HubService (com.blackducksoftware.integration.hub.service.HubService)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)3 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)2 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 HubProject (com.blackducksoftware.integration.hub.alert.hub.model.HubProject)2 AssignedUserView (com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView)2 ComponentService (com.blackducksoftware.integration.hub.service.ComponentService)2 Logger (org.slf4j.Logger)2 OutputLogger (com.blackducksoftware.integration.hub.alert.OutputLogger)1 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)1 VulnerabilityV2View (com.blackducksoftware.integration.hub.api.generated.view.VulnerabilityV2View)1 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)1