View Javadoc

    1   /* JmxUtilsTest.java
    2    *
    3    * $Id: JmxUtilsTest.java 4644 2006-09-20 22:40:21Z paul_jack $
    4    *
    5    * Created Dec 7, 2005
    6    *
    7    * Copyright (C) 2005 Internet Archive.
    8    *
    9    * This file is part of the Heritrix web crawler (crawler.archive.org).
    10   *
    11   * Heritrix is free software; you can redistribute it and/or modify
    12   * it under the terms of the GNU Lesser Public License as published by
    13   * the Free Software Foundation; either version 2.1 of the License, or
    14   * any later version.
    15   *
    16   * Heritrix is distributed in the hope that it will be useful,
    17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19   * GNU Lesser Public License for more details.
    20   *
    21   * You should have received a copy of the GNU Lesser Public License
    22   * along with Heritrix; if not, write to the Free Software
    23   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24   */
    25  package org.archive.util;
    26
    27  import java.util.HashMap;
    28  import java.util.Iterator;
    29  import java.util.Map;
    30
    31  import javax.management.openmbean.CompositeData;
    32  import javax.management.openmbean.CompositeDataSupport;
    33  import javax.management.openmbean.CompositeType;
    34  import javax.management.openmbean.OpenDataException;
    35
    36  import junit.framework.TestCase;
    37
    38  public class JmxUtilsTest extends TestCase {
    39      public void testCreateCompositeType() throws OpenDataException {
    40          Map<String,Object> m =  new HashMap<String,Object>();
    41          m.put("0", new Long(0));
    42          m.put("1", new Double(1));
    43          m.put("2", "2");
    44          CompositeType ct = JmxUtils.createCompositeType(m, "ct", "description");
    45          testCompositeDataHasMapContent(ct, m);
    46          // Now mess with the order.
    47          Map<String,Object> n = new HashMap<String,Object>();
    48          n.put("0", new Long(17));
    49          n.put("2", "Some old string");
    50          n.put("1", new Double(17.45));
    51          testCompositeDataHasMapContent(ct, n);
    52      }
    53
    54      private void testCompositeDataHasMapContent(final CompositeType ct,
    55              final Map m)
    56      throws OpenDataException {
    57          CompositeData cd = new CompositeDataSupport(ct, m);
    58          for (final Iterator i = m.keySet().iterator(); i.hasNext();) {
    59              String key = (String)i.next();
    60              assertTrue(cd.containsKey(key));
    61              assertEquals(m.get(key), cd.get(key));
    62          }
    63      }
    64
    65  }