Fix for bug 355381 - Add subproject for tests to gemini management.
diff --git a/org.eclipse.gemini.mgmt.tests/.classpath b/org.eclipse.gemini.mgmt.tests/.classpath
new file mode 100644
index 0000000..9aa40d0
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry excluding="**/.svn/*" kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.gemini.mgmt.tests/.project b/org.eclipse.gemini.mgmt.tests/.project
new file mode 100644
index 0000000..e4ddbc0
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.gemini.mgmt.tests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.gemini.mgmt.tests/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.gemini.mgmt.tests/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..9055ad4
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Wed Jul 13 17:17:27 EEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/org.eclipse.gemini.mgmt.tests/.settings/org.eclipse.pde.core.prefs b/org.eclipse.gemini.mgmt.tests/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..fe0811d
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,4 @@
+#Wed Jul 13 17:17:27 EEST 2011
+eclipse.preferences.version=1
+pluginProject.extensions=false
+resolve.requirebundle=false
diff --git a/org.eclipse.gemini.mgmt.tests/META-INF/MANIFEST.MF b/org.eclipse.gemini.mgmt.tests/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..83e14cf
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/META-INF/MANIFEST.MF
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Gemini Management Tests
+Bundle-SymbolicName: org.eclipse.gemini.mgmt.tests
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: javax.management,
+ javax.management.remote,
+ org.osgi.framework;version="1.3.0"
+Fragment-Host: org.eclipse.gemini.mgmt
+Require-Bundle: org.junit4
diff --git a/org.eclipse.gemini.mgmt.tests/build.properties b/org.eclipse.gemini.mgmt.tests/build.properties
new file mode 100644
index 0000000..cf6aae6
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
+jars.extra.classpath=platform:/plugin/org.eclipse.gemini.mgmt/osgi.enterprise.jar
\ No newline at end of file
diff --git a/org.eclipse.gemini.mgmt.tests/pom.xml b/org.eclipse.gemini.mgmt.tests/pom.xml
new file mode 100644
index 0000000..37d2d33
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/pom.xml
@@ -0,0 +1,54 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.eclipse.gemini.mgmt</groupId>
+ <artifactId>org.eclipse.gemini.mgmt_parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../gemini.mgmt.releng/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.eclipse.gemini.mgmt.tests</artifactId>
+ <packaging>eclipse-test-plugin</packaging>
+ <name>Gemini Management Bundle Tests</name>
+
+<!-- <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.enterprise</artifactId>
+ <version>4.2.0</version>
+ </dependency>
+ </dependencies>
+-->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.sonatype.tycho</groupId>
+ <artifactId>maven-osgi-test-plugin</artifactId>
+ <configuration>
+ <argLine>-Xmx512m -Xms128m -XX:PermSize=128m -XX:MaxPermSize=384m -Dcom.sun.management.jmxremote.port=21045 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false</argLine>
+ <bundleStartLevel>
+ <bundle>
+ <id>osgi.enterprise</id>
+ <level>1</level>
+ <autoStart>true</autoStart>
+ </bundle>
+ </bundleStartLevel>
+ </configuration>
+ </plugin>
+ <!-- <plugin>
+ <groupId>org.sonatype.tycho</groupId>
+ <artifactId>maven-osgi-source-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-pmd-plugin</artifactId>
+ </plugin> -->
+ </plugins>
+ </build>
+</project>
diff --git a/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTest.java b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTest.java
new file mode 100644
index 0000000..66e0302
--- /dev/null
+++ b/org.eclipse.gemini.mgmt.tests/src/org/eclipse/gemini/mgmt/framework/BundleStateTest.java
@@ -0,0 +1,436 @@
+package org.eclipse.gemini.mgmt.framework;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerConnection;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.framework.BundleStateMBean;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.startlevel.StartLevel;
+
+import org.eclipse.gemini.mgmt.Activator;
+//import com.sap.core.js.conf.bundlestate.util.BundleState;
+import org.eclipse.gemini.mgmt.codec.Util;
+import org.eclipse.gemini.mgmt.framework.codec.OSGiBundle;
+import org.eclipse.gemini.mgmt.framework.BundleState;
+
+public class BundleStateTest {
+
+ @Test
+ public void nameAndVersionTest() throws Exception {
+ BundleContext bc = FrameworkUtil.getBundle(Activator.class).getBundleContext();
+ ServiceReference ref = bc.getServiceReference(MBeanServer.class.getCanonicalName());
+ if (ref == null) {
+ bc.registerService(MBeanServer.class.getCanonicalName(), ManagementFactory.getPlatformMBeanServer(), null);
+ }
+ JMXConnector connector = null;
+ CompositeData bundleInfo;
+ String symbolicName;
+ String version;
+ Object key;
+ Object[] keysArray;
+ Bundle bundle;
+ int mask = BundleState.SYMBOLIC_NAME + BundleState.IDENTIFIER + BundleState.VERSION;
+ long start = System.currentTimeMillis();
+ TabularDataSupport table = jmxInvokeListBundles(mask);
+ long end = System.currentTimeMillis();
+ assertTrue((end - start) < 1000);
+ Set keys = table.keySet();
+ Iterator iter = keys.iterator();
+ while (iter.hasNext()) {
+ key = iter.next();
+ keysArray = ((Collection) key).toArray();
+ bundleInfo = (CompositeData) table.get(keysArray);
+ symbolicName = (String) bundleInfo
+ .get(BundleStateMBean.SYMBOLIC_NAME);
+ version = (String) bundleInfo.get(BundleStateMBean.VERSION);
+ bundle = bc.getBundle((Long) keysArray[0]);
+ assertEquals(symbolicName, bundle.getSymbolicName());
+ assertEquals(version, bundle.getVersion().toString());
+ }
+ }
+
+ @Test
+ public void fullMaskTest() throws Exception {
+ JMXConnector connector = null;
+ CompositeData bundleInfo;
+ String location;
+ String symbolicName;
+ String version;
+ int startLevel;
+ String state;
+ long lastModified;
+ boolean persistenlyStarted;
+ boolean removalPending;
+ boolean required;
+ boolean fragment;
+ Long[] registeredServices;
+ Long[] servicesInUse;
+ Map<String, CompositeData> headers;
+ String[] exportedPackages;
+ String[] importedPackages;
+ Long[] fragments;
+ Long[] hosts;
+ Long[] requiringBundles;
+ Long[] requiredBundles;
+ Object key;
+ Object[] keysArray;
+ Bundle bundle;
+ int mask = BundleState.LOCATION + BundleState.IDENTIFIER
+ + BundleState.SYMBOLIC_NAME + BundleState.VERSION
+ + BundleState.START_LEVEL + BundleState.STATE
+ + BundleState.LAST_MODIFIED + BundleState.PERSISTENTLY_STARTED
+ + BundleState.REMOVAL_PENDING + BundleState.REQUIRED
+ + BundleState.FRAGMENT + BundleState.REGISTERED_SERVICES
+ + BundleState.SERVICES_IN_USE + BundleState.HEADERS
+ + BundleState.EXPORTED_PACKAGES + BundleState.IMPORTED_PACKAGES
+ + BundleState.FRAGMENTS + BundleState.HOSTS
+ + BundleState.REQUIRING_BUNDLES + BundleState.REQUIRED_BUNDLES;
+ TabularDataSupport table = jmxInvokeListBundles(mask);
+ Set keys = table.keySet();
+ Iterator iter = keys.iterator();
+ BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();
+ StartLevel sl = (StartLevel) bc.getService(bc
+ .getServiceReference(StartLevel.class.getCanonicalName()));
+ PackageAdmin admin = (PackageAdmin) bc.getService(bc
+ .getServiceReference(PackageAdmin.class.getCanonicalName()));
+ while (iter.hasNext()) {
+ key = iter.next();
+ keysArray = ((Collection) key).toArray();
+ bundleInfo = (CompositeData) table.get(keysArray);
+
+ location = (String) bundleInfo.get(BundleStateMBean.LOCATION);
+ symbolicName = (String) bundleInfo
+ .get(BundleStateMBean.SYMBOLIC_NAME);
+ version = (String) bundleInfo.get(BundleStateMBean.VERSION);
+ startLevel = ((Integer) bundleInfo
+ .get(BundleStateMBean.START_LEVEL)).intValue();
+ state = (String) bundleInfo.get(BundleStateMBean.STATE);
+ lastModified = ((Long) bundleInfo
+ .get(BundleStateMBean.LAST_MODIFIED)).longValue();
+ persistenlyStarted = ((Boolean) bundleInfo
+ .get(BundleStateMBean.PERSISTENTLY_STARTED)).booleanValue();
+ removalPending = ((Boolean) bundleInfo
+ .get(BundleStateMBean.REMOVAL_PENDING)).booleanValue();
+ required = ((Boolean) bundleInfo.get(BundleStateMBean.REQUIRED))
+ .booleanValue();
+ fragment = ((Boolean) bundleInfo.get(BundleStateMBean.FRAGMENT))
+ .booleanValue();
+ registeredServices = (Long[]) bundleInfo
+ .get(BundleStateMBean.REGISTERED_SERVICES);
+ servicesInUse = (Long[]) bundleInfo
+ .get(BundleStateMBean.SERVICES_IN_USE);
+ headers = (Map<String, CompositeData>) bundleInfo
+ .get(BundleStateMBean.HEADERS);
+ exportedPackages = (String[]) bundleInfo
+ .get(BundleStateMBean.EXPORTED_PACKAGES);
+ importedPackages = (String[]) bundleInfo
+ .get(BundleStateMBean.IMPORTED_PACKAGES);
+ fragments = (Long[]) bundleInfo.get(BundleStateMBean.FRAGMENTS);
+ hosts = (Long[]) bundleInfo.get(BundleStateMBean.HOSTS);
+ requiringBundles = (Long[]) bundleInfo
+ .get(BundleStateMBean.REQUIRING_BUNDLES);
+ requiredBundles = (Long[]) bundleInfo
+ .get(BundleStateMBean.REQUIRED_BUNDLES);
+
+ bundle = bc.getBundle((Long) keysArray[0]);
+ assertEquals(location, bundle.getLocation());
+ assertEquals(symbolicName, bundle.getSymbolicName());
+ assertEquals(version, bundle.getVersion().toString());
+ assertEquals(startLevel, sl.getBundleStartLevel(bundle));
+ assertEquals(state, stateToString(bundle.getState()));
+ assertEquals(lastModified, bundle.getLastModified());
+ assertEquals(persistenlyStarted,
+ Util.isBundlePersistentlyStarted(bundle, sl));
+ assertEquals(removalPending,
+ Util.isRequiredBundleRemovalPending(bundle, bc, admin));
+ assertEquals(required, Util.isBundleRequired(bundle, bc, admin));
+ assertEquals(fragment, Util.isBundleFragment(bundle, admin));
+
+ long[] rs = new long[registeredServices.length];
+ for (int i = 0; i < registeredServices.length; i++) {
+ rs[i] = registeredServices[i].longValue();
+ }
+ long[] rs2 = Util.serviceIds(bundle.getRegisteredServices());
+ Arrays.sort(rs);
+ Arrays.sort(rs2);
+ assertTrue(Arrays.equals(rs, rs2));
+
+ long[] siu = new long[servicesInUse.length];
+ for (int i = 0; i < servicesInUse.length; i++) {
+ siu[i] = servicesInUse[i].longValue();
+ }
+ Arrays.sort(siu);
+ long[] siu2 = Util.serviceIds(bundle.getServicesInUse());
+ Arrays.sort(siu2);
+ assertTrue(Arrays.equals(siu, siu2));
+
+ assertEquals((TabularData) headers,
+ OSGiBundle.headerTable(Util.getBundleHeaders(bundle)));
+
+ String[] exportedPackages2 = Util.getBundleExportedPackages(bundle,
+ admin);
+ Arrays.sort(exportedPackages);
+ Arrays.sort(exportedPackages2);
+ assertTrue(Arrays.equals(exportedPackages, exportedPackages2));
+
+ String[] importedPackages2 = Util.getBundleImportedPackages(bundle,
+ bc, admin);
+ Arrays.sort(importedPackages);
+ Arrays.sort(importedPackages2);
+ assertTrue(Arrays.equals(importedPackages, importedPackages2));
+
+ long[] frags = new long[fragments.length];
+ for (int i = 0; i < fragments.length; i++) {
+ frags[i] = fragments[i].longValue();
+ }
+ Arrays.sort(frags);
+ long[] frags2 = Util.getBundleFragments(bundle, admin);
+ Arrays.sort(frags2);
+ assertTrue(Arrays.equals(frags, frags2));
+
+ long[] hst = new long[hosts.length];
+ for (int i = 0; i < hosts.length; i++) {
+ hst[i] = hosts[i].longValue();
+ }
+ Arrays.sort(hst);
+ long[] hst2 = Util.bundleIds(admin.getHosts(bundle));
+ Arrays.sort(hst2);
+ assertTrue(Arrays.equals(hst, hst2));
+
+ long[] reqB = new long[requiringBundles.length];
+ for (int i = 0; i < requiringBundles.length; i++) {
+ reqB[i] = requiringBundles[i].longValue();
+ }
+ Arrays.sort(reqB);
+ long[] reqB2 = Util.getBundlesRequiring(bundle, bc, admin);
+ Arrays.sort(reqB2);
+ assertTrue(Arrays.equals(reqB, reqB2));
+
+ long[] requiredB = new long[requiredBundles.length];
+ for (int i = 0; i < requiredBundles.length; i++) {
+ requiredB[i] = requiredBundles[i].longValue();
+ }
+ Arrays.sort(requiredB);
+ long[] requiredB2 = Util.getDependencies(bundle, admin);
+ Arrays.sort(requiredB2);
+ assertTrue(Arrays.equals(requiredB, requiredB2));
+ }
+ }
+
+ @Test
+ public void randomMaskTest() throws Exception {
+ JMXConnector connector = null;
+ CompositeData bundleInfo;
+ String version;
+ String state;
+ long lastModified;
+ boolean persistenlyStarted;
+ boolean removalPending;
+ Long[] registeredServices;
+ Long[] servicesInUse;
+ String[] exportedPackages;
+ String[] importedPackages;
+ Long[] hosts;
+ Long[] requiringBundles;
+ Object key;
+ Object[] keysArray;
+ Bundle bundle;
+ int mask = BundleState.IDENTIFIER + BundleState.VERSION
+ + BundleState.STATE + BundleState.LAST_MODIFIED
+ + BundleState.PERSISTENTLY_STARTED + BundleState.REMOVAL_PENDING
+ + BundleState.REGISTERED_SERVICES + BundleState.SERVICES_IN_USE
+ + BundleState.EXPORTED_PACKAGES + BundleState.IMPORTED_PACKAGES
+ + BundleState.HOSTS + BundleState.REQUIRING_BUNDLES;
+ TabularDataSupport table = jmxInvokeListBundles(mask);
+ Set keys = table.keySet();
+ Iterator iter = keys.iterator();
+ BundleContext bc = FrameworkUtil.getBundle(BundleState.class).getBundleContext();
+ StartLevel sl = (StartLevel) bc.getService(bc
+ .getServiceReference(StartLevel.class.getCanonicalName()));
+ PackageAdmin admin = (PackageAdmin) bc.getService(bc
+ .getServiceReference(PackageAdmin.class.getCanonicalName()));
+ while (iter.hasNext()) {
+ key = iter.next();
+ keysArray = ((Collection) key).toArray();
+ bundleInfo = (CompositeData) table.get(keysArray);
+
+ version = (String) bundleInfo.get(BundleStateMBean.VERSION);
+ state = (String) bundleInfo.get(BundleStateMBean.STATE);
+ lastModified = ((Long) bundleInfo
+ .get(BundleStateMBean.LAST_MODIFIED)).longValue();
+ persistenlyStarted = ((Boolean) bundleInfo
+ .get(BundleStateMBean.PERSISTENTLY_STARTED)).booleanValue();
+ removalPending = ((Boolean) bundleInfo
+ .get(BundleStateMBean.REMOVAL_PENDING)).booleanValue();
+ registeredServices = (Long[]) bundleInfo
+ .get(BundleStateMBean.REGISTERED_SERVICES);
+ servicesInUse = (Long[]) bundleInfo
+ .get(BundleStateMBean.SERVICES_IN_USE);
+ exportedPackages = (String[]) bundleInfo
+ .get(BundleStateMBean.EXPORTED_PACKAGES);
+ importedPackages = (String[]) bundleInfo
+ .get(BundleStateMBean.IMPORTED_PACKAGES);
+ hosts = (Long[]) bundleInfo.get(BundleStateMBean.HOSTS);
+ requiringBundles = (Long[]) bundleInfo
+ .get(BundleStateMBean.REQUIRING_BUNDLES);
+ bundle = bc.getBundle((Long) keysArray[0]);
+
+ assertEquals(version, bundle.getVersion().toString());
+ assertEquals(state, stateToString(bundle.getState()));
+ assertEquals(lastModified, bundle.getLastModified());
+ assertEquals(persistenlyStarted,
+ Util.isBundlePersistentlyStarted(bundle, sl));
+ assertEquals(removalPending,
+ Util.isRequiredBundleRemovalPending(bundle, bc, admin));
+
+ long[] rs = new long[registeredServices.length];
+ for (int i = 0; i < registeredServices.length; i++) {
+ rs[i] = registeredServices[i].longValue();
+ }
+ long[] rs2 = Util.serviceIds(bundle.getRegisteredServices());
+ Arrays.sort(rs);
+ Arrays.sort(rs2);
+ assertTrue(Arrays.equals(rs, rs2));
+
+ long[] siu = new long[servicesInUse.length];
+ for (int i = 0; i < servicesInUse.length; i++) {
+ siu[i] = servicesInUse[i].longValue();
+ }
+ Arrays.sort(siu);
+ long[] siu2 = Util.serviceIds(bundle.getServicesInUse());
+ Arrays.sort(siu2);
+ assertTrue(Arrays.equals(siu, siu2));
+
+ String[] exportedPackages2 = Util.getBundleExportedPackages(bundle,
+ admin);
+ Arrays.sort(exportedPackages);
+ Arrays.sort(exportedPackages2);
+ assertTrue(Arrays.equals(exportedPackages, exportedPackages2));
+
+ String[] importedPackages2 = Util.getBundleImportedPackages(bundle,
+ bc, admin);
+ Arrays.sort(importedPackages);
+ Arrays.sort(importedPackages2);
+ assertTrue(Arrays.equals(importedPackages, importedPackages2));
+
+ long[] hst = new long[hosts.length];
+ for (int i = 0; i < hosts.length; i++) {
+ hst[i] = hosts[i].longValue();
+ }
+ Arrays.sort(hst);
+ long[] hst2 = Util.bundleIds(admin.getHosts(bundle));
+ Arrays.sort(hst2);
+ assertTrue(Arrays.equals(hst, hst2));
+
+ long[] reqB = new long[requiringBundles.length];
+ for (int i = 0; i < requiringBundles.length; i++) {
+ reqB[i] = requiringBundles[i].longValue();
+ }
+ Arrays.sort(reqB);
+ long[] reqB2 = Util.getBundlesRequiring(bundle, bc, admin);
+ Arrays.sort(reqB2);
+ assertTrue(Arrays.equals(reqB, reqB2));
+ }
+ }
+
+ private TabularDataSupport jmxInvokeListBundles(int mask)
+ throws MalformedURLException, IOException,
+ MalformedObjectNameException, InstanceNotFoundException,
+ MBeanException, ReflectionException {
+ JMXConnector connector;
+ String url = "service:jmx:rmi:///jndi/rmi://localhost:21045/jmxrmi";
+ JMXServiceURL jmxURL = new JMXServiceURL(url);
+ connector = JMXConnectorFactory.connect(jmxURL);
+ MBeanServerConnection connection = connector.getMBeanServerConnection();
+ ObjectName name = new ObjectName(CustomBundleStateMBean.OBJECTNAME);
+ TabularDataSupport table = (TabularDataSupport) connection.invoke(name,
+ "listBundles", new Object[] { new Integer(mask) },
+ new String[] { "int" });
+ return table;
+ }
+
+ @Test
+ public void illegalMaskTest() throws Exception {
+ JMXConnector connector = null;
+ CompositeData bundleInfo;
+ String version;
+ String state;
+ long lastModified;
+ boolean persistenlyStarted;
+ boolean removalPending;
+ Long[] registeredServices;
+ Long[] servicesInUse;
+ String[] exportedPackages;
+ String[] importedPackages;
+ Long[] hosts;
+ Long[] requiringBundles;
+ Object key;
+ Object[] keysArray;
+ Bundle bundle;
+ int mask = 1048576;
+ try {
+ TabularDataSupport table = jmxInvokeListBundles(mask);
+ fail("Expected exception did not occur!");
+ } catch (Exception e) {
+ assertTrue(e.getCause() instanceof java.lang.IllegalArgumentException);
+ }
+ }
+
+ private String stateToString(int state) {
+ String strState = null;
+ switch (state) {
+ case 1:
+ strState = "UNINSTALLED";
+ break;
+ case 2:
+ strState = "INSTALLED";
+ break;
+ case 4:
+ strState = "RESOLVED";
+ break;
+ case 8:
+ strState = "STARTING";
+ break;
+ case 16:
+ strState = "STOPPING";
+ break;
+ case 32:
+ strState = "ACTIVE";
+ break;
+ default:
+ strState = "UNKNOWN";
+ break;
+ }
+ return strState;
+ }
+}
+