Search in sources :

Example 1 with ProjectView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectView in project hub-alert by blackducksoftware.

the class AccumulatorProcessorTestIT method testProcess.

@Test
public void testProcess() throws Exception {
    final Long timestamp = (new Date()).getTime();
    final String testProjectName = "hub-Alert-NotificationAccumulatorTest-" + timestamp;
    final String testProjectVersionName = "1.0.0";
    final ProjectRequest projectRequest = new ProjectRequest();
    projectRequest.name = testProjectName;
    final String projectUrl = projectService.createHubProject(projectRequest);
    final ProjectView projectItem = hubService.getResponse(projectUrl, ProjectView.class);
    System.out.println("projectUrl: " + projectUrl);
    final ProjectVersionRequest projectVersionRequest = new ProjectVersionRequest();
    projectVersionRequest.distribution = ProjectVersionDistributionType.INTERNAL;
    projectVersionRequest.phase = ProjectVersionPhaseType.DEVELOPMENT;
    projectVersionRequest.versionName = testProjectVersionName;
    projectService.createHubVersion(projectItem, projectVersionRequest);
    uploadBdio("bdio/component-bdio.jsonld");
    TimeUnit.SECONDS.sleep(60);
    final NotificationResults notificationData = notificationDataService.getAllNotificationResults(new Date(System.currentTimeMillis() - 100000), new Date());
    final AccumulatorProcessor accumulatorProcessor = new AccumulatorProcessor(globalProperties);
    final DBStoreEvent storeEvent = accumulatorProcessor.process(notificationData);
    assertNotNull(storeEvent);
    final List<NotificationEvent> notificationEvents = storeEvent.getNotificationList();
    assertFalse(notificationEvents.isEmpty());
    assertEquals(storeEvent.getEventId().length(), 36);
    NotificationEvent apacheEvent = null;
    for (final NotificationEvent event : notificationEvents) {
        System.out.println(event);
        if ("Apache Commons FileUpload".equals(event.getDataSet().get("COMPONENT"))) {
            apacheEvent = event;
        }
    }
    assertNotNull(apacheEvent);
    final AccumulatorProcessor accumulatorProcessorNull = new AccumulatorProcessor(null);
    final DBStoreEvent storeEventNull = accumulatorProcessorNull.process(notificationData);
    assertNull(storeEventNull);
}
Also used : NotificationResults(com.blackducksoftware.integration.hub.notification.NotificationResults) ProjectRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest) DBStoreEvent(com.blackducksoftware.integration.hub.alert.event.DBStoreEvent) NotificationEvent(com.blackducksoftware.integration.hub.notification.NotificationEvent) ProjectView(com.blackducksoftware.integration.hub.api.generated.view.ProjectView) Date(java.util.Date) ProjectVersionRequest(com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest) Test(org.junit.Test) HubConnectionTest(com.blackducksoftware.integration.test.annotation.HubConnectionTest)

Example 2 with ProjectView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectView 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 3 with ProjectView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectView 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

ProjectView (com.blackducksoftware.integration.hub.api.generated.view.ProjectView)3 HubProject (com.blackducksoftware.integration.hub.alert.hub.model.HubProject)2 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)1 DBStoreEvent (com.blackducksoftware.integration.hub.alert.event.DBStoreEvent)1 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)1 ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)1 ProjectVersionRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectVersionRequest)1 NotificationEvent (com.blackducksoftware.integration.hub.notification.NotificationEvent)1 NotificationResults (com.blackducksoftware.integration.hub.notification.NotificationResults)1 HubService (com.blackducksoftware.integration.hub.service.HubService)1 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)1 HubConnectionTest (com.blackducksoftware.integration.test.annotation.HubConnectionTest)1 Date (java.util.Date)1 Logger (org.slf4j.Logger)1