KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jcaprops > test > JBossRaXmlOverrideUnitTestCase


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.jcaprops.test;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.AttributeList JavaDoc;
26 import javax.management.MBeanServerConnection JavaDoc;
27
28 import junit.framework.Test;
29
30 import org.jboss.test.JBossTestCase;
31 import org.jboss.test.jcaprops.support.PropertyTestResourceAdapterMBean;
32
33 /**
34  * A JBossRaXmlOverrideTestCase.
35  *
36  * @author <a HREF="weston.price@jboss.com">Weston Price</a>
37  * @version $Revision: 46110 $
38  */

39 public class JBossRaXmlOverrideUnitTestCase extends JBossTestCase
40 {
41
42    public JBossRaXmlOverrideUnitTestCase(String JavaDoc name)
43    {
44       super(name);
45    }
46    
47    public void testJBossRaXmlOverride() throws Exception JavaDoc
48    {
49       
50       AttributeList JavaDoc expected = new AttributeList JavaDoc();
51       expected.add(new Attribute JavaDoc("StringRAR", "XMLOVERRIDE"));
52       expected.add(new Attribute JavaDoc("BooleanRAR", Boolean.FALSE));
53       expected.add(new Attribute JavaDoc("ByteRAR", new Byte JavaDoc((byte) 1)));
54       expected.add(new Attribute JavaDoc("CharacterRAR", new Character JavaDoc('A')));
55       expected.add(new Attribute JavaDoc("ShortRAR", new Short JavaDoc((short) 2)));
56       expected.add(new Attribute JavaDoc("IntegerRAR", new Integer JavaDoc(3)));
57       expected.add(new Attribute JavaDoc("LongRAR", new Long JavaDoc(4)));
58       expected.add(new Attribute JavaDoc("FloatRAR", Float.valueOf("5e6")));
59       expected.add(new Attribute JavaDoc("DoubleRAR", Double.valueOf("7e8")));
60       MBeanServerConnection JavaDoc connection = getServer();
61       AttributeList JavaDoc result = connection.getAttributes(PropertyTestResourceAdapterMBean.NAME, getExpectedStringArray(expected));
62       
63       AttributeList JavaDoc resultClone = (AttributeList JavaDoc) result.clone();
64       resultClone.removeAll(expected);
65       assertTrue("Did not expect: " + list(resultClone) + " expected " + list(expected), resultClone.size() == 0);
66       
67       expected.removeAll(result);
68       assertTrue("Expected: " + list(expected) + " got " + list(result), expected.size() == 0);
69
70    }
71    
72    public static Test suite() throws Exception JavaDoc
73    {
74       return getDeploySetup(JBossRaXmlOverrideUnitTestCase.class, "testjcaprops-override.rar");
75    }
76    
77    protected String JavaDoc[] getExpectedStringArray(AttributeList JavaDoc attributes)
78    {
79       String JavaDoc[] result = new String JavaDoc[attributes.size()];
80       for (int i = 0; i < attributes.size(); ++i)
81          result [i] = ((Attribute JavaDoc) attributes.get(i)).getName();
82       return result;
83    }
84    
85    protected String JavaDoc list(AttributeList JavaDoc list)
86    {
87       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
88       buffer.append('[');
89       for (int i = 0; i < list.size(); ++i)
90       {
91          Attribute JavaDoc attribute = (Attribute JavaDoc) list.get(i);
92          buffer.append(attribute.getName());
93          buffer.append('=');
94          buffer.append(attribute.getValue());
95          if (i+1 < list.size())
96             buffer.append(", ");
97       }
98       buffer.append(']');
99       return buffer.toString();
100    }
101    
102    
103 }
104
Popular Tags