Search in sources :

Example 6 with ProjectService

use of com.blackducksoftware.integration.hub.service.ProjectService 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"));
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) 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) OutputLogger(com.blackducksoftware.integration.hub.alert.OutputLogger) ComponentVersionView(com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView) Test(org.junit.Test)

Example 7 with ProjectService

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

the class NotificationItemProcessor method init.

public void init(final GlobalProperties globalProperties, final IntLogger intLogger) {
    HubServicesFactory hubServicesFactory;
    try {
        hubServicesFactory = globalProperties.createHubServicesFactory(intLogger);
        final ProjectService projectService = hubServicesFactory.createProjectService();
        final MapProcessorCache policyCache = new UserNotificationCache(projectService);
        final VulnerabilityCache vulnerabilityCache = new VulnerabilityCache(projectService, hubServicesFactory);
        getCacheList().add(policyCache);
        getCacheList().add(vulnerabilityCache);
        getProcessorMap().put(PolicyViolationContentItem.class, new PolicyViolationProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyViolationClearedContentItem.class, new PolicyViolationClearedProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyOverrideContentItem.class, new PolicyOverrideProcessor(policyCache, intLogger));
        getProcessorMap().put(VulnerabilityContentItem.class, new VulnerabilityProcessor(vulnerabilityCache, intLogger));
    } catch (final IntegrationException ex) {
        intLogger.error("Error building the notification processor", ex);
    }
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache)

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