Search in sources :

Example 66 with TabularData

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

the class PackageStateTest method testListPackages.

@Test
public void testListPackages() throws IOException {
    Bundle bundle = Mockito.mock(Bundle.class);
    Bundle impBundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundles()).thenReturn(new Bundle[] { bundle });
    ExportedPackage exported = Mockito.mock(ExportedPackage.class);
    Mockito.when(exported.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
    Mockito.when(exported.getImportingBundles()).thenReturn(new Bundle[] { impBundle });
    Mockito.when(exported.getName()).thenReturn("test");
    Mockito.when(exported.getExportingBundle()).thenReturn(bundle);
    Mockito.when(bundle.getBundleId()).thenReturn(Long.valueOf(4));
    Mockito.when(impBundle.getBundleId()).thenReturn(Long.valueOf(5));
    Mockito.when(admin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] { exported });
    TabularData table = mbean.listPackages();
    Assert.assertEquals(PackageStateMBean.PACKAGES_TYPE, table.getTabularType());
    Collection values = table.values();
    Assert.assertEquals(1, values.size());
    CompositeData data = (CompositeData) values.iterator().next();
    Long[] exportingBundles = (Long[]) data.get(PackageStateMBean.EXPORTING_BUNDLES);
    Assert.assertArrayEquals(new Long[] { Long.valueOf(4) }, exportingBundles);
    String name = (String) data.get(PackageStateMBean.NAME);
    Assert.assertEquals("test", name);
    String version = (String) data.get(PackageStateMBean.VERSION);
    Assert.assertEquals("1.0.0", version);
}
Also used : Bundle(org.osgi.framework.Bundle) ExportedPackage(org.osgi.service.packageadmin.ExportedPackage) CompositeData(javax.management.openmbean.CompositeData) Collection(java.util.Collection) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 67 with TabularData

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

the class ProvisioningServiceTest method testListInformation.

@Test
public void testListInformation() throws Exception {
    org.osgi.service.provisioning.ProvisioningService provService = mock(org.osgi.service.provisioning.ProvisioningService.class);
    ProvisioningService mbean = new ProvisioningService(provService);
    Dictionary<String, Object> info = new Hashtable<String, Object>();
    info.put(PROVISIONING_AGENT_CONFIG, new byte[] { 20, 30, 40 });
    info.put(PROVISIONING_SPID, "x.test");
    info.put(PROVISIONING_REFERENCE, "rsh://0.0.0.0/provX");
    info.put(PROVISIONING_RSH_SECRET, new byte[] { 15, 25, 35 });
    info.put(PROVISIONING_UPDATE_COUNT, 1);
    when(provService.getInformation()).thenReturn(info);
    TabularData provData = mbean.listInformation();
    assertNotNull(provData);
    assertEquals(PROPERTIES_TYPE, provData.getTabularType());
    assertEquals(5, provData.values().size());
    PropertyData<byte[]> agentConfig = PropertyData.from(provData.get(new Object[] { PROVISIONING_AGENT_CONFIG }));
    assertArrayEquals(new byte[] { 20, 30, 40 }, agentConfig.getValue());
    PropertyData<String> spid = PropertyData.from(provData.get(new Object[] { PROVISIONING_SPID }));
    assertEquals("x.test", spid.getValue());
    PropertyData<String> ref = PropertyData.from(provData.get(new Object[] { PROVISIONING_REFERENCE }));
    assertEquals("rsh://0.0.0.0/provX", ref.getValue());
    PropertyData<byte[]> sec = PropertyData.from(provData.get(new Object[] { PROVISIONING_RSH_SECRET }));
    assertArrayEquals(new byte[] { 15, 25, 35 }, sec.getValue());
    PropertyData<Integer> count = PropertyData.from(provData.get(new Object[] { PROVISIONING_UPDATE_COUNT }));
    assertEquals(new Integer(1), count.getValue());
}
Also used : Hashtable(java.util.Hashtable) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 68 with TabularData

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

the class ConfigurationAdminTest method testGetProperties.

@Test
public void testGetProperties() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin admin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    String pid = "org.apache.aries.jmx.mock";
    Configuration config = mock(Configuration.class);
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("one", "value");
    props.put("two", 2);
    when(admin.getConfiguration(eq(pid), anyString())).thenReturn(config);
    when(config.getProperties()).thenReturn(props);
    ConfigurationAdmin mbean = new ConfigurationAdmin(admin);
    TabularData properties = mbean.getPropertiesForLocation(pid, null);
    assertNotNull(properties);
    assertEquals(PROPERTIES_TYPE, properties.getTabularType());
    assertEquals(2, properties.values().size());
    PropertyData<? extends Object> oneData = PropertyData.from(properties.get(new Object[] { "one" }));
    assertEquals("value", oneData.getValue());
    PropertyData<? extends Object> twoData = PropertyData.from(properties.get(new Object[] { "two" }));
    assertEquals(2, twoData.getValue());
    assertEquals("2", twoData.getEncodedValue());
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Matchers.anyString(org.mockito.Matchers.anyString) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 69 with TabularData

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

the class BundleWiringState method getRevisionsDeclaredCapabilities.

/* (non-Javadoc)
     * @see org.osgi.jmx.framework.BundleRevisionsStateMBean#getRevisionsDeclaredCapabilities(long, java.lang.String, boolean)
     */
public TabularData getRevisionsDeclaredCapabilities(long bundleId, String namespace) throws IOException {
    Bundle bundle = FrameworkUtils.resolveBundle(bundleContext, bundleId);
    BundleRevisions revisions = bundle.adapt(BundleRevisions.class);
    TabularData td = new TabularDataSupport(BundleWiringStateMBean.REVISIONS_CAPABILITIES_TYPE);
    for (BundleRevision revision : revisions.getRevisions()) {
        td.put(BundleWiringData.getRevisionCapabilities(System.identityHashCode(revision), revision.getDeclaredCapabilities(namespace)));
    }
    return td;
}
Also used : Bundle(org.osgi.framework.Bundle) TabularDataSupport(javax.management.openmbean.TabularDataSupport) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleRevisions(org.osgi.framework.wiring.BundleRevisions) TabularData(javax.management.openmbean.TabularData)

Example 70 with TabularData

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

the class UserAdmin method getCredentials.

/**
     * @see org.osgi.jmx.service.useradmin.UserAdminMBean#getCredentials(java.lang.String)
     */
public TabularData getCredentials(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);
    Dictionary<String, Object> credentials = ((User) role).getCredentials();
    if (credentials == null) {
        return null;
    }
    TabularData data = new TabularDataSupport(JmxConstants.PROPERTIES_TYPE);
    for (Enumeration<String> keys = credentials.keys(); keys.hasMoreElements(); ) {
        String key = keys.nextElement();
        data.put(PropertyData.newInstance(key, credentials.get(key)).toCompositeData());
    }
    return data;
}
Also used : Role(org.osgi.service.useradmin.Role) User(org.osgi.service.useradmin.User) TabularDataSupport(javax.management.openmbean.TabularDataSupport) IOException(java.io.IOException) TabularData(javax.management.openmbean.TabularData)

Aggregations

TabularData (javax.management.openmbean.TabularData)183 CompositeData (javax.management.openmbean.CompositeData)91 TabularDataSupport (javax.management.openmbean.TabularDataSupport)67 ObjectName (javax.management.ObjectName)54 MBeanServer (javax.management.MBeanServer)50 CompositeType (javax.management.openmbean.CompositeType)47 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)43 Test (org.junit.Test)38 Map (java.util.Map)28 ArrayList (java.util.ArrayList)23 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)21 HashMap (java.util.HashMap)20 TabularType (javax.management.openmbean.TabularType)17 Bundle (org.osgi.framework.Bundle)17 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)15 Collection (java.util.Collection)13 IOException (java.io.IOException)11 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)9 List (java.util.List)8 ServiceReference (org.osgi.framework.ServiceReference)8