From 2a55846c7fd94f20d41062cc786a6288dfec76a4 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Thu, 07 Jun 2007 17:19:20 +0000
Subject: [PATCH] Fix for issue 1633 (JMX port should be disabled by default)

---
 opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java |   49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java
index 6b58c56..8d042e4 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/protocols/jmx/JmxConnectTest.java
@@ -57,14 +57,21 @@
 import org.opends.server.core.AddOperation;
 import org.opends.server.core.DeleteOperation;
 import org.opends.server.core.DirectoryServer;
+import org.opends.server.core.ModifyOperation;
 import org.opends.server.protocols.internal.InternalClientConnection;
 import org.opends.server.types.ConfigChangeResult;
+import org.opends.server.types.Control;
+import org.opends.server.types.Control;
 import org.opends.server.types.DN;
 import org.opends.server.types.Entry;
+import org.opends.server.types.Modification;
+import org.opends.server.types.ModificationType;
 import org.opends.server.types.ResultCode;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
+
+import static org.opends.server.config.ConfigConstants.ATTR_LISTEN_PORT;
 import static org.testng.Assert.*;
 
 
@@ -420,9 +427,9 @@
 
   /**
    * @param config
-   * @throws ConfigException
+   * @throws Exception
    */
-  private void configureJmx(Entry entry) throws ConfigException {
+  private void configureJmx(Entry entry) throws Exception {
     ArrayList<String> reasons = new ArrayList<String>();
 
     // Get the Jmx connection handler from the core server
@@ -448,8 +455,9 @@
 
   /**
    * Get a reference to the JMX connection handler.
+   * @throws an Exception is something went wrong.
    */
-  private JmxConnectionHandler getJmxConnectionHandler() {
+  private JmxConnectionHandler getJmxConnectionHandler() throws Exception {
     List<ConnectionHandler> handlers = DirectoryServer
         .getConnectionHandlers();
     assertNotNull(handlers);
@@ -460,6 +468,20 @@
         break;
       }
     }
+    if (jmxConnectionHandler == null)
+    {
+      enableJmx();
+      synchronized (this) {
+        this.wait(500);
+      }
+      for (ConnectionHandler handler : handlers) {
+        if (handler instanceof JmxConnectionHandler) {
+          jmxConnectionHandler = (JmxConnectionHandler) handler;
+          break;
+        }
+      }
+    }
+    
     return jmxConnectionHandler;
   }
 
@@ -627,4 +649,25 @@
 
     mbsc.setAttribute(name, attr);
   }
+  
+  /**
+   * Enable JMX with the port chosen in TestCaseUtils.
+   * @throws Exception if the handler cannot be enabled.
+   */
+  private void enableJmx() throws Exception
+  {
+    ArrayList<Modification> mods = new ArrayList<Modification>();
+
+    InternalClientConnection conn =
+        InternalClientConnection.getRootConnection();
+    mods.add(new Modification(ModificationType.REPLACE,
+      new org.opends.server.types.Attribute("ds-cfg-connection-handler-enabled",
+              "true")));
+    ModifyOperation op = new ModifyOperation(conn, conn.nextOperationID(),
+      conn.nextMessageID(), new ArrayList<Control>(),
+      DN.decode(
+        "cn=JMX Connection Handler,cn=Connection Handlers,cn=config"),
+      mods);
+    op.run();
+  }
 }

--
Gitblit v1.10.0