KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jmx > export > assembler > MethodNameBasedMBeanInfoAssemblerMappedTests


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

16
17 package org.springframework.jmx.export.assembler;
18
19 import java.util.Properties JavaDoc;
20
21 import javax.management.MBeanAttributeInfo JavaDoc;
22 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
23 import javax.management.modelmbean.ModelMBeanInfo JavaDoc;
24
25 /**
26  * @author Rob Harrop
27  */

28 public class MethodNameBasedMBeanInfoAssemblerMappedTests extends AbstractJmxAssemblerTests {
29
30     protected static final String JavaDoc OBJECT_NAME = "bean:name=testBean4";
31
32     public void testGetAgeIsReadOnly() throws Exception JavaDoc {
33         ModelMBeanInfo JavaDoc info = getMBeanInfoFromAssembler();
34         ModelMBeanAttributeInfo JavaDoc attr = info.getAttribute(AGE_ATTRIBUTE);
35
36         assertTrue("Age is not readable", attr.isReadable());
37         assertFalse("Age is not writable", attr.isWritable());
38     }
39
40     public void testWithFallThrough() throws Exception JavaDoc {
41         MethodNameBasedMBeanInfoAssembler assembler =
42                 getWithMapping("foobar", "add,myOperation,getName,setName,getAge");
43         assembler.setManagedMethods(new String JavaDoc[] {"getNickName", "setNickName"});
44
45         ModelMBeanInfo JavaDoc inf = assembler.getMBeanInfo(getBean(), getObjectName());
46         MBeanAttributeInfo JavaDoc attr = inf.getAttribute("NickName");
47
48         assertNickName(attr);
49     }
50
51     public void testNickNameIsExposed() throws Exception JavaDoc {
52         ModelMBeanInfo JavaDoc inf = (ModelMBeanInfo JavaDoc) getMBeanInfo();
53         MBeanAttributeInfo JavaDoc attr = inf.getAttribute("NickName");
54
55         assertNickName(attr);
56     }
57
58     protected String JavaDoc getObjectName() {
59         return OBJECT_NAME;
60     }
61
62     protected int getExpectedOperationCount() {
63         return 7;
64     }
65
66     protected int getExpectedAttributeCount() {
67         return 3;
68     }
69
70     protected MBeanInfoAssembler getAssembler() throws Exception JavaDoc {
71         return getWithMapping("getNickName,setNickName,add,myOperation,getName,setName,getAge");
72     }
73
74     protected String JavaDoc getApplicationContextPath() {
75         return "org/springframework/jmx/export/assembler/methodNameAssemblerMapped.xml";
76     }
77
78     private MethodNameBasedMBeanInfoAssembler getWithMapping(String JavaDoc mapping) {
79         return getWithMapping(OBJECT_NAME, mapping);
80     }
81
82     private MethodNameBasedMBeanInfoAssembler getWithMapping(String JavaDoc name, String JavaDoc mapping) {
83         MethodNameBasedMBeanInfoAssembler assembler = new MethodNameBasedMBeanInfoAssembler();
84         Properties JavaDoc props = new Properties JavaDoc();
85         props.setProperty(name, mapping);
86         assembler.setMethodMappings(props);
87         return assembler;
88     }
89
90     private void assertNickName(MBeanAttributeInfo JavaDoc attr) {
91         assertNotNull("Nick Name should not be null", attr);
92         assertTrue("Nick Name should be writable", attr.isWritable());
93         assertTrue("Nick Name should be readab;e", attr.isReadable());
94     }
95
96 }
97
Popular Tags