incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r953097 - in /incubator/aries/trunk/jmx: jmx-core/src/main/java/org/apache/aries/jmx/cm/ jmx-core/src/main/java/org/apache/aries/jmx/codec/ jmx-core/src/main/java/org/apache/aries/jmx/framework/ jmx-core/src/main/java/org/apache/aries/jmx/u...
Date Wed, 09 Jun 2010 17:48:01 GMT
Author: gawor
Date: Wed Jun  9 17:48:01 2010
New Revision: 953097

URL: http://svn.apache.org/viewvc?rev=953097&view=rev
Log:
ARIES-333: 1) Do not throw RuntimeExceptions, and 2) in BundleStateMBean return depedencies
based on static or dynamic imports, required or fragment bundles

Modified:
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/GroupData.java
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/useradmin/UserAdmin.java
    incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java
    incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
    incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/cm/ConfigurationAdmin.java
Wed Jun  9 17:48:01 2010
@@ -101,7 +101,7 @@ public class ConfigurationAdmin implemen
         try {
             configuations = configurationAdmin.listConfigurations(filter);
         } catch (InvalidSyntaxException e) {
-            throw new IllegalArgumentException("Invalid filter [" + filter + "] : " + e);
+            throw new IOException("Invalid filter [" + filter + "] : " + e);
         }
         if (configuations != null) {
             for (Configuration config : configuations) {
@@ -134,7 +134,7 @@ public class ConfigurationAdmin implemen
         try {
             configurations = configurationAdmin.listConfigurations(filter);
         } catch (InvalidSyntaxException e) {
-            throw new IllegalArgumentException("Invalid filter [" + filter + "] : " + e);
+            throw new IOException("Invalid filter [" + filter + "] : " + e);
         }
         if (configurations != null) {
             for (Configuration config : configurations) {
@@ -222,7 +222,7 @@ public class ConfigurationAdmin implemen
         }
                 
         if (!PROPERTIES_TYPE.equals(configurationTable.getTabularType())) {
-            throw new IllegalArgumentException("Invalid TabularType ["  + configurationTable.getTabularType()
+ "]");
+            throw new IOException("Invalid TabularType ["  + configurationTable.getTabularType()
+ "]");
         }
         Dictionary<String, Object> configurationProperties = new Hashtable<String,
Object>();
         Collection<CompositeData> compositeData = (Collection<CompositeData>)
configurationTable.values();

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/GroupData.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/GroupData.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/GroupData.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/codec/GroupData.java
Wed Jun  9 17:48:01 2010
@@ -57,8 +57,8 @@ public class GroupData extends UserData 
      */
     public GroupData(Group group) {
         super(group.getName(), Role.GROUP);
-        setRequiredMembers(group);
-        setMembers(group);
+        this.members = toArray(group.getMembers());
+        this.requiredMembers = toArray(group.getRequiredMembers());
     }
 
     /**
@@ -70,8 +70,8 @@ public class GroupData extends UserData 
      */
     public GroupData(String name, String[] members, String[] requiredMembers) {
         super(name, Role.GROUP);
-        this.members = members;
-        this.requiredMembers = requiredMembers;
+        this.members = (members == null) ? new String[0] : members;
+        this.requiredMembers = (requiredMembers == null) ? new String[0] : requiredMembers;
     }
 
     /**
@@ -123,34 +123,13 @@ public class GroupData extends UserData 
         return requiredMembers;
     }
 
-    /**
-     * Sets group basic members by getting them from Group object.
-     * @param group {@link Group} instance.
-     */
-    private void setMembers(org.osgi.service.useradmin.Group group) {
-        Role[] roles = group.getMembers();
+    private static String[] toArray(Role[] roles) {
+        List<String> members = new ArrayList<String>();
         if (roles != null) {
-            List<String> members = new ArrayList<String>();
             for (Role role : roles) {
                 members.add(role.getName());
             }
-            this.members = members.toArray(new String[roles.length]);
         }
+        return members.toArray(new String[members.size()]);
     }
-
-    /**
-     * Sets group required members by getting them from Group object.
-     * @param group {@link Group} instance.
-     */
-    private void setRequiredMembers(org.osgi.service.useradmin.Group group) {
-        Role[] requiredRoles = group.getRequiredMembers();
-        if (requiredRoles != null) {
-            List<String> reqMembers = new ArrayList<String>();
-            for (Role role : requiredRoles) {
-                reqMembers.add(role.getName());
-            }
-            this.requiredMembers = reqMembers.toArray(new String[requiredRoles.length]);
-        }
-    }
-
 }
\ No newline at end of file

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/framework/Framework.java
Wed Jun  9 17:48:01 2010
@@ -239,7 +239,11 @@ public class Framework implements Framew
      */
     public void setBundleStartLevel(long bundleIdentifier, int newlevel) throws IOException
{
         Bundle bundle = FrameworkUtils.resolveBundle(context, bundleIdentifier);
-        startLevel.setBundleStartLevel(bundle, newlevel);
+        try {
+            startLevel.setBundleStartLevel(bundle, newlevel);
+        } catch (IllegalArgumentException e) {
+            throw new IOException("Unable to set bundle start level", e);
+        }
     }
 
     /**

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/useradmin/UserAdmin.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/useradmin/UserAdmin.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/useradmin/UserAdmin.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/useradmin/UserAdmin.java
Wed Jun  9 17:48:01 2010
@@ -79,7 +79,7 @@ public class UserAdmin implements UserAd
      */
     private void validateRoleType(Role role, int roleType) throws IOException {
         if (role.getType() != roleType) {
-            throw new IllegalArgumentException("Unexpected role type. Expected " + roleType
+ " but got " + role.getType());
+            throw new IOException("Unexpected role type. Expected " + roleType + " but got
" + role.getType());
         }
     }
 

Modified: incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/main/java/org/apache/aries/jmx/util/FrameworkUtils.java
Wed Jun  9 17:48:01 2010
@@ -24,9 +24,12 @@ import static org.osgi.jmx.framework.Bun
 import static org.osgi.jmx.framework.BundleStateMBean.UNINSTALLED;
 import static org.osgi.jmx.framework.BundleStateMBean.UNKNOWN;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Dictionary;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -58,13 +61,13 @@ public class FrameworkUtils {
      * @throws IllegalArgumentException
      *             if no Bundle is found with matching bundleId
      */
-    public static Bundle resolveBundle(BundleContext bundleContext, long bundleId) throws
IllegalArgumentException {
+    public static Bundle resolveBundle(BundleContext bundleContext, long bundleId) throws
IOException {
         if (bundleContext == null) {
             throw new IllegalArgumentException("Argument bundleContext cannot be null");
         }
         Bundle bundle = bundleContext.getBundle(bundleId);
         if (bundle == null) {
-            throw new IllegalArgumentException("Bundle with id [" + bundleId + "] not found");
+            throw new IOException("Bundle with id [" + bundleId + "] not found");
         }
         return bundle;
     }
@@ -109,10 +112,10 @@ public class FrameworkUtils {
      * @param bundleContext
      * @param serviceId
      * @return ServiceReference with matching service.id property
-     * @throws IllegalArgumentException
-     *             if bundleContext is null or no service is found with the given id
+     * @throws IllegalArgumentException if bundleContext is null
+     * @throws IOException if no service is found with the given id
      */
-    public static ServiceReference resolveService(BundleContext bundleContext, long serviceId)
{
+    public static ServiceReference resolveService(BundleContext bundleContext, long serviceId)
throws IOException {
         if (bundleContext == null) {
             throw new IllegalArgumentException("Argument bundleContext cannot be null");
         }
@@ -121,12 +124,12 @@ public class FrameworkUtils {
             ServiceReference[] references = bundleContext.getAllServiceReferences(null, "("
+ Constants.SERVICE_ID
                     + "=" + serviceId + ")");
             if (references == null || references.length < 1) {
-                throw new IllegalArgumentException("Service with id [" + serviceId + "] not
found");
+                throw new IOException("Service with id [" + serviceId + "] not found");
             } else {
                 result = references[0];
             }
         } catch (InvalidSyntaxException e) {
-            throw new IllegalStateException("Failure when resolving service ", e);
+            throw new IOException("Failure when resolving service ", e);
         }
         return result;
     }
@@ -365,15 +368,26 @@ public class FrameworkUtils {
             throw new IllegalArgumentException("Argument packageAdmin cannot be null");
         }
         boolean result = false;
-        RequiredBundle[] requiredBundles = packageAdmin.getRequiredBundles(bundle.getSymbolicName());
-        if (requiredBundles != null) {
-            for (RequiredBundle requiredBundle : requiredBundles) {
-                Bundle required = requiredBundle.getBundle();
-                if (required != null && required.equals(bundle)) {
-                    result = requiredBundle.isRemovalPending();
+        ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle);
+        if (exportedPackages != null) {
+            for (ExportedPackage exportedPackage : exportedPackages) {
+                if (exportedPackage.isRemovalPending()) {
+                    result = true;
                     break;
                 }
-            }// end for requiredBundles
+            }
+        }
+        if (!result) {
+            RequiredBundle[] requiredBundles = packageAdmin.getRequiredBundles(bundle.getSymbolicName());
+            if (requiredBundles != null) {
+                for (RequiredBundle requiredBundle : requiredBundles) {
+                    Bundle required = requiredBundle.getBundle();
+                    if (required == bundle) {
+                        result = requiredBundle.isRemovalPending();
+                        break;
+                    }
+                }
+            }
         }
         return result;
     }
@@ -396,18 +410,39 @@ public class FrameworkUtils {
             throw new IllegalArgumentException("Argument packageAdmin cannot be null");
         }
         boolean result = false;
-        RequiredBundle[] requiredBundles = packageAdmin.getRequiredBundles(bundle.getSymbolicName());
-        if (requiredBundles != null) {
-            for (RequiredBundle requiredBundle : requiredBundles) {
-                Bundle required = requiredBundle.getBundle();
-                if (required != null && required.equals(bundle)) {
-                    Bundle[] requiring = requiredBundle.getRequiringBundles();
-                    if (requiring != null && requiring.length > 0) {
-                        result = true;
-                        break;
+        // Check imported packages (statically or dynamically)
+        ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle);
+        if (exportedPackages != null) {
+            for (ExportedPackage exportedPackage : exportedPackages) {
+                Bundle[] importingBundles = exportedPackage.getImportingBundles();
+                if (importingBundles != null && importingBundles.length > 0) {
+                    result = true;
+                    break;
+                }
+            }
+        }
+        if (!result) {
+            // Check required bundles
+            RequiredBundle[] requiredBundles = packageAdmin.getRequiredBundles(bundle.getSymbolicName());
+            if (requiredBundles != null) {
+                for (RequiredBundle requiredBundle : requiredBundles) {
+                    Bundle required = requiredBundle.getBundle();
+                    if (required == bundle) {
+                        Bundle[] requiring = requiredBundle.getRequiringBundles();
+                        if (requiring != null && requiring.length > 0) {
+                            result = true;
+                            break;
+                        }
                     }
                 }
-            }// end for requiredBundles
+            }
+        }
+        if (!result) {
+            // Check fragment bundles
+            Bundle[] fragments = packageAdmin.getFragments(bundle);
+            if (fragments != null && fragments.length > 0) {
+                result = true;
+            }
         }
         return result;
     }
@@ -426,24 +461,40 @@ public class FrameworkUtils {
      *             if bundle or packageAdmin are null
      */
     @SuppressWarnings("unchecked")
-    public static long[] getBundleDependencies(BundleContext localBundleContext, Bundle bundle,
-            PackageAdmin packageAdmin) throws IllegalArgumentException {
+    public static long[] getBundleDependencies(BundleContext localBundleContext, 
+                                               Bundle bundle,
+                                               PackageAdmin packageAdmin) throws IllegalArgumentException
{
         if (bundle == null) {
             throw new IllegalArgumentException("Argument bundle cannot be null");
         }
         if (packageAdmin == null) {
             throw new IllegalArgumentException("Argument packageAdmin cannot be null");
         }
-        List<Bundle> dependencies = new ArrayList<Bundle>();
+        Set<Bundle> dependencies = new HashSet<Bundle>();
+        // Handle imported packages (statically or dynamically)
+        for (Bundle exportBundle : localBundleContext.getBundles()) {
+            if (exportBundle == bundle) {
+                continue;
+            }
+            ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(exportBundle);
+            if (exportedPackages != null) {
+                for (ExportedPackage exportedPackage : exportedPackages) {
+                    Bundle[] importingBundles = exportedPackage.getImportingBundles();
+                    if (importingBundles != null && arrayContains(importingBundles,
bundle)) {
+                        dependencies.add(exportBundle);
+                        break;
+                    }
+                }
+            }
+        }
+        // Handle required bundles
         Dictionary<String, String> bundleHeaders = bundle.getHeaders();
         String requireBundleHeader = bundleHeaders.get(Constants.REQUIRE_BUNDLE);
         if (requireBundleHeader != null) { // only check if Require-Bundle is used
             List<String> bundleSymbolicNames = extractHeaderDeclaration(requireBundleHeader);
             for (String bundleSymbolicName: bundleSymbolicNames) {
                 RequiredBundle[] candidateRequiredBundles = packageAdmin.getRequiredBundles(bundleSymbolicName);
-                if (candidateRequiredBundles == null) {
-                    continue;
-                } else {
+                if (candidateRequiredBundles != null) {
                     for (RequiredBundle candidateRequiredBundle : candidateRequiredBundles)
{
                         Bundle[] bundlesRequiring = candidateRequiredBundle.getRequiringBundles();
                         if (bundlesRequiring != null && arrayContains(bundlesRequiring,
bundle)) {
@@ -453,9 +504,16 @@ public class FrameworkUtils {
                 }
             }
         }
+        // Handle fragment bundles
+        Bundle[] hosts = packageAdmin.getHosts(bundle);
+        if (hosts != null) {
+            for (Bundle host : hosts) {
+                dependencies.add(host);
+            }
+        }
         return getBundleIds(dependencies.toArray(new Bundle[dependencies.size()]));
     }
-
+    
     /**
      * Returns an array of ids of bundles that depend on the given bundle
      * 
@@ -471,18 +529,43 @@ public class FrameworkUtils {
         }
         if (packageAdmin == null) {
             throw new IllegalArgumentException("Argument packageAdmin cannot be null");
+        }        
+        Set<Bundle> dependencies = new HashSet<Bundle>();
+        // Handle imported packages (statically or dynamically)
+        ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages(bundle);
+        if (exportedPackages != null) {
+            for (ExportedPackage exportedPackage : exportedPackages) {
+                Bundle[] importingBundles = exportedPackage.getImportingBundles();
+                if (importingBundles != null) {
+                    for (Bundle importingBundle : importingBundles) {
+                        dependencies.add(importingBundle);
+                    }
+                }
+            }
         }
-        long[] bundleIds = new long[0];
+        // Handle required bundles
         RequiredBundle[] requiredBundles = packageAdmin.getRequiredBundles(bundle.getSymbolicName());
         if (requiredBundles != null) {
             for (RequiredBundle requiredBundle : requiredBundles) {
                 Bundle required = requiredBundle.getBundle();
-                if (required != null && required.equals(bundle)) {
-                    bundleIds = getBundleIds(requiredBundle.getRequiringBundles());
+                if (required == bundle) {
+                    Bundle[] requiringBundles = requiredBundle.getRequiringBundles();
+                    if (requiringBundles != null) {
+                        for (Bundle requiringBundle : requiringBundles) {
+                            dependencies.add(requiringBundle);
+                        }
+                    }
                 }
             }
         }
-        return bundleIds;
+        // Handle fragment bundles
+        Bundle[] fragments = packageAdmin.getFragments(bundle);
+        if (fragments != null) {
+            for (Bundle fragment : fragments) {
+                dependencies.add(fragment);
+            }
+        }
+        return getBundleIds(dependencies.toArray(new Bundle[dependencies.size()]));
     }
 
     /**

Modified: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/codec/BundleDataTest.java
Wed Jun  9 17:48:01 2010
@@ -50,8 +50,10 @@ import static org.osgi.jmx.framework.Bun
 
 import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Map;
+import java.util.Set;
 
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeDataSupport;
@@ -180,7 +182,7 @@ public class BundleDataTest {
         
         assertArrayEquals(new String[] { "org.apache.aries.jmx;1.0.0"} , (String[]) compositeData.get(EXPORTED_PACKAGES));
         assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"},
(String[]) compositeData.get(IMPORTED_PACKAGES));
-        assertArrayEquals(new Long[] { new Long(44), new Long(66) }, (Long[]) compositeData.get(REQUIRED_BUNDLES));
+        assertEquals(toSet(new long[] { 44, 55, 66 }), toSet((Long[]) compositeData.get(REQUIRED_BUNDLES)));
         assertArrayEquals(new Long[] { new Long(15), new Long(16), new Long(17) },(Long[])
compositeData.get(SERVICES_IN_USE));
         assertEquals("UNKNOWN", compositeData.get(STATE)); //default no return stub
         assertEquals(0,((Long[]) compositeData.get(HOSTS)).length);
@@ -252,4 +254,20 @@ public class BundleDataTest {
         assertEquals("d", header.getValue());
         
     }
+        
+    private static Set<Long> toSet(long[] array) {
+        Set<Long> set = new HashSet<Long>();
+        for (long value : array) {
+            set.add(value);
+        }
+        return set;
+    }
+    
+    private static Set<Long> toSet(Long[] array) {
+        Set<Long> set = new HashSet<Long>();
+        for (Long value : array) {
+            set.add(value);
+        }
+        return set;
+    }
 }

Modified: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/framework/FrameworkTest.java
Wed Jun  9 17:48:01 2010
@@ -184,8 +184,8 @@ public class FrameworkTest {
 
         try {
             mbean.refreshBundle(2);
-            Assert.fail("Shouldn't happen illegal argument");
-        } catch (IllegalArgumentException iae) {
+            Assert.fail("IOException should be thrown");
+        } catch (IOException e) {
             // expected
         }
     }
@@ -304,8 +304,8 @@ public class FrameworkTest {
         Mockito.when(context.getBundle(6)).thenReturn(null);
         try {
             mbean.startBundle(6);
-            Assert.fail("IllegalArgumentException should be thrown");
-        } catch (IllegalArgumentException iae) {
+            Assert.fail("IOException should be thrown");
+        } catch (IOException e) {
             //expected
         }
     }
@@ -342,8 +342,8 @@ public class FrameworkTest {
         Mockito.when(context.getBundle(5)).thenReturn(null);
         try {
             mbean.stopBundle(5);
-            Assert.fail("IllegalArgumentException should be thrown");
-        } catch (IllegalArgumentException iae) {
+            Assert.fail("IOException should be thrown");
+        } catch (IOException e) {
             //expected
         }
        

Modified: incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
Wed Jun  9 17:48:01 2010
@@ -36,7 +36,9 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.util.Dictionary;
+import java.util.HashSet;
 import java.util.Hashtable;
+import java.util.Set;
 
 import org.junit.Test;
 import org.osgi.framework.Bundle;
@@ -279,10 +281,15 @@ public class FrameworkUtilsTest {
         when(admin.getRequiredBundles("b2")).thenReturn(new RequiredBundle[] { rb2 });
         when(admin.getRequiredBundles("b3")).thenReturn(new RequiredBundle[] { rb3 });
         
-        assertArrayEquals(new long[] { 44, 66 }, getBundleDependencies(context, bundle, admin));
-        
-        
+        assertEquals(toSet(new long[] { 44, 66 }), toSet(getBundleDependencies(context, bundle,
admin)));
     }
     
+    private static Set<Long> toSet(long[] array) {
+        Set<Long> set = new HashSet<Long>();
+        for (long value : array) {
+            set.add(value);
+        }
+        return set;
+    }
     
 }

Modified: incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java?rev=953097&r1=953096&r2=953097&view=diff
==============================================================================
--- incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
(original)
+++ incubator/aries/trunk/jmx/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
Wed Jun  9 17:48:01 2010
@@ -203,8 +203,10 @@ public class BundleStateMBeanTest extend
         //requiring bundles
         
         long[] requiring = mbean.getRequiringBundles(a.getBundleId());
-        assertEquals(1, requiring.length);
-        assertEquals(d.getBundleId(), requiring[0]);
+        assertEquals(3, requiring.length);
+        assertTrue(b.getSymbolicName(), arrayContains(frag.getBundleId(), requiring));
+        assertTrue(frag.getSymbolicName(), arrayContains(frag.getBundleId(), requiring));
+        assertTrue(d.getSymbolicName(), arrayContains(d.getBundleId(), requiring));
         
         //services in use
         
@@ -231,7 +233,7 @@ public class BundleStateMBeanTest extend
         // isRequired
        
         assertTrue(mbean.isRequired(a.getBundleId()));
-        assertFalse(mbean.isRequired(b.getBundleId()));
+        assertTrue(mbean.isRequired(b.getBundleId())); 
         
         // listBundles
         
@@ -267,5 +269,12 @@ public class BundleStateMBeanTest extend
         
     }
     
-
+    private static boolean arrayContains(long value, long[] values) {
+        for (long i : values) {
+            if (i == value) {
+                return true;
+            }
+        }
+        return false;
+    }
 }



Mime
View raw message