Search in sources :

Example 1 with HubGroup

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());
}
Also used : GlobalProperties(com.blackducksoftware.integration.hub.alert.config.GlobalProperties) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) Logger(org.slf4j.Logger) HubGroup(com.blackducksoftware.integration.hub.alert.hub.model.HubGroup) HubService(com.blackducksoftware.integration.hub.service.HubService) Test(org.junit.Test)

Example 2 with HubGroup

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());
}
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 3 with HubGroup

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.");
    }
}
Also used : UserGroupView(com.blackducksoftware.integration.hub.api.generated.view.UserGroupView) ArrayList(java.util.ArrayList) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) HubGroup(com.blackducksoftware.integration.hub.alert.hub.model.HubGroup) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Aggregations

HubGroup (com.blackducksoftware.integration.hub.alert.hub.model.HubGroup)3 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 UserGroupView (com.blackducksoftware.integration.hub.api.generated.view.UserGroupView)2 HubService (com.blackducksoftware.integration.hub.service.HubService)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Logger (org.slf4j.Logger)2 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)1 ResourceMetadata (com.blackducksoftware.integration.hub.api.generated.component.ResourceMetadata)1