1 25 package org.objectweb.jonas.jtests.clients.mbeans; 26 27 import java.util.Properties ; 28 29 import javax.management.ObjectName ; 30 import javax.management.j2ee.Management ; 31 import javax.management.j2ee.ManagementHome ; 32 import javax.naming.InitialContext ; 33 import javax.rmi.PortableRemoteObject ; 34 35 import junit.framework.Test; 36 import junit.framework.TestSuite; 37 38 import org.objectweb.jonas.jtests.util.JWebServicesTestCase; 39 40 45 public class F_WebServicesMBeans extends JWebServicesTestCase { 46 47 50 private Management mejb = null; 51 52 55 private static final String SERVICE_MBEAN_ON = "jonas:type=WebService,name=TimeWebService,J2EEServer=jonas,J2EEApplication=time-test,EJBModule=time"; 56 57 60 private static final String PC_MBEAN_ON = "jonas:type=WebServicePortComponent,name=TimePort,WebService=TimeWebService,J2EEServer=jonas,EJBModule=time,J2EEApplication=time-test"; 61 62 65 private static final String HANDLER_MBEAN_ON = "jonas:type=WebServiceHandler,name=TimeBeanHandler,WebServicePortComponent=TimePort,EJBModule=time,J2EEServer=jonas,J2EEApplication=time-test,WebService=TimeWebService"; 66 67 70 private static final String SSB_MBEAN_ON = "jonas:j2eeType=StatelessSessionBean,name=TimeBeanSLR,EJBModule=time,J2EEApplication=time-test,J2EEServer=jonas"; 71 72 74 77 private static final String [] SERVICE_PCS_ATT = new String [] { PC_MBEAN_ON }; 78 79 82 private static final String [] PC_HANDLERS_ATT = new String [] { HANDLER_MBEAN_ON }; 83 84 87 private static final String [] SOAP_HEADERS = new String [] { }; 88 89 92 private static final String [] SOAP_ROLES = new String [] { }; 93 94 97 private static Properties INIT_PARAMS = null; 98 99 104 private static class WsTest { 105 108 public String name; 109 110 113 public Class type; 114 115 118 public Object expected; 119 120 123 public boolean isObjectName; 124 125 131 public WsTest(String name, Class type, Object expected) { 132 this(name, type, expected, false); 133 } 134 135 141 public WsTest(String name, Class type, Object expected, boolean on) { 142 super(); 143 this.name = name; 144 this.type = type; 145 this.expected = expected; 146 this.isObjectName = on; 147 } 148 } 149 150 153 private WsTest[] SERVICE_TEST = null; 154 155 158 private WsTest[] PORT_TEST = null; 159 160 163 private WsTest[] HANDLER_TEST = null; 164 165 168 private boolean initialized = false; 169 170 public F_WebServicesMBeans(String s) { 171 super(s); 172 } 173 174 public static Test suite() { 175 return new TestSuite(F_WebServicesMBeans.class); 176 } 177 178 public void setUp() throws Exception { 179 super.setUp(); 180 useEar("time-test"); 181 mejb = getMEJB(); 182 if (!initialized) { 183 initTestsTables(); 184 initialized = true; 185 } 186 } 187 188 191 private void initTestsTables() { 192 193 INIT_PARAMS = new Properties (); 194 INIT_PARAMS.put("jonas.test.server.handler", "JOnAS"); 195 196 SERVICE_TEST = new WsTest[] { 197 new WsTest("name", java.lang.String .class, "TimeWebService"), 198 new WsTest("portComponents", java.lang.String [].class, SERVICE_PCS_ATT, true), 199 new WsTest("wsdlURL", java.lang.String .class, getAbsoluteUrl("/time/TimePort/TimePort?JWSDL")), 200 new WsTest("mappingFilename", java.lang.String .class, "META-INF/mapping.xml"), 201 new WsTest("wsdlFilename", java.lang.String .class, "META-INF/wsdl/TimePort.wsdl") }; 202 203 PORT_TEST = new WsTest[] { 204 new WsTest("name", java.lang.String .class, "TimePort"), 205 new WsTest("handlers", java.lang.String [].class, PC_HANDLERS_ATT, true), 206 new WsTest("wsdlPort", java.lang.String .class, "{jonas:Time}TimePort"), 207 new WsTest("serviceEndpointInterface", java.lang.String .class, "org.objectweb.jonas.jtests.beans.time.TimeEndpoint"), 208 new WsTest("endpoint", java.lang.String .class, getAbsoluteUrl("/time/TimePort/TimePort")), 209 new WsTest("implementationBean", java.lang.String .class, SSB_MBEAN_ON, true) }; 210 211 HANDLER_TEST = new WsTest[] { 212 new WsTest("name", java.lang.String .class, "TimeBeanHandler"), 213 new WsTest("classname", java.lang.String .class, "org.objectweb.jonas.jtests.beans.time.TimeBeanHandler"), 214 new WsTest("soapHeaders", java.lang.String [].class, SOAP_HEADERS), 215 new WsTest("soapRoles", java.lang.String [].class, SOAP_ROLES), 216 new WsTest("initParams", java.util.Properties .class, INIT_PARAMS) }; 217 218 } 219 220 221 private Management getMEJB() throws Exception { 222 InitialContext ic = new InitialContext (); 223 Object o = ic.lookup("ejb/mgmt/MEJB"); 224 ManagementHome home = (ManagementHome ) PortableRemoteObject.narrow(o, ManagementHome .class); 225 return home.create(); 226 } 227 228 public void tearDown() throws Exception { 229 super.tearDown(); 230 mejb = null; 231 } 232 233 public void testWebServiceMBean() throws Exception { 234 checkMBean(SERVICE_MBEAN_ON, SERVICE_TEST); 235 } 236 237 public void testPortComponentMBean() throws Exception { 238 checkMBean(PC_MBEAN_ON, PORT_TEST); 239 String se = (String ) mejb.getAttribute(new ObjectName (PC_MBEAN_ON), "implementationBean"); 241 assertTrue("implementationBean MBean must be registered", mejb.isRegistered(new ObjectName (se))); 242 } 243 244 public void testHandlerMBean() throws Exception { 245 checkMBean(HANDLER_MBEAN_ON, HANDLER_TEST); 246 } 247 248 private void checkMBean(String onStr, WsTest[] tests) throws Exception { 249 ObjectName on = ObjectName.getInstance(onStr); 250 assertTrue("ObjectName not registered " + on, mejb.isRegistered(on)); 251 252 for (int i = 0; i < tests.length; i++) { 253 254 boolean isObjectName = tests[i].isObjectName; 255 256 Object o = mejb.getAttribute(on, tests[i].name); 257 assertNotNull("Cannot retrieve attribute '" + tests[i].name 258 + "' from " + on, o); 259 assertEquals("Expecting type " + tests[i].type + " for attribute " 260 + tests[i].name, tests[i].type, o.getClass()); 261 if (tests[i].type.isArray()) { 262 Object [] a1 = (Object []) o; 263 Object [] a2 = (Object []) tests[i].expected; 264 assertEquals("'" + tests[i].name + "' Array size error", a2.length, a1.length); 265 266 for (int j = 0; j < a1.length; j++) { 267 if (isObjectName) { 268 assertEquals("'" + tests[i].name + "[" + j + "]' mismatch", new ObjectName ((String ) a2[j]), new ObjectName ((String ) a1[j])); 269 } else { 270 assertEquals("'" + tests[i].name + "[" + j + "]' mismatch", a2[j], a1[j]); 271 } 272 } 273 } else { 274 if (isObjectName) { 275 assertEquals("'" + tests[i].name + "' mismatch", new ObjectName ((String ) tests[i].expected), new ObjectName ((String ) o)); 276 } else { 277 assertEquals("'" + tests[i].name + "' mismatch", tests[i].expected, o); 278 } 279 } 280 } 281 } 282 283 } 284 | Popular Tags |