use of com.blackducksoftware.integration.hub.alert.hub.model.HubGroup in project hub-alert by blackducksoftware.
the class HubDataActionsTest method testGetHubGroupsNoGroups.
@Test
public void testGetHubGroupsNoGroups() throws Exception {
final GlobalProperties globalProperties = Mockito.mock(GlobalProperties.class);
final HubServicesFactory hubServicesFactory = Mockito.mock(HubServicesFactory.class);
final HubService hubService = Mockito.mock(HubService.class);
Mockito.when(hubService.getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE)).thenReturn(Collections.emptyList());
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(0, hubGroups.size());
}
use of com.blackducksoftware.integration.hub.alert.hub.model.HubGroup 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.alert.hub.model.HubGroup in project hub-alert by blackducksoftware.
the class HubDataActions method getHubGroups.
public List<HubGroup> getHubGroups() throws IntegrationException {
final HubServicesFactory hubServicesFactory = globalProperties.createHubServicesFactory(logger);
if (hubServicesFactory != null) {
final List<UserGroupView> rawGroups = hubServicesFactory.createHubService().getAllResponses(ApiDiscovery.USERGROUPS_LINK_RESPONSE);
final List<HubGroup> groups = new ArrayList<>();
for (final UserGroupView userGroupView : rawGroups) {
final HubGroup hubGroup = new HubGroup(userGroupView.name, userGroupView.active, userGroupView._meta.href);
groups.add(hubGroup);
}
return groups;
} else {
throw new AlertException("Missing global configuration.");
}
}
Aggregations