/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2011, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.remoting3.jmx;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.io.IOException;

import org.jboss.remoting3.jmx.common.JMXRemotingServer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Test case to test the client side of the interactions.
 *
 * @author <a href="mailto:darran.lofthouse@jboss.com">Darran Lofthouse</a>
 */
public class ClientTest {

    private static final int PORT = 12345;

    private static final String URL = "service:jmx:remoting://localhost:" + PORT;

    private static JMXRemotingServer remotingServer;

    @BeforeClass
    public static void setupServer() throws IOException {
        remotingServer = new JMXRemotingServer(PORT);
        remotingServer.start();
    }

    @AfterClass
    public static void tearDownServer() throws IOException {
        try {
            remotingServer.stop();
        } finally {
            remotingServer = null;
        }

    }

    @Test
    public void testNewJMXConnector() throws Exception {
        JMXServiceURL serviceUrl = new JMXServiceURL(URL);
        JMXConnector connector = JMXConnectorFactory.newJMXConnector(serviceUrl, null);

        assertNotNull(connector);
    }

    @Test
    public void testConnect() throws Exception {
        JMXServiceURL serviceUrl = new JMXServiceURL(URL);
        JMXConnector connector = JMXConnectorFactory.connect(serviceUrl);

        assertNotNull(connector);
    }

    @Test
    public void testConnectId() throws Exception {
        JMXServiceURL serviceUrl = new JMXServiceURL(URL);
        JMXConnector connector = JMXConnectorFactory.connect(serviceUrl);

        String connectionId = connector.getConnectionId();
        assertNotNull("connectionId", connectionId);
        assertTrue("connectionId length", connectionId.length() > 0);
    }
}

@@ -1140,16 +1140,89 @@
 tTrue;%0A%0A
+import javax.management.MBeanServer;%0Aimport javax.management.ObjectName;%0A
 import j
@@ -1383,16 +1383,85 @@
 ception;
+%0Aimport java.lang.management.ManagementFactory;%0Aimport java.util.Set;
 %0A%0Aimport
@@ -3186,11 +3186,345 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testWhatIsRegistered() throws Exception %7B%0A        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();%0A        Set%3CObjectName%3E names = mbeanServer.queryNames(null, null);%0A        for (ObjectName current : names) %7B%0A            System.out.println(%22 - %22 + current.toString());%0A        %7D%0A    %7D
 %0A%7D%0A

Add previously added test case.