Search in sources :

Example 1 with CachedGroupMapping

use of alluxio.security.group.CachedGroupMapping in project alluxio by Alluxio.

the class CommonUtilsTest method getGroups.

/**
 * Test for the {@link CommonUtils#getGroups(String)} and
 * {@link CommonUtils#getPrimaryGroupName(String)} method.
 */
@Test
public void getGroups() throws Throwable {
    InstancedConfiguration conf = ConfigurationTestUtils.defaults();
    String userName = "alluxio-user1";
    String userGroup1 = "alluxio-user1-group1";
    String userGroup2 = "alluxio-user1-group2";
    List<String> userGroups = new ArrayList<>();
    userGroups.add(userGroup1);
    userGroups.add(userGroup2);
    CachedGroupMapping cachedGroupService = PowerMockito.mock(CachedGroupMapping.class);
    PowerMockito.when(cachedGroupService.getGroups(Mockito.anyString())).thenReturn(Lists.newArrayList(userGroup1, userGroup2));
    PowerMockito.mockStatic(GroupMappingService.Factory.class);
    Mockito.when(GroupMappingService.Factory.get(conf)).thenReturn(cachedGroupService);
    List<String> groups = CommonUtils.getGroups(userName, conf);
    assertEquals(Arrays.asList(userGroup1, userGroup2), groups);
    String primaryGroup = CommonUtils.getPrimaryGroupName(userName, conf);
    assertNotNull(primaryGroup);
    assertEquals(userGroup1, primaryGroup);
}
Also used : GroupMappingService(alluxio.security.group.GroupMappingService) InstancedConfiguration(alluxio.conf.InstancedConfiguration) ArrayList(java.util.ArrayList) CachedGroupMapping(alluxio.security.group.CachedGroupMapping) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

InstancedConfiguration (alluxio.conf.InstancedConfiguration)1 CachedGroupMapping (alluxio.security.group.CachedGroupMapping)1 GroupMappingService (alluxio.security.group.GroupMappingService)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1