Search in sources :

Example 11 with HubServicesFactory

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

the class LoginActions method isUserRoleValid.

public boolean isUserRoleValid(final String userName, final RestConnection restConnection) {
    final HubServicesFactory hubServicesFactory = new HubServicesFactory(restConnection);
    final UserGroupService userGroupService = hubServicesFactory.createUserGroupService();
    try {
        final List<RoleAssignmentView> userRoles = userGroupService.getRolesForUser(userName);
        for (final RoleAssignmentView roles : userRoles) {
            if ("System Administrator".equalsIgnoreCase(roles.name)) {
                return true;
            }
        }
    } catch (final IntegrationException e) {
        return false;
    }
    return false;
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UserGroupService(com.blackducksoftware.integration.hub.service.UserGroupService) RoleAssignmentView(com.blackducksoftware.integration.hub.api.generated.view.RoleAssignmentView) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory)

Example 12 with HubServicesFactory

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

the class AccumulatorProcessorTestIT method init.

@Before
public void init() throws Exception {
    globalProperties = new TestGlobalProperties();
    final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactoryWithCredential(new PrintStreamIntLogger(System.out, LogLevel.TRACE));
    projectService = hubServicesFactory.createProjectService();
    notificationDataService = hubServicesFactory.createNotificationService();
    codeLocationService = hubServicesFactory.createCodeLocationService();
    hubService = hubServicesFactory.createHubService();
}
Also used : PrintStreamIntLogger(com.blackducksoftware.integration.log.PrintStreamIntLogger) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) TestGlobalProperties(com.blackducksoftware.integration.hub.alert.TestGlobalProperties) Before(org.junit.Before)

Example 13 with HubServicesFactory

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

the class HubDataActionsTest method testGetHubGroups.

@Test
public void testGetHubGroups() throws Exception {
    final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
    final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
    final HubService hubService = Mockito.mock(HubService.class);
    final List<UserGroupView> userGroups = new ArrayList<>();
    final Boolean active = true;
    final String username = "User";
    final String href = "href";
    final UserGroupView userGroup = new UserGroupView();
    final ResourceMetadata metaView = new ResourceMetadata();
    metaView.href = href;
    userGroup._meta = metaView;
    userGroup.active = active;
    userGroup.name = username;
    userGroups.add(userGroup);
    Mockito.when(hubService.getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE)).thenReturn(userGroups);
    Mockito.when(hubServicesFactory.createHubService()).thenReturn(hubService);
    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(1, hubGroups.size());
    final HubGroup hubGroup = hubGroups.get(0);
    assertEquals(active, hubGroup.getActive());
    assertEquals(username, hubGroup.getName());
    assertEquals(href, hubGroup.getUrl());
}
Also used : ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ResourceMetadata(com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata) Logger(org.slf4j.Logger) HubGroup(com.blackducksoftware.integration.hub.alert.hub.model.HubGroup) UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 14 with HubServicesFactory

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

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

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