Search in sources :

Example 6 with HubService

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

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

the class ChannelRequestHelper method sendGenericRequest.

public Response sendGenericRequest(final Request request) throws IntegrationException {
    Response response = null;
    try {
        final HubService service = hubServicesFactory.createHubService();
        response = service.executeRequest(request);
        logger.trace("Response: " + response.toString());
        return response;
    } catch (final Exception generalException) {
        logger.error("Error sending request", generalException);
        throw new AlertException(generalException.getMessage());
    }
}
Also used : Response(com.blackducksoftware.integration.hub.request.Response) HubService(com.blackducksoftware.integration.hub.service.HubService) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Aggregations

HubService (com.blackducksoftware.integration.hub.service.HubService)7 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)6 Test (org.junit.Test)6 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)4 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)4 Logger (org.slf4j.Logger)4 HubGroup (com.blackducksoftware.integration.hub.alert.hub.model.HubGroup)2 HubProject (com.blackducksoftware.integration.hub.alert.hub.model.HubProject)2 ComponentVersionView (com.blackducksoftware.integration.hub.api.generated.view.ComponentVersionView)2 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)2 ProjectVersionModel (com.blackducksoftware.integration.hub.notification.ProjectVersionModel)2 ComponentService (com.blackducksoftware.integration.hub.service.ComponentService)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)1 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)1 AssignedUserView (com.blackducksoftware.integration.hub.api.generated.view.AssignedUserView)1 ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)1