Search in sources :

Example 1 with HubProject

use of com.blackducksoftware.integration.hub.alert.hub.model.HubProject 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 2 with HubProject

use of com.blackducksoftware.integration.hub.alert.hub.model.HubProject 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 3 with HubProject

use of com.blackducksoftware.integration.hub.alert.hub.model.HubProject 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)

Aggregations

HubProject (com.blackducksoftware.integration.hub.alert.hub.model.HubProject)3 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)2 HubService (com.blackducksoftware.integration.hub.service.HubService)2 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)1