Search in sources :

Example 11 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testGetImpliedRoles.

/**
     * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#getImpliedRoles(java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testGetImpliedRoles() throws IOException {
    User user1 = Mockito.mock(User.class);
    Authorization auth = Mockito.mock(Authorization.class);
    Mockito.when(user1.getType()).thenReturn(Role.USER);
    Mockito.when(auth.getRoles()).thenReturn(new String[] { "role1" });
    Mockito.when(userAdmin.getRole("role1")).thenReturn(user1);
    Mockito.when(userAdmin.getAuthorization(user1)).thenReturn(auth);
    String[] roles = mbean.getImpliedRoles("role1");
    Assert.assertArrayEquals(new String[] { "role1" }, roles);
}
Also used : Authorization(org.osgi.service.useradmin.Authorization) User(org.osgi.service.useradmin.User) Test(org.junit.Test)

Example 12 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testRemoveMember.

/**
     * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#removeMember(java.lang.String, java.lang.String)}
     * .
     * 
     * @throws IOException
     */
@Test
public void testRemoveMember() throws IOException {
    Group group1 = Mockito.mock(Group.class);
    User user1 = Mockito.mock(User.class);
    Mockito.when(userAdmin.getRole("group1")).thenReturn(group1);
    Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
    Mockito.when(group1.getType()).thenReturn(Role.GROUP);
    Mockito.when(group1.removeMember(user1)).thenReturn(true);
    boolean isAdded = mbean.removeMember("group1", "user1");
    Assert.assertTrue(isAdded);
    Mockito.verify(group1).removeMember(user1);
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User) Test(org.junit.Test)

Example 13 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testAddCredential.

/**
     * Test method for
     * {@link org.apache.aries.jmx.useradmin.UserAdmin#addCredential(java.lang.String, byte[], java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testAddCredential() throws IOException {
    User user1 = Mockito.mock(User.class);
    Dictionary<String, Object> credentials = new Hashtable<String, Object>();
    Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
    Mockito.when(user1.getType()).thenReturn(Role.USER);
    Mockito.when(user1.getCredentials()).thenReturn(credentials);
    mbean.addCredential("password", new byte[] { 1, 2 }, "user1");
    Assert.assertArrayEquals(new byte[] { 1, 2 }, (byte[]) credentials.get("password"));
}
Also used : User(org.osgi.service.useradmin.User) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Example 14 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testGetProperties.

/**
     * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#getProperties(java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testGetProperties() throws IOException {
    User user1 = Mockito.mock(User.class);
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put("key", "value");
    Mockito.when(user1.getProperties()).thenReturn(properties);
    Mockito.when(userAdmin.getRole(Mockito.anyString())).thenReturn(user1);
    TabularData data = mbean.getProperties("user1");
    Assert.assertNotNull(data);
    Assert.assertEquals(JmxConstants.PROPERTIES_TYPE, data.getTabularType());
    CompositeData composite = data.get(new Object[] { "key" });
    Assert.assertNotNull(composite);
    Assert.assertEquals("key", (String) composite.get(JmxConstants.KEY));
    Assert.assertEquals("value", (String) composite.get(JmxConstants.VALUE));
}
Also used : User(org.osgi.service.useradmin.User) Hashtable(java.util.Hashtable) CompositeData(javax.management.openmbean.CompositeData) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 15 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testRemoveProperty.

/**
     * Test method for
     * {@link org.apache.aries.jmx.useradmin.UserAdmin#removeProperty(java.lang.String, java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testRemoveProperty() throws IOException {
    User user1 = Mockito.mock(User.class);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
    Mockito.when(user1.getType()).thenReturn(Role.USER);
    Mockito.when(user1.getProperties()).thenReturn(props);
    mbean.removeProperty("key", "user1");
    Assert.assertEquals(0, props.size());
}
Also used : User(org.osgi.service.useradmin.User) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Aggregations

User (org.osgi.service.useradmin.User)25 Test (org.junit.Test)22 Hashtable (java.util.Hashtable)8 CompositeData (javax.management.openmbean.CompositeData)5 Group (org.osgi.service.useradmin.Group)5 IOException (java.io.IOException)3 TabularData (javax.management.openmbean.TabularData)3 Role (org.osgi.service.useradmin.Role)3 UserData (org.apache.aries.jmx.codec.UserData)2 Authorization (org.osgi.service.useradmin.Authorization)2 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 AuthorizationData (org.apache.aries.jmx.codec.AuthorizationData)1 RoleData (org.apache.aries.jmx.codec.RoleData)1