Search in sources :

Example 1 with HubServicesFactory

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

the class TestGlobalProperties method createHubServicesFactoryWithCredential.

public HubServicesFactory createHubServicesFactoryWithCredential(final IntLogger logger) throws Exception {
    setHubUrl(testProperties.getProperty(TestPropertyKey.TEST_HUB_SERVER_URL));
    setHubTrustCertificate(true);
    final HubServerConfig hubServerConfig = createHubServerConfigWithCredentials(logger);
    final RestConnection restConnection = hubServerConfig.createCredentialsRestConnection(logger);
    return new HubServicesFactory(restConnection);
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory)

Example 2 with HubServicesFactory

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

Example 3 with HubServicesFactory

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

the class HubDataActions method getHubProjects.

public List<HubProject> getHubProjects() throws IntegrationException {
    final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactory(logger);
    if (hubServicesFactory != null) {
        final List<ProjectView> rawProjects = hubServicesFactory.createHubService().getAllResponses(ApiDiscovery.PROJECTS_LINK_RESPONSE);
        final List<HubProject> projects = new ArrayList<>();
        for (final ProjectView projectView : rawProjects) {
            final HubProject project = new HubProject(projectView.name);
            projects.add(project);
        }
        return projects;
    } else {
        throw new AlertException("Missing global configuration.");
    }
}
Also used : ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectView(com.blackducksoftware.integration.hub.api.generated.view.ProjectView) HubProject(com.blackducksoftware.integration.hub.alert.hub.model.HubProject) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 4 with HubServicesFactory

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

the class DailyItemReader method phoneHome.

private PhoneHomeResponse phoneHome() {
    final String productVersion = globalProperties.getProductVersion();
    if (!GlobalProperties.PRODUCT_VERSION_UNKNOWN.equals(productVersion)) {
        final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactoryAndLogErrors(logger);
        final PhoneHomeService phoneHomeService = hubServicesFactory.createPhoneHomeService();
        final PhoneHomeRequestBodyBuilder phoneHomeRequestBodyBuilder = phoneHomeService.createInitialPhoneHomeRequestBodyBuilder(ThirdPartyName.ALERT, productVersion, productVersion);
        final PhoneHomeRequestBody phoneHomeRequestBody = phoneHomeRequestBodyBuilder.build();
        return phoneHomeService.startPhoneHome(phoneHomeRequestBody);
    } else {
        return null;
    }
}
Also used : PhoneHomeRequestBody(com.blackducksoftware.integration.phonehome.PhoneHomeRequestBody) PhoneHomeRequestBodyBuilder(com.blackducksoftware.integration.phonehome.PhoneHomeRequestBodyBuilder) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) PhoneHomeService(com.blackducksoftware.integration.hub.service.PhoneHomeService)

Example 5 with HubServicesFactory

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

Aggregations

HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)21 Test (org.junit.Test)7 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)6 HubService (com.blackducksoftware.integration.hub.service.HubService)6 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)5 Logger (org.slf4j.Logger)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)4 ArrayList (java.util.ArrayList)4 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 HubGroup (com.blackducksoftware.integration.hub.alert.hub.model.HubGroup)3 HubProject (com.blackducksoftware.integration.hub.alert.hub.model.HubProject)3 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)3 UserGroupView (com.blackducksoftware.integration.hub.api.generated.view.UserGroupView)3 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)3 Date (java.util.Date)3 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)2 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)2 NotificationContentItem (com.blackducksoftware.integration.hub.notification.NotificationContentItem)2 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)2 NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)2