public void TestJsr262Connector()
        {
            var             jsr262ConnectorProvider = new Jsr262ConnectorProvider();
            INetMXConnector connector = null;
            string          uri       = string.Format("http://{0}:8888/MBeanServer", GetLocalAddress());

            Logger.DebugFormat("URI used to connect to the MBeanServer: {0}", uri);
            try
            {
                var url = new Uri(uri);
                connector = jsr262ConnectorProvider.NewNetMXConnector(url);
            }
            catch (Exception)
            {
                string msg = string.Format("Unable to create a client connection to the MBeanServer: URI-{0}", uri);
                Logger.Error(msg);
                Assert.Fail(msg);
            }
            connector.Connect(null);

            using (connector)
            {
                Logger.Debug("Starting the connection...");
                IMBeanServerConnection remoteServer = connector.MBeanServerConnection;

                var       name = new ObjectName("MBeanServer:component=ValidMBean");
                MBeanInfo info = remoteServer.GetMBeanInfo(name);
                Assert.AreEqual("MBean", info.Description);
                Assert.AreEqual("CrimsonLogic.Common.Library.Tests.ValidInstanceMBean, CrimsonLogic.Common.Library.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5fb9aab394206ec1", info.ClassName);
                foreach (MBeanAttributeInfo attributeInfo in info.Attributes)
                {
                    string attribute = string.Format("Attribute {0} ({1}) [{2}{3}]: {4}", attributeInfo.Name,
                                                     attributeInfo.Description,
                                                     attributeInfo.Readable ? "r" : "", attributeInfo.Writable ? "w" : "",
                                                     attributeInfo.Type);
                    Assert.AreEqual("Attribute Counter (Counter value) [rw]: System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", attribute);
                }
                int index = 0;
                foreach (MBeanOperationInfo operationInfo in info.Operations)
                {
                    string operation = string.Format("Operation {0} ({1}) [{2}]", operationInfo.Name, operationInfo.Description,
                                                     operationInfo.Impact);
                    Assert.AreEqual(
                        index == 0
                            ? "Operation AddAmount (Adds specified value to value of the counter) [Action]"
                            : "Operation ResetCounter (Sets counter value to 0) [Action]", operation);

                    index++;
                }

                object counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(0, counter);

                remoteServer.SetAttribute(name, "Counter", 5);
                counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(5, counter);

                remoteServer.Invoke(name, "AddAmount", new object[] { 5 });
                counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(10, counter);

                remoteServer.Invoke(name, "ResetCounter", new object[] { });
                counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(0, counter);

                Logger.Debug("Completed the JSR262 server-side tests!");
            }
        }
        public void TestJsr262Connector()
        {
            var jsr262ConnectorProvider = new Jsr262ConnectorProvider();
            INetMXConnector connector = null;
            string uri = string.Format("http://{0}:8888/MBeanServer", GetLocalAddress());
            Logger.DebugFormat("URI used to connect to the MBeanServer: {0}", uri);
            try
            {
                var url = new Uri(uri);
                connector = jsr262ConnectorProvider.NewNetMXConnector(url);
            }
            catch (Exception)
            {
                string msg = string.Format("Unable to create a client connection to the MBeanServer: URI-{0}", uri);
                Logger.Error(msg);
                Assert.Fail(msg);
            }
            connector.Connect(null);

            using (connector)
            {
                Logger.Debug("Starting the connection...");
                IMBeanServerConnection remoteServer = connector.MBeanServerConnection;

                var name = new ObjectName("MBeanServer:component=ValidMBean");
                MBeanInfo info = remoteServer.GetMBeanInfo(name);
                Assert.AreEqual("MBean", info.Description);
                Assert.AreEqual("CrimsonLogic.Common.Library.Tests.ValidInstanceMBean, CrimsonLogic.Common.Library.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5fb9aab394206ec1", info.ClassName);
                foreach (MBeanAttributeInfo attributeInfo in info.Attributes)
                {
                    string attribute = string.Format("Attribute {0} ({1}) [{2}{3}]: {4}", attributeInfo.Name,
                                      attributeInfo.Description,
                                      attributeInfo.Readable ? "r" : "", attributeInfo.Writable ? "w" : "",
                                      attributeInfo.Type);
                    Assert.AreEqual("Attribute Counter (Counter value) [rw]: System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", attribute);
                }
                int index = 0;
                foreach (MBeanOperationInfo operationInfo in info.Operations)
                {
                    string operation = string.Format("Operation {0} ({1}) [{2}]", operationInfo.Name, operationInfo.Description,
                                      operationInfo.Impact);
                    Assert.AreEqual(
                        index == 0
                            ? "Operation AddAmount (Adds specified value to value of the counter) [Action]"
                            : "Operation ResetCounter (Sets counter value to 0) [Action]", operation);

                    index++;
                }

                object counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(0, counter);

                remoteServer.SetAttribute(name, "Counter", 5);
                counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(5, counter);

                remoteServer.Invoke(name, "AddAmount", new object[] { 5 });
                counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(10, counter);

                remoteServer.Invoke(name, "ResetCounter", new object[] { });
                counter = remoteServer.GetAttribute(name, "Counter");

                Assert.AreEqual(0, counter);

                Logger.Debug("Completed the JSR262 server-side tests!");
            }
        }