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;
}
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();
}
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());
}
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());
}
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());
}
Aggregations