KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > AttributesUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jmx.test;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import junit.framework.Test;
28
29 import org.jboss.test.JBossTestCase;
30
31 /** Tests of mbean attributes.
32  *
33  * @author Scott.Stark@jboss.org
34  * @version $Revision: 37406 $
35  */

36 public class AttributesUnitTestCase
37    extends JBossTestCase
38 {
39    public AttributesUnitTestCase(String JavaDoc name)
40    {
41       super(name);
42    }
43
44    public static Test suite()
45       throws Exception JavaDoc
46    {
47       return getDeploySetup(AttributesUnitTestCase.class, "attrtest.sar");
48    }
49
50    public void testXmlString()
51       throws Exception JavaDoc
52    {
53       getLog().info("+++ testXmlString");
54       MBeanServerConnection JavaDoc server = super.getServer();
55       ObjectName JavaDoc serviceName = new ObjectName JavaDoc("test:name=AttrTests,case=#1");
56       String JavaDoc xml = (String JavaDoc) server.getAttribute(serviceName, "XmlString");
57       getLog().info("XmlString: '"+xml+"'");
58       String JavaDoc expectedXml = "<depinfo>\n<value name='abc'>A Value</value>\n</depinfo>";
59       assertTrue("xml cdata as expected", xml.equals(expectedXml));
60    }
61
62    public void testSysPropRef()
63       throws Exception JavaDoc
64    {
65       MBeanServerConnection JavaDoc server = super.getServer();
66       ObjectName JavaDoc serviceName = new ObjectName JavaDoc("test:name=AttrTests,case=#1");
67       String JavaDoc prop = (String JavaDoc) server.getAttribute(serviceName, "SysPropRef");
68       assertTrue("prop has been replaced", prop.equals("${java.vm.version}") == false);
69    }
70
71    public void testTrimedString()
72       throws Exception JavaDoc
73    {
74       MBeanServerConnection JavaDoc server = super.getServer();
75       ObjectName JavaDoc serviceName = new ObjectName JavaDoc("test:name=AttrTests,case=#1");
76       String JavaDoc prop = (String JavaDoc) server.getAttribute(serviceName, "TrimedString");
77       assertTrue("whitespace is trimed", prop.equals("123456789"));
78    }
79
80    public void testSysPropRefNot()
81       throws Exception JavaDoc
82    {
83       MBeanServerConnection JavaDoc server = super.getServer();
84       ObjectName JavaDoc serviceName = new ObjectName JavaDoc("test:name=AttrTests,case=#2");
85       String JavaDoc prop = (String JavaDoc) server.getAttribute(serviceName, "SysPropRef");
86       assertTrue("prop has NOT been replaced", prop.equals("${java.vm.version}"));
87    }
88
89    public void testTrimedStringNot()
90       throws Exception JavaDoc
91    {
92       MBeanServerConnection JavaDoc server = super.getServer();
93       ObjectName JavaDoc serviceName = new ObjectName JavaDoc("test:name=AttrTests,case=#2");
94       String JavaDoc prop = (String JavaDoc) server.getAttribute(serviceName, "TrimedString");
95       assertTrue("whitespace is NOT trimed", prop.equals(" 123456789 "));
96    }
97 }
98
Popular Tags