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