Search in sources :

Example 1 with Header

use of org.apache.aries.jmx.codec.BundleData.Header in project aries by apache.

the class BundleState method getHeaders.

private TabularData getHeaders(Dictionary<String, String> bundleHeaders) {
    List<Header> headers = new ArrayList<Header>();
    Enumeration<String> keys = bundleHeaders.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        headers.add(new Header(key, bundleHeaders.get(key)));
    }
    TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
    for (Header header : headers) {
        headerTable.put(header.toCompositeData());
    }
    return headerTable;
}
Also used : Header(org.apache.aries.jmx.codec.BundleData.Header) TabularDataSupport(javax.management.openmbean.TabularDataSupport) ArrayList(java.util.ArrayList) TabularData(javax.management.openmbean.TabularData)

Example 2 with Header

use of org.apache.aries.jmx.codec.BundleData.Header in project aries by apache.

the class BundleDataTest method testHeaderToCompositeData.

@Test
public void testHeaderToCompositeData() throws Exception {
    Header h1 = new Header("a", "b");
    CompositeData compositeData = h1.toCompositeData();
    assertEquals("a", compositeData.get(KEY));
    assertEquals("b", compositeData.get(VALUE));
}
Also used : Header(org.apache.aries.jmx.codec.BundleData.Header) CompositeData(javax.management.openmbean.CompositeData) Test(org.junit.Test)

Example 3 with Header

use of org.apache.aries.jmx.codec.BundleData.Header in project aries by apache.

the class BundleDataTest method testHeaderFromCompositeData.

@Test
public void testHeaderFromCompositeData() throws Exception {
    CompositeData compositeData = new CompositeDataSupport(HEADER_TYPE, new String[] { KEY, VALUE }, new String[] { "c", "d" });
    Header header = Header.from(compositeData);
    assertEquals("c", header.getKey());
    assertEquals("d", header.getValue());
}
Also used : Header(org.apache.aries.jmx.codec.BundleData.Header) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) Test(org.junit.Test)

Example 4 with Header

use of org.apache.aries.jmx.codec.BundleData.Header in project aries by apache.

the class BundleDataTest method testFromCompositeData.

@Test
public void testFromCompositeData() throws Exception {
    Map<String, Object> items = new HashMap<String, Object>();
    items.put(EXPORTED_PACKAGES, new String[] { "org.apache.aries.jmx;1.0.0" });
    items.put(FRAGMENT, false);
    items.put(FRAGMENTS, new Long[0]);
    items.put(HOSTS, new Long[0]);
    items.put(IDENTIFIER, new Long(3));
    items.put(IMPORTED_PACKAGES, new String[] { "org.apache.aries.jmx.b1;0.0.0", "org.apache.aries.jmx.b2;2.0.1" });
    items.put(LAST_MODIFIED, new Long(8797));
    items.put(LOCATION, "");
    items.put(ACTIVATION_POLICY_USED, true);
    items.put(PERSISTENTLY_STARTED, false);
    items.put(REGISTERED_SERVICES, new Long[0]);
    items.put(REMOVAL_PENDING, false);
    items.put(REQUIRED, true);
    items.put(REQUIRED_BUNDLES, new Long[] { new Long(44), new Long(66) });
    items.put(REQUIRING_BUNDLES, new Long[0]);
    items.put(SERVICES_IN_USE, new Long[] { new Long(15), new Long(16), new Long(17) });
    items.put(START_LEVEL, 1);
    items.put(STATE, "ACTIVE");
    items.put(SYMBOLIC_NAME, "test");
    items.put(VERSION, "0.0.0");
    TabularData headerTable = new TabularDataSupport(HEADERS_TYPE);
    headerTable.put(new Header("a", "a").toCompositeData());
    headerTable.put(new Header("b", "b").toCompositeData());
    items.put(HEADERS, headerTable);
    CompositeData compositeData = new CompositeDataSupport(BUNDLE_TYPE, items);
    BundleData b = BundleData.from(compositeData);
    assertEquals("test", b.getSymbolicName());
    assertEquals("0.0.0", b.getVersion());
    assertEquals(2, b.getHeaders().size());
    assertArrayEquals(new String[] { "org.apache.aries.jmx;1.0.0" }, b.getExportedPackages());
    assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0", "org.apache.aries.jmx.b2;2.0.1" }, b.getImportedPackages());
    assertArrayEquals(new long[] { 44, 66 }, b.getRequiredBundles());
    assertArrayEquals(new long[] { 15, 16, 17 }, b.getServicesInUse());
    //default no return stub
    assertEquals("ACTIVE", b.getState());
    assertEquals(0, b.getHosts().length);
    assertEquals(0, b.getFragments().length);
}
Also used : Header(org.apache.aries.jmx.codec.BundleData.Header) HashMap(java.util.HashMap) TabularDataSupport(javax.management.openmbean.TabularDataSupport) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Aggregations

Header (org.apache.aries.jmx.codec.BundleData.Header)4 CompositeData (javax.management.openmbean.CompositeData)3 Test (org.junit.Test)3 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 TabularData (javax.management.openmbean.TabularData)2 TabularDataSupport (javax.management.openmbean.TabularDataSupport)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1