UserAdmin implements UserAdminMBean { 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(); } UserAdmin(org.osgi.service.useradmin.UserAdmin userAdmin); void addCredential(String key, byte[] value, String username); void addCredentialString(String key, String value, String username); boolean addMember(String groupname, String rolename); void addPropertyString(String key, String value, String rolename); void addProperty(String key, byte[] value, String rolename); boolean addRequiredMember(String groupname, String rolename); void createGroup(String name); void createRole(String name); void createUser(String name); CompositeData getAuthorization(String username); TabularData getCredentials(String username); CompositeData getGroup(String groupname); String[] getGroups(String filter); String[] getImpliedRoles(String username); String[] getMembers(String groupname); TabularData getProperties(String rolename); String[] getRequiredMembers(String groupname); CompositeData getRole(String name); String[] getRoles(String filter); CompositeData getUser(String username); String getUserWithProperty(String key, String value); String[] getUsers(String filter); String[] listGroups(); String[] listRoles(); String[] listUsers(); void removeCredential(String key, String username); boolean removeGroup(String name); boolean removeMember(String groupname, String rolename); void removeProperty(String key, String rolename); boolean removeRole(String name); boolean removeUser(String name);  }
@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()); }