harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ndbe...@apache.org
Subject svn commit: r495839 [5/7] - in /harmony/enhanced/classlib/trunk/modules/lang-management: ./ META-INF/ make/ src/main/java/com/ src/main/java/com/ibm/ src/main/java/com/ibm/lang/ src/main/java/com/ibm/lang/management/ src/main/java/java/lang/management/...
Date Sat, 13 Jan 2007 05:08:52 GMT
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+
+import junit.framework.TestCase;
+
+public class MemoryMXBeanTest extends TestCase {
+
+    private MemoryMXBean mb;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = ManagementFactory.getMemoryMXBean();
+        assertNotNull(mb);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryMXBean.getHeapMemoryUsage()'
+     */
+    public void testGetHeapMemoryUsage() {
+        MemoryUsage mu = mb.getHeapMemoryUsage();
+        assertNotNull(mu);
+        assertTrue(mu.getCommitted() >= mu.getUsed());
+        assertTrue(mu.getCommitted() <= mu.getMax());
+        assertTrue(mu.getUsed() <= mu.getMax());
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryMXBean.getNonHeapMemoryUsage()'
+     */
+    public void testGetNonHeapMemoryUsage() {
+        MemoryUsage mu = mb.getNonHeapMemoryUsage();
+        assertNotNull(mu);
+        assertTrue(mu.getCommitted() >= mu.getUsed());
+        if (mu.getMax() != -1) {
+            // If max is defined then used and committed will always
+            // be less than or equal to it
+            assertTrue(mu.getCommitted() <= mu.getMax());
+            assertTrue(mu.getUsed() <= mu.getMax());
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryMXBean.getObjectPendingFinalizationCount()'
+     */
+    public void testGetObjectPendingFinalizationCount() {
+        assertTrue(mb.getObjectPendingFinalizationCount() > -1);
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryMXBean.setVerbose(boolean)'
+     */
+    public void testSetVerbose() {
+        boolean initialVal = mb.isVerbose();
+        mb.setVerbose(!initialVal);
+        assertTrue(mb.isVerbose() != initialVal);
+        mb.setVerbose(initialVal);
+        assertTrue(mb.isVerbose() == initialVal);
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryManagerMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryManagerMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryManagerMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryManagerMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryManagerMXBean;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class MemoryManagerMXBeanTest extends TestCase {
+
+    private List<MemoryManagerMXBean> allBeans;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        allBeans = ManagementFactory.getMemoryManagerMXBeans();
+        assertNotNull(allBeans);
+        for (MemoryManagerMXBean mb : allBeans) {
+            assertNotNull(mb);
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryManagerMXBean.getMemoryPoolNames()'
+     */
+    public void testGetMemoryPoolNames() {
+        for (MemoryManagerMXBean mb : allBeans) {
+            String[] managedPools = mb.getMemoryPoolNames();
+            assertNotNull(managedPools);
+            for (String poolName : managedPools) {
+                assertNotNull(poolName);
+                assertTrue(poolName.length() > 0);
+            }// end for all managed pools
+        }// end for all garbage collector beans
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryManagerMXBean.getName()'
+     */
+    public void testGetName() {
+        for (MemoryManagerMXBean mb : allBeans) {
+            String name = mb.getName();
+            assertNotNull(name);
+            assertTrue(name.length() > 0);
+        }
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryManagerMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryPoolMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryPoolMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryPoolMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryPoolMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,360 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryType;
+import java.lang.management.MemoryUsage;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class MemoryPoolMXBeanTest extends TestCase {
+
+    private List<MemoryPoolMXBean> allBeans;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        allBeans = ManagementFactory.getMemoryPoolMXBeans();
+        for (MemoryPoolMXBean mb : allBeans) {
+            assertNotNull(mb);
+        }
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.getCollectionUsage()'
+     */
+    public void testGetCollectionUsage() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            // If this method is not supported then it returns null.
+            MemoryUsage mu = mb.getCollectionUsage();
+            if (mu != null) {
+                assertTrue(mu.getCommitted() >= mu.getUsed());
+                assertTrue(mu.getCommitted() <= mu.getMax());
+                assertTrue(mu.getUsed() <= mu.getMax());
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.getCollectionUsageThreshold()'
+     */
+    public void testGetCollectionUsageThreshold() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isCollectionUsageThresholdSupported()) {
+                assertTrue(mb.getCollectionUsageThreshold() > -1);
+            } else {
+                try {
+                    long val = mb.getCollectionUsageThreshold();
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.getCollectionUsageThresholdCount()'
+     */
+    public void testGetCollectionUsageThresholdCount() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isCollectionUsageThresholdSupported()) {
+                assertTrue(mb.getCollectionUsageThresholdCount() > -1);
+            } else {
+                try {
+                    long val = mb.getCollectionUsageThresholdCount();
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.getMemoryManagerNames()'
+     */
+    public void testGetMemoryManagerNames() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            String[] managers = mb.getMemoryManagerNames();
+            assertNotNull(managers);
+            for (String mgrName : managers) {
+                assertNotNull(mgrName);
+                assertTrue(mgrName.length() > 0);
+            }
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryPoolMXBean.getName()'
+     */
+    public void testGetName() {
+        allBeans = ManagementFactory.getMemoryPoolMXBeans();
+        for (MemoryPoolMXBean mb : allBeans) {
+            String name = mb.getName();
+            assertNotNull(name);
+            assertTrue(name.length() > 0);
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryPoolMXBean.getPeakUsage()'
+     */
+    public void testGetPeakUsage() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isValid()) {
+                MemoryUsage mu = mb.getPeakUsage();
+                assertNotNull(mu);
+                assertTrue(mu.getCommitted() >= mu.getUsed());
+                if (mu.getMax() != -1) {
+                    // If max is defined then used and committed will always
+                    // be less than or equal to it
+                    assertTrue(mu.getCommitted() <= mu.getMax());
+                    assertTrue(mu.getUsed() <= mu.getMax());
+                }
+            } else {
+                assertNull(mb.getPeakUsage());
+            }
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryPoolMXBean.getType()'
+     */
+    public void testGetType() {
+        MemoryType[] allTypes = MemoryType.values();
+        for (MemoryPoolMXBean mb : allBeans) {
+            MemoryType type = mb.getType();
+            assertNotNull(type);
+            boolean isOfKnownType = false;
+            for (MemoryType knownType : allTypes) {
+                if (type.equals(knownType)) {
+                    isOfKnownType = true;
+                    break;
+                }
+            }
+            assertTrue(isOfKnownType);
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryPoolMXBean.getUsage()'
+     */
+    public void testGetUsage() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isValid()) {
+                MemoryUsage mu = mb.getUsage();
+                assertNotNull(mu);
+                assertTrue(mu.getCommitted() >= mu.getUsed());
+                if (mu.getMax() != -1) {
+                    // If max is defined then used and committed will always
+                    // be less than or equal to it
+                    assertTrue(mu.getCommitted() <= mu.getMax());
+                    assertTrue(mu.getUsed() <= mu.getMax());
+                }
+            } else {
+                assertNull(mb.getUsage());
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.getUsageThreshold()'
+     */
+    public void testGetUsageThreshold() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isUsageThresholdSupported()) {
+                assertTrue(mb.getUsageThreshold() > -1);
+            } else {
+                try {
+                    long val = mb.getUsageThreshold();
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.getUsageThresholdCount()'
+     */
+    public void testGetUsageThresholdCount() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isUsageThresholdSupported()) {
+                assertTrue(mb.getUsageThresholdCount() > -1);
+            } else {
+                try {
+                    long val = mb.getUsageThresholdCount();
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.isCollectionUsageThresholdExceeded()'
+     */
+    public void testIsCollectionUsageThresholdExceeded() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isCollectionUsageThresholdSupported()) {
+                // Not a lot to test here. Maybe it will throw an exception ?
+                boolean val = mb.isCollectionUsageThresholdExceeded();
+            } else {
+                try {
+                    boolean val = mb.isCollectionUsageThresholdExceeded();
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.isUsageThresholdExceeded()'
+     */
+    public void testIsUsageThresholdExceeded() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isUsageThresholdSupported()) {
+                boolean value = mb.isUsageThresholdExceeded();
+            } else {
+                try {
+                    boolean value = mb.isUsageThresholdExceeded();
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryPoolMXBean.resetPeakUsage()'
+     */
+    public void testResetPeakUsage() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            MemoryUsage current = mb.getUsage();
+            mb.resetPeakUsage();
+            MemoryUsage newPeak = mb.getPeakUsage();
+            assertEquals(newPeak.getCommitted(), current.getCommitted());
+            assertEquals(newPeak.getInit(), current.getInit());
+            assertEquals(newPeak.getUsed(), current.getUsed());
+            assertEquals(newPeak.getMax(), current.getMax());
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.setCollectionUsageThreshold(long)'
+     */
+    public void testSetCollectionUsageThreshold() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isCollectionUsageThresholdSupported()) {
+                long before = mb.getCollectionUsageThreshold();
+                mb.setCollectionUsageThreshold(before + (8 * 1024));
+                long after = mb.getCollectionUsageThreshold();
+                assertEquals((before + (8 * 1024)), after);
+            } else {
+                try {
+                    mb.setCollectionUsageThreshold(1024);
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignored) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.setCollectionUsageThreshold(long)'
+     */
+    public void testSetCollectionUsageThresholdWithNegative() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isCollectionUsageThresholdSupported()) {
+                try {
+                    mb.setCollectionUsageThreshold(-1024);
+                    fail("Should have thrown IllegalArgumentException");
+                } catch (IllegalArgumentException ignored) {
+                }
+            } else {
+                try {
+                    mb.setCollectionUsageThreshold(1024);
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignored) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.setUsageThreshold(long)'
+     */
+    public void testSetUsageThreshold() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isUsageThresholdSupported()) {
+                long before = mb.getUsageThreshold();
+                mb.setUsageThreshold(before + (8 * 1024));
+                long after = mb.getUsageThreshold();
+                assertEquals((before + (8 * 1024)), after);
+            } else {
+                try {
+                    mb.setUsageThreshold(1024);
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.MemoryPoolMXBean.setUsageThreshold(long)'
+     */
+    public void testSetUsageThresholdWithNegative() {
+        for (MemoryPoolMXBean mb : allBeans) {
+            if (mb.isUsageThresholdSupported()) {
+                try {
+                    mb.setUsageThreshold(-1024);
+                    fail("Should have thrown IllegalArgumentException");
+                } catch (IllegalArgumentException ignored) {
+                }
+            } else {
+                try {
+                    mb.setUsageThreshold(1024);
+                    fail("Should have thrown UnsupportedOperationException");
+                } catch (UnsupportedOperationException ignore) {
+                }
+            }
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryPoolMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryUsageTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryUsageTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryUsageTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryUsageTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.MemoryUsage;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import junit.framework.TestCase;
+
+public class MemoryUsageTest extends TestCase {
+
+    private MemoryUsage mu;
+
+    private static final long GOOD_MU_INIT_VAL = 1024;
+
+    private static final long GOOD_MU_USED_VAL = 2 * 1024;
+
+    private static final long GOOD_MU_COMMITTED_VAL = 5 * 1024;
+
+    private static final long GOOD_MU_MAX_VAL = 10 * 1024;
+
+    private static final String GOOD_TOSTRING_VAL = "init = 1024(1K) used = 2048(2K) committed = 5120(5K) max = 10240(10K)";
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mu = new MemoryUsage(GOOD_MU_INIT_VAL, GOOD_MU_USED_VAL,
+                GOOD_MU_COMMITTED_VAL, GOOD_MU_MAX_VAL);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.hashCode()'
+     */
+    public void testHashCode() {
+        // Two equal MemoryUsage instances should have identical hash codes
+        MemoryUsage memUsage = new MemoryUsage(GOOD_MU_INIT_VAL,
+                GOOD_MU_USED_VAL, GOOD_MU_COMMITTED_VAL, GOOD_MU_MAX_VAL);
+        // This test fails on the RI.
+        assertEquals(mu, memUsage);
+        assertEquals(mu.hashCode(), memUsage.hashCode());
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.MemoryUsage(long, long,
+     * long, long)'
+     */
+    public void testMemoryUsage() throws Exception {
+        // Expect IllegalArgumentException if the value of init or max is
+        // negative but not -1
+        MemoryUsage memUsage = new MemoryUsage(-1, GOOD_MU_USED_VAL,
+                GOOD_MU_COMMITTED_VAL, -1);
+
+        try {
+            memUsage = new MemoryUsage(-2, GOOD_MU_USED_VAL,
+                    GOOD_MU_COMMITTED_VAL, -1);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        try {
+            memUsage = new MemoryUsage(GOOD_MU_INIT_VAL, GOOD_MU_USED_VAL,
+                    GOOD_MU_COMMITTED_VAL, -200);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Expect IllegalArgumentException if the value of used or committed
+        // is negative
+        try {
+            memUsage = new MemoryUsage(GOOD_MU_INIT_VAL, -1,
+                    GOOD_MU_COMMITTED_VAL, GOOD_MU_MAX_VAL);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        try {
+            memUsage = new MemoryUsage(GOOD_MU_INIT_VAL, GOOD_MU_USED_VAL,
+                    -399, GOOD_MU_MAX_VAL);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Expect IllegalArgumentException if the value of used is greater
+        // than the value of committed
+        try {
+            memUsage = new MemoryUsage(GOOD_MU_INIT_VAL, 3 * GOOD_MU_USED_VAL,
+                    GOOD_MU_COMMITTED_VAL, GOOD_MU_MAX_VAL);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Expect IllegalArgumentException if the value of committed is greater
+        // than the value of max...
+        try {
+            memUsage = new MemoryUsage(GOOD_MU_INIT_VAL, GOOD_MU_USED_VAL,
+                    4 * GOOD_MU_COMMITTED_VAL, GOOD_MU_MAX_VAL);
+            fail("should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // ... but only if the max has been defined
+        memUsage = new MemoryUsage(GOOD_MU_INIT_VAL, GOOD_MU_USED_VAL,
+                4 * GOOD_MU_COMMITTED_VAL, -1);
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.getCommitted()'
+     */
+    public void testGetCommitted() {
+        assertEquals(GOOD_MU_COMMITTED_VAL, mu.getCommitted());
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.getInit()'
+     */
+    public void testGetInit() {
+        assertEquals(GOOD_MU_INIT_VAL, mu.getInit());
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.getMax()'
+     */
+    public void testGetMax() {
+        assertEquals(GOOD_MU_MAX_VAL, mu.getMax());
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.getUsed()'
+     */
+    public void testGetUsed() {
+        assertEquals(GOOD_MU_USED_VAL, mu.getUsed());
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.toString()'
+     */
+    public void testToString() {
+        assertEquals(GOOD_TOSTRING_VAL, mu.toString());
+
+        MemoryUsage memUsage = new MemoryUsage(1 * 1024, 2 * 1024, 3 * 1024, -1);
+        assertEquals(
+                "init = 1024(1K) used = 2048(2K) committed = 3072(3K) max = -1(-1K)",
+                memUsage.toString());
+        memUsage = new MemoryUsage(-1, 2 * 1024, 3 * 1024, 10 * 1024);
+        assertEquals(
+                "init = -1(-1K) used = 2048(2K) committed = 3072(3K) max = 10240(10K)",
+                memUsage.toString());
+    }
+
+    /*
+     * Test method for 'java.lang.management.MemoryUsage.from(CompositeData)'
+     */
+    public void testFrom() {
+        MemoryUsage memUsage = MemoryUsage.from(createGoodCompositeData());
+        assertNotNull(memUsage);
+        assertEquals(GOOD_MU_INIT_VAL, memUsage.getInit());
+        assertEquals(GOOD_MU_USED_VAL, memUsage.getUsed());
+        assertEquals(GOOD_MU_COMMITTED_VAL, memUsage.getCommitted());
+        assertEquals(GOOD_MU_MAX_VAL, memUsage.getMax());
+    }
+
+    public static CompositeData createGoodCompositeData() {
+        CompositeData result = null;
+        String[] names = { "init", "used", "committed", "max" };
+        Object[] values = {
+        /* init */new Long(GOOD_MU_INIT_VAL),
+        /* used */new Long(GOOD_MU_USED_VAL),
+        /* committed */new Long(GOOD_MU_COMMITTED_VAL),
+        /* max */new Long(GOOD_MU_MAX_VAL) };
+        CompositeType cType = createGoodMemoryUsageCompositeType();
+        try {
+            result = new CompositeDataSupport(cType, names, values);
+        } catch (OpenDataException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public static CompositeType createGoodMemoryUsageCompositeType() {
+        CompositeType result = null;
+        try {
+            String[] typeNames = { "init", "used", "committed", "max" };
+            String[] typeDescs = { "init", "used", "committed", "max" };
+            OpenType[] typeTypes = { SimpleType.LONG, SimpleType.LONG,
+                    SimpleType.LONG, SimpleType.LONG };
+            result = new CompositeType(MemoryUsage.class.getName(),
+                    MemoryUsage.class.getName(), typeNames, typeDescs,
+                    typeTypes);
+        } catch (OpenDataException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/MemoryUsageTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/OperatingSystemMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/OperatingSystemMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/OperatingSystemMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/OperatingSystemMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+
+import junit.framework.TestCase;
+
+public class OperatingSystemMXBeanTest extends TestCase {
+
+    private OperatingSystemMXBean mb;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = ManagementFactory.getOperatingSystemMXBean();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'java.lang.management.OperatingSystemMXBean.getArch()'
+     */
+    public void testGetArch() {
+        assertEquals(mb.getArch(), System.getProperty("os.arch"));
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.OperatingSystemMXBean.getAvailableProcessors()'
+     */
+    public void testGetAvailableProcessors() {
+        assertEquals(mb.getAvailableProcessors(), Runtime.getRuntime()
+                .availableProcessors());
+    }
+
+    /*
+     * Test method for 'java.lang.management.OperatingSystemMXBean.getName()'
+     */
+    public void testGetName() {
+        assertEquals(mb.getName(), System.getProperty("os.name"));
+    }
+
+    /*
+     * Test method for 'java.lang.management.OperatingSystemMXBean.getVersion()'
+     */
+    public void testGetVersion() {
+        assertEquals(mb.getVersion(), System.getProperty("os.version"));
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/OperatingSystemMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/RuntimeMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/RuntimeMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/RuntimeMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/RuntimeMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+public class RuntimeMXBeanTest extends TestCase {
+
+    private RuntimeMXBean mb;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = ManagementFactory.getRuntimeMXBean();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getBootClassPath()'
+     */
+    public void testGetBootClassPath() {
+        if (mb.isBootClassPathSupported()) {
+            String bootclasspath = mb.getBootClassPath();
+            assertNotNull(bootclasspath);
+            assertTrue(bootclasspath.length() > 0);
+        } else {
+            try {
+                mb.getBootClassPath();
+                fail("Should have thrown an UnsupportedOperationException");
+            } catch (UnsupportedOperationException ignore) {
+            }
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getClassPath()'
+     */
+    public void testGetClassPath() {
+        assertEquals(mb.getClassPath(), System.getProperty("java.class.path"));
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getInputArguments()'
+     */
+    public void testGetInputArguments() {
+        List<String> args = mb.getInputArguments();
+        assertNotNull(args);
+        for (String string : args) {
+            assertNotNull(string);
+            assertTrue(string.length() > 0);
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getLibraryPath()'
+     */
+    public void testGetLibraryPath() {
+        assertEquals(mb.getLibraryPath(), System
+                .getProperty("java.library.path"));
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.RuntimeMXBean.getManagementSpecVersion()'
+     */
+    public void testGetManagementSpecVersion() {
+        String specVersion = mb.getManagementSpecVersion();
+        assertNotNull(specVersion);
+        assertTrue(specVersion.length() > 0);
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getName()'
+     */
+    public void testGetName() {
+        String name = mb.getName();
+        assertNotNull(name);
+        assertTrue(name.length() > 0);
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getSpecName()'
+     */
+    public void testGetSpecName() {
+        assertEquals(mb.getSpecName(), System
+                .getProperty("java.vm.specification.name"));
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getSpecVendor()'
+     */
+    public void testGetSpecVendor() {
+        assertEquals(mb.getSpecVendor(), System
+                .getProperty("java.vm.specification.vendor"));
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getSpecVersion()'
+     */
+    public void testGetSpecVersion() {
+        assertEquals(mb.getSpecVersion(), System
+                .getProperty("java.vm.specification.version"));
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getStartTime()'
+     */
+    public void testGetStartTime() {
+        assertTrue(mb.getStartTime() > -1);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.RuntimeMXBean.getSystemProperties()'
+     */
+    public void testGetSystemProperties() {
+        Map<String, String> props = mb.getSystemProperties();
+        assertNotNull(props);
+        assertTrue(props.size() > 0);
+        assertTrue(props.size() == System.getProperties().size());
+        for (Map.Entry<String, String> entry : props.entrySet()) {
+            assertNotNull(entry.getKey());
+            assertNotNull(entry.getValue());
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getUptime()'
+     */
+    public void testGetUptime() {
+        assertTrue(mb.getUptime() > -1);
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getVmName()'
+     */
+    public void testGetVmName() {
+        assertEquals(mb.getVmName(), System.getProperty("java.vm.name"));
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getVmVendor()'
+     */
+    public void testGetVmVendor() {
+        assertEquals(mb.getVmVendor(), System.getProperty("java.vm.vendor"));
+    }
+
+    /*
+     * Test method for 'java.lang.management.RuntimeMXBean.getVmVersion()'
+     */
+    public void testGetVmVersion() {
+        assertEquals(mb.getVmVersion(), System.getProperty("java.vm.version"));
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/RuntimeMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ThreadMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ThreadMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ThreadMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ThreadMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,453 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+import junit.framework.TestCase;
+
+public class ThreadMXBeanTest extends TestCase {
+
+    private ThreadMXBean mb;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = ManagementFactory.getThreadMXBean();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.findMonitorDeadlockedThreads()'
+     */
+    public void testFindMonitorDeadlockedThreads() {
+        // Check that if there are no deadlocked threads we get back
+        // a null rather than a zero length array.
+        long[] ids = mb.findMonitorDeadlockedThreads();
+        if (ids != null) {
+            assertTrue(ids.length != 0);
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.ThreadMXBean.getAllThreadIds()'
+     */
+    public void testGetAllThreadIds() {
+        int count = mb.getThreadCount();
+        long[] ids = mb.getAllThreadIds();
+        assertNotNull(ids);
+        assertEquals(count, ids.length);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.getCurrentThreadCpuTime()'
+     */
+    public void testGetCurrentThreadCpuTime() {
+        // Outcome depends on whether or not CPU time measurement is supported
+        // and enabled.
+        if (mb.isCurrentThreadCpuTimeSupported()) {
+            if (mb.isThreadCpuTimeEnabled()) {
+                assertTrue(mb.getCurrentThreadCpuTime() > -1);
+            } else {
+                assertEquals(-1, mb.getCurrentThreadCpuTime());
+            }
+        } else {
+            try {
+                mb.getCurrentThreadCpuTime();
+                fail("Should have thrown an UnsupportedOperationException!");
+            } catch (UnsupportedOperationException ignore) {
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.getCurrentThreadUserTime()'
+     */
+    public void testGetCurrentThreadUserTime() {
+        // Outcome depends on whether or not CPU time measurement is supported
+        // and enabled.
+        if (mb.isCurrentThreadCpuTimeSupported()) {
+            if (mb.isThreadCpuTimeEnabled()) {
+                assertTrue(mb.getCurrentThreadUserTime() > -1);
+            } else {
+                assertEquals(-1, mb.getCurrentThreadUserTime());
+            }
+        } else {
+            try {
+                mb.getCurrentThreadUserTime();
+                fail("Should have thrown an UnsupportedOperationException!");
+            } catch (UnsupportedOperationException ignore) {
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.getDaemonThreadCount()'
+     */
+    public void testGetDaemonThreadCount() {
+        assertTrue(mb.getDaemonThreadCount() > -1);
+    }
+
+    /*
+     * Test method for 'java.lang.management.ThreadMXBean.getPeakThreadCount()'
+     */
+    public void testGetPeakThreadCount() {
+        assertTrue(mb.getPeakThreadCount() > -1);
+    }
+
+    /*
+     * Test method for 'java.lang.management.ThreadMXBean.getThreadCount()'
+     */
+    public void testGetThreadCount() {
+        assertTrue(mb.getThreadCount() > -1);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.getThreadCpuTime(long)'
+     */
+    public void testGetThreadCpuTime() {
+        // Outcome depends on whether or not CPU time measurement is supported
+        // and enabled.
+        if (mb.isThreadCpuTimeSupported()) {
+            if (mb.isThreadCpuTimeEnabled()) {
+                // Good case
+                assertTrue(mb.getThreadCpuTime(Thread.currentThread().getId()) > -1);
+
+                // Should throw a wobbler if a bad Thread id is passed in.
+                try {
+                    mb.getThreadCpuTime(-122);
+                    fail("Should have thrown an IllegalArgumentException!");
+                } catch (IllegalArgumentException ignore) {
+                }
+            } else {
+                // Should return -1 if CPU time measurement is currently
+                // disabled.
+                assertEquals(-1, mb.getThreadCpuTime(Thread.currentThread()
+                        .getId()));
+            }
+        } else {
+            try {
+                mb.getThreadCpuTime(100);
+                fail("Should have thrown an UnsupportedOperationException!");
+            } catch (UnsupportedOperationException ignore) {
+            }
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.ThreadMXBean.getThreadInfo(long)'
+     */
+    public void testGetThreadInfoLong() {
+        // Should throw exception if a Thread id of 0 or less is input
+        try {
+            mb.getThreadInfo(0);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // For now, just check we don't get a null returned if we pass in
+        // a Thread id which is definitely valid (i.e. our Thread id)...
+        assertNotNull(mb.getThreadInfo(Thread.currentThread().getId()));
+    }
+
+    public final void testGetThreadInfoLongForUnstartedThread() {
+        // Create another thread in the VM.
+        Runnable r = new Runnable() {
+            public void run() {
+                try {
+                    Thread.sleep(2000);
+                } catch (InterruptedException ignore) {
+                }
+            }
+        };
+        Thread thread = new Thread(r);
+        // deliberately not starting
+        long thrdId = thread.getId();
+        assertNull(mb.getThreadInfo(thrdId));
+    }
+
+    public final void testGethThreadInfoLongForTerminatedThread() {
+        // Create another thread in the VM.
+        Runnable r = new Runnable() {
+            public void run() {
+                try {
+                    Thread.sleep(2000);
+                } catch (InterruptedException ignore) {
+                }
+            }
+        };
+        Thread thread = new Thread(r);
+        thread.start();
+        try {
+            thread.join();
+        } catch (InterruptedException ignore) {
+        }
+        long thrdId = thread.getId();
+        assertNull(mb.getThreadInfo(thrdId));
+    }
+
+    /*
+     * Test method for 'java.lang.management.ThreadMXBean.getThreadInfo(long[])'
+     */
+    public void testGetThreadInfoLongArray() {
+        // Should throw exception if a Thread id of 0 or less is input
+        try {
+            long[] input = new long[] { 0 };
+            ThreadInfo[] tmp = mb.getThreadInfo(input);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // For now, just check we don't get a null returned if we pass in
+        // a couple of Thread ids which are definitely valid (i.e. our Thread
+        // id)...
+        long[] input = new long[] { Thread.currentThread().getId(),
+                Thread.currentThread().getId() };
+        ThreadInfo[] tiArray = mb.getThreadInfo(input);
+        assertNotNull(tiArray);
+        for (ThreadInfo info : tiArray) {
+            assertNotNull(info);
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.ThreadMXBean.getThreadInfo(long[],
+     * int)'
+     */
+    public void testGetThreadInfoLongArrayInt() {
+        // Should throw exception if a Thread id of 0 or less is input
+        try {
+            long[] input = new long[] { 0 };
+            mb.getThreadInfo(input, 0);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Should throw exception if maxDepth is negative
+        try {
+            long[] input = new long[] { Thread.currentThread().getId() };
+            mb.getThreadInfo(input, -2445);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // For now, just check we don't get a null returned if we pass in
+        // a Thread id which is definitely valid (i.e. our Thread id)...
+        long[] input = new long[] { Thread.currentThread().getId(),
+                Thread.currentThread().getId() };
+        ThreadInfo[] tiArray = mb.getThreadInfo(input, 0);
+        assertNotNull(tiArray);
+        for (ThreadInfo info : tiArray) {
+            assertNotNull(info);
+        }
+    }
+
+    /*
+     * Test method for 'java.lang.management.ThreadMXBean.getThreadInfo(long,
+     * int)'
+     */
+    public void testGetThreadInfoLongInt() {
+        // Should throw exception if a Thread id of 0 or less is input
+        try {
+            mb.getThreadInfo(0, 0);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Should throw exception if maxDepth is negative
+        try {
+            mb.getThreadInfo(0, -44);
+            fail("Should have thrown an IllegalArgumentException");
+        } catch (IllegalArgumentException ignore) {
+        }
+        // For now, just check we don't get a null returned if we pass in
+        // a Thread id which is definitely valid (i.e. our Thread id)...
+        assertNotNull(mb.getThreadInfo(Thread.currentThread().getId(), 0));
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.getThreadUserTime(long)'
+     */
+    public void testGetThreadUserTime() {
+        // Outcome depends on whether or not CPU time measurement is supported
+        // and enabled.
+        if (mb.isThreadCpuTimeSupported()) {
+            if (mb.isThreadCpuTimeEnabled()) {
+                // Good case
+                assertTrue(mb.getThreadUserTime(Thread.currentThread().getId()) > -1);
+
+                // Should throw a wobbler if a bad Thread id is passed in.
+                try {
+                    long tmp = mb.getThreadUserTime(-122);
+                    fail("Should have thrown an IllegalArgumentException!");
+                } catch (IllegalArgumentException ignore) {
+                }
+            } else {
+                // Should return -1 if CPU time measurement is currently
+                // disabled.
+                assertEquals(-1, mb.getThreadUserTime(Thread.currentThread()
+                        .getId()));
+            }
+        } else {
+            try {
+                mb.getThreadUserTime(100);
+                fail("Should have thrown an UnsupportedOperationException!");
+            } catch (UnsupportedOperationException ignore) {
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.getTotalStartedThreadCount()'
+     */
+    public void testGetTotalStartedThreadCount() {
+        long before = mb.getTotalStartedThreadCount();
+
+        // Create another thread in the VM.
+        Runnable r = new Runnable() {
+            public void run() {
+                try {
+                    Thread.sleep(2000);
+                } catch (InterruptedException ignore) {
+                }
+            }
+        };
+        Thread thread = new Thread(r);
+        thread.start();
+
+        // Sleep a while as on some VM implementations the new thread may
+        // not start immediately.
+        try {
+            Thread.sleep(1000);
+        } catch (InterruptedException ignore) {
+        }
+
+        long after = mb.getTotalStartedThreadCount();
+        assertTrue(after > before);
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.isCurrentThreadCpuTimeSupported()'
+     */
+    public void testIsCurrentThreadCpuTimeSupported() {
+        // Should get the same response as a call to the
+        // method isThreadCpuTimeSupported().
+        assertEquals(mb.isCurrentThreadCpuTimeSupported(), mb
+                .isThreadCpuTimeSupported());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.resetPeakThreadCount()'
+     */
+    public void testResetPeakThreadCount() {
+        int currentThreadCount = mb.getThreadCount();
+        mb.resetPeakThreadCount();
+        assertEquals(currentThreadCount, mb.getPeakThreadCount());
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.setThreadContentionMonitoringEnabled(boolean)'
+     */
+    public void testSetThreadContentionMonitoringEnabled() {
+        // Response depends on whether or not thread contention
+        // monitoring is supported.
+        if (mb.isThreadContentionMonitoringSupported()) {
+            // Disable tcm
+            while (mb.isThreadContentionMonitoringEnabled()) {
+                mb.setThreadContentionMonitoringEnabled(false);
+                Thread.yield();
+            }// end while
+
+            // Check that a ThreadInfo returns -1 where expected.
+            ThreadInfo info = mb.getThreadInfo(Thread.currentThread().getId());
+            assertEquals(-1, info.getBlockedTime());
+            assertEquals(-1, info.getWaitedTime());
+
+            // re-enable tcm
+            while (!mb.isThreadContentionMonitoringEnabled()) {
+                mb.setThreadContentionMonitoringEnabled(true);
+                Thread.yield();
+            }// end while
+
+            // Check that waited time and blocked time are now no longer
+            // set to -1.
+            ThreadInfo info2 = mb.getThreadInfo(Thread.currentThread().getId());
+            assertTrue(info2.getBlockedTime() > -1);
+            assertTrue(info2.getWaitedTime() > -1);
+        } else {
+            try {
+                mb.isThreadContentionMonitoringEnabled();
+                fail("Should have thrown UnsupportedOperationException!");
+            } catch (UnsupportedOperationException ignore) {
+            }
+        }
+    }
+
+    /*
+     * Test method for
+     * 'java.lang.management.ThreadMXBean.setThreadCpuTimeEnabled(boolean)'
+     */
+    public void testSetThreadCpuTimeEnabled() {
+        // Depends on whether or not Thread CPU timing is actually
+        // supported on the current VM.
+        if (mb.isThreadCpuTimeSupported()) {
+            // Disable thread CPU time measuring
+            while (mb.isThreadCpuTimeEnabled()) {
+                mb.setThreadCpuTimeEnabled(false);
+                Thread.yield();
+            }// end while
+
+            // Check that we get a -1 for the thread CPU time
+            long time = mb.getThreadCpuTime(Thread.currentThread().getId());
+            assertEquals(-1, time);
+
+            // re-enable thread CPU time measuring
+            while (!mb.isThreadCpuTimeEnabled()) {
+                mb.setThreadCpuTimeEnabled(true);
+                Thread.yield();
+            }// end while
+
+            // Check that we no longer get a -1 for the thread CPU time
+            time = mb.getThreadCpuTime(Thread.currentThread().getId());
+            assertTrue(time > -1);
+        } else {
+            try {
+                mb.setThreadCpuTimeEnabled(false);
+                fail("Should have thrown an UnsupportedOperationException!");
+            } catch (UnsupportedOperationException ignore) {
+            }
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/lang/management/ThreadMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/util/logging/LoggingMXBeanTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/util/logging/LoggingMXBeanTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/util/logging/LoggingMXBeanTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/util/logging/LoggingMXBeanTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package tests.java.util.logging;
+
+import java.util.Enumeration;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+import java.util.logging.LoggingMXBean;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ */
+public class LoggingMXBeanTest extends TestCase {
+
+    private LoggingMXBean mb;
+
+    private Enumeration<String> loggerNames;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = LogManager.getLoggingMXBean();
+        loggerNames = LogManager.getLogManager().getLoggerNames();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see junit.framework.TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /**
+     * Test method for
+     * {@link java.util.logging.LoggingMXBean#getLoggerLevel(java.lang.String)}.
+     */
+    public void testGetLoggerLevel() {
+        // Verify we get something sensible back for the known loggers...
+        while (loggerNames.hasMoreElements()) {
+            String loggerName = (String) loggerNames.nextElement();
+            String level = mb.getLoggerLevel(loggerName);
+            assertNotNull(level);
+            if (level.length() > 0) {
+                Level l = Level.parse(level);
+            }// end if not an empty string
+        }// end while
+    }
+
+    /**
+     * Test method for
+     * {@link java.util.logging.LoggingMXBean#getLoggerLevel(java.lang.String)}.
+     */
+    public void testGetNonExistentLoggerLevel() {
+        assertNull(mb.getLoggerLevel("madeuploggername"));
+    }
+
+    /**
+     * Test method for {@link java.util.logging.LoggingMXBean#getLoggerNames()}.
+     */
+    public void testGetLoggerNames() {
+        // The answer according to the bean ...
+        List<String> loggerNamesFromBean = mb.getLoggerNames();
+        assertNotNull(loggerNamesFromBean);
+
+        while (loggerNames.hasMoreElements()) {
+            String realLoggerName = loggerNames.nextElement();
+            assertTrue(loggerNamesFromBean.contains(realLoggerName));
+        }
+    }
+
+    /**
+     * Test method for
+     * {@link java.util.logging.LoggingMXBean#getParentLoggerName(java.lang.String)}.
+     */
+    public void testGetParentLoggerName() {
+        // Verify we get something sensible back for the known loggers...
+        while (loggerNames.hasMoreElements()) {
+            String loggerName = loggerNames.nextElement();
+            Logger logger = LogManager.getLogManager().getLogger(loggerName);
+            Logger parent = logger.getParent();
+            if (parent != null) {
+                // The logger is not the root logger
+                String parentName = logger.getParent().getName();
+                assertEquals(parentName, mb.getParentLoggerName(loggerName));
+            } else {
+                // The logger is the root logger and has no parent.
+                assertTrue(mb.getParentLoggerName(loggerName).equals(""));
+            }
+        }// end while
+    }
+
+    /**
+     * Test method for
+     * {@link java.util.logging.LoggingMXBean#getParentLoggerName(java.lang.String)}.
+     */
+    public void testNonExistentGetParentLoggerName() {
+        // Ensure we get a null back if the named Logger is fictional...
+        assertNull(mb.getParentLoggerName("made up name"));
+    }
+
+    /**
+     * Test method for
+     * {@link java.util.logging.LoggingMXBean#setLoggerLevel(java.lang.String, java.lang.String)}.
+     */
+    public void testSetLoggerLevel() {
+        String loggerName = null;
+        while (loggerNames.hasMoreElements()) {
+            loggerName = (String) loggerNames.nextElement();
+
+            // Store the logger's current log level.
+            Logger logger = LogManager.getLogManager().getLogger(loggerName);
+            Level originalLevel = logger.getLevel();
+
+            // Set the logger to have a new level.
+            mb.setLoggerLevel(loggerName, Level.SEVERE.getName());
+
+            // Verify the set worked
+            assertEquals(Level.SEVERE.getName(), logger.getLevel().getName());
+
+            // Restore to original level. Need to take into account the fact
+            // that the original level may have been null (level inherited
+            // from parent)
+            if (originalLevel != null) {
+                mb.setLoggerLevel(loggerName, originalLevel.getName());
+                assertEquals(originalLevel.getName(), logger.getLevel()
+                        .getName());
+            } else {
+                mb.setLoggerLevel(loggerName, null);
+                assertNull(logger.getLevel());
+            }
+        }// end while
+
+        // Verify that we get an IllegalArgumentException if we supply a
+        // bogus loggerName.
+        try {
+            mb.setLoggerLevel("Grant W McLennan", Level.SEVERE.getName());
+            fail("Should have thrown IllegalArgumentException!");
+        } catch (IllegalArgumentException ignore) {
+        }
+
+        // Verify that we get an IllegalArgumentException if we supply a
+        // bogus log level value.
+        try {
+            mb.setLoggerLevel(loggerName, "Scott Walker");
+            fail("Should have thrown IllegalArgumentException!");
+        } catch (IllegalArgumentException ignore) {
+        }
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/api/java/tests/java/util/logging/LoggingMXBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/AttributeData.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/AttributeData.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/AttributeData.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/AttributeData.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package com.ibm.lang.management;
+
+/**
+ * Helper class
+ * 
+ */
+public class AttributeData {
+    public final String type;
+
+    public final boolean readable;
+
+    public final boolean writable;
+
+    public final boolean isAccessor;
+
+    public AttributeData(String type, boolean readable, boolean writable,
+            boolean isAccessor) {
+        this.type = type;
+        this.readable = readable;
+        this.writable = writable;
+        this.isAccessor = isAccessor;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/AttributeData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/ClassLoadingMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/ClassLoadingMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/ClassLoadingMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/ClassLoadingMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package com.ibm.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+
+import com.ibm.lang.management.ClassLoadingMXBeanImpl;
+
+public class ClassLoadingMXBeanImplTest extends
+        SingleInstanceDynamicMXBeanImplTest {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = (ClassLoadingMXBeanImpl) ManagementFactory.getClassLoadingMXBean();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    // -----------------------------------------------------------------
+    // DynamicMBean behaviour tests follow ....
+    // -----------------------------------------------------------------
+
+    public final void testGetAttribute() throws Exception {
+        // The good attributes...
+        assertTrue(((Integer) (mb.getAttribute("LoadedClassCount"))) > -1);
+        assertTrue(((Long) (mb.getAttribute("TotalLoadedClassCount"))) > -1);
+        assertTrue(((Long) (mb.getAttribute("UnloadedClassCount"))) > -1);
+
+        // This could be true or false - just so long as we don't get an
+        // exception raised...
+        boolean verboseVal = ((Boolean) (mb.getAttribute("Verbose")));
+
+        // A nonexistent attribute should throw an AttributeNotFoundException
+        try {
+            long rpm = ((Long) (mb.getAttribute("RPM")));
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        // Type mismatch should result in a casting exception
+        try {
+            String bad = (String) (mb.getAttribute("TotalLoadedClassCount"));
+            fail("Should have thrown a ClassCastException");
+        } catch (ClassCastException ignore) {
+        }
+    }
+
+    public final void testSetAttribute() throws Exception {
+        Attribute attr = null;
+        // The one writable attribute of ClassLoadingMXBeanImpl...
+        Boolean before = (Boolean) mb.getAttribute("Verbose");
+        boolean newVal = !before;
+        attr = new Attribute("Verbose", new Boolean(newVal));
+        mb.setAttribute(attr);
+        Boolean after = (Boolean) mb.getAttribute("Verbose");
+        assert (newVal == after);
+
+        // Let's try and set some non-writable attributes.
+        attr = new Attribute("LoadedClassCount", new Integer(25));
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        attr = new Attribute("TotalLoadedClassCount", new Long(3300));
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        attr = new Attribute("UnloadedClassCount", new Long(38));
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        // Try and set the Verbose attribute with an incorrect type.
+        attr = new Attribute("Verbose", new Long(42));
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an InvalidAttributeValueException.");
+        } catch (InvalidAttributeValueException ignore) {
+        }
+    }
+
+    public final void testGetAttributes() throws Exception {
+        AttributeList attributes = mb.getAttributes(attribs.keySet().toArray(
+                new String[] {}));
+        assertNotNull(attributes);
+        assertTrue(attributes.size() == attribs.size());
+
+        // Check through the returned values
+        Iterator<?> it = attributes.iterator();
+        while (it.hasNext()) {
+            Attribute element = (Attribute) it.next();
+            assertNotNull(element);
+            String name = element.getName();
+            Object value = element.getValue();
+            if (name.equals("Verbose")) {
+                // This could be true or false - just so long as we don't
+                // get an exception raised...
+                boolean verboseVal = ((Boolean) value).booleanValue();
+            } else if (name.equals("LoadedClassCount")) {
+                assertTrue(((Integer) (value)) > -1);
+            } else if (name.equals("TotalLoadedClassCount")) {
+                assertTrue(((Long) (mb.getAttribute("TotalLoadedClassCount"))) > -1);
+            } else if (name.equals("UnloadedClassCount")) {
+                assertTrue(((Long) (value)) > -1);
+            } else {
+                fail("Unexpected attribute name returned!");
+            }
+        }// end while
+    }
+
+    public final void testSetAttributes() {
+        // Ideal scenario...
+        AttributeList attList = new AttributeList();
+        Attribute verbose = new Attribute("Verbose", new Boolean(false));
+        attList.add(verbose);
+        AttributeList setAttrs = mb.setAttributes(attList);
+        assertNotNull(setAttrs);
+        assertTrue(setAttrs.size() == 1);
+        assertTrue(((Attribute) (setAttrs.get(0))).getName().equals("Verbose"));
+
+        // A failure scenario - a non-existent attribute...
+        AttributeList badList = new AttributeList();
+        Attribute garbage = new Attribute("Bantry", new Long(2888));
+        badList.add(garbage);
+        setAttrs = mb.setAttributes(badList);
+        assertNotNull(setAttrs);
+        assertTrue(setAttrs.size() == 0);
+
+        // Another failure scenario - a non-writable attribute...
+        badList = new AttributeList();
+        garbage = new Attribute("TotalLoadedClassCount", new Long(2888));
+        badList.add(garbage);
+        setAttrs = mb.setAttributes(badList);
+        assertNotNull(setAttrs);
+        assertTrue(setAttrs.size() == 0);
+
+        // Yet another failure scenario - a wrongly-typed attribute...
+        badList = new AttributeList();
+        garbage = new Attribute("Verbose", new Long(2888));
+        badList.add(garbage);
+        setAttrs = mb.setAttributes(badList);
+        assertNotNull(setAttrs);
+        assertTrue(setAttrs.size() == 0);
+    }
+
+    public final void testGetMBeanInfo() {
+        MBeanInfo mbi = mb.getMBeanInfo();
+        assertNotNull(mbi);
+
+        // Now make sure that what we got back is what we expected.
+
+        // Class name
+        assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
+
+        // No public constructors
+        MBeanConstructorInfo[] constructors = mbi.getConstructors();
+        assertNotNull(constructors);
+        assertTrue(constructors.length == 0);
+
+        // No public operations
+        MBeanOperationInfo[] operations = mbi.getOperations();
+        assertNotNull(operations);
+        assertTrue(operations.length == 0);
+
+        // No notifications
+        MBeanNotificationInfo[] notifications = mbi.getNotifications();
+        assertNotNull(notifications);
+        assertTrue(notifications.length == 0);
+
+        // Description is just the class name (until I hear it should be
+        // different)
+        assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
+
+        // Four attributes - only Verbose is writable.
+        MBeanAttributeInfo[] attributes = mbi.getAttributes();
+        assertNotNull(attributes);
+        assertTrue(attributes.length == 4);
+        for (int i = 0; i < attributes.length; i++) {
+            MBeanAttributeInfo info = attributes[i];
+            assertNotNull(info);
+            validateAttributeInfo(info);
+        }// end for
+    }
+
+    @Override
+    protected void populateTestAttributes() {
+        attribs = new Hashtable<String, AttributeData>();
+        attribs.put("Verbose", new AttributeData(Boolean.TYPE.getName(), true,
+                true, true));
+        attribs.put("LoadedClassCount", new AttributeData(Integer.TYPE
+                .getName(), true, false, false));
+        attribs.put("TotalLoadedClassCount", new AttributeData(Long.TYPE
+                .getName(), true, false, false));
+        attribs.put("UnloadedClassCount", new AttributeData(
+                Long.TYPE.getName(), true, false, false));
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/ClassLoadingMXBeanImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/CompilationMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/CompilationMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/CompilationMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/CompilationMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package com.ibm.lang.management;
+
+import java.lang.management.ManagementFactory;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+
+import com.ibm.lang.management.CompilationMXBeanImpl;
+
+public class CompilationMXBeanImplTest extends
+        SingleInstanceDynamicMXBeanImplTest {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        mb = (CompilationMXBeanImpl) ManagementFactory.getCompilationMXBean();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    // -----------------------------------------------------------------
+    // DynamicMBean behaviour tests follow ....
+    // -----------------------------------------------------------------
+    public final void testGetAttribute() throws Exception {
+        // The good attributes...
+        assertTrue(mb.getAttribute("Name").getClass().equals(String.class));
+
+        if (((CompilationMXBeanImpl) mb).isCompilationTimeMonitoringSupported()) {
+            assertTrue(((Long) mb.getAttribute("TotalCompilationTime")) > -1);
+        } else {
+            try {
+                assertTrue(((Long) mb.getAttribute("TotalCompilationTime")) > -1);
+                fail("Should have thrown MBeanException");
+            } catch (MBeanException ignore) {
+            }
+        }
+
+        // This could be true or false - just so long as we don't get an
+        // exception raised...
+        boolean ctmSupported = ((Boolean) (mb
+                .getAttribute("CompilationTimeMonitoringSupported")));
+
+        // A nonexistent attribute should throw an AttributeNotFoundException
+        try {
+            long rpm = ((Long) (mb.getAttribute("RPM")));
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        // Type mismatch should result in a casting exception
+        try {
+            String bad = (String) (mb.getAttribute("TotalCompilationTime"));
+            fail("Should have thrown a ClassCastException");
+        } catch (ClassCastException ignore) {
+        }
+    }
+
+    public final void testSetAttribute() throws Exception {
+        // Nothing is writable for this type
+        Attribute attr = new Attribute("Name", "Boris");
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        attr = new Attribute("TotalCompilationTime", new Long(65533));
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        attr = new Attribute("CompilationTimeMonitoringSupported", new Boolean(
+                true));
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+
+        // Try and set the Name attribute with an incorrect type.
+        attr = new Attribute("Name", new Long(42));
+        try {
+            mb.setAttribute(attr);
+            fail("Should have thrown an AttributeNotFoundException.");
+        } catch (AttributeNotFoundException ignore) {
+        }
+    }
+
+    public final void testGetAttributes() {
+        AttributeList attributes = mb.getAttributes(attribs.keySet().toArray(
+                new String[] {}));
+        assertNotNull(attributes);
+        assertTrue(attribs.size() >= attributes.size());
+
+        // Check through the returned values
+        Iterator<?> it = attributes.iterator();
+        while (it.hasNext()) {
+            Attribute element = (Attribute) it.next();
+            assertNotNull(element);
+            String name = element.getName();
+            Object value = element.getValue();
+            if (name.equals("Name")) {
+                assertTrue(value != null);
+            } else if (name.equals("TotalCompilationTime")) {
+                assertTrue(((Long) (value)) > -1);
+            } else if (name.equals("CompilationTimeMonitoringSupported")) {
+                // This could be true or false - just so long as we don't
+                // get an exception raised...
+                boolean ctmsVal = ((Boolean) value).booleanValue();
+            } else {
+                fail("Unexpected attribute!");
+            }
+        }// end while
+    }
+
+    public final void testSetAttributes() {
+        // No writable attributes for this type - should get a failure...
+        AttributeList badList = new AttributeList();
+        Attribute garbage = new Attribute("Name", "Curtains");
+        badList.add(garbage);
+        AttributeList setAttrs = mb.setAttributes(badList);
+        assertNotNull(setAttrs);
+        assertTrue(setAttrs.size() == 0);
+    }
+
+    public final void testGetMBeanInfo() {
+        MBeanInfo mbi = mb.getMBeanInfo();
+        assertNotNull(mbi);
+
+        // Now make sure that what we got back is what we expected.
+
+        // Class name
+        assertTrue(mbi.getClassName().equals(mb.getClass().getName()));
+
+        // No public constructors
+        MBeanConstructorInfo[] constructors = mbi.getConstructors();
+        assertNotNull(constructors);
+        assertTrue(constructors.length == 0);
+
+        // No public operations
+        MBeanOperationInfo[] operations = mbi.getOperations();
+        assertNotNull(operations);
+        assertTrue(operations.length == 0);
+
+        // No notifications
+        MBeanNotificationInfo[] notifications = mbi.getNotifications();
+        assertNotNull(notifications);
+        assertTrue(notifications.length == 0);
+
+        // Description is just the class name (until I hear it should be
+        // different)
+        assertTrue(mbi.getDescription().equals(mb.getClass().getName()));
+
+        // Three attributes - none writable.
+        MBeanAttributeInfo[] attributes = mbi.getAttributes();
+        assertNotNull(attributes);
+        assertTrue(attributes.length == 3);
+        for (int i = 0; i < attributes.length; i++) {
+            MBeanAttributeInfo info = attributes[i];
+            assertNotNull(info);
+            validateAttributeInfo(info);
+        }// end for
+    }
+
+    @Override
+    protected void populateTestAttributes() {
+        attribs = new Hashtable<String, AttributeData>();
+        attribs.put("Name", new AttributeData(String.class.getName(), true,
+                false, false));
+        attribs.put("TotalCompilationTime", new AttributeData(Long.TYPE
+                .getName(), true, false, false));
+        attribs.put("CompilationTimeMonitoringSupported", new AttributeData(
+                Boolean.TYPE.getName(), true, false, true));
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/CompilationMXBeanImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/DynamicMXBeanImplTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/DynamicMXBeanImplTest.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/DynamicMXBeanImplTest.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/DynamicMXBeanImplTest.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ */
+
+package com.ibm.lang.management;
+
+import java.util.Map;
+
+import javax.management.MBeanAttributeInfo;
+
+import junit.framework.TestCase;
+
+/**
+ * 
+ */
+public abstract class DynamicMXBeanImplTest extends TestCase {
+
+    protected Map<String, AttributeData> attribs;
+
+    abstract protected void populateTestAttributes();
+
+    public DynamicMXBeanImplTest() {
+        populateTestAttributes();
+    }
+
+    /**
+     * @param info
+     */
+    protected void validateAttributeInfo(MBeanAttributeInfo info) {
+        AttributeData example = attribs.get(info.getName());
+        assertNotNull(example);
+        assertTrue(info.getType().equals(example.type));
+        assertTrue(info.isReadable() == example.readable);
+        assertTrue(info.isWritable() == example.writable);
+        assertTrue(info.isIs() == example.isAccessor);
+    }
+
+    
+    abstract public void testGetAttribute() throws Exception;
+    
+    abstract public void testGetAttributes() throws Exception;
+    
+    abstract public void testGetMBeanInfo() throws Exception;
+    
+    abstract public void testSetAttribute() throws Exception;
+
+    abstract public void testSetAttributes() throws Exception;
+}

Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/test/impl/java/com/ibm/lang/management/DynamicMXBeanImplTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message