/*
 * Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
 * This file is part of SIGAR.
 * 
 * SIGAR is free software; you can redistribute it and/or modify
 * it under the terms version 2 of the GNU General Public License as
 * published by the Free Software Foundation. This program 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 General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA.
 */

package org.hyperic.sigar.test;

import java.util.Set;

import javax.management.MBeanServer;
import javax.management.ObjectName;

import org.hyperic.sigar.SigarException;
import org.hyperic.sigar.cmd.Mx;
import org.hyperic.sigar.jmx.SigarRegistry;

public class TestMx extends SigarTestCase {

    public TestMx(String name) {
        super(name);
    }

    public void testRegister() throws Exception {
        try {
            _testRegister();
        } catch (NoClassDefFoundError e) {
            //1.4 jre
            traceln(e + ", skipping");
        }
    }

    private void _testRegister() throws Exception {
        MBeanServer server;
        try {
            server = Mx.getMBeanServer();
        } catch (SigarException e) {
            traceln(e.getMessage());
            return;
        }

        server.registerMBean(new SigarRegistry(), null);
        Set beans =
            server.queryNames(new ObjectName("sigar:*"), null);

        assertGtZeroTrace("beans.size", beans.size());
    }
}

@@ -781,13 +781,119 @@
 til.
-Set;%0A
+Iterator;%0Aimport java.util.Set;%0A%0Aimport javax.management.MBeanAttributeInfo;%0Aimport javax.management.MBeanInfo;
 %0Aimp
@@ -1835,21 +1835,496 @@
 ans.size());
+%0A%0A        for (Iterator it=beans.iterator(); it.hasNext();) %7B%0A            ObjectName name = (ObjectName)it.next(); %0A            MBeanInfo info = server.getMBeanInfo(name);%0A            MBeanAttributeInfo%5B%5D attrs = info.getAttributes();%0A            for (int k = 0; k %3C attrs.length; k++) %7B%0A                String attr = attrs%5Bk%5D.getName();%0A                Object o = server.getAttribute(name, attr);%0A                traceln(name + %22:%22 + attr + %22=%22 + o);%0A            %7D%0A        %7D
 %0A    %7D%0A%7D%0A

test getAttribute