aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1195179 - in /aries/trunk/sandbox/jmx-next: jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
Date Sun, 30 Oct 2011 15:38:24 GMT
Author: davidb
Date: Sun Oct 30 15:38:24 2011
New Revision: 1195179

URL: http://svn.apache.org/viewvc?rev=1195179&view=rev
Log:
More contents for Bundle Wiring Data.

Modified:
    aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
    aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java

Modified: aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java?rev=1195179&r1=1195178&r2=1195179&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-core/src/main/java/org/apache/aries/jmx/codec/BundleWiringData.java
Sun Oct 30 15:38:24 2011
@@ -31,28 +31,55 @@ import javax.management.openmbean.Tabula
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.jmx.framework.BundleRevisionsStateMBean;
 
 public class BundleWiringData {
     private final long bundleId;
     private final List<BundleCapability> capabilities;
     private final List<BundleRequirement> requirements;
+    private List<BundleWire> requiredWires;
 
     public BundleWiringData(long bundleId, List<BundleCapability> capabilities, List<BundleRequirement>
requirements, List<BundleWire> requiredWires) {
         this.bundleId = bundleId;
         this.capabilities = capabilities;
         this.requirements = requirements;
+        this.requiredWires = requiredWires;
     }
 
     public CompositeData toCompositeData() {
         try {
             Map<String, Object> items = new HashMap<String, Object>();
             items.put(BundleRevisionsStateMBean.BUNDLE_ID, bundleId);
-            items.put(BundleRevisionsStateMBean.BUNDLE_REVISION_ID, null);
+            items.put(BundleRevisionsStateMBean.BUNDLE_REVISION_ID, null); // TODO
 
             items.put(BundleRevisionsStateMBean.REQUIREMENTS, getRequirements());
             items.put(BundleRevisionsStateMBean.CAPABILITIES, getCapabilities());
-            items.put(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE, null);
+
+            CompositeData[] reqWiresData = new CompositeData[requiredWires.size()];
+            for (int i=0; i < requiredWires.size(); i++) {
+                BundleWire requiredWire = requiredWires.get(i);
+                Map<String, Object> wireItems = new HashMap<String, Object>();
+                BundleWiring providerWiring = requiredWire.getProviderWiring();
+                wireItems.put(BundleRevisionsStateMBean.PROVIDER_BUNDLE_ID, providerWiring.getBundle().getBundleId());
+                wireItems.put(BundleRevisionsStateMBean.PROVIDER_BUNDLE_REVISION_ID, null);
// TODO
+                BundleWiring requirerWiring = requiredWire.getRequirerWiring();
+                wireItems.put(BundleRevisionsStateMBean.REQUIRER_BUNDLE_ID, requirerWiring.getBundle().getBundleId());
+                wireItems.put(BundleRevisionsStateMBean.REQUIRER_BUNDLE_REVISION_ID, null);
// TODO
+                BundleCapability capability = requiredWire.getCapability();
+                wireItems.put(BundleRevisionsStateMBean.BUNDLE_CAPABILITY,
+                    getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_CAPABILITY_TYPE,
+                    capability.getNamespace(), capability.getAttributes().entrySet(), capability.getDirectives().entrySet()));
+                BundleRequirement requirement = requiredWire.getRequirement();
+                wireItems.put(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT,
+                    getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT_TYPE,
+                    requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet()));
+
+                CompositeData wireData = new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_WIRE_TYPE,
wireItems);
+                reqWiresData[i] = wireData;
+            }
+
+            items.put(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE, reqWiresData);
 
             return new CompositeDataSupport(BundleRevisionsStateMBean.BUNDLE_WIRING_TYPE,
items);
         } catch (OpenDataException e) {
@@ -75,7 +102,7 @@ public class BundleWiringData {
         for (int i=0; i < requirements.size(); i++) {
             BundleRequirement requirement = requirements.get(i);
             reqData[i] = getCapReqCompositeData(BundleRevisionsStateMBean.BUNDLE_REQUIREMENT_TYPE,
-                    requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
+                requirement.getNamespace(), requirement.getAttributes().entrySet(), requirement.getDirectives().entrySet());
         }
         return reqData;
     }

Modified: aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java?rev=1195179&r1=1195178&r2=1195179&view=diff
==============================================================================
--- aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
(original)
+++ aries/trunk/sandbox/jmx-next/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleRevisionsStateMBeanTest.java
Sun Oct 30 15:38:24 2011
@@ -24,6 +24,9 @@ import static org.ops4j.pax.swissbox.tin
 import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
 
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import javax.management.ObjectName;
 import javax.management.openmbean.CompositeData;
@@ -34,9 +37,15 @@ import org.junit.Test;
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.container.def.PaxRunnerOptions;
+import org.ops4j.pax.exam.container.def.options.VMOption;
 import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.options.TimeoutOption;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Constants;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+import org.osgi.framework.wiring.BundleWire;
 import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.jmx.framework.BundleRevisionsStateMBean;
 import org.osgi.jmx.framework.PackageStateMBean;
@@ -51,8 +60,8 @@ public class BundleRevisionsStateMBeanTe
     @Configuration
     public static Option[] configuration() {
         return testOptions(
-                //  new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
),
-                //  new TimeoutOption( 0 ),
+                  new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
),
+                  new TimeoutOption( 0 ),
 
             PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
             CoreOptions.equinox().version("3.7.0.v20110613"),
@@ -112,7 +121,6 @@ public class BundleRevisionsStateMBeanTe
 
     @Test
     public void testMBeanInterface() throws IOException {
-        // BundleStateMBean bsMBean = getMBean(BundleStateMBean.OBJECTNAME, BundleStateMBean.class);
         BundleRevisionsStateMBean brsMBean = getMBean(BundleRevisionsStateMBean.OBJECTNAME,
BundleRevisionsStateMBean.class);
 
         Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
@@ -123,34 +131,23 @@ public class BundleRevisionsStateMBeanTe
         Assert.assertEquals(a.getBundleId(), wiring.get(BundleRevisionsStateMBean.BUNDLE_ID));
 
         BundleWiring bw = a.adapt(BundleWiring.class);
-        CompositeData[] capabilities = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.CAPABILITIES);
-        Assert.assertEquals(bw.getCapabilities(BundleRevisionsStateMBean.PACKAGE_NAMESPACE).size(),
capabilities.length);
+        CompositeData[] jmxCapabilities = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.CAPABILITIES);
+        List<BundleCapability> capabilities = bw.getCapabilities(BundleRevision.PACKAGE_NAMESPACE);
+        Assert.assertEquals(capabilities.size(), jmxCapabilities.length);
+
+        Map<Map<String, Object>, Map<String, String>> m = new HashMap<Map<String,Object>,
Map<String,String>>();
+        for (BundleCapability cap : capabilities) {
+            m.put(cap.getAttributes(), cap.getDirectives());
+        }
+
+        CompositeData[] jmxRequirements = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.REQUIREMENTS);
+        List<BundleRequirement> requirements = bw.getRequirements(BundleRevision.PACKAGE_NAMESPACE);
+        Assert.assertEquals(requirements.size(), jmxRequirements.length);
+
+        List<BundleWire> requiredWires = bw.getRequiredWires(BundleRevision.PACKAGE_NAMESPACE);
+        CompositeData[] jmxRequiredWires = (CompositeData[]) wiring.get(BundleRevisionsStateMBean.BUNDLE_WIRES_TYPE);
+        // currently the wires only contains the required wires.
+        Assert.assertEquals(requiredWires.size(), jmxRequiredWires.length);
 
-        /*
-        PackageStateMBean packagaState = getMBean(PackageStateMBean.OBJECTNAME, PackageStateMBean.class);
-        assertNotNull(packagaState);
-
-        long[] exportingBundles = packagaState.getExportingBundles("org.osgi.jmx.framework",
"1.5.0");
-        assertNotNull(exportingBundles);
-        assertTrue("Should find a bundle exporting org.osgi.jmx.framework", exportingBundles.length
> 0);
-
-        long[] exportingBundles2 = packagaState.getExportingBundles("test", "1.0.0");
-        assertNull("Shouldn't find a bundle exporting test package", exportingBundles2);
-
-        long[] importingBundlesId = packagaState
-                .getImportingBundles("org.osgi.jmx.framework", "1.5.0", exportingBundles[0]);
-        assertTrue("Should find bundles importing org.osgi.jmx.framework", importingBundlesId.length
> 0);
-
-        TabularData table = packagaState.listPackages();
-        assertNotNull("TabularData containing CompositeData with packages info shouldn't
be null", table);
-        assertEquals("TabularData should be a type PACKAGES", PackageStateMBean.PACKAGES_TYPE,
table.getTabularType());
-        Collection colData = table.values();
-        assertNotNull("Collection of CompositeData shouldn't be null", colData);
-        assertFalse("Collection of CompositeData should contain elements", colData.isEmpty());
-
-        boolean isRemovalPending = packagaState.isRemovalPending("org.osgi.jmx.framework",
"1.5.0", exportingBundles[0]);
-        assertFalse("Should removal pending on org.osgi.jmx.framework be false", isRemovalPending);
-        */
     }
-
 }



Mime
View raw message