Search in sources :

Example 1 with UserData

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

the class UserAdminTest method testGetUser.

/**
     * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#getUser(java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testGetUser() throws IOException {
    User user1 = Mockito.mock(User.class);
    Mockito.when(user1.getType()).thenReturn(Role.USER);
    Mockito.when(user1.getName()).thenReturn("user1");
    Mockito.when(userAdmin.getRole(Mockito.anyString())).thenReturn(user1);
    CompositeData data = mbean.getUser("user1");
    Assert.assertNotNull(data);
    UserData user = UserData.from(data);
    Assert.assertNotNull(user);
    Assert.assertEquals("user1", user.getName());
    Assert.assertEquals(Role.USER, user.getType());
    Mockito.verify(userAdmin).getRole(Mockito.anyString());
}
Also used : User(org.osgi.service.useradmin.User) UserData(org.apache.aries.jmx.codec.UserData) CompositeData(javax.management.openmbean.CompositeData) Test(org.junit.Test)

Example 2 with UserData

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

the class UserAdmin method getUser.

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

Aggregations

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