karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf git commit: KARAF-1897 - Use dynamic allocated network ports in itest and fix couple of itests
Date Tue, 26 Jan 2016 17:13:29 GMT
Repository: karaf
Updated Branches:
  refs/heads/karaf-4.0.x 627d8c402 -> 06aa72451


KARAF-1897 - Use dynamic allocated network ports in itest and fix couple of itests


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/06aa7245
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/06aa7245
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/06aa7245

Branch: refs/heads/karaf-4.0.x
Commit: 06aa72451308c46a39749ff5c32ad753ed4cc99d
Parents: 627d8c4
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Tue Jan 26 17:48:42 2016 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Tue Jan 26 17:49:35 2016 +0100

----------------------------------------------------------------------
 .../org/apache/karaf/itests/BundleTests.java    | 15 ++--
 .../karaf/itests/ConditionalFeaturesTest.java   | 29 --------
 .../itests/ConfigSshCommandSecurityTest.java    |  2 +
 .../org/apache/karaf/itests/ConfigTest.java     | 24 +++---
 .../org/apache/karaf/itests/DiagnosticTest.java | 17 ++---
 .../org/apache/karaf/itests/FeatureTest.java    | 77 ++++++--------------
 .../java/org/apache/karaf/itests/HttpTest.java  | 20 ++---
 .../org/apache/karaf/itests/InstanceTest.java   | 63 ++++++----------
 .../apache/karaf/itests/JMXSecurityTest.java    |  9 ++-
 .../java/org/apache/karaf/itests/JmsTest.java   | 58 +++++++--------
 .../java/org/apache/karaf/itests/JndiTest.java  | 38 ----------
 .../java/org/apache/karaf/itests/KarTest.java   | 20 ++---
 .../apache/karaf/itests/KarafTestSupport.java   | 60 +++++++++++++--
 .../java/org/apache/karaf/itests/LogTest.java   | 23 +++---
 .../java/org/apache/karaf/itests/ObrTest.java   | 24 +++---
 .../org/apache/karaf/itests/PackageTest.java    | 33 +++------
 .../org/apache/karaf/itests/ServiceTest.java    | 19 ++---
 .../apache/karaf/itests/SshCommandTestBase.java |  4 +-
 .../apache/karaf/itests/SshKeyFormatTest.java   |  4 +-
 .../apache/karaf/itests/SystemShutdownTest.java | 17 ++---
 .../org/apache/karaf/itests/SystemTest.java     | 62 +++++-----------
 .../java/org/apache/karaf/itests/WebTest.java   | 19 ++---
 .../org/apache/karaf/itests/WrapperTest.java    | 17 ++---
 23 files changed, 247 insertions(+), 407 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/BundleTests.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/BundleTests.java b/itests/src/test/java/org/apache/karaf/itests/BundleTests.java
index a4a1171..7d740ed 100644
--- a/itests/src/test/java/org/apache/karaf/itests/BundleTests.java
+++ b/itests/src/test/java/org/apache/karaf/itests/BundleTests.java
@@ -16,10 +16,9 @@ package org.apache.karaf.itests;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularDataSupport;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -27,6 +26,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class BundleTests extends KarafTestSupport {
@@ -40,16 +41,10 @@ public class BundleTests extends KarafTestSupport {
 
     @Test
     public void listViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
             ObjectName name = new ObjectName("org.apache.karaf:type=bundle,name=root");
-            TabularDataSupport value = (TabularDataSupport) connection.getAttribute(name, "Bundles");
+            TabularDataSupport value = (TabularDataSupport) mbeanServer.getAttribute(name, "Bundles");
             assertTrue(value.size() > 0);
-        } finally {
-        	close(connector);
-        }
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java b/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
index 18ef2d0..2cd3973 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ConditionalFeaturesTest.java
@@ -16,7 +16,6 @@
  */
 package org.apache.karaf.itests;
 
-
 import java.util.EnumSet;
 
 import org.apache.karaf.features.FeaturesService;
@@ -29,34 +28,6 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class ConditionalFeaturesTest extends KarafTestSupport {
-    /*
-    @Inject
-    private FeaturesService featuresService;
-
-    @Inject
-    private BundleContext bundleContext;
-    
-    @Inject
-    BootFinished bootFinished;
-
-
-    @ProbeBuilder
-    public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
-        probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE, "*,org.apache.felix.service.*;status=provisional");
-        return probe;
-    }
-
-
-    @Configuration
-    public Option[] config() {
-        
-        MavenArtifactUrlReference karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("zip").versionAsInProject();
-        return new Option[]{
-            karafDistributionConfiguration().frameworkUrl(karafUrl),
-            KarafDistributionOption.editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", KarafTestSupport.HTTP_PORT)
-        };
-    }
-    */
 
     @Test
     public void testScr() throws Exception {

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/ConfigSshCommandSecurityTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ConfigSshCommandSecurityTest.java b/itests/src/test/java/org/apache/karaf/itests/ConfigSshCommandSecurityTest.java
index fb9ec96..06d2729 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ConfigSshCommandSecurityTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ConfigSshCommandSecurityTest.java
@@ -29,7 +29,9 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class ConfigSshCommandSecurityTest extends SshCommandTestBase {
+
     private static int counter = 0;
+
     @Test
     public void testConfigCommandSecurityViaSsh() throws Exception {
         String manageruser = "man" + System.nanoTime() + "_" + counter++;

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/ConfigTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ConfigTest.java b/itests/src/test/java/org/apache/karaf/itests/ConfigTest.java
index c0639d4..188774c 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ConfigTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ConfigTest.java
@@ -16,12 +16,12 @@ package org.apache.karaf.itests;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.lang.management.ManagementFactory;
 import java.util.List;
 import java.util.Map;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -46,19 +46,13 @@ public class ConfigTest extends KarafTestSupport {
     @SuppressWarnings("unchecked")
     @Test
     public void configsViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=config,name=root");
-            List<String> configs = (List<String>) connection.getAttribute(name, "Configs");
-            assertTrue(configs.size() > 0);
-            assertTrue(configs.contains("org.apache.karaf.features"));
-            Map<String, String> properties = (Map<String, String>) connection.invoke(name, "listProperties", new Object[]{ "org.apache.karaf.features" }, new String[]{ "java.lang.String" });
-            assertTrue(properties.keySet().size() > 0);
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=config,name=root");
+        List<String> configs = (List<String>) mbeanServer.getAttribute(name, "Configs");
+        assertTrue(configs.size() > 0);
+        assertTrue(configs.contains("org.apache.karaf.features"));
+        Map<String, String> properties = (Map<String, String>) mbeanServer.invoke(name, "listProperties", new Object[]{"org.apache.karaf.features"}, new String[]{"java.lang.String"});
+        assertTrue(properties.keySet().size() > 0);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/DiagnosticTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/DiagnosticTest.java b/itests/src/test/java/org/apache/karaf/itests/DiagnosticTest.java
index cb844bd..e0a502f 100644
--- a/itests/src/test/java/org/apache/karaf/itests/DiagnosticTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/DiagnosticTest.java
@@ -13,9 +13,8 @@
  */
 package org.apache.karaf.itests;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -23,6 +22,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class DiagnosticTest extends KarafTestSupport {
@@ -49,15 +50,9 @@ public class DiagnosticTest extends KarafTestSupport {
     
     @Test
     public void createDumpViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=diagnostic,name=root");
-            connection.invoke(name, "createDump", new Object[]{ "itest" }, new String[]{ "java.lang.String" });
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=diagnostic,name=root");
+        mbeanServer.invoke(name, "createDump", new Object[]{ "itest" }, new String[]{ "java.lang.String" });
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
index e87b111..b6b3e99 100644
--- a/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/FeatureTest.java
@@ -16,10 +16,9 @@ package org.apache.karaf.itests;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
 
 import org.apache.karaf.jaas.boot.principal.RolePrincipal;
 import org.junit.Test;
@@ -28,6 +27,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class FeatureTest extends KarafTestSupport {
@@ -50,16 +51,10 @@ public class FeatureTest extends KarafTestSupport {
 
     @Test
     public void listViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
-            TabularData features = (TabularData) connection.getAttribute(name, "Features");
-            assertTrue(features.size() > 0);
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
+        TabularData features = (TabularData) mbeanServer.getAttribute(name, "Features");
+        assertTrue(features.size() > 0);
     }
 
     @Test
@@ -72,18 +67,12 @@ public class FeatureTest extends KarafTestSupport {
 
     @Test
     public void installUninstallViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
-            connection.invoke(name, "installFeature", new Object[] { "wrapper", true }, new String[]{ "java.lang.String", "boolean" });
-            assertFeatureInstalled("wrapper");
-            connection.invoke(name, "uninstallFeature", new Object[] { "wrapper", true }, new String[]{ "java.lang.String", "boolean" });
-            assertFeatureNotInstalled("wrapper");
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
+        mbeanServer.invoke(name, "installFeature", new Object[]{"wrapper", true}, new String[]{"java.lang.String", "boolean"});
+        assertFeatureInstalled("wrapper");
+        mbeanServer.invoke(name, "uninstallFeature", new Object[]{"wrapper", true}, new String[]{"java.lang.String", "boolean"});
+        assertFeatureNotInstalled("wrapper");
     }
 
     @Test
@@ -104,30 +93,18 @@ public class FeatureTest extends KarafTestSupport {
 
     @Test
     public void repoAddRemoveViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
-            connection.invoke(name, "addRepository", new Object[] { "mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features" }, new String[]{ "java.lang.String" });
-            connection.invoke(name, "removeRepository", new Object[] { "mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features" }, new String[]{ "java.lang.String" });
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
+        mbeanServer.invoke(name, "addRepository", new Object[] { "mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features" }, new String[]{ "java.lang.String" });
+        mbeanServer.invoke(name, "removeRepository", new Object[] { "mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features" }, new String[]{ "java.lang.String" });
     }
 
     @Test
     public void repoAddRemoveWithRegexViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
-            connection.invoke(name, "addRepository", new Object[] { "mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features" }, new String[]{ "java.lang.String" });
-            connection.invoke(name, "removeRepository", new Object[] { ".*apache-karaf-cellar.*" }, new String[]{ "java.lang.String" });
-        } finally {
-            close(connector);
-        }
+        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
+        mBeanServer.invoke(name, "addRepository", new Object[] { "mvn:org.apache.karaf.cellar/apache-karaf-cellar/3.0.0/xml/features" }, new String[]{ "java.lang.String" });
+        mBeanServer.invoke(name, "removeRepository", new Object[] { ".*apache-karaf-cellar.*" }, new String[]{ "java.lang.String" });
     }
 
     @Test
@@ -139,15 +116,9 @@ public class FeatureTest extends KarafTestSupport {
 
     @Test
     public void repoRefreshViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
-            connection.invoke(name, "refreshRepository", new Object[] { ".*pax-web.*" }, new String[]{ "java.lang.String" });
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=feature,name=root");
+        mbeanServer.invoke(name, "refreshRepository", new Object[] { ".*pax-web.*" }, new String[]{ "java.lang.String" });
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/HttpTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/HttpTest.java b/itests/src/test/java/org/apache/karaf/itests/HttpTest.java
index 66ea463..4496148 100644
--- a/itests/src/test/java/org/apache/karaf/itests/HttpTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/HttpTest.java
@@ -15,10 +15,9 @@ package org.apache.karaf.itests;
 
 import static org.junit.Assert.assertTrue;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -26,7 +25,8 @@ import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
-import org.osgi.framework.Constants;
+
+import java.lang.management.ManagementFactory;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
@@ -45,16 +45,10 @@ public class HttpTest extends KarafTestSupport {
 
     @Test
     public void listViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=http,name=root");
-            TabularData servlets = (TabularData) connection.getAttribute(name, "Servlets");
-            assertTrue(servlets.size() > 0);
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=http,name=root");
+        TabularData servlets = (TabularData) mbeanServer.getAttribute(name, "Servlets");
+        assertTrue(servlets.size() > 0);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/InstanceTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/InstanceTest.java b/itests/src/test/java/org/apache/karaf/itests/InstanceTest.java
index b76d589..911760d 100644
--- a/itests/src/test/java/org/apache/karaf/itests/InstanceTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/InstanceTest.java
@@ -15,10 +15,10 @@ package org.apache.karaf.itests;
 
 import static org.junit.Assert.assertTrue;
 
+import javax.management.MBeanServer;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -27,6 +27,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class InstanceTest extends KarafTestSupport {
@@ -41,21 +43,14 @@ public class InstanceTest extends KarafTestSupport {
 
     @Test
     public void createDestroyViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
-            int oldNum = getInstancesNum(connection, name);  
-            connection.invoke(name, "createInstance", new Object[]{ "itest2", 0, 0, 0, null, null, null, null },
-                    new String[]{ "java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String" });
-            Assert.assertEquals(oldNum + 1, getInstancesNum(connection, name));
-            connection.invoke(name, "destroyInstance", new Object[]{ "itest2" }, new String[]{ "java.lang.String" });
-            Assert.assertEquals(oldNum, getInstancesNum(connection, name));
-        } finally {
-            if (connector != null)
-        	    close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
+        int oldNum = getInstancesNum(mbeanServer, name);
+        mbeanServer.invoke(name, "createInstance", new Object[]{"itest2", 0, 0, 0, null, null, null, null},
+                new String[]{"java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
+        Assert.assertEquals(oldNum + 1, getInstancesNum(mbeanServer, name));
+        mbeanServer.invoke(name, "destroyInstance", new Object[]{"itest2"}, new String[]{"java.lang.String"});
+        Assert.assertEquals(oldNum, getInstancesNum(mbeanServer, name));
     }
 
     @Test
@@ -109,19 +104,12 @@ public class InstanceTest extends KarafTestSupport {
 
     @Test
     public void cloneViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
-            int oldNum = getInstancesNum(connection, name);
-            connection.invoke(name, "cloneInstance", new Object[]{ "root", "itest4", 0, 0, 0, null, null },
-                    new String[]{ "java.lang.String", "java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String" });
-            Assert.assertEquals(oldNum + 1, getInstancesNum(connection, name));
-        } finally {
-            if (connector != null)
-                connector.close();
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
+        int oldNum = getInstancesNum(mbeanServer, name);
+        mbeanServer.invoke(name, "cloneInstance", new Object[]{"root", "itest4", 0, 0, 0, null, null},
+                new String[]{"java.lang.String", "java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String"});
+        Assert.assertEquals(oldNum + 1, getInstancesNum(mbeanServer, name));
     }
 
     @Test
@@ -135,18 +123,11 @@ public class InstanceTest extends KarafTestSupport {
 
     @Test
     public void renameViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
-            connection.invoke(name, "createInstance", new Object[]{ "itest5", 0, 0, 0, null, null, null, null },
-                    new String[]{ "java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String" });
-            connection.invoke(name, "renameInstance", new Object[]{ "itest5", "new_itest5" }, new String[]{ "java.lang.String", "java.lang.String" });
-        } finally {
-            if (connector != null)
-                connector.close();
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=instance,name=root");
+        mbeanServer.invoke(name, "createInstance", new Object[]{"itest5", 0, 0, 0, null, null, null, null},
+                new String[]{"java.lang.String", "int", "int", "int", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
+        mbeanServer.invoke(name, "renameInstance", new Object[]{"itest5", "new_itest5"}, new String[]{"java.lang.String", "java.lang.String"});
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/JMXSecurityTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/JMXSecurityTest.java b/itests/src/test/java/org/apache/karaf/itests/JMXSecurityTest.java
index 9825592..0e3b9ce 100644
--- a/itests/src/test/java/org/apache/karaf/itests/JMXSecurityTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/JMXSecurityTest.java
@@ -54,13 +54,14 @@ import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.options.extra.VMOption;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.service.cm.ConfigurationAdmin;
 
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class JMXSecurityTest extends KarafTestSupport {
+
     private static AtomicInteger counter = new AtomicInteger(0);
 
     @Configuration
@@ -94,6 +95,12 @@ public class JMXSecurityTest extends KarafTestSupport {
             ";jaas:realm-manage --realm karaf" +
             ";jaas:user-list", new RolePrincipal("admin")));
 
+        ConfigurationAdmin configurationAdmin = getOsgiService(ConfigurationAdmin.class, 30000);
+        org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration("org.apache.karaf.management", null);
+        if (configuration == null) {
+
+        }
+
         JMXConnector connector = getJMXConnector(viewerUser, viewerUser);
         MBeanServerConnection connection = connector.getMBeanServerConnection();
         ObjectName systemMBean = new ObjectName("org.apache.karaf:type=system,name=root");

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/JmsTest.java b/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
index 2a3aee0..90ecb18 100644
--- a/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/JmsTest.java
@@ -24,9 +24,9 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertEquals;
 
 import javax.jms.ConnectionFactory;
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
+import java.lang.management.ManagementFactory;
 import java.net.Socket;
 import java.net.URI;
 import java.util.List;
@@ -105,36 +105,30 @@ public class JmsTest extends KarafTestSupport {
 
     @Test(timeout = 120000)
     public void testMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=jms,name=root");
-            // create operation
-            System.out.println("JMS MBean create operation invocation");
-            connection.invoke(name, "create", new String[]{ "testMBean", "activemq", "tcp://localhost:61616", "karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String" });
-            // give time to fileinstall to load the blueprint file by looking for the connection factory OSGi service
-            getOsgiService(ConnectionFactory.class, "name=testMBean" , 30000);
-            List<String> connectionFactories = (List<String>) connection.getAttribute(name, "Connectionfactories");
-            assertEquals(true, connectionFactories.size() >= 1);
-            // send operation
-            System.out.println("JMS MBean send operation invocation");
-            connection.invoke(name, "send", new String[]{ "testMBean", "queueMBean", "message", null, "karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
-            // count operation
-            System.out.println("JMS MBean count operation invocation");
-            Integer count = (Integer) connection.invoke(name, "count", new String[]{ "testMBean", "queueMBean", "karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
-            assertEquals(1, count.intValue());
-            // queues operation
-            System.out.print("JMS MBean queues operation invocation: ");
-            List<String> queues = (List<String>) connection.invoke(name, "queues", new String[]{ "testMBean", "karaf", "karaf" }, new String[]{ "java.lang.String", "java.lang.String", "java.lang.String"});
-            System.out.println(queues);
-            assertTrue(queues.size() >= 1);
-            // delete operation
-            System.out.println("JMS MBean delete operation invocation");
-            connection.invoke(name, "delete", new String[]{"testMBean"}, new String[]{"java.lang.String"});
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=jms,name=root");
+        // create operation
+        System.out.println("JMS MBean create operation invocation");
+        mbeanServer.invoke(name, "create", new String[]{"testMBean", "activemq", "tcp://localhost:61616", "karaf", "karaf"}, new String[]{"java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
+        // give time to fileinstall to load the blueprint file by looking for the connection factory OSGi service
+        getOsgiService(ConnectionFactory.class, "name=testMBean", 30000);
+        List<String> connectionFactories = (List<String>) mbeanServer.getAttribute(name, "Connectionfactories");
+        assertEquals(true, connectionFactories.size() >= 1);
+        // send operation
+        System.out.println("JMS MBean send operation invocation");
+        mbeanServer.invoke(name, "send", new String[]{"testMBean", "queueMBean", "message", null, "karaf", "karaf"}, new String[]{"java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
+        // count operation
+        System.out.println("JMS MBean count operation invocation");
+        Integer count = (Integer) mbeanServer.invoke(name, "count", new String[]{"testMBean", "queueMBean", "karaf", "karaf"}, new String[]{"java.lang.String", "java.lang.String", "java.lang.String", "java.lang.String"});
+        assertEquals(1, count.intValue());
+        // queues operation
+        System.out.print("JMS MBean queues operation invocation: ");
+        List<String> queues = (List<String>) mbeanServer.invoke(name, "queues", new String[]{"testMBean", "karaf", "karaf"}, new String[]{"java.lang.String", "java.lang.String", "java.lang.String"});
+        System.out.println(queues);
+        assertTrue(queues.size() >= 1);
+        // delete operation
+        System.out.println("JMS MBean delete operation invocation");
+        mbeanServer.invoke(name, "delete", new String[]{"testMBean"}, new String[]{"java.lang.String"});
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/JndiTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/JndiTest.java b/itests/src/test/java/org/apache/karaf/itests/JndiTest.java
index 8912515..ff0fbb5 100644
--- a/itests/src/test/java/org/apache/karaf/itests/JndiTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/JndiTest.java
@@ -13,8 +13,6 @@
  */
 package org.apache.karaf.itests;
 
-import static org.junit.Assert.assertEquals;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -23,11 +21,6 @@ import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.apache.karaf.jndi.JndiService;
 
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
-import java.util.Map;
-
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class JndiTest extends KarafTestSupport {
@@ -58,35 +51,4 @@ public class JndiTest extends KarafTestSupport {
         assertContainsNot("/test/bar", output);
     }
 
-    @Test
-    public void testMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=jndi,name=root");
-            // names attribute
-            System.out.println("MBean get names attribute");
-            Map<String, String> names = (Map<String, String>) connection.getAttribute(name, "names");
-            assertEquals(1, names.keySet().size());
-            // invoke alias operation
-            System.out.println("MBean invoke alias operation");
-            connection.invoke(name, "alias", new Object[]{ "osgi:service/jndi", "/test/foo" }, new String[]{ "java.lang.String", "java.lang.String" });
-            names = (Map<String, String>) connection.getAttribute(name, "names");
-            assertEquals(2, names.keySet().size());
-            // invoke bind operation
-            System.out.println("MBean invoke bind operation");
-            connection.invoke(name, "bind", new Object[]{ new Long(40), "/test/bar" }, new String[]{ "java.lang.String", "java.lang.Long" });
-            names = (Map<String, String>) connection.getAttribute(name, "names");
-            assertEquals(3, names.keySet().size());
-            // invoke unbind operation
-            System.out.println("MBean invoke unbind operation");
-            connection.invoke(name, "unbind", new Object[]{ "/test/bar" }, new String[]{ "java.lang.String" });
-            names = (Map<String, String>) connection.getAttribute(name, "names");
-            assertEquals(2, names.keySet().size());
-        } catch (Exception e) {
-
-        }
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/KarTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/KarTest.java b/itests/src/test/java/org/apache/karaf/itests/KarTest.java
index 80f89d2..286eb3b 100644
--- a/itests/src/test/java/org/apache/karaf/itests/KarTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/KarTest.java
@@ -15,11 +15,11 @@ package org.apache.karaf.itests;
 
 import static org.junit.Assert.assertEquals;
 
+import java.lang.management.ManagementFactory;
 import java.util.List;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -38,17 +38,11 @@ public class KarTest extends KarafTestSupport {
 
     @Test
     public void listViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=kar,name=root");
-            @SuppressWarnings("unchecked")
-            List<String> kars = (List<String>) connection.getAttribute(name, "Kars");
-            assertEquals(0, kars.size());
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=kar,name=root");
+        @SuppressWarnings("unchecked")
+        List<String> kars = (List<String>) mbeanServer.getAttribute(name, "Kars");
+        assertEquals(0, kars.size());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
index 5ba293e..740007d 100644
--- a/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
+++ b/itests/src/test/java/org/apache/karaf/itests/KarafTestSupport.java
@@ -27,6 +27,7 @@ import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.net.ServerSocket;
 import java.net.URL;
 import java.security.Principal;
 import java.security.PrivilegedExceptionAction;
@@ -73,15 +74,21 @@ import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class KarafTestSupport {
 
-    public static final String RMI_SERVER_PORT = "44445";
-    public static final String HTTP_PORT = "9081";
-    public static final String RMI_REG_PORT = "1100";
+    public static final String MIN_RMI_SERVER_PORT = "44444";
+    public static final String MAX_RMI_SERVER_PORT = "66666";
+    public static final String MIN_HTTP_PORT = "9080";
+    public static final String MAX_HTTP_PORT = "9999";
+    public static final String MIN_RMI_REG_PORT = "1099";
+    public static final String MAX_RMI_REG_PORT = "9999";
+    public static final String MIN_SSH_PORT = "8101";
+    public static final String MAX_SSH_PORT = "8888";
 
     static final Long COMMAND_TIMEOUT = 30000L;
     static final Long SERVICE_TIMEOUT = 30000L;
@@ -103,6 +110,9 @@ public class KarafTestSupport {
     @Inject
     protected SessionFactory sessionFactory;
 
+    @Inject
+    protected ConfigurationAdmin configurationAdmin;
+
     /**
      * To make sure the tests run only when the boot features are fully installed
      */
@@ -126,6 +136,12 @@ public class KarafTestSupport {
     @Configuration
     public Option[] config() {
         MavenArtifactUrlReference karafUrl = maven().groupId("org.apache.karaf").artifactId("apache-karaf").versionAsInProject().type("tar.gz");
+
+        String httpPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_HTTP_PORT), Integer.parseInt(MAX_HTTP_PORT)));
+        String rmiRegistryPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_RMI_REG_PORT), Integer.parseInt(MAX_RMI_REG_PORT)));
+        String rmiServerPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_RMI_SERVER_PORT), Integer.parseInt(MAX_RMI_SERVER_PORT)));
+        String sshPort = Integer.toString(getAvailablePort(Integer.parseInt(MIN_SSH_PORT), Integer.parseInt(MAX_SSH_PORT)));
+
         return new Option[]{
             // KarafDistributionOption.debugConfiguration("8889", true),
             karafDistributionConfiguration().frameworkUrl(karafUrl).name("Apache Karaf").unpackDirectory(new File("target/exam")),
@@ -134,9 +150,10 @@ public class KarafTestSupport {
             keepRuntimeFolder(),
             logLevel(LogLevel.INFO),
             replaceConfigurationFile("etc/org.ops4j.pax.logging.cfg", getConfigFile("/etc/org.ops4j.pax.logging.cfg")),
-            editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", HTTP_PORT),
-            editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", RMI_REG_PORT),
-            editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", RMI_SERVER_PORT),
+            editConfigurationFilePut("etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", httpPort),
+            editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiRegistryPort", rmiRegistryPort),
+            editConfigurationFilePut("etc/org.apache.karaf.management.cfg", "rmiServerPort", rmiServerPort),
+            editConfigurationFilePut("etc/org.apache.karaf.shell.cfg", "sshPort", sshPort),
             editConfigurationFilePut("etc/system.properties", "spring31.version", System.getProperty("spring31.version")),
             editConfigurationFilePut("etc/system.properties", "spring32.version", System.getProperty("spring32.version")),
             editConfigurationFilePut("etc/system.properties", "spring40.version", System.getProperty("spring40.version")),
@@ -145,6 +162,19 @@ public class KarafTestSupport {
         };
     }
 
+    private int getAvailablePort(int min, int max) {
+        for (int i = min; i <= max; i++) {
+            try {
+                ServerSocket socket = new ServerSocket(i);
+                return socket.getLocalPort();
+            } catch (Exception e) {
+                System.err.println("Port " + i + " not available, trying next one");
+                continue; // try next port
+            }
+        }
+        throw new IllegalStateException("Can't find available network ports");
+    }
+
     /**
      * Executes a shell command and returns output as a String.
      * Commands have a default timeout of 10 seconds.
@@ -366,7 +396,7 @@ public class KarafTestSupport {
     }
 
     public JMXConnector getJMXConnector(String userName, String passWord) throws Exception {
-        JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + RMI_REG_PORT+ "/karaf-root");
+        JMXServiceURL url = new JMXServiceURL(getJmxServiceUrl());
         Hashtable<String, Object> env = new Hashtable<String, Object>();
         String[] credentials = new String[]{ userName, passWord };
         env.put("jmx.remote.credentials", credentials);
@@ -374,6 +404,22 @@ public class KarafTestSupport {
         return connector;
     }
 
+    public String getJmxServiceUrl() throws Exception {
+        org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration("org.apache.karaf.management", null);
+        if (configuration != null) {
+            return configuration.getProperties().get("serviceUrl").toString();
+        }
+        return "service:jmx:rmi:///jndi/rmi://localhost:" + MIN_RMI_SERVER_PORT + "/karaf-root";
+    }
+
+    public String getSshPort() throws Exception {
+        org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration("org.apache.karaf.shell", null);
+        if (configuration != null) {
+            return configuration.getProperties().get("sshPort").toString();
+        }
+        return "8101";
+    }
+
     public void assertFeatureInstalled(String featureName) throws Exception {
         String name;
         String version;

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/LogTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/LogTest.java b/itests/src/test/java/org/apache/karaf/itests/LogTest.java
index ba226c7..307f1e8 100644
--- a/itests/src/test/java/org/apache/karaf/itests/LogTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/LogTest.java
@@ -17,9 +17,8 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import javax.management.Attribute;
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Ignore;
 import org.junit.Test;
@@ -30,6 +29,8 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class LogTest extends KarafTestSupport {
@@ -45,18 +46,12 @@ public class LogTest extends KarafTestSupport {
     @Test
     public void setDebugViaMBean() throws Exception {
         assertSetLevel("INFO");
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=log,name=root");
-            Attribute attribute = new Attribute("Level", "DEBUG");
-            connection.setAttribute(name, attribute);
-            String logLevel = (String) connection.getAttribute(name, "Level");
-            assertEquals("DEBUG", logLevel);
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=log,name=root");
+        Attribute attribute = new Attribute("Level", "DEBUG");
+        mbeanServer.setAttribute(name, attribute);
+        String logLevel = (String) mbeanServer.getAttribute(name, "Level");
+        assertEquals("DEBUG", logLevel);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/ObrTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ObrTest.java b/itests/src/test/java/org/apache/karaf/itests/ObrTest.java
index 4809257..64b7eef 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ObrTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ObrTest.java
@@ -15,12 +15,12 @@ package org.apache.karaf.itests;
 
 import static org.junit.Assert.assertEquals;
 
+import java.lang.management.ManagementFactory;
 import java.util.List;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -46,19 +46,13 @@ public class ObrTest extends KarafTestSupport {
 
     @Test
     public void listsViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=obr,name=root");
-            @SuppressWarnings("unchecked")
-            List<String> urls = (List<String>) connection.getAttribute(name, "Urls");
-            assertEquals(0, urls.size());
-            TabularData bundles = (TabularData) connection.getAttribute(name, "Bundles");
-            assertEquals(0, bundles.size());
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=obr,name=root");
+        @SuppressWarnings("unchecked")
+        List<String> urls = (List<String>) mbeanServer.getAttribute(name, "Urls");
+        assertEquals(0, urls.size());
+        TabularData bundles = (TabularData) mbeanServer.getAttribute(name, "Bundles");
+        assertEquals(0, bundles.size());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/PackageTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/PackageTest.java b/itests/src/test/java/org/apache/karaf/itests/PackageTest.java
index 815c587..78e1d7f 100644
--- a/itests/src/test/java/org/apache/karaf/itests/PackageTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/PackageTest.java
@@ -16,16 +16,15 @@ package org.apache.karaf.itests;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.lang.management.ManagementFactory;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.SortedMap;
 
 import javax.inject.Inject;
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
 
 import org.apache.karaf.packages.core.PackageService;
 import org.apache.karaf.packages.core.PackageVersion;
@@ -51,16 +50,10 @@ public class PackageTest extends KarafTestSupport {
 
     @Test
     public void exportsViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=package,name=root");
-            TabularData exports = (TabularData)connection.getAttribute(name, "Exports");
-            assertTrue(exports.size() > 0);
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=package,name=root");
+        TabularData exports = (TabularData) mbeanServer.getAttribute(name, "Exports");
+        assertTrue(exports.size() > 0);
     }
 
     @Test
@@ -72,16 +65,10 @@ public class PackageTest extends KarafTestSupport {
 
     @Test
     public void importsViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=package,name=root");
-            TabularData imports = (TabularData)connection.getAttribute(name, "Imports");
-            assertTrue(imports.size() > 0);
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=package,name=root");
+        TabularData imports = (TabularData) mbeanServer.getAttribute(name, "Imports");
+        assertTrue(imports.size() > 0);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/ServiceTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/ServiceTest.java b/itests/src/test/java/org/apache/karaf/itests/ServiceTest.java
index 7e736b5..f2ad8ed 100644
--- a/itests/src/test/java/org/apache/karaf/itests/ServiceTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/ServiceTest.java
@@ -16,10 +16,9 @@ package org.apache.karaf.itests;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -27,6 +26,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class ServiceTest extends KarafTestSupport {
@@ -40,16 +41,10 @@ public class ServiceTest extends KarafTestSupport {
 
     @Test
     public void listViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=service,name=root");
-            TabularData services = (TabularData) connection.getAttribute(name, "Services");
-            assertTrue(services.size() > 0);
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=service,name=root");
+        TabularData services = (TabularData) mbeanServer.getAttribute(name, "Services");
+        assertTrue(services.size() > 0);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/SshCommandTestBase.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/SshCommandTestBase.java b/itests/src/test/java/org/apache/karaf/itests/SshCommandTestBase.java
index eaf5cda..aaa0c04 100644
--- a/itests/src/test/java/org/apache/karaf/itests/SshCommandTestBase.java
+++ b/itests/src/test/java/org/apache/karaf/itests/SshCommandTestBase.java
@@ -37,6 +37,7 @@ import org.ops4j.pax.exam.spi.reactors.PerClass;
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class SshCommandTestBase extends KarafTestSupport {
+
     enum Result { OK, NOT_FOUND, NO_CREDENTIALS };
 
     private SshClient client;
@@ -116,7 +117,8 @@ public class SshCommandTestBase extends KarafTestSupport {
     private OutputStream openSshChannel(String username, String password, OutputStream ... outputs) throws Exception {
         client = SshClient.setUpDefaultClient();
         client.start();
-        ConnectFuture future = client.connect(username, "localhost", 8101).await();
+        String sshPort = getSshPort();
+        ConnectFuture future = client.connect(username, "localhost", Integer.parseInt(sshPort)).await();
         session = future.getSession();
 
         int ret = ClientSession.WAIT_AUTH;

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java b/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
index dd9184b..3db1544 100644
--- a/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/SshKeyFormatTest.java
@@ -60,9 +60,11 @@ public class SshKeyFormatTest extends SshCommandTestBase {
         ByteSource source = Resources.asByteSource(testPemURL);
         PKCS8Key pkcs8 = new PKCS8Key(source.openStream(), null);
 
+        String sshPort = getSshPort();
+
         client.setServerKeyVerifier(new RequiredServerKeyVerifier(pkcs8.getPublicKey()));
         client.start();
-        ConnectFuture future = client.connect("karaf", "localhost", 8101).await();
+        ConnectFuture future = client.connect("karaf", "localhost", Integer.parseInt(sshPort)).await();
         ClientSession session = future.getSession();
         int ret = ClientSession.WAIT_AUTH;
         while ((ret & ClientSession.WAIT_AUTH) != 0) {

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/SystemShutdownTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/SystemShutdownTest.java b/itests/src/test/java/org/apache/karaf/itests/SystemShutdownTest.java
index 9dadb10..fc6cb59 100644
--- a/itests/src/test/java/org/apache/karaf/itests/SystemShutdownTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/SystemShutdownTest.java
@@ -13,9 +13,8 @@
  */
 package org.apache.karaf.itests;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
 
 import org.apache.karaf.jaas.boot.principal.RolePrincipal;
 import org.junit.Test;
@@ -24,6 +23,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerMethod;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerMethod.class)
 public class SystemShutdownTest extends KarafTestSupport {
@@ -35,15 +36,9 @@ public class SystemShutdownTest extends KarafTestSupport {
 
     @Test
     public void shutdownViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
-            connection.invoke(name, "halt", new Object[]{}, new String[]{});
-        } finally {
-        	close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
+        mbeanServer.invoke(name, "halt", new Object[]{}, new String[]{});
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/SystemTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/SystemTest.java b/itests/src/test/java/org/apache/karaf/itests/SystemTest.java
index 9582106..c9d22ca 100644
--- a/itests/src/test/java/org/apache/karaf/itests/SystemTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/SystemTest.java
@@ -15,9 +15,8 @@ package org.apache.karaf.itests;
 
 import static org.junit.Assert.assertEquals;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
 
 import org.apache.karaf.jaas.boot.principal.RolePrincipal;
 import org.junit.Test;
@@ -26,6 +25,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class SystemTest extends KarafTestSupport {
@@ -41,16 +42,10 @@ public class SystemTest extends KarafTestSupport {
 
     @Test
     public void nameViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
-            String currentName = (String) connection.getAttribute(name, "Name");
-            assertEquals("root", currentName);
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
+        String currentName = (String) mbeanServer.getAttribute(name, "Name");
+        assertEquals("root", currentName);
     }
 
     @Test
@@ -60,16 +55,9 @@ public class SystemTest extends KarafTestSupport {
 
     @Test
     public void versionViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
-            assertContains(KARAF_VERSION, (String) connection.getAttribute(name, "Version"));
-        } finally {
-            if (connector != null)
-                connector.close();
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
+        assertContains(KARAF_VERSION, (String) mbeanServer.getAttribute(name, "Version"));
     }
 
     @Test
@@ -79,17 +67,10 @@ public class SystemTest extends KarafTestSupport {
 
     @Test
     public void frameworkViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
-            String framework = (String) connection.getAttribute(name, "Framework");
-            assertEquals("felix", framework);
-        } finally {
-            if (connector != null)
-                connector.close();
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
+        String framework = (String) mbeanServer.getAttribute(name, "Framework");
+        assertEquals("felix", framework);
     }
 
     @Test
@@ -100,17 +81,10 @@ public class SystemTest extends KarafTestSupport {
 
     @Test
     public void startLevelViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
-            int startLevel = (Integer) connection.getAttribute(name, "StartLevel");
-            assertEquals(100, startLevel);
-        } finally {
-            if (connector != null)
-                connector.close();
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=system,name=root");
+        int startLevel = (Integer) mbeanServer.getAttribute(name, "StartLevel");
+        assertEquals(100, startLevel);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/WebTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/WebTest.java b/itests/src/test/java/org/apache/karaf/itests/WebTest.java
index da28aaf..a4f181f 100644
--- a/itests/src/test/java/org/apache/karaf/itests/WebTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/WebTest.java
@@ -16,10 +16,9 @@ package org.apache.karaf.itests;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import javax.management.openmbean.TabularData;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -28,6 +27,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class WebTest extends KarafTestSupport {
@@ -46,16 +47,10 @@ public class WebTest extends KarafTestSupport {
 
     @Test
     public void listViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=web,name=root");
-            TabularData webBundles = (TabularData) connection.getAttribute(name, "WebBundles");
-            assertEquals(0, webBundles.size());
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=web,name=root");
+        TabularData webBundles = (TabularData) mbeanServer.getAttribute(name, "WebBundles");
+        assertEquals(0, webBundles.size());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06aa7245/itests/src/test/java/org/apache/karaf/itests/WrapperTest.java
----------------------------------------------------------------------
diff --git a/itests/src/test/java/org/apache/karaf/itests/WrapperTest.java b/itests/src/test/java/org/apache/karaf/itests/WrapperTest.java
index 5aca413..b919622 100644
--- a/itests/src/test/java/org/apache/karaf/itests/WrapperTest.java
+++ b/itests/src/test/java/org/apache/karaf/itests/WrapperTest.java
@@ -15,9 +15,8 @@ package org.apache.karaf.itests;
 
 import static org.junit.Assert.assertFalse;
 
-import javax.management.MBeanServerConnection;
+import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.remote.JMXConnector;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -26,6 +25,8 @@ import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 
+import java.lang.management.ManagementFactory;
+
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class WrapperTest extends KarafTestSupport {
@@ -44,15 +45,9 @@ public class WrapperTest extends KarafTestSupport {
 
     @Test
     public void installViaMBean() throws Exception {
-        JMXConnector connector = null;
-        try {
-            connector = this.getJMXConnector();
-            MBeanServerConnection connection = connector.getMBeanServerConnection();
-            ObjectName name = new ObjectName("org.apache.karaf:type=wrapper,name=root");
-            connection.invoke(name, "install", new Object[]{}, new String[]{});
-        } finally {
-            close(connector);
-        }
+        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
+        ObjectName name = new ObjectName("org.apache.karaf:type=wrapper,name=root");
+        mbeanServer.invoke(name, "install", new Object[]{}, new String[]{});
     }
 
 }


Mime
View raw message