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);
}
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());
}
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());
}
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;
}
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;
}
Aggregations