KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > management > mbeans > TestAbstractDynamicMBean


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.management.mbeans;
16
17 import javax.management.Attribute JavaDoc;
18 import javax.management.AttributeList JavaDoc;
19 import javax.management.MBeanInfo JavaDoc;
20
21 import junit.framework.TestCase;
22
23 /**
24  * Test of {@link org.apache.hivemind.management.mbeans.AbstractDynamicMBean}
25  *
26  * @author Achim Huegen
27  */

28 public class TestAbstractDynamicMBean extends TestCase
29 {
30     public void testMBeanInfo()
31     {
32         ConcreteMBean mbean = new ConcreteMBean();
33         MBeanInfo JavaDoc beanInfo = mbean.getMBeanInfo();
34         assertEquals(2, beanInfo.getAttributes().length);
35         assertEquals("attribute1", beanInfo.getAttributes()[0].getName());
36         assertEquals("attribute2", beanInfo.getAttributes()[1].getName());
37         assertEquals("constructor", beanInfo.getConstructors()[0].getName());
38         assertEquals("notification", beanInfo.getNotifications()[0].getName());
39         assertEquals("operation", beanInfo.getOperations()[0].getName());
40     }
41
42     public void testGetAttributes() throws Exception JavaDoc
43     {
44         ConcreteMBean mbean = new ConcreteMBean();
45         AttributeList JavaDoc list = mbean.getAttributes(new String JavaDoc[]
46         { "attribute1", "attribute2" });
47         assertEquals("value1", ((Attribute JavaDoc) list.get(0)).getValue());
48         assertEquals("value2", ((Attribute JavaDoc) list.get(1)).getValue());
49     }
50
51     public void testSetAttributes() throws Exception JavaDoc
52     {
53         ConcreteMBean mbean = new ConcreteMBean();
54
55         AttributeList JavaDoc list = new AttributeList JavaDoc();
56         list.add(new Attribute JavaDoc("attribute1", "newvalue1"));
57         list.add(new Attribute JavaDoc("attribute2", "newvalue2"));
58         mbean.setAttributes(list);
59         assertEquals("newvalue1", mbean.getAttribute("attribute1"));
60         assertEquals("newvalue2", mbean.getAttribute("attribute2"));
61     }
62 }
63
64
Popular Tags