Search in sources :

Example 1 with GroupData

use of org.apache.aries.jmx.codec.GroupData in project aries by apache.

the class UserAdminTest method testGetGroup.

/**
 * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#getGroup(java.lang.String)}.
 *
 * @throws IOException
 */
@Test
public void testGetGroup() throws IOException {
    Group group1 = Mockito.mock(Group.class);
    Mockito.when(group1.getType()).thenReturn(Role.GROUP);
    Mockito.when(group1.getName()).thenReturn("group1");
    Role role1 = Mockito.mock(Role.class);
    Mockito.when(role1.getName()).thenReturn("role1");
    Role role2 = Mockito.mock(Role.class);
    Mockito.when(role2.getName()).thenReturn("role2");
    Mockito.when(group1.getRequiredMembers()).thenReturn(new Role[] { role1 });
    Mockito.when(group1.getMembers()).thenReturn(new Role[] { role2 });
    Mockito.when(userAdmin.getRole(Mockito.anyString())).thenReturn(group1);
    CompositeData data = mbean.getGroup("group1");
    Assert.assertNotNull(data);
    GroupData group = GroupData.from(data);
    Assert.assertNotNull(group);
    Assert.assertEquals("group1", group.getName());
    Assert.assertEquals(Role.GROUP, group.getType());
    Assert.assertArrayEquals(new String[] { "role2" }, group.getMembers());
    Assert.assertArrayEquals(new String[] { "role1" }, group.getRequiredMembers());
    Mockito.verify(userAdmin).getRole(Mockito.anyString());
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) CompositeData(javax.management.openmbean.CompositeData) GroupData(org.apache.aries.jmx.codec.GroupData) Test(org.junit.Test)

Example 2 with GroupData

use of org.apache.aries.jmx.codec.GroupData in project aries by apache.

the class UserAdmin method getGroup.

/**
 * @see org.osgi.jmx.service.useradmin.UserAdminMBean#getGroup(java.lang.String)
 */
public CompositeData getGroup(String groupname) throws IOException {
    if (groupname == null) {
        throw new IOException("Group name cannot be null");
    }
    Role role = userAdmin.getRole(groupname);
    if (role == null) {
        return null;
    }
    validateRoleType(role, Role.GROUP);
    return new GroupData((Group) role).toCompositeData();
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) IOException(java.io.IOException) GroupData(org.apache.aries.jmx.codec.GroupData)

Aggregations

GroupData (org.apache.aries.jmx.codec.GroupData)2 Group (org.osgi.service.useradmin.Group)2 Role (org.osgi.service.useradmin.Role)2 IOException (java.io.IOException)1 CompositeData (javax.management.openmbean.CompositeData)1 Test (org.junit.Test)1