Search in sources :

Example 51 with CompositeData

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

the class FrameworkMBeanTest method testMBeanInterface.

@Test
public void testMBeanInterface() throws IOException {
    long[] bundleIds = new long[] { 1, 2 };
    int[] newlevels = new int[] { 1, 1 };
    CompositeData compData = framework.setBundleStartLevels(bundleIds, newlevels);
    assertNotNull(compData);
    BatchActionResult batch2 = BatchActionResult.from(compData);
    assertNotNull(batch2.getCompleted());
    assertTrue(batch2.isSuccess());
    assertNull(batch2.getError());
    assertNull(batch2.getRemainingItems());
    File file = File.createTempFile("bundletest", ".jar");
    file.deleteOnExit();
    Manifest man = new Manifest();
    man.getMainAttributes().putValue("Manifest-Version", "1.0");
    JarOutputStream jaros = new JarOutputStream(new FileOutputStream(file), man);
    jaros.flush();
    jaros.close();
    long bundleId = 0;
    try {
        bundleId = framework.installBundleFromURL(file.getAbsolutePath(), file.toURI().toString());
    } catch (Exception e) {
        fail("Installation of test bundle shouldn't fail");
    }
    try {
        framework.uninstallBundle(bundleId);
    } catch (Exception e) {
        fail("Uninstallation of test bundle shouldn't fail");
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) File(java.io.File) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 52 with CompositeData

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

the class Util method decode.

public static CompositeData decode(Byte[] wrap) {
    if (null == wrap)
        return null;
    byte[] prim = new byte[wrap.length];
    for (int i = 0; i < wrap.length; i++) {
        prim[i] = wrap[i];
    }
    ByteArrayInputStream inBytes = new ByteArrayInputStream(prim);
    ObjectInputStream inObject;
    CompositeData data;
    try {
        inObject = new ObjectInputStream(inBytes);
        data = (CompositeData) inObject.readObject();
        inObject.close();
        return data;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CompositeData(javax.management.openmbean.CompositeData) ObjectInputStream(java.io.ObjectInputStream)

Example 53 with CompositeData

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

the class ServiceStateMBeanTest method testGetServiceAndGetProperty.

@Test
public void testGetServiceAndGetProperty() throws Exception {
    ServiceReference sref = bundleContext.getServiceReference(InterfaceA.class);
    // Get service to increase service references
    context().getService(sref);
    Long serviceID = (Long) sref.getProperty(Constants.SERVICE_ID);
    CompositeData svcData = mbean.getService(serviceID);
    assertEquals(serviceID, svcData.get(ServiceStateMBean.IDENTIFIER));
    assertEquals(sref.getBundle().getBundleId(), svcData.get(ServiceStateMBean.BUNDLE_IDENTIFIER));
    Set<String> expectedClasses = new HashSet<String>(Arrays.asList(InterfaceA.class.getName(), ManagedService.class.getName()));
    Set<String> actualClasses = new HashSet<String>(Arrays.asList((String[]) svcData.get(ServiceStateMBean.OBJECT_CLASS)));
    assertEquals(expectedClasses, actualClasses);
    Bundle[] ub = sref.getUsingBundles();
    assertEquals("Precondition", 1, ub.length);
    assertTrue(Arrays.equals(new Long[] { ub[0].getBundleId() }, (Long[]) svcData.get("UsingBundles")));
    // Test mbean.getProperty()
    String pid = (String) sref.getProperty(Constants.SERVICE_PID);
    CompositeData pidData = mbean.getProperty(serviceID, Constants.SERVICE_PID);
    assertEquals(pid, pidData.get("Value"));
    assertEquals("String", pidData.get("Type"));
    CompositeData idData = mbean.getProperty(serviceID, Constants.SERVICE_ID);
    assertEquals("" + serviceID, idData.get("Value"));
    assertEquals("Long", idData.get("Type"));
    CompositeData ocData = mbean.getProperty(serviceID, Constants.OBJECTCLASS);
    String form1 = InterfaceA.class.getName() + "," + ManagedService.class.getName();
    String form2 = ManagedService.class.getName() + "," + InterfaceA.class.getName();
    assertTrue(ocData.get("Value").equals(form1) || ocData.get("Value").equals(form2));
    assertEquals("Array of String", ocData.get("Type"));
    context().ungetService(sref);
}
Also used : ManagedService(org.osgi.service.cm.ManagedService) InterfaceA(org.apache.aries.jmx.test.bundlea.api.InterfaceA) Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) ServiceReference(org.osgi.framework.ServiceReference) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 54 with CompositeData

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

the class ServiceStateMBeanTest method testListServicesSelectiveItems.

@SuppressWarnings("unchecked")
@Test
public void testListServicesSelectiveItems() throws Exception {
    String filter = "(|(service.pid=org.apache.aries.jmx.test.ServiceB)(service.pid=jmx.test.B.factory))";
    ServiceReference[] refs = bundleContext.getAllServiceReferences(null, filter);
    TabularData svcData = mbean.listServices(null, filter, ServiceStateMBean.BUNDLE_IDENTIFIER);
    assertEquals(refs.length, svcData.size());
    long id = refs[0].getBundle().getBundleId();
    for (ServiceReference ref : refs) {
        assertEquals("Precondition", id, ref.getBundle().getBundleId());
    }
    for (CompositeData cd : new ArrayList<CompositeData>((Collection<CompositeData>) svcData.values())) {
        assertEquals(id, cd.get(ServiceStateMBean.BUNDLE_IDENTIFIER));
        assertNotNull(cd.get(ServiceStateMBean.IDENTIFIER));
        assertNull(cd.get(ServiceStateMBean.OBJECT_CLASS));
        assertNull(cd.get(ServiceStateMBean.USING_BUNDLES));
    }
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) ServiceReference(org.osgi.framework.ServiceReference) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Example 55 with CompositeData

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

the class BundleWiringStateMBeanTest method jmxCapReqToMap.

private Map<Map<String, Object>, Map<String, String>> jmxCapReqToMap(CompositeData[] jmxCapabilitiesOrRequirements) {
    Map<Map<String, Object>, Map<String, String>> actualCapabilities = new HashMap<Map<String, Object>, Map<String, String>>();
    for (CompositeData jmxCapReq : jmxCapabilitiesOrRequirements) {
        Map<String, Object> aMap = getJmxAttributes(jmxCapReq);
        Map<String, String> dMap = getJmxDirectives(jmxCapReq);
        actualCapabilities.put(aMap, dMap);
    }
    return actualCapabilities;
}
Also used : HashMap(java.util.HashMap) CompositeData(javax.management.openmbean.CompositeData) HashMap(java.util.HashMap) Map(java.util.Map)

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