Search in sources :

Example 81 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class FrameworkTest method testUninstallBundles.

@Test
public void testUninstallBundles() throws Exception {
    Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(5)).thenReturn(bundle);
    CompositeData data = mbean.uninstallBundles(new long[] { 5 });
    Mockito.verify(bundle).uninstall();
    BatchActionResult batch = BatchActionResult.from(data);
    Assert.assertEquals(5, batch.getCompleted()[0]);
    Assert.assertTrue(batch.isSuccess());
    Assert.assertNull(batch.getError());
    Assert.assertNull(batch.getRemainingItems());
    CompositeData data2 = mbean.uninstallBundles(null);
    BatchActionResult batch2 = BatchActionResult.from(data2);
    Assert.assertNull(batch2.getCompleted());
    Assert.assertFalse(batch2.isSuccess());
    Assert.assertNotNull(batch2.getError());
    Assert.assertNull(batch2.getRemainingItems());
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 82 with CompositeData

use of javax.management.openmbean.CompositeData 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 83 with CompositeData

use of javax.management.openmbean.CompositeData 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 84 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class FrameworkTest method testStartBundles.

@Test
public void testStartBundles() throws Exception {
    Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(5)).thenReturn(bundle);
    CompositeData data = mbean.startBundles(new long[] { 5 });
    Mockito.verify(bundle).start();
    BatchActionResult batch = BatchActionResult.from(data);
    Assert.assertEquals(5, batch.getCompleted()[0]);
    Assert.assertTrue(batch.isSuccess());
    Assert.assertNull(batch.getError());
    Assert.assertNull(batch.getRemainingItems());
    CompositeData data2 = mbean.startBundles(null);
    BatchActionResult batch2 = BatchActionResult.from(data2);
    Assert.assertNull(batch2.getCompleted());
    Assert.assertFalse(batch2.isSuccess());
    Assert.assertNotNull(batch2.getError());
    Assert.assertNull(batch2.getRemainingItems());
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 85 with CompositeData

use of javax.management.openmbean.CompositeData in project aries by apache.

the class FrameworkTest method testSetBundleStartLevels.

@Test
public void testSetBundleStartLevels() throws IOException {
    Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(2)).thenReturn(bundle);
    CompositeData data = mbean.setBundleStartLevels(new long[] { 2 }, new int[] { 2 });
    Mockito.verify(startLevel).setBundleStartLevel(bundle, 2);
    BatchActionResult batch = BatchActionResult.from(data);
    Assert.assertEquals(2, batch.getCompleted()[0]);
    Assert.assertTrue(batch.isSuccess());
    Assert.assertNull(batch.getError());
    Assert.assertNull(batch.getRemainingItems());
    CompositeData data2 = mbean.setBundleStartLevels(new long[] { 2 }, new int[] { 2, 4 });
    BatchActionResult batch2 = BatchActionResult.from(data2);
    Assert.assertNull(batch2.getCompleted());
    Assert.assertFalse(batch2.isSuccess());
    Assert.assertNotNull(batch2.getError());
    Assert.assertNull(batch2.getRemainingItems());
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Aggregations

CompositeData (javax.management.openmbean.CompositeData)229 TabularData (javax.management.openmbean.TabularData)91 Test (org.junit.Test)73 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)68 TabularDataSupport (javax.management.openmbean.TabularDataSupport)51 CompositeType (javax.management.openmbean.CompositeType)50 HashMap (java.util.HashMap)31 ArrayList (java.util.ArrayList)27 Map (java.util.Map)27 Bundle (org.osgi.framework.Bundle)24 ObjectName (javax.management.ObjectName)21 OpenDataException (javax.management.openmbean.OpenDataException)18 IOException (java.io.IOException)17 Collection (java.util.Collection)16 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)16 AuditEvent (org.nhindirect.common.audit.AuditEvent)15 TabularType (javax.management.openmbean.TabularType)13 MBeanServer (javax.management.MBeanServer)12 DefaultAuditContext (org.nhindirect.common.audit.DefaultAuditContext)11 MBeanException (javax.management.MBeanException)8