KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > util > JmxUtilsTest


1 /* JmxUtilsTest.java
2  *
3  * $Id: JmxUtilsTest.java,v 1.1.10.1 2007/01/13 01:31:39 stack-sf Exp $
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 JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30
31 import javax.management.openmbean.CompositeData JavaDoc;
32 import javax.management.openmbean.CompositeDataSupport JavaDoc;
33 import javax.management.openmbean.CompositeType JavaDoc;
34 import javax.management.openmbean.OpenDataException JavaDoc;
35
36 import junit.framework.TestCase;
37
38 public class JmxUtilsTest extends TestCase {
39     public void testCreateCompositeType() throws OpenDataException JavaDoc {
40         Map JavaDoc<String JavaDoc,Object JavaDoc> m = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
41         m.put("0", new Long JavaDoc(0));
42         m.put("1", new Double JavaDoc(1));
43         m.put("2", "2");
44         CompositeType JavaDoc ct = JmxUtils.createCompositeType(m, "ct", "description");
45         testCompositeDataHasMapContent(ct, m);
46         // Now mess with the order.
47
Map JavaDoc<String JavaDoc,Object JavaDoc> n = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
48         n.put("0", new Long JavaDoc(17));
49         n.put("2", "Some old string");
50         n.put("1", new Double JavaDoc(17.45));
51         testCompositeDataHasMapContent(ct, n);
52     }
53
54     private void testCompositeDataHasMapContent(final CompositeType JavaDoc ct,
55             final Map JavaDoc m)
56     throws OpenDataException JavaDoc {
57         CompositeData JavaDoc cd = new CompositeDataSupport JavaDoc(ct, m);
58         for (final Iterator JavaDoc i = m.keySet().iterator(); i.hasNext();) {
59             String JavaDoc key = (String JavaDoc)i.next();
60             assertTrue(cd.containsKey(key));
61             assertEquals(m.get(key), cd.get(key));
62         }
63     }
64
65 }
66
Popular Tags