You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by zo...@apache.org on 2011/02/27 18:58:23 UTC

svn commit: r1075096 [11/13] - in /aries/tags/jmx-0.1-incubating: ./ jmx-api/ jmx-api/src/ jmx-api/src/main/ jmx-api/src/main/appended-resources/ jmx-api/src/main/appended-resources/META-INF/ jmx-api/src/main/java/ jmx-api/src/main/java/org/ jmx-api/sr...

Added: aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/FrameworkUtilsTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,288 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.util;
+
+import static org.apache.aries.jmx.util.FrameworkUtils.getBundleDependencies;
+import static org.apache.aries.jmx.util.FrameworkUtils.getBundleExportedPackages;
+import static org.apache.aries.jmx.util.FrameworkUtils.getBundleIds;
+import static org.apache.aries.jmx.util.FrameworkUtils.getBundleImportedPackages;
+import static org.apache.aries.jmx.util.FrameworkUtils.getRegisteredServiceIds;
+import static org.apache.aries.jmx.util.FrameworkUtils.getServiceIds;
+import static org.apache.aries.jmx.util.FrameworkUtils.getServicesInUseByBundle;
+import static org.apache.aries.jmx.util.FrameworkUtils.isBundlePendingRemoval;
+import static org.apache.aries.jmx.util.FrameworkUtils.isBundleRequiredByOthers;
+import static org.apache.aries.jmx.util.FrameworkUtils.resolveService;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.Version;
+import org.osgi.service.packageadmin.ExportedPackage;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.service.packageadmin.RequiredBundle;
+
+/**
+ * 
+ * 
+ *
+ * @version $Rev: 898026 $ $Date: 2010-01-11 19:35:03 +0000 (Mon, 11 Jan 2010) $
+ */
+public class FrameworkUtilsTest {
+
+   
+    @Test
+    public void testGetBundleIds() throws Exception {
+
+        assertEquals(0, getBundleIds(null).length);
+        assertEquals(0, getBundleIds(new Bundle[0]).length);
+        
+        Bundle b1 = mock(Bundle.class);
+        when(b1.getBundleId()).thenReturn(new Long(47));
+        Bundle b2 = mock(Bundle.class);
+        when(b2.getBundleId()).thenReturn(new Long(23));
+        
+        assertArrayEquals(new long[] { 47 , 23 }, getBundleIds(new Bundle[] { b1, b2 }));
+        
+    }
+    
+    @Test
+    public void testResolveService() throws Exception {
+        
+        BundleContext context = mock(BundleContext.class);
+        ServiceReference reference = mock(ServiceReference.class);
+        when(context.getAllServiceReferences(anyString(), anyString())).thenReturn(new ServiceReference[] { reference });        
+        ServiceReference result = resolveService(context, 998);
+        assertNotNull(result);
+        
+    }
+
+    @Test
+    public void testGetServiceIds() throws Exception {
+        
+        assertEquals(0, getServiceIds(null).length);
+        assertEquals(0, getServiceIds(new ServiceReference[0]).length);
+        
+        ServiceReference s1 = mock(ServiceReference.class);
+        when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(15));
+        ServiceReference s2 = mock(ServiceReference.class);
+        when(s2.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(5));
+        ServiceReference s3 = mock(ServiceReference.class);
+        when(s3.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(25));
+        
+        assertArrayEquals(new long[] { 15, 5, 25 }, 
+                getServiceIds(new ServiceReference[] {s1, s2, s3} ) );
+    }
+    
+    @Test
+    public void testGetBundleExportedPackages() throws Exception {
+        
+        Bundle bundle = mock(Bundle.class);
+        PackageAdmin admin = mock(PackageAdmin.class);
+        
+        assertEquals(0, getBundleExportedPackages(bundle, admin).length);
+        
+        ExportedPackage exported = mock(ExportedPackage.class);
+        when(exported.getName()).thenReturn("org.apache.aries.jmx");
+        when(exported.getVersion()).thenReturn(new Version("1.0.0"));
+        when(admin.getExportedPackages(bundle)).thenReturn(new ExportedPackage[] { exported });
+        
+        assertArrayEquals(new String[] { "org.apache.aries.jmx;1.0.0"} , getBundleExportedPackages(bundle, admin));
+        
+    }
+    
+    
+    @Test
+    public void testGetBundleImportedPackages() throws Exception {
+        
+        Bundle bundle = mock(Bundle.class);
+        BundleContext context = mock(BundleContext.class);
+        
+        Bundle b1 = mock(Bundle.class);
+        Bundle b2 = mock(Bundle.class);
+        Bundle b3 = mock(Bundle.class);
+        when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
+        
+        ExportedPackage ep1 = mock(ExportedPackage.class);
+        when(ep1.getImportingBundles()).thenReturn(new Bundle[] { bundle, b2, b3 });
+        when(ep1.getName()).thenReturn("org.apache.aries.jmx.b1");
+        when(ep1.getVersion()).thenReturn(Version.emptyVersion);
+        ExportedPackage ep2 = mock(ExportedPackage.class);
+        when(ep2.getImportingBundles()).thenReturn(new Bundle[] { bundle, b3 });
+        when(ep2.getName()).thenReturn("org.apache.aries.jmx.b2");
+        when(ep2.getVersion()).thenReturn(Version.parseVersion("2.0.1"));
+       
+        
+        PackageAdmin admin = mock(PackageAdmin.class);
+        when(admin.getExportedPackages(b1)).thenReturn(new ExportedPackage[] { ep1 });
+        when(admin.getExportedPackages(b2)).thenReturn(new ExportedPackage[] { ep2 });
+        when(admin.getExportedPackages(b3)).thenReturn(null);
+        
+        //check first with DynamicImport
+        Dictionary<String, String> headers = new Hashtable<String, String>();
+        headers.put(Constants.DYNAMICIMPORT_PACKAGE, "*");
+        when(bundle.getHeaders()).thenReturn(headers);
+        assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"} 
+                    , getBundleImportedPackages(context, bundle, admin));
+        
+        //check with ImportPackage statement
+        headers.remove(Constants.DYNAMICIMPORT_PACKAGE);
+        String importPackageStatement = "org.apache.aries.jmx.b1;version=0.0.0;resolution:=optional,org.apache.aries.jmx.b2;attribute:=value"; 
+        headers.put(Constants.IMPORT_PACKAGE, importPackageStatement);
+        when(admin.getExportedPackages("org.apache.aries.jmx.b1")).thenReturn(new ExportedPackage[] { ep1 });
+        when(admin.getExportedPackages("org.apache.aries.jmx.b2")).thenReturn(new ExportedPackage[] { ep2 });
+        
+        assertArrayEquals(new String[] { "org.apache.aries.jmx.b1;0.0.0" , "org.apache.aries.jmx.b2;2.0.1"} 
+                    , getBundleImportedPackages(context, bundle, admin));
+        
+        
+    }
+    
+    @Test
+    public void testGetRegisteredServiceIds() throws Exception {
+        
+        Bundle bundle = mock(Bundle.class);
+        
+        ServiceReference s1 = mock(ServiceReference.class);
+        when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(56));
+        ServiceReference s2 = mock(ServiceReference.class);
+        when(s2.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(5));
+        ServiceReference s3 = mock(ServiceReference.class);
+        when(s3.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(34));
+        
+        when(bundle.getRegisteredServices()).thenReturn(new ServiceReference[] { s1, s2, s3 });
+        
+        assertArrayEquals(new long[] { 56, 5, 34}, getRegisteredServiceIds(bundle));
+        
+    }
+    
+    @Test
+    public void testGetServicesInUseByBundle() throws Exception {
+        
+        Bundle bundle = mock(Bundle.class);
+        
+        ServiceReference s1 = mock(ServiceReference.class);
+        when(s1.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(15));
+        ServiceReference s2 = mock(ServiceReference.class);
+        when(s2.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(16));
+        ServiceReference s3 = mock(ServiceReference.class);
+        when(s3.getProperty(Constants.SERVICE_ID)).thenReturn(new Long(17));
+        
+        when(bundle.getServicesInUse()).thenReturn(new ServiceReference[] { s1, s2, s3 });
+        
+        assertArrayEquals(new long[] { 15, 16, 17 }, getServicesInUseByBundle(bundle));
+        
+    }
+    
+    @Test
+    public void testIsBundlePendingRemoval() throws Exception {
+        
+        Bundle bundle = mock(Bundle.class);
+        when(bundle.getSymbolicName()).thenReturn("org.apache.testb");
+        
+        RequiredBundle reqBundle = mock(RequiredBundle.class);
+        when(reqBundle.getBundle()).thenReturn(bundle);
+        when(reqBundle.isRemovalPending()).thenReturn(true);
+        
+        PackageAdmin admin = mock(PackageAdmin.class);
+        when(admin.getRequiredBundles("org.apache.testb")).thenReturn(new RequiredBundle[] { reqBundle });
+        
+        assertTrue(isBundlePendingRemoval(bundle, admin));
+        
+    }
+    
+    @Test
+    public void testIsBundleRequiredByOthers() throws Exception {
+        
+        Bundle bundle = mock(Bundle.class);
+        when(bundle.getSymbolicName()).thenReturn("org.apache.testb");
+        
+        RequiredBundle reqBundle = mock(RequiredBundle.class);
+        when(reqBundle.getBundle()).thenReturn(bundle);
+        when(reqBundle.getRequiringBundles()).thenReturn(new Bundle[0]);
+        
+        PackageAdmin admin = mock(PackageAdmin.class);
+        when(admin.getRequiredBundles("org.apache.testb")).thenReturn(new RequiredBundle[] { reqBundle });
+        
+        assertFalse(isBundleRequiredByOthers(bundle, admin));
+        
+        Bundle user = mock(Bundle.class);
+        when(reqBundle.getRequiringBundles()).thenReturn(new Bundle[] { user });
+        
+        assertTrue(isBundleRequiredByOthers(bundle, admin));
+    }
+    
+    
+    @Test
+    public void testGetBundleDependencies() throws Exception {
+        
+        Bundle bundle = mock(Bundle.class);
+        BundleContext context = mock(BundleContext.class);
+       
+        Bundle b1 = mock(Bundle.class);
+        when(b1.getSymbolicName()).thenReturn("b1");
+        when(b1.getBundleId()).thenReturn(new Long(44));
+        Bundle b2 = mock(Bundle.class);
+        when(b2.getSymbolicName()).thenReturn("b2");
+        when(b2.getBundleId()).thenReturn(new Long(55));
+        Bundle b3 = mock(Bundle.class);
+        when(b3.getSymbolicName()).thenReturn("b3");
+        when(b3.getBundleId()).thenReturn(new Long(66));
+        
+        when(context.getBundles()).thenReturn(new Bundle[] { bundle, b1, b2, b3 });
+        
+        Dictionary<String, String> headers = new Hashtable<String, String>();
+        when(bundle.getHeaders()).thenReturn(headers);
+        
+        PackageAdmin admin = mock(PackageAdmin.class);
+        assertEquals(0, getBundleDependencies(context, bundle, admin).length);
+        
+        RequiredBundle rb1 = mock(RequiredBundle.class);
+        when(rb1.getBundle()).thenReturn(b1);
+        when(rb1.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b2 });
+        RequiredBundle rb2 = mock(RequiredBundle.class);
+        when(rb2.getBundle()).thenReturn(b2);
+        when(rb2.getRequiringBundles()).thenReturn(new Bundle[] { b1 });
+        RequiredBundle rb3 = mock(RequiredBundle.class);
+        when(rb3.getBundle()).thenReturn(b3);
+        when(rb3.getRequiringBundles()).thenReturn(new Bundle[] { bundle, b1, b2 });
+        
+        headers.put(Constants.REQUIRE_BUNDLE, "b1;bundle-version=\"1.0.0\",b3;bundle-version=\"2.0.0\"");
+        
+        when(admin.getRequiredBundles("b1")).thenReturn(new RequiredBundle[] { rb1 });
+        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));
+        
+        
+    }
+    
+    
+}

Added: aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/TypeUtilsTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/TypeUtilsTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/TypeUtilsTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-core/src/test/java/org/apache/aries/jmx/util/TypeUtilsTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,104 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.util;
+
+import static org.apache.aries.jmx.util.TypeUtils.fromDictionary;
+import static org.apache.aries.jmx.util.TypeUtils.fromString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class TypeUtilsTest {
+
+    
+    @Test
+    public void testMapFromDictionary() throws Exception{
+        
+        Dictionary<String, String> dictionary = new Hashtable<String, String>();
+        dictionary.put("one", "1");
+        dictionary.put("two", "2");
+        
+        Map<String,String> map = fromDictionary(dictionary);
+        assertEquals(2, map.size());
+        assertEquals("1", map.get("one"));
+        assertEquals("2", map.get("two"));
+        
+    }
+    
+    @Test
+    public void testFromString() throws Exception {
+        
+        String value;
+        
+        value = "1";
+        Integer integerValue = fromString(Integer.class, value);
+        assertEquals(new Integer(1), integerValue);
+        
+        int intValue = fromString(Integer.TYPE, value);
+        assertEquals(1, intValue);
+        
+        Long wrappedLongValue = fromString(Long.class, value);
+        assertEquals(Long.valueOf(1), wrappedLongValue);
+        
+        long longValue = fromString(Long.TYPE, value);
+        assertEquals(1, longValue);
+        
+        Double wrappedDoubleValue = fromString(Double.class, value);
+        assertEquals(Double.valueOf(1), wrappedDoubleValue);
+        
+        double doubleValue = fromString(Double.TYPE, value);
+        assertEquals(1, doubleValue, 0);
+        
+        Float wrappedFloatValue = fromString(Float.class, value);
+        assertEquals(Float.valueOf(1), wrappedFloatValue);
+        
+        float floatValue = fromString(Float.TYPE, value);
+        assertEquals(1, floatValue, 0);
+        
+        Short shortValue = fromString(Short.class, value);
+        assertEquals(Short.valueOf(value), shortValue);
+        
+        Byte byteValue = fromString(Byte.class, value);
+        assertEquals(Byte.valueOf(value), byteValue);
+        
+        value = "true";
+        assertTrue(fromString(Boolean.class, value));
+        assertTrue(fromString(Boolean.TYPE, value));
+        
+        char charValue = fromString(Character.TYPE, "a");
+        assertEquals('a', charValue);
+        Character characterValue = fromString(Character.class, "a");
+        assertEquals(Character.valueOf('a'), characterValue);
+        
+        BigDecimal bigDecimal = fromString(BigDecimal.class, "2");
+        assertEquals(new BigDecimal("2"), bigDecimal);
+     
+        BigInteger bigInteger = fromString(BigInteger.class, "2");
+        assertEquals(new BigInteger("2"), bigInteger);
+        
+        String stringValue = fromString(String.class, value);
+        assertEquals(stringValue, value);
+        
+    }
+}

Added: aries/tags/jmx-0.1-incubating/jmx-itests/pom.xml
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/pom.xml?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/pom.xml (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/pom.xml Sun Feb 27 17:58:16 2011
@@ -0,0 +1,175 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<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/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.aries.jmx</groupId>
+        <artifactId>jmx</artifactId>
+        <version>0.1-incubating</version>
+    </parent>
+
+    <groupId>org.apache.aries.jmx</groupId>
+    <artifactId>org.apache.aries.jmx.itests</artifactId>
+    <packaging>jar</packaging>
+    <name>Apache Aries JMX integration tests</name>
+    <description>
+       Integration tests for the JMX component (using the standalone composite jmx-bundle)
+    </description>
+
+    <!--
+        pluginRepositories> <pluginRepository> <id>ops4j.releases</id>
+        <url>http://repository.ops4j.org/maven2</url> <snapshots> <enabled>false</enabled>
+        </snapshots> </pluginRepository> </pluginRepositories -->
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.aries.jmx</groupId>
+            <artifactId>org.apache.aries.jmx</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.jmx</groupId>
+            <artifactId>org.apache.aries.jmx.blueprint</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint.sample</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.configadmin</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries</groupId>
+            <artifactId>org.apache.aries.util</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.aries.blueprint</groupId>
+            <artifactId>org.apache.aries.blueprint</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.logging</groupId>
+            <artifactId>pax-logging-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.logging</groupId>
+            <artifactId>pax-logging-service</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-default</artifactId>
+            <scope>test</scope>
+        </dependency>
+		<dependency>
+			<groupId>org.ops4j.pax.swissbox</groupId>
+			<artifactId>pax-swissbox-tinybundles</artifactId>
+			<scope>test</scope>
+		</dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-mvn</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>depends-maven-plugin</artifactId>
+                <version>1.1</version>
+                <executions>
+                    <execution>
+                        <id>generate-depends-file</id>
+                        <goals>
+                            <goal>generate-depends-file</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <forkMode>pertest</forkMode>
+                    <excludes>
+                        <exclude>**/*$*</exclude>
+                        <exclude>**/Abstract*.java</exclude>
+                    </excludes>
+                    <includes>
+                        <include>**/Test*.java</include>
+                        <include>**/*Test.java</include>
+                    </includes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <profiles>
+        <profile>
+            <id>ci-build-profile</id>
+            <activation>
+                <property>
+                    <name>maven.repo.local</name>
+                </property>
+            </activation>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <!--
+                                when the local repo location has been specified, we need to pass on
+                                this information to PAX mvn url
+                            -->
+                            <argLine>-Dorg.ops4j.pax.url.mvn.localRepository=${maven.repo.local}</argLine>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
+
+</project>

Added: aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/AbstractIntegrationTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,222 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx;
+
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import org.ops4j.pax.exam.options.MavenArtifactProvisionOption;
+import static org.junit.Assert.*;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanServerInvocationHandler;
+import javax.management.ObjectName;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Inject;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.Version;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * 
+ * 
+ *
+ * @version $Rev: 926162 $ $Date: 2010-03-22 16:28:46 +0000 (Mon, 22 Mar 2010) $
+ */
+@RunWith(JUnit4TestRunner.class)
+public class AbstractIntegrationTest {
+    
+    public static final long DEFAULT_TIMEOUT = 30000;
+
+    ServiceRegistration registration;
+    ServiceReference reference;
+    protected MBeanServer mbeanServer;
+
+    @Inject
+    protected BundleContext bundleContext;
+    
+    @Before
+    public void setUp() throws Exception {
+        mbeanServer = MBeanServerFactory.createMBeanServer();
+
+        registration = bundleContext.registerService(MBeanServer.class
+                .getCanonicalName(), mbeanServer, null);
+            
+        String key = MBeanServer.class.getCanonicalName();
+        System.out.println(key);
+
+        reference = bundleContext.getServiceReference(key);
+        assertNotNull(reference);
+        MBeanServer mbeanService = (MBeanServer) bundleContext.getService(reference);
+        assertNotNull(mbeanService);
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        bundleContext.ungetService(reference);
+        //plainRegistration.unregister();
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected <T> T getMBean(String name, Class<T> type) {
+        ObjectName objectName = null;
+        try {
+            objectName = new ObjectName(name);
+        } catch (Exception e) {
+            fail(e.toString());
+        }
+        assertNotNull(mbeanServer);
+        assertNotNull(objectName);
+        T mbean = (T) MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName,
+                type, false);
+        return mbean;
+    }
+    
+    protected Bundle getBundle(String symbolicName) {
+        return getBundle(symbolicName, null);
+    }
+    
+    protected Bundle getBundle(String bundleSymbolicName, String version) {
+        Bundle result = null;
+        for (Bundle b : bundleContext.getBundles()) {
+            if ( b.getSymbolicName().equals(bundleSymbolicName) ) {
+                if (version == null || b.getVersion().equals(Version.parseVersion(version))) {
+                    result = b;
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+    
+    protected <T> T getOsgiService(Class<T> type, long timeout) {
+        return getOsgiService(type, null, timeout);
+    }
+
+    protected <T> T getOsgiService(Class<T> type) {
+        return getOsgiService(type, null, DEFAULT_TIMEOUT);
+    }
+
+    protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
+        ServiceTracker tracker = null;
+        try {
+            String flt;
+            if (filter != null) {
+                if (filter.startsWith("(")) {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")" + filter + ")";
+                } else {
+                    flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")(" + filter + "))";
+                }
+            } else {
+                flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
+            }
+            Filter osgiFilter = FrameworkUtil.createFilter(flt);
+            tracker = new ServiceTracker(bundleContext, osgiFilter, null);
+            tracker.open(true);
+            // Note that the tracker is not closed to keep the reference
+            // This is buggy, as the service reference may change i think
+            Object svc = type.cast(tracker.waitForService(timeout));
+            if (svc == null) {
+                Dictionary dic = bundleContext.getBundle().getHeaders();
+                System.err.println("Test bundle headers: " + explode(dic));
+
+                for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, null))) {
+                    System.err.println("ServiceReference: " + ref);
+                }
+
+                for (ServiceReference ref : asCollection(bundleContext.getAllServiceReferences(null, flt))) {
+                    System.err.println("Filtered ServiceReference: " + ref);
+                }
+
+                throw new RuntimeException("Gave up waiting for service " + flt);
+            }
+            return type.cast(svc);
+        } catch (InvalidSyntaxException e) {
+            throw new IllegalArgumentException("Invalid filter", e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static MavenArtifactProvisionOption mavenBundle(String groupId, String artifactId) {
+        return CoreOptions.mavenBundle().groupId(groupId).artifactId(artifactId).versionAsInProject();
+    }
+
+    protected static Option[] updateOptions(Option[] options) {
+        // We need to add pax-exam-junit here when running with the ibm
+        // jdk to avoid the following exception during the test run:
+        // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
+        if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
+            Option[] ibmOptions = options(
+                wrappedBundle(mavenBundle("org.ops4j.pax.exam", "pax-exam-junit"))
+            );
+            options = combine(ibmOptions, options);
+        }
+
+        return options;
+    }
+
+    /*
+     * Explode the dictionary into a ,-delimited list of key=value pairs
+     */
+    private static String explode(Dictionary dictionary) {
+        Enumeration keys = dictionary.keys();
+        StringBuffer result = new StringBuffer();
+        while (keys.hasMoreElements()) {
+            Object key = keys.nextElement();
+            result.append(String.format("%s=%s", key, dictionary.get(key)));
+            if (keys.hasMoreElements()) {
+                result.append(", ");
+            }
+        }
+        return result.toString();
+    }
+
+    /*
+     * Provides an iterable collection of references, even if the original array is null
+     */
+    private static final Collection<ServiceReference> asCollection(ServiceReference[] references) {
+        List<ServiceReference> result = new LinkedList<ServiceReference>();
+        if (references != null) {
+            for (ServiceReference reference : references) {
+                result.add(reference);
+            }
+        }
+        return result;
+    }
+
+}
\ No newline at end of file

Added: aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/cm/ConfigurationAdminMBeanTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,270 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.cm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+
+import java.io.InputStream;
+import java.util.Dictionary;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.apache.aries.jmx.codec.PropertyData;
+import org.apache.aries.jmx.test.bundlea.api.InterfaceA;
+import org.apache.aries.jmx.test.bundleb.api.InterfaceB;
+import org.apache.aries.jmx.test.bundleb.api.MSF;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.jmx.service.cm.ConfigurationAdminMBean;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * 
+ *
+ * @version $Rev: 922888 $ $Date: 2010-03-14 16:31:18 +0000 (Sun, 14 Mar 2010) $
+ */
+public class ConfigurationAdminMBeanTest extends AbstractIntegrationTest {
+
+    @Configuration
+    public static Option[] configuration() {
+        Option[] options = CoreOptions
+                .options(
+                        CoreOptions.equinox(),
+                        mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+                        mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+                        mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+                        mavenBundle("org.osgi", "org.osgi.compendium"),
+                        mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
+                        new Customizer() {
+                            public InputStream customizeTestProbe(InputStream testProbe) throws Exception {
+                                return modifyBundle(testProbe)
+                                           .removeHeader(Constants.DYNAMICIMPORT_PACKAGE)
+                                           .set(Constants.REQUIRE_BUNDLE, "org.apache.aries.jmx.test.bundlea,org.apache.aries.jmx.test.bundleb")
+                                           .build(withBnd());
+                            }
+                        },
+                        provision(newBundle()
+                                .add(org.apache.aries.jmx.test.bundlea.Activator.class)
+                                .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
+                                .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
+                                .set(Constants.BUNDLE_VERSION, "2.0.0")
+                                .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api;version=2.0.0")
+                                .set(Constants.IMPORT_PACKAGE,
+                                        "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional" +
+                                        ",org.osgi.service.cm")
+                                .set(Constants.BUNDLE_ACTIVATOR,
+                                        org.apache.aries.jmx.test.bundlea.Activator.class.getName())
+                                .build(withBnd())),
+                        provision(newBundle()
+                                .add(org.apache.aries.jmx.test.bundleb.Activator.class)
+                                .add(org.apache.aries.jmx.test.bundleb.api.InterfaceB.class)
+                                .add(org.apache.aries.jmx.test.bundleb.api.MSF.class)
+                                .add(org.apache.aries.jmx.test.bundleb.impl.B.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME,"org.apache.aries.jmx.test.bundleb")
+                                .set(Constants.BUNDLE_VERSION, "1.0.0")
+                                .set(Constants.EXPORT_PACKAGE,"org.apache.aries.jmx.test.bundleb.api;version=1.1.0")
+                                .set(Constants.IMPORT_PACKAGE,"org.osgi.framework;version=1.5.0,org.osgi.util.tracker" +
+                                        ",org.osgi.service.cm")
+                                .set(Constants.BUNDLE_ACTIVATOR,
+                                        org.apache.aries.jmx.test.bundleb.Activator.class.getName())
+                                .build(withBnd()))
+                        );
+        options = updateOptions(options);
+        return options;
+    }
+    
+    @Before
+    public void doSetUp() throws Exception {
+        super.setUp();
+        int i=0;
+        while (true) {
+            try {
+                mbeanServer.getObjectInstance(new ObjectName(ConfigurationAdminMBean.OBJECTNAME));
+                break;
+            } catch (InstanceNotFoundException e) {
+                if (i == 5) {
+                    throw new Exception("ConfigurationAdminMBean not available after waiting 5 seconds");
+                }
+            }
+            i++;
+            Thread.sleep(1000);
+        }
+    }
+    
+    @Ignore("ManagedServiceFactory tests failing.. " +
+            "Some issues surrounding creating a factory configuration and then retrieving by pid to update.. Needs investigation")
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testMBeanInterface() throws Exception {
+        
+        ConfigurationAdminMBean mbean = getMBean(ConfigurationAdminMBean.OBJECTNAME, ConfigurationAdminMBean.class);
+        assertNotNull(mbean);
+       
+        // get bundles
+        
+        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
+        assertNotNull(a);
+        
+        Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
+        assertNotNull(b);
+       
+        
+        // get services
+        
+        ServiceTracker trackerA = new ServiceTracker(bundleContext, InterfaceA.class.getName(), null);
+        trackerA.open();
+        InterfaceA managedServiceA = (InterfaceA) trackerA.getService();
+        assertNotNull(managedServiceA);
+        
+        Filter filter = bundleContext.createFilter("(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+        ServiceTracker trackerMSF = new ServiceTracker(bundleContext, filter, null);
+        trackerMSF.open();
+        MSF managedFactory = (MSF) trackerMSF.getService();
+        assertNotNull(managedFactory);
+        
+        ServiceTracker tracker = new ServiceTracker(bundleContext, ConfigurationAdmin.class.getName(), null);
+        tracker.open();
+        ConfigurationAdmin configAdmin = (ConfigurationAdmin) tracker.getService();
+        assertNotNull(configAdmin);
+        
+        // ManagedService operations
+        
+        assertNull(managedServiceA.getConfig());
+        
+        // create a configuration for A
+        TabularData data = mbean.getProperties("org.apache.aries.jmx.test.ServiceA");
+        assertEquals(0, data.size());
+        
+        PropertyData<String> p1 = PropertyData.newInstance("A1", "first");
+        data.put(p1.toCompositeData());
+        PropertyData<Integer> p2 = PropertyData.newInstance("A2", 2);
+        data.put(p2.toCompositeData());
+        
+        mbean.update("org.apache.aries.jmx.test.ServiceA", data);
+        
+        Thread.sleep(1000);
+        Dictionary<String, Object> config = managedServiceA.getConfig();
+        assertNotNull(config);
+        assertEquals(3, config.size());
+        assertEquals("org.apache.aries.jmx.test.ServiceA", config.get(Constants.SERVICE_PID));
+        assertEquals("first", config.get("A1"));
+        assertEquals(2, config.get("A2"));
+        
+        //delete
+        mbean.deleteForLocation("org.apache.aries.jmx.test.ServiceA", a.getLocation());
+        
+        Thread.sleep(1000);
+        assertNull(managedServiceA.getConfig());
+        
+        
+        // ManagedServiceFactory operations
+        
+        String cpid = mbean.createFactoryConfiguration("jmx.test.B.factory");
+        assertNotNull(cpid);
+        assertTrue(cpid.contains("jmx.test.B.factory"));
+        
+        TabularData fConfig = mbean.getProperties(cpid);
+        assertNotNull(fConfig);
+        assertEquals(0, fConfig.values().size());
+        
+        PropertyData<String> prop1 = PropertyData.newInstance("B1", "value1");
+        fConfig.put(prop1.toCompositeData());
+        PropertyData<Boolean> prop2 = PropertyData.newInstance("B2", true);
+        fConfig.put(prop2.toCompositeData());
+        
+        mbean.update(cpid, fConfig);
+        
+        Thread.sleep(1000);
+        
+        InterfaceB configured = managedFactory.getConfigured(cpid);
+        assertNotNull(configured);
+        config = configured.getConfig();
+        assertNotNull(config);
+        assertTrue(config.size() >= 4);
+        assertEquals("jmx.test.B.factory", config.get(ConfigurationAdmin.SERVICE_FACTORYPID));
+        assertEquals(cpid, config.get(Constants.SERVICE_PID));
+        assertEquals("value1", config.get("B1"));
+        assertEquals("true", config.get("B2"));
+        
+        assertEquals("jmx.test.B.factory", mbean.getFactoryPid(cpid));
+        
+        mbean.delete(cpid);
+        
+        Thread.sleep(1000);
+        
+        assertNull(managedFactory.getConfigured(cpid));
+       
+        // list operations
+        
+        data = mbean.getProperties("org.apache.aries.jmx.test.ServiceA");
+        assertEquals(0, data.size());
+        
+        p1 = PropertyData.newInstance("A1", "a1Value");
+        data.put(p1.toCompositeData());
+        
+        mbean.update("org.apache.aries.jmx.test.ServiceA", data);
+        
+        Thread.sleep(1000);
+        
+        config = managedServiceA.getConfig();
+        assertNotNull(config);
+        assertEquals(2, config.size());
+        assertEquals("org.apache.aries.jmx.test.ServiceA", config.get(Constants.SERVICE_PID));
+        assertEquals("a1Value", config.get("A1"));
+
+        
+        String[][] configurations = mbean.getConfigurations("(A1=a1Value)");
+        assertNotNull(configurations);
+        assertEquals(1, configurations.length);
+        assertEquals("org.apache.aries.jmx.test.ServiceA", configurations[0][0]);
+        assertEquals(a.getLocation(), configurations[0][1]);
+        
+        // delete with filter
+        mbean.deleteConfigurations("(A1=a1Value)");
+        
+        Thread.sleep(1000);
+        
+        assertNull(managedServiceA.getConfig());
+        
+        //clean up
+        
+        trackerA.close();
+        trackerMSF.close();
+        tracker.close();
+        
+    }
+}

Added: aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/BundleStateMBeanTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,271 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+import static org.osgi.jmx.framework.BundleStateMBean.OBJECTNAME;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.apache.aries.jmx.codec.BundleData.Header;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.jmx.framework.BundleStateMBean;
+
+/**
+ * 
+ * 
+ * 
+ * @version $Rev: 898957 $ $Date: 2010-01-13 21:59:01 +0000 (Wed, 13 Jan 2010) $
+ */
+public class BundleStateMBeanTest extends AbstractIntegrationTest {
+
+    @Configuration
+    public static Option[] configuration() {
+        Option[] options = CoreOptions
+                .options(
+                        CoreOptions.equinox(),
+                        mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+                        mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+                        mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+                        mavenBundle("org.osgi", "org.osgi.compendium"),
+                        mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
+                        provision(newBundle()
+                                .add(org.apache.aries.jmx.test.bundlea.Activator.class)
+                                .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
+                                .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
+                                .set(Constants.BUNDLE_VERSION, "2.0.0")
+                                .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api;version=2.0.0")
+                                .set(Constants.IMPORT_PACKAGE,
+                                        "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional" +
+                                        ",org.osgi.service.cm")
+                                .set(Constants.BUNDLE_ACTIVATOR,
+                                        org.apache.aries.jmx.test.bundlea.Activator.class.getName())
+                                .build(withBnd())),
+                        provision(newBundle()
+                                .add(org.apache.aries.jmx.test.bundleb.Activator.class)
+                                .add(org.apache.aries.jmx.test.bundleb.api.InterfaceB.class)
+                                .add(org.apache.aries.jmx.test.bundleb.api.MSF.class)
+                                .add(org.apache.aries.jmx.test.bundleb.impl.B.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME,"org.apache.aries.jmx.test.bundleb")
+                                .set(Constants.BUNDLE_VERSION, "1.0.0")
+                                .set(Constants.EXPORT_PACKAGE,"org.apache.aries.jmx.test.bundleb.api;version=1.1.0")
+                                .set(Constants.IMPORT_PACKAGE,"org.osgi.framework;version=1.5.0,org.osgi.util.tracker," +
+                                		"org.osgi.service.cm,org.apache.aries.jmx.test.fragmentc")
+                                .set(Constants.BUNDLE_ACTIVATOR,
+                                        org.apache.aries.jmx.test.bundleb.Activator.class.getName())
+                                .build(withBnd())),
+                        provision(newBundle()
+                                .add(org.apache.aries.jmx.test.fragmentc.C.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.fragc")
+                                .set(Constants.FRAGMENT_HOST, "org.apache.aries.jmx.test.bundlea")
+                                .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.fragmentc")
+                                .build(withBnd())),
+                        provision(newBundle()
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundled")
+                                .set(Constants.BUNDLE_VERSION, "3.0.0")
+                                .set(Constants.REQUIRE_BUNDLE, "org.apache.aries.jmx.test.bundlea;bundle-version=2.0.0")
+                                .build(withBnd()))
+                        );
+        options = updateOptions(options);
+        return options;
+    }
+    
+    @Before
+    public void doSetUp() throws Exception {
+        super.setUp();
+        int i=0;
+        while (true) {
+            try {
+                mbeanServer.getObjectInstance(new ObjectName(BundleStateMBean.OBJECTNAME));
+                break;
+            } catch (InstanceNotFoundException e) {
+                if (i == 5) {
+                    throw new Exception("BundleStateMBean not available after waiting 5 seconds");
+                }
+            }
+            i++;
+            Thread.sleep(1000);
+        }
+    }
+
+    @Test
+    public void testMBeanInterface() throws Exception {
+        
+        BundleStateMBean mbean = getMBean(OBJECTNAME, BundleStateMBean.class);
+        assertNotNull(mbean);
+        
+        //get bundles
+        
+        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
+        assertNotNull(a);
+        
+        Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
+        assertNotNull(b);
+        
+        Bundle frag = getBundle("org.apache.aries.jmx.test.fragc");
+        assertNotNull(frag);
+
+        Bundle d = getBundle("org.apache.aries.jmx.test.bundled");
+        assertNotNull(d);
+        
+        // exportedPackages
+        
+        String[] exports = mbean.getExportedPackages(a.getBundleId());
+        assertEquals(2, exports.length);
+        
+        List<String> packages = Arrays.asList(exports);
+        assertTrue(packages.contains("org.apache.aries.jmx.test.bundlea.api;2.0.0"));
+        assertTrue(packages.contains("org.apache.aries.jmx.test.fragmentc;0.0.0"));
+        
+        //fragments
+        
+        long[] fragments = mbean.getFragments(a.getBundleId());
+        assertEquals(1, fragments.length);
+        assertEquals(frag.getBundleId() , fragments[0]);
+       
+        //headers
+
+        TabularData headers = mbean.getHeaders(b.getBundleId());
+        assertNotNull(headers);
+        assertEquals(BundleStateMBean.HEADERS_TYPE, headers.getTabularType());
+        assertTrue(headers.values().size() >= 4 );
+        assertEquals("org.apache.aries.jmx.test.bundleb", Header.from(headers.get(new Object[] {Constants.BUNDLE_SYMBOLICNAME})).getValue());
+        
+        //hosts 
+        
+        long[] hosts = mbean.getHosts(frag.getBundleId());
+        assertEquals(1, hosts.length);
+        assertEquals(a.getBundleId() , hosts[0]);
+        
+        //imported packages
+           
+        String[] imports = mbean.getImportedPackages(a.getBundleId());
+        assertTrue(imports.length >= 3);
+        List<String> importedPackages = Arrays.asList(imports);
+        assertTrue(importedPackages.contains("org.osgi.framework;1.5.0"));
+        assertTrue(importedPackages.contains("org.apache.aries.jmx.test.bundleb.api;1.1.0"));
+        
+        //last modified
+        
+        assertTrue(mbean.getLastModified(b.getBundleId()) > 0);
+        
+        //location
+        
+        assertEquals(b.getLocation(), mbean.getLocation(b.getBundleId()));
+        
+        //registered services
+        
+        long[] serviceIds = mbean.getRegisteredServices(a.getBundleId());
+        assertEquals(1, serviceIds.length);
+        
+        //required bundles
+        
+        long[] required = mbean.getRequiredBundles(d.getBundleId());
+        assertEquals(1, required.length);
+        assertEquals(a.getBundleId(), required[0]);
+        
+        //requiring bundles
+        
+        long[] requiring = mbean.getRequiringBundles(a.getBundleId());
+        assertEquals(1, requiring.length);
+        assertEquals(d.getBundleId(), requiring[0]);
+        
+        //services in use
+        
+        long[] servicesInUse = mbean.getServicesInUse(a.getBundleId());
+        assertEquals(1, servicesInUse.length);
+        
+        //start level
+        
+        long startLevel = mbean.getStartLevel(b.getBundleId());
+        assertTrue(startLevel >= 0);
+        
+        //state 
+        
+        assertEquals("ACTIVE", mbean.getState(b.getBundleId()));
+        
+        //isFragment
+        
+        assertFalse(mbean.isFragment(b.getBundleId()));
+        assertTrue(mbean.isFragment(frag.getBundleId()));
+        
+        //isRemovalPending
+        assertFalse(mbean.isRemovalPending(b.getBundleId()));
+        
+        // isRequired
+       
+        assertTrue(mbean.isRequired(a.getBundleId()));
+        assertFalse(mbean.isRequired(b.getBundleId()));
+        
+        // listBundles
+        
+        TabularData bundlesTable = mbean.listBundles();
+        assertNotNull(bundlesTable);
+        assertEquals(BundleStateMBean.BUNDLES_TYPE, bundlesTable.getTabularType());
+        assertEquals(bundleContext.getBundles().length, bundlesTable.values().size());
+        
+        
+        // notifications
+        
+        final List<Notification> received = new ArrayList<Notification>();
+      
+        mbeanServer.addNotificationListener(new ObjectName(BundleStateMBean.OBJECTNAME), new NotificationListener() {
+            public void handleNotification(Notification notification, Object handback) {
+               received.add(notification);
+            }
+        }, null, null);
+        
+        assertEquals(Bundle.ACTIVE, b.getState());
+        b.stop();
+        assertEquals(Bundle.RESOLVED, b.getState());
+        b.start();
+        assertEquals(Bundle.ACTIVE, b.getState());
+        
+        int i = 0;
+        while (received.size() < 2 && i < 3) {
+            Thread.sleep(1000);
+            i++;
+        }
+        
+        assertEquals(2, received.size());
+        
+    }
+    
+
+}

Added: aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/FrameworkMBeanTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,99 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import javax.management.openmbean.CompositeData;
+
+import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.apache.aries.jmx.codec.BatchActionResult;
+import org.junit.Test;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.jmx.framework.FrameworkMBean;
+
+/**
+ * 
+ * 
+ * @version $Rev: 929327 $ $Date: 2010-03-30 23:51:43 +0100 (Tue, 30 Mar 2010) $
+ */
+public class FrameworkMBeanTest extends AbstractIntegrationTest {    
+
+    @Configuration
+    public static Option[] configuration() {
+        
+        Option[] options = CoreOptions.options(
+            CoreOptions.equinox(),
+            mavenBundle("org.ops4j.pax.logging", "pax-logging-api"), 
+            mavenBundle("org.ops4j.pax.logging", "pax-logging-service"), 
+            mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx")
+        );
+        
+        options = updateOptions(options);
+        return options;
+    }
+
+    @Test
+    public void testMBeanInterface() throws IOException {
+        FrameworkMBean framework = getMBean(FrameworkMBean.OBJECTNAME, FrameworkMBean.class);
+        assertNotNull(framework);
+        
+        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");
+        }
+    }
+
+}
\ No newline at end of file

Added: aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/PackageStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/PackageStateMBeanTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/PackageStateMBeanTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/PackageStateMBeanTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,101 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Collection;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.jmx.framework.PackageStateMBean;
+
+/**
+ * 
+ * 
+ * @version $Rev: 919658 $ $Date: 2010-03-05 22:41:40 +0000 (Fri, 05 Mar 2010) $
+ */
+public class PackageStateMBeanTest extends AbstractIntegrationTest {
+
+    @Configuration
+    public static Option[] configuration() {
+        Option[] options = CoreOptions.options(CoreOptions.equinox(), mavenBundle("org.ops4j.pax.logging",
+                "pax-logging-api"), mavenBundle("org.ops4j.pax.logging", "pax-logging-service"), mavenBundle(
+                "org.apache.aries.jmx", "org.apache.aries.jmx"));
+        options = updateOptions(options);
+        return options;
+    }
+
+    @Before
+    public void doSetUp() throws Exception {
+        super.setUp();
+        int i = 0;
+        while (true) {
+            try {
+                mbeanServer.getObjectInstance(new ObjectName(PackageStateMBean.OBJECTNAME));
+                break;
+            } catch (InstanceNotFoundException e) {
+                if (i == 5) {
+                    throw new Exception("PackageStateMBean not available after waiting 5 seconds");
+                }
+            }
+            i++;
+            Thread.sleep(1000);
+        }
+    }
+
+    @Test
+    public void testMBeanInterface() throws IOException {
+        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);
+    }
+
+}

Added: aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/framework/ServiceStateMBeanTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,232 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.framework;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.modifyBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.apache.aries.jmx.codec.PropertyData;
+import org.apache.aries.jmx.test.bundlea.api.InterfaceA;
+import org.apache.aries.jmx.test.bundleb.api.InterfaceB;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Customizer;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.JmxConstants;
+import org.osgi.jmx.framework.ServiceStateMBean;
+import org.osgi.service.cm.ManagedService;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+/**
+ * 
+ *
+ * @version $Rev: 898958 $ $Date: 2010-01-13 22:00:58 +0000 (Wed, 13 Jan 2010) $
+ */
+public class ServiceStateMBeanTest extends AbstractIntegrationTest {
+
+    @Configuration
+    public static Option[] configuration() {
+        Option[] options = CoreOptions
+                .options(
+                        CoreOptions.equinox(),
+                        mavenBundle("org.apache.felix", "org.apache.felix.configadmin"),
+                        mavenBundle("org.ops4j.pax.logging", "pax-logging-api"),
+                        mavenBundle("org.ops4j.pax.logging", "pax-logging-service"),
+                        mavenBundle("org.osgi", "org.osgi.compendium"),
+                        mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
+                        new Customizer() {
+                            public InputStream customizeTestProbe(InputStream testProbe) throws Exception {
+                                return modifyBundle(testProbe)
+                                           .removeHeader(Constants.DYNAMICIMPORT_PACKAGE)
+                                           .set(Constants.REQUIRE_BUNDLE, "org.apache.aries.jmx.test.bundlea,org.apache.aries.jmx.test.bundleb")
+                                           .build(withBnd());
+                            }
+                        },
+                        provision(newBundle()
+                                .add(org.apache.aries.jmx.test.bundlea.Activator.class)
+                                .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
+                                .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
+                                .set(Constants.BUNDLE_VERSION, "2.0.0")
+                                .set(Constants.EXPORT_PACKAGE, "org.apache.aries.jmx.test.bundlea.api;version=2.0.0")
+                                .set(Constants.IMPORT_PACKAGE,
+                                        "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional" +
+                                        ",org.osgi.service.cm")
+                                .set(Constants.BUNDLE_ACTIVATOR,
+                                        org.apache.aries.jmx.test.bundlea.Activator.class.getName())
+                                .build(withBnd())),
+                        provision(newBundle()
+                                .add(org.apache.aries.jmx.test.bundleb.Activator.class)
+                                .add(org.apache.aries.jmx.test.bundleb.api.InterfaceB.class)
+                                .add(org.apache.aries.jmx.test.bundleb.api.MSF.class)
+                                .add(org.apache.aries.jmx.test.bundleb.impl.B.class)
+                                .set(Constants.BUNDLE_SYMBOLICNAME,"org.apache.aries.jmx.test.bundleb")
+                                .set(Constants.BUNDLE_VERSION, "1.0.0")
+                                .set(Constants.EXPORT_PACKAGE,"org.apache.aries.jmx.test.bundleb.api;version=1.1.0")
+                                .set(Constants.IMPORT_PACKAGE,"org.osgi.framework;version=1.5.0,org.osgi.util.tracker" +
+                                		",org.osgi.service.cm")
+                                .set(Constants.BUNDLE_ACTIVATOR,
+                                        org.apache.aries.jmx.test.bundleb.Activator.class.getName())
+                                .build(withBnd()))
+                        );
+        options = updateOptions(options);
+        return options;
+    }
+    
+    @Before
+    public void doSetUp() throws Exception {
+        super.setUp();
+        int i=0;
+        while (true) {
+            try {
+                mbeanServer.getObjectInstance(new ObjectName(ServiceStateMBean.OBJECTNAME));
+                break;
+            } catch (InstanceNotFoundException e) {
+                if (i == 5) {
+                    throw new Exception("ServiceStateMBean not available after waiting 5 seconds");
+                }
+            }
+            i++;
+            Thread.sleep(1000);
+        }
+    }
+    
+    
+    @Test
+    public void testMBeanInterface() throws Exception {
+        
+        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
+        assertNotNull(mbean);
+        
+        //get bundles
+        
+        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
+        assertNotNull(a);
+        
+        Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
+        assertNotNull(b);
+        
+        // get services
+        
+        ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
+        assertNotNull(refA);
+        long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
+        assertTrue(serviceAId > -1);
+        
+        ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
+        assertNotNull(refB);
+        long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
+        assertTrue(serviceBId > -1);
+        
+        ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+        assertNotNull(refs);
+        assertEquals(1, refs.length);
+        ServiceReference msf = refs[0];
+
+        
+        // getBundleIdentifier
+        
+        assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
+        
+        //getObjectClass
+        
+        String[] objectClass = mbean.getObjectClass(serviceAId);
+        assertEquals(2, objectClass.length);
+        List<String> classNames = Arrays.asList(objectClass);
+        assertTrue(classNames.contains(InterfaceA.class.getName()));
+        assertTrue(classNames.contains(ManagedService.class.getName()));
+        
+        // getProperties
+        
+        TabularData serviceProperties = mbean.getProperties(serviceBId);
+        assertNotNull(serviceProperties);
+        assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
+        assertTrue(serviceProperties.values().size() > 1);
+        assertEquals("org.apache.aries.jmx.test.ServiceB", 
+                PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
+        
+        // getUsingBundles
+        
+        long[] usingBundles = mbean.getUsingBundles(serviceBId);
+        assertEquals(1, usingBundles.length);
+        assertEquals(a.getBundleId(), usingBundles[0]);
+        
+        // listServices
+        
+        TabularData allServices = mbean.listServices();
+        assertNotNull(allServices);
+        assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
+        
+        // notifications
+        
+        final List<Notification> received = new ArrayList<Notification>();
+      
+        mbeanServer.addNotificationListener(new ObjectName(ServiceStateMBean.OBJECTNAME), new NotificationListener() {
+            public void handleNotification(Notification notification, Object handback) {
+               received.add(notification);
+            }
+        }, null, null);
+        
+      
+        assertNotNull(refB);
+        assertNotNull(msf);
+        b.stop();
+        refB = bundleContext.getServiceReference(InterfaceB.class.getName()); 
+        refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+        assertNull(refs);
+        assertNull(refB);
+        b.start();
+        refB = bundleContext.getServiceReference(InterfaceB.class.getName());
+        refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
+        assertNotNull(refB);
+        assertNotNull(refs);
+        assertEquals(1, refs.length);
+        
+        int i = 0;
+        while (received.size() < 4 && i < 3) {
+            Thread.sleep(1000);
+            i++;
+        }
+        
+        assertEquals(4, received.size());
+            
+    }
+
+}

Added: aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java
URL: http://svn.apache.org/viewvc/aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java?rev=1075096&view=auto
==============================================================================
--- aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java (added)
+++ aries/tags/jmx-0.1-incubating/jmx-itests/src/test/java/org/apache/aries/jmx/permissionadmin/PermissionAdminMBeanTest.java Sun Feb 27 17:58:16 2011
@@ -0,0 +1,152 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.aries.jmx.permissionadmin;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.ops4j.pax.exam.CoreOptions.provision;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+
+import java.io.IOException;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+
+import org.apache.aries.jmx.AbstractIntegrationTest;
+import org.junit.Before;
+import org.junit.Test;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.jmx.service.permissionadmin.PermissionAdminMBean;
+import org.osgi.service.permissionadmin.PermissionAdmin;
+import org.osgi.service.permissionadmin.PermissionInfo;
+
+/**
+ * 
+ *
+ * @version $Rev: 929346 $ $Date: 2010-03-31 01:23:36 +0100 (Wed, 31 Mar 2010) $
+ */
+public class PermissionAdminMBeanTest extends AbstractIntegrationTest {
+    
+    @Configuration
+    public static Option[] configuration() {
+        Option[] options = CoreOptions.options(
+            CoreOptions.equinox(),
+            mavenBundle("org.ops4j.pax.logging", "pax-logging-api"), 
+            mavenBundle("org.ops4j.pax.logging", "pax-logging-service"), 
+            mavenBundle("org.apache.aries.jmx", "org.apache.aries.jmx"),
+            provision(newBundle()
+                    .add(org.apache.aries.jmx.test.bundlea.Activator.class)
+                    .add(org.apache.aries.jmx.test.bundlea.api.InterfaceA.class)
+                    .add(org.apache.aries.jmx.test.bundlea.impl.A.class)
+                    .set(Constants.BUNDLE_SYMBOLICNAME, "org.apache.aries.jmx.test.bundlea")
+                    .set(Constants.BUNDLE_VERSION, "2.0.0")
+                    .set(Constants.IMPORT_PACKAGE,
+                            "org.osgi.framework;version=1.5.0,org.osgi.util.tracker,org.apache.aries.jmx.test.bundleb.api;version=1.1.0;resolution:=optional")
+                    .set(Constants.BUNDLE_ACTIVATOR,
+                            org.apache.aries.jmx.test.bundlea.Activator.class.getName())
+                    .build(withBnd()))
+        );
+        options = updateOptions(options);
+        return options;
+    }
+    
+    @Before
+    public void doSetUp() throws Exception {
+        super.setUp();
+        int i = 0;
+        while (true) {
+            try {
+                mbeanServer.getObjectInstance(new ObjectName(PermissionAdminMBean.OBJECTNAME));
+                break;
+            } catch (InstanceNotFoundException e) {
+                if (i == 5) {
+                    throw new Exception("PermissionAdminMBean not available after waiting 5 seconds");
+                }
+            }
+            i++;
+            Thread.sleep(1000);
+        }
+    }
+
+    @Test
+    public void testMBeanInterface() throws IOException {
+        PermissionAdminMBean mBean = getMBean(PermissionAdminMBean.OBJECTNAME, PermissionAdminMBean.class);
+        PermissionAdmin permAdminService = getService(PermissionAdmin.class);
+        assertNotNull(permAdminService);
+
+        String[] serviceLocation = permAdminService.getLocations();
+        String[] mBeanLocations = mBean.listLocations();
+        assertArrayEquals(serviceLocation, mBeanLocations);
+
+        PermissionInfo defPerm = new PermissionInfo("AllPermission", "*", "*");
+        permAdminService.setDefaultPermissions(new PermissionInfo[]{defPerm});
+        PermissionInfo[] permissions = permAdminService.getDefaultPermissions();
+        assertNotNull(permissions);
+
+        String[] encoded = toEncodedPerm(permissions);
+        String[] mBeanDefPermissions = mBean.listDefaultPermissions();
+        assertArrayEquals(encoded, mBeanDefPermissions);
+        
+        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
+        assertNotNull(a);
+        
+        String location = a.getLocation();
+        
+        PermissionInfo bundleaPerm = new PermissionInfo("ServicePermission", "ServiceA", "GET");
+        mBean.setPermissions(location, new String[]{bundleaPerm.getEncoded()});
+        
+        String[] serviceBundleaPerm = toEncodedPerm(permAdminService.getPermissions(location));
+        String[] mBeanBundleaPerm = mBean.getPermissions(location);
+        assertNotNull(mBeanBundleaPerm);
+        assertArrayEquals(serviceBundleaPerm, mBeanBundleaPerm);
+        
+        PermissionInfo defaultPerm = new PermissionInfo("AllPermission", "*", "GET");
+        mBean.setDefaultPermissions(new String[]{defaultPerm.getEncoded()});
+        
+        String[] serviceDefaultPerm = toEncodedPerm(permAdminService.getDefaultPermissions());
+        String[] mBeanDefaultPerm = mBean.listDefaultPermissions();
+        assertNotNull(mBeanDefaultPerm);
+        assertArrayEquals(serviceDefaultPerm, mBeanDefaultPerm);
+    }
+    
+    private String[] toEncodedPerm(PermissionInfo[] permissions){
+        assertNotNull(permissions);
+        String[] encoded = new String[permissions.length];
+        for (int i = 0; i < permissions.length; i++) {
+            PermissionInfo info = permissions[i];
+            encoded[i] = info.getEncoded();
+        }       
+        return encoded;
+    }
+    
+    private <S> S getService(Class<S> serviceInterface){
+        ServiceReference ref =  bundleContext.getServiceReference(serviceInterface.getName());
+        if(ref != null){
+            Object service = bundleContext.getService(ref);
+            if(service != null){
+                return (S)service;
+            }
+        }     
+        return null;
+    }
+}
\ No newline at end of file