KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.lang.reflect.Method JavaDoc;
25
26 import javax.management.Attribute JavaDoc;
27 import javax.management.AttributeList JavaDoc;
28 import javax.management.MBeanServerConnection JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.naming.InitialContext JavaDoc;
31
32 import junit.framework.Test;
33
34 import org.jboss.test.JBossTestCase;
35 import org.jboss.test.jcaprops.support.PropertyTestActivationSpecMBean;
36 import org.jboss.test.jcaprops.support.PropertyTestAdminObject;
37 import org.jboss.test.jcaprops.support.PropertyTestResourceAdapterMBean;
38
39 /**
40  * A GoodrarUnitTestCase.
41  *
42  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
43  * @version $Revision: 37406 $
44  */

45 public class UpperGoodrarUnitTestCase extends JBossTestCase
46 {
47    public UpperGoodrarUnitTestCase(String JavaDoc name)
48    {
49       super(name);
50    }
51    
52    public static Test suite() throws Exception JavaDoc
53    {
54       return getDeploySetup(UpperGoodrarUnitTestCase.class, "testjcaprops-upper-good.rar");
55    }
56
57    public void testRARProperties() throws Exception JavaDoc
58    {
59       AttributeList JavaDoc expected = new AttributeList JavaDoc();
60       expected.add(new Attribute JavaDoc("StringRAR", "StringFromRARProperties"));
61       expected.add(new Attribute JavaDoc("BooleanRAR", Boolean.TRUE));
62       expected.add(new Attribute JavaDoc("ByteRAR", new Byte JavaDoc((byte) 1)));
63       expected.add(new Attribute JavaDoc("CharacterRAR", new Character JavaDoc('A')));
64       expected.add(new Attribute JavaDoc("ShortRAR", new Short JavaDoc((short) 2)));
65       expected.add(new Attribute JavaDoc("IntegerRAR", new Integer JavaDoc(3)));
66       expected.add(new Attribute JavaDoc("LongRAR", new Long JavaDoc(4)));
67       expected.add(new Attribute JavaDoc("FloatRAR", Float.valueOf("5e6")));
68       expected.add(new Attribute JavaDoc("DoubleRAR", Double.valueOf("7e8")));
69       MBeanServerConnection JavaDoc connection = getServer();
70       AttributeList JavaDoc result = connection.getAttributes(PropertyTestResourceAdapterMBean.NAME, getExpectedStringArray(expected));
71       
72       AttributeList JavaDoc resultClone = (AttributeList JavaDoc) result.clone();
73       resultClone.removeAll(expected);
74       assertTrue("Did not expect: " + list(resultClone) + " expected " + list(expected), resultClone.size() == 0);
75       
76       expected.removeAll(result);
77       assertTrue("Expected: " + list(expected) + " got " + list(result), expected.size() == 0);
78    }
79
80    public void testASProperties() throws Exception JavaDoc
81    {
82       AttributeList JavaDoc expected = new AttributeList JavaDoc();
83       expected.add(new Attribute JavaDoc("StringAS", "StringFromASProperties"));
84       expected.add(new Attribute JavaDoc("BooleanAS", Boolean.TRUE));
85       expected.add(new Attribute JavaDoc("ByteAS", new Byte JavaDoc((byte) 11)));
86       expected.add(new Attribute JavaDoc("CharacterAS", new Character JavaDoc('B')));
87       expected.add(new Attribute JavaDoc("ShortAS", new Short JavaDoc((short) 12)));
88       expected.add(new Attribute JavaDoc("IntegerAS", new Integer JavaDoc(13)));
89       expected.add(new Attribute JavaDoc("LongAS", new Long JavaDoc(14)));
90       expected.add(new Attribute JavaDoc("FloatAS", Float.valueOf("5e16")));
91       expected.add(new Attribute JavaDoc("DoubleAS", Double.valueOf("7e18")));
92       MBeanServerConnection JavaDoc connection = getServer();
93       AttributeList JavaDoc result = connection.getAttributes(PropertyTestActivationSpecMBean.NAME, getExpectedStringArray(expected));
94       
95       AttributeList JavaDoc resultClone = (AttributeList JavaDoc) result.clone();
96       resultClone.removeAll(expected);
97       assertTrue("Did not expect: " + list(resultClone) + " expected " + list(expected), resultClone.size() == 0);
98       
99       expected.removeAll(result);
100       assertTrue("Expected: " + list(expected) + " got " + list(result), expected.size() == 0);
101    }
102
103    public void testMCFProperties() throws Exception JavaDoc
104    {
105       AttributeList JavaDoc expected = new AttributeList JavaDoc();
106       expected.add(new Attribute JavaDoc("StringRAR", "StringFromRARProperties"));
107       expected.add(new Attribute JavaDoc("BooleanRAR", Boolean.TRUE));
108       expected.add(new Attribute JavaDoc("ByteRAR", new Byte JavaDoc((byte) 1)));
109       expected.add(new Attribute JavaDoc("CharacterRAR", new Character JavaDoc('A')));
110       expected.add(new Attribute JavaDoc("ShortRAR", new Short JavaDoc((short) 2)));
111       expected.add(new Attribute JavaDoc("IntegerRAR", new Integer JavaDoc(3)));
112       expected.add(new Attribute JavaDoc("LongRAR", new Long JavaDoc(4)));
113       expected.add(new Attribute JavaDoc("FloatRAR", Float.valueOf("5e6")));
114       expected.add(new Attribute JavaDoc("DoubleRAR", Double.valueOf("7e8")));
115       expected.add(new Attribute JavaDoc("StringMCF", "StringFromMCFProperties"));
116       expected.add(new Attribute JavaDoc("BooleanMCF", Boolean.TRUE));
117       expected.add(new Attribute JavaDoc("ByteMCF", new Byte JavaDoc((byte) 21)));
118       expected.add(new Attribute JavaDoc("CharacterMCF", new Character JavaDoc('C')));
119       expected.add(new Attribute JavaDoc("ShortMCF", new Short JavaDoc((short) 22)));
120       expected.add(new Attribute JavaDoc("IntegerMCF", new Integer JavaDoc(23)));
121       expected.add(new Attribute JavaDoc("LongMCF", new Long JavaDoc(24)));
122       expected.add(new Attribute JavaDoc("FloatMCF", Float.valueOf("5e26")));
123       expected.add(new Attribute JavaDoc("DoubleMCF", Double.valueOf("7e28")));
124       expected.add(new Attribute JavaDoc("StringCD", "StringFromCDProperties"));
125       expected.add(new Attribute JavaDoc("BooleanCD", Boolean.TRUE));
126       expected.add(new Attribute JavaDoc("ByteCD", new Byte JavaDoc((byte) 31)));
127       expected.add(new Attribute JavaDoc("CharacterCD", new Character JavaDoc('D')));
128       expected.add(new Attribute JavaDoc("ShortCD", new Short JavaDoc((short) 32)));
129       expected.add(new Attribute JavaDoc("IntegerCD", new Integer JavaDoc(33)));
130       expected.add(new Attribute JavaDoc("LongCD", new Long JavaDoc(34)));
131       expected.add(new Attribute JavaDoc("FloatCD", Float.valueOf("6e26")));
132       expected.add(new Attribute JavaDoc("DoubleCD", Double.valueOf("8e28")));
133       AttributeList JavaDoc result = getMCFAttributes(expected);
134       
135       AttributeList JavaDoc resultClone = (AttributeList JavaDoc) result.clone();
136       resultClone.removeAll(expected);
137       assertTrue("Did not expect: " + list(resultClone) + " expected " + list(expected), resultClone.size() == 0);
138       
139       expected.removeAll(result);
140       assertTrue("Expected: " + list(expected) + " got " + list(result), expected.size() == 0);
141    }
142
143    public void testAdminObjectProperties() throws Exception JavaDoc
144    {
145       AttributeList JavaDoc expected = new AttributeList JavaDoc();
146       expected.add(new Attribute JavaDoc("StringAOMBean", "StringFromAOMBeanProperties"));
147       expected.add(new Attribute JavaDoc("BooleanAOMBean", Boolean.TRUE));
148       expected.add(new Attribute JavaDoc("ByteAOMBean", new Byte JavaDoc((byte) 21)));
149       expected.add(new Attribute JavaDoc("CharacterAOMBean", new Character JavaDoc('C')));
150       expected.add(new Attribute JavaDoc("ShortAOMBean", new Short JavaDoc((short) 22)));
151       expected.add(new Attribute JavaDoc("IntegerAOMBean", new Integer JavaDoc(23)));
152       expected.add(new Attribute JavaDoc("LongAOMBean", new Long JavaDoc(24)));
153       expected.add(new Attribute JavaDoc("FloatAOMBean", Float.valueOf("5e26")));
154       expected.add(new Attribute JavaDoc("DoubleAOMBean", Double.valueOf("7e28")));
155       expected.add(new Attribute JavaDoc("StringAO", "StringFromAOProperties"));
156       expected.add(new Attribute JavaDoc("BooleanAO", Boolean.TRUE));
157       expected.add(new Attribute JavaDoc("ByteAO", new Byte JavaDoc((byte) 31)));
158       expected.add(new Attribute JavaDoc("CharacterAO", new Character JavaDoc('D')));
159       expected.add(new Attribute JavaDoc("ShortAO", new Short JavaDoc((short) 32)));
160       expected.add(new Attribute JavaDoc("IntegerAO", new Integer JavaDoc(33)));
161       expected.add(new Attribute JavaDoc("LongAO", new Long JavaDoc(34)));
162       expected.add(new Attribute JavaDoc("FloatAO", Float.valueOf("6e26")));
163       expected.add(new Attribute JavaDoc("DoubleAO", Double.valueOf("8e28")));
164       AttributeList JavaDoc result = getAOAttributes(expected);
165       
166       AttributeList JavaDoc resultClone = (AttributeList JavaDoc) result.clone();
167       resultClone.removeAll(expected);
168       assertTrue("Did not expect: " + list(resultClone) + " expected " + list(expected), resultClone.size() == 0);
169       
170       expected.removeAll(result);
171       assertTrue("Expected: " + list(expected) + " got " + list(result), expected.size() == 0);
172    }
173
174    protected AttributeList JavaDoc getMCFAttributes(AttributeList JavaDoc attributes) throws Exception JavaDoc
175    {
176       MBeanServerConnection JavaDoc connection = getServer();
177       ObjectName JavaDoc name = new ObjectName JavaDoc("jboss.jca:service=ManagedConnectionFactory,name=UpperGoodrar");
178       AttributeList JavaDoc result = new AttributeList JavaDoc();
179       for (int i = 0; i < attributes.size(); ++i)
180       {
181          String JavaDoc attributeName = ((Attribute JavaDoc) attributes.get(i)).getName();
182          try
183          {
184             Object JavaDoc value = connection.invoke(name, "getManagedConnectionFactoryAttribute",
185                new Object JavaDoc[] { attributeName }, new String JavaDoc[] { String JavaDoc.class.getName() } );
186             result.add(new Attribute JavaDoc(attributeName, value));
187          }
188          catch (Exception JavaDoc e)
189          {
190             log.debug("Could not retrieve attribute " + attributeName, e);
191          }
192       }
193       return result;
194    }
195    
196    protected AttributeList JavaDoc getAOAttributes(AttributeList JavaDoc attributes) throws Exception JavaDoc
197    {
198       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
199       PropertyTestAdminObject ao = (PropertyTestAdminObject) ctx.lookup("UpperGoodrarAO");
200       AttributeList JavaDoc result = new AttributeList JavaDoc();
201       for (int i = 0; i < attributes.size(); ++i)
202       {
203          String JavaDoc attributeName = ((Attribute JavaDoc) attributes.get(i)).getName();
204          try
205          {
206             String JavaDoc getter = "get" + Character.toUpperCase(attributeName.charAt(0)) + attributeName.substring(1);
207             Method JavaDoc method = PropertyTestAdminObject.class.getMethod(getter, null);
208             Object JavaDoc value = method.invoke(ao, null);
209             result.add(new Attribute JavaDoc(attributeName, value));
210          }
211          catch (Exception JavaDoc e)
212          {
213             log.debug("Could not retrieve attribute " + attributeName, e);
214          }
215       }
216       return result;
217    }
218
219    protected String JavaDoc[] getExpectedStringArray(AttributeList JavaDoc attributes)
220    {
221       String JavaDoc[] result = new String JavaDoc[attributes.size()];
222       for (int i = 0; i < attributes.size(); ++i)
223          result [i] = ((Attribute JavaDoc) attributes.get(i)).getName();
224       return result;
225    }
226    
227    protected String JavaDoc list(AttributeList JavaDoc list)
228    {
229       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
230       buffer.append('[');
231       for (int i = 0; i < list.size(); ++i)
232       {
233          Attribute JavaDoc attribute = (Attribute JavaDoc) list.get(i);
234          buffer.append(attribute.getName());
235          buffer.append('=');
236          buffer.append(attribute.getValue());
237          if (i+1 < list.size())
238             buffer.append(", ");
239       }
240       buffer.append(']');
241       return buffer.toString();
242    }
243 }
244
Popular Tags