1 25 package org.objectweb.jonas.jtests.clients.service; 26 27 import java.io.BufferedReader ; 28 import java.io.BufferedWriter ; 29 import java.io.File ; 30 import java.io.InputStream ; 31 import java.io.InputStreamReader ; 32 import java.io.Reader ; 33 import java.io.StringReader ; 34 import java.io.StringWriter ; 35 import java.net.URL ; 36 import java.util.HashMap ; 37 import java.util.Map ; 38 import java.util.Properties ; 39 import javax.naming.RefAddr ; 40 import javax.naming.Reference ; 41 import javax.naming.StringRefAddr ; 42 import javax.xml.namespace.QName ; 43 import junit.framework.Test; 44 import junit.framework.TestSuite; 45 import org.objectweb.jonas_lib.deployment.digester.JDigester; 46 import org.objectweb.jonas_lib.deployment.rules.JonasServiceRefRuleSet; 47 import org.objectweb.jonas_lib.deployment.rules.ServiceRefRuleSet; 48 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 49 import org.objectweb.jonas_ws.deployment.api.WSDLFile; 50 51 import org.objectweb.jonas.common.JNDIUtils; 52 import org.objectweb.jonas.jtests.util.JWebServicesTestCase; 53 import org.objectweb.jonas.ws.JServiceFactory; 54 import org.objectweb.jonas.ws.axis.JAxisServiceFactory; 55 56 59 public class F_AxisService extends JWebServicesTestCase { 60 private String resources = null; 61 62 private JServiceFactory jfactory = null; 63 64 public F_AxisService(String name) { 65 super(name); 66 } 67 68 public static Test suite() { 69 return new TestSuite(F_AxisService.class); 70 } 71 72 public void setUp() throws Exception { 73 super.setUp(); 74 resources = System.getProperty("ws.resources"); 75 jfactory = new JAxisServiceFactory(); 76 } 77 78 public void tearDown() throws Exception { 79 jfactory = null; 80 super.tearDown(); 81 } 82 83 public void testClientWSDDDefaultWhenWSDDNotSpecified() throws Exception { 84 String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 85 + "<deployment name=\"defaultClientConfig\"" 86 + " xmlns=\"http://xml.apache.org/axis/wsdd/\"" 87 + " xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">\n" 88 + " <globalConfiguration>\n" 89 + " <!-- Add global configurations elements here -->\n" 90 + " <parameter name=\"disablePrettyXML\" value=\"true\"/>\n" 91 + " <parameter name=\"sendMultiRefs\" value=\"false\"/>\n" 92 + " </globalConfiguration>\n" 93 + " <transport name=\"http\" pivot=\"java:org.apache.axis.transport.http.HTTPSender\"/>\n" 94 + " <transport name=\"local\" pivot=\"java:org.apache.axis.transport.local.LocalSender\"/>\n" 95 + " <transport name=\"java\" pivot=\"java:org.apache.axis.transport.java.JavaSender\"/>\n" 96 + "</deployment>\n"; 97 Reference ref = createServiceReference("no-wsdd-specified-j2ee.xml", 98 "no-wsdd-specified-jonas.xml"); 99 assertNotNull("Shouldn't have a wsdd", ref 100 .get(JAxisServiceFactory.REF_CLIENT_CONFIG)); 101 assertEquals("WSDD is not the default one", expected, ref.get( 102 JAxisServiceFactory.REF_CLIENT_CONFIG).getContent()); 103 } 104 105 public void testClientWSDDMergingWhenWSDDSpecified() throws Exception { 106 String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 107 + "<deployment name=\"defaultClientConfig\"" 108 + " xmlns=\"http://xml.apache.org/axis/wsdd/\"" 109 + " xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">\n" 110 + " <globalConfiguration>\n" 111 + " <!-- Add global configurations elements here -->\n" 112 + " <parameter name=\"disablePrettyXML\" value=\"true\"/>\n" 113 + " <parameter name=\"sendMultiRefs\" value=\"false\"/>\n" 114 + " </globalConfiguration>\n" 115 + " <transport name=\"http\" pivot=\"java:org.apache.axis.transport.http.HTTPSender\"/>\n" 116 + " <transport name=\"local\" pivot=\"java:org.apache.axis.transport.local.LocalSender\"/>\n" 117 + " <transport name=\"java\" pivot=\"java:org.apache.axis.transport.java.JavaSender\"/>\n" 118 + " <service name=\"HelloService\"/>\n" + "</deployment>\n"; 119 Reference ref = createServiceReference("wsdd-specified-j2ee.xml", 120 "wsdd-specified-jonas.xml"); 121 assertEquals("Something is missing in serialized WSDD", expected, ref 122 .get(JAxisServiceFactory.REF_CLIENT_CONFIG).getContent()); 123 } 124 125 public void testWSDLUrlWithNoWSDLOverride() throws Exception { 126 Reference ref = createServiceReference("wsdl-url-default-j2ee.xml", 127 "wsdl-url-default-jonas.xml"); 128 assertEquals("WSDL URL is not set appropriately", "file:" 129 + this.resources + "/wsdl/oneService.wsdl", ref.get( 130 JAxisServiceFactory.REF_SERVICE_WSDL).getContent()); 131 } 132 133 public void testWSDLUrlWithWSDLOverride() throws Exception { 134 Reference ref = createServiceReference("wsdl-url-override-j2ee.xml", 135 "wsdl-url-override-jonas.xml"); 136 URL urlMatching = new File (new File (resources, "wsdl"), "twoService.wsdl").toURL(); 138 assertEquals( 139 "WSDL URL is not set appropriately", 140 urlMatching.toString(), 141 ref.get(JAxisServiceFactory.REF_SERVICE_WSDL).getContent()); 142 } 143 144 public void testServiceQNameWhenNotSpecified() throws Exception { 145 Reference ref = createServiceReference("service-qname-auto-j2ee.xml", 146 "service-qname-auto-jonas.xml"); 147 QName exp = new QName ("http://hello.simple", "HelloWsService"); 148 QName auto = (QName ) JNDIUtils.getObjectFromBytes((byte[]) ref.get( 149 JAxisServiceFactory.REF_SERVICE_QNAME).getContent()); 150 assertEquals("Service QName is incorrect", exp, auto); 151 } 152 153 public void testServiceQNameWhenExplicitelySet() throws Exception { 154 Reference ref = createServiceReference( 155 "service-qname-explicit-j2ee.xml", 156 "service-qname-explicit-jonas.xml"); 157 QName exp = new QName ("http://hello.simple", "HelloWsService2"); 158 QName auto = (QName ) JNDIUtils.getObjectFromBytes((byte[]) ref.get( 159 JAxisServiceFactory.REF_SERVICE_QNAME).getContent()); 160 assertEquals("Service QName is incorrect", exp, auto); 161 } 162 163 public void testPort2WSDLMapWhenNoPortComponentRefSpecified() 164 throws Exception { 165 Reference ref = createServiceReference("no-port2wsdl-map-j2ee.xml", 166 "no-port2wsdl-map-jonas.xml"); 167 assertNull("Shouldn't have a Port2WSDL Map", ref 168 .get(JAxisServiceFactory.REF_SERVICE_PORT2WSDL)); 169 } 170 171 public void testPort2WSDLMapWithMultiplePortComponent() throws Exception { 172 Reference ref = createServiceReference("port2wsdl-map-j2ee.xml", 173 "port2wsdl-map-jonas.xml"); 174 Map exp = new HashMap (); 175 exp.put("org.objectweb.jonas.jtests.hello.HelloWs", new QName ( 176 "http://hello.simple", "HelloPortComponent")); 177 exp.put("org.objectweb.jonas.jtests.hello.HelloWs2", new QName ( 178 "http://hello.simple", "HelloPortComponent2")); 179 Map returned = (Map ) JNDIUtils.getObjectFromBytes((byte[]) ref.get( 180 JAxisServiceFactory.REF_SERVICE_PORT2WSDL).getContent()); 181 assertEquals("Map are not identical", exp, returned); 182 } 183 184 public void testStubPropertiesNull() throws Exception { 185 Reference ref = createServiceReference("stub-props-null-j2ee.xml", 186 "stub-props-null-jonas.xml"); 187 assertNull("Stub properties should be null", ref 188 .get(JAxisServiceFactory.REF_SERVICE_STUB_PROPS 189 + "_HelloPortComponent")); 190 } 191 192 public void testStubPropertiesEmpty() throws Exception { 193 Reference ref = createServiceReference("stub-props-empty-j2ee.xml", 194 "stub-props-empty-jonas.xml"); 195 RefAddr ra = ref.get(JAxisServiceFactory.REF_SERVICE_STUB_PROPS 196 + "_HelloPortComponent"); 197 assertNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_STUB_PROPS 198 + "_HelloPortComponent" + " must be null", ra); 199 RefAddr ra2 = ref.get(JAxisServiceFactory.REF_SERVICE_STUB_PROPS 200 + "_HelloPortComponent2"); 201 assertNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_STUB_PROPS 202 + "_HelloPortComponent2" + " must be null", ra2); 203 } 204 205 public void testStubPropertiesForGivenPortName() throws Exception { 206 Reference ref = createServiceReference("stub-props-j2ee.xml", 207 "stub-props-jonas.xml"); 208 RefAddr ra = ref.get(JAxisServiceFactory.REF_SERVICE_STUB_PROPS 210 + "_HelloPortComponent"); 211 assertNotNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_STUB_PROPS 212 + "_HelloPortComponent" + " must be not null", ra); 213 Map returned = (Map ) JNDIUtils.getObjectFromBytes((byte[]) ra 214 .getContent()); 215 assertFalse("Stub properties shouldn't be empty", returned.isEmpty()); 216 Properties exp = new Properties (); 217 exp.setProperty("my.test.property", "test.value"); 218 exp.setProperty("my.test.property.2", "test.value.2"); 219 assertEquals( 220 "Stub Properties for port 'HelloPortComponent' not identical", 221 exp, returned); 222 RefAddr ra2 = ref.get(JAxisServiceFactory.REF_SERVICE_STUB_PROPS 224 + "_HelloPortComponent2"); 225 assertNotNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_STUB_PROPS 226 + "_HelloPortComponent2" + " must be not null", ra2); 227 Map returned2 = (Map ) JNDIUtils.getObjectFromBytes((byte[]) ra2 228 .getContent()); 229 assertFalse("Stub properties shouldn't be empty", returned2.isEmpty()); 230 Properties exp2 = new Properties (); 231 exp2.setProperty("other.test.property", "test.value"); 232 exp2.setProperty("other.test.property.2", "test.value.2"); 233 assertEquals( 234 "Stub Properties for port 'HelloPortComponent' not identical", 235 exp2, returned2); 236 } 237 238 public void testCallPropertiesNull() throws Exception { 239 Reference ref = createServiceReference("call-props-null-j2ee.xml", 240 "call-props-null-jonas.xml"); 241 assertNull("Call properties should be null", ref 242 .get(JAxisServiceFactory.REF_SERVICE_CALL_PROPS 243 + "_HelloPortComponent")); 244 } 245 246 public void testCallPropertiesEmpty() throws Exception { 247 Reference ref = createServiceReference("call-props-empty-j2ee.xml", 248 "call-props-empty-jonas.xml"); 249 RefAddr ra = ref.get(JAxisServiceFactory.REF_SERVICE_CALL_PROPS 250 + "_HelloPortComponent"); 251 assertNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_CALL_PROPS 252 + "_HelloPortComponent" + " must be null", ra); 253 RefAddr ra2 = ref.get(JAxisServiceFactory.REF_SERVICE_CALL_PROPS 254 + "_HelloPortComponent2"); 255 assertNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_CALL_PROPS 256 + "_HelloPortComponent2" + " must be null", ra2); 257 } 258 259 public void testCallPropertiesForGivenPortName() throws Exception { 260 Reference ref = createServiceReference("call-props-j2ee.xml", 261 "call-props-jonas.xml"); 262 RefAddr ra = ref.get(JAxisServiceFactory.REF_SERVICE_CALL_PROPS 264 + "_HelloPortComponent"); 265 assertNotNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_CALL_PROPS 266 + "_HelloPortComponent" + " must be not null", ra); 267 Map returned = (Map ) JNDIUtils.getObjectFromBytes((byte[]) ra 268 .getContent()); 269 assertFalse("Stub properties shouldn't be empty", returned.isEmpty()); 270 Properties exp = new Properties (); 271 exp.setProperty("my.test.property", "test.value"); 272 exp.setProperty("my.test.property.2", "test.value.2"); 273 assertEquals( 274 "Stub Properties for port 'HelloPortComponent' not identical", 275 exp, returned); 276 RefAddr ra2 = ref.get(JAxisServiceFactory.REF_SERVICE_CALL_PROPS 278 + "_HelloPortComponent2"); 279 assertNotNull("RefAddr " + JAxisServiceFactory.REF_SERVICE_CALL_PROPS 280 + "_HelloPortComponent2" + " must be not null", ra2); 281 Map returned2 = (Map ) JNDIUtils.getObjectFromBytes((byte[]) ra2 282 .getContent()); 283 assertFalse("Call properties shouldn't be empty", returned2.isEmpty()); 284 Properties exp2 = new Properties (); 285 exp2.setProperty("other.test.property", "test.value"); 286 exp2.setProperty("other.test.property.2", "test.value.2"); 287 assertEquals( 288 "Call Properties for port 'HelloPortComponent' not identical", 289 exp2, returned2); 290 } 291 292 public void testPortNameListEmpty() throws Exception { 293 Reference ref = createServiceReference("port-name-list-empty-j2ee.xml", 294 "port-name-list-empty-jonas.xml"); 295 assertNull(JAxisServiceFactory.REF_SERVICE_WSDL_PORT_LIST 296 + " should be null", ref 297 .get(JAxisServiceFactory.REF_SERVICE_WSDL_PORT_LIST)); 298 } 299 300 public void testPortNameListWithMultiplePortComponent() throws Exception { 301 Reference ref = createServiceReference("port-name-list-j2ee.xml", 302 "port-name-list-jonas.xml"); 303 RefAddr ra = ref.get(JAxisServiceFactory.REF_SERVICE_WSDL_PORT_LIST); 304 assertNotNull(JAxisServiceFactory.REF_SERVICE_WSDL_PORT_LIST 305 + " shouldn't be null", ra); 306 assertEquals("portname list incorrect", 307 "HelloPortComponent,HelloPortComponent2", ra.getContent()); 308 } 309 310 private Reference createServiceReference(String standard, String specific) 311 throws Exception { 312 ServiceRefDesc sr = createServiceRefDesc(standard, specific); 314 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 315 return jfactory.getServiceReference(sr, cl); 316 } 317 318 public void testGetObjectInstance() throws Exception { 319 String cfg = "<deployment xmlns=\"http://xml.apache.org/axis/wsdd/\" " 320 + "xmlns:java=\"http://xml.apache.org/axis/wsdd/providers/java\">" 321 + "<service name=\"AxisServiceTest\"/>" 322 + "<transport name=\"java\" pivot=\"java:org.apache.axis.transport.java.JavaSender\"/>" 323 + "<transport name=\"http\" pivot=\"java:org.apache.axis.transport.http.HTTPSender\"/>" 324 + "<transport name=\"local\" pivot=\"java:org.apache.axis.transport.local.LocalSender\"/>" 325 + "</deployment>"; 326 Reference ref = new Reference ( 327 "org.objectweb.jonas.jtests.hello.HelloWsServiceLocator", 328 jfactory.getClass().getName(), null); 329 ref.add(new StringRefAddr (JAxisServiceFactory.REF_CLIENT_CONFIG, cfg)); 330 try { 331 jfactory.getObjectInstance(ref, null, null, null); 332 } catch (Exception e) { 333 fail("JAxisServiceFactory.getObjectInstance has failed " + e); 334 } 335 } 337 338 private ServiceRefDesc createServiceRefDesc(String srFilename, 339 String jsrFilename) throws Exception { 340 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 342 ServiceRefTLE srTopLevel = new ServiceRefTLE(); 343 JDigester serviceRefDigester = new JDigester(new ServiceRefRuleSet(""), 347 true, true, null, null); 348 Reader r = new InputStreamReader (cl.getResourceAsStream(srFilename)); 350 serviceRefDigester.parse(r, srFilename, srTopLevel); 352 JDigester jonasServiceRefDigester = new JDigester( 356 new JonasServiceRefRuleSet(""), true, true, null, null); 357 358 InputStream contentIs = cl.getResourceAsStream(jsrFilename); 360 BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (contentIs)); 361 StringWriter stringWriter = new StringWriter (); 362 String line = null; 363 while (((line = bufferedReader.readLine()) != null)) { 364 if (line.indexOf("@@RESOURCES_DIR@@") != -1) { 365 line = line.replaceAll("@@RESOURCES_DIR@@", "file://" + resources); 366 } 367 stringWriter.write(line); 368 } 369 370 371 372 r = new StringReader (stringWriter.toString()); 374 bufferedReader.close(); 375 stringWriter.close(); 376 jonasServiceRefDigester.parse(r, jsrFilename, srTopLevel); 378 ServiceRefDesc sr = new ServiceRefDesc(cl, srTopLevel.getServiceRef(), 379 srTopLevel.getJonasServiceRef(), resources); 380 381 return sr; 382 } 383 384 public static void main(String args[]) { 385 String testtorun = null; 386 for (int argn = 0; argn < args.length; argn++) { 388 String s_arg = args[argn]; 389 if (s_arg.equals("-n")) { 390 testtorun = args[++argn]; 391 } 392 } 393 if (testtorun == null) { 394 junit.textui.TestRunner.run(suite()); 395 } else { 396 junit.textui.TestRunner.run(new F_AxisService(testtorun)); 397 } 398 } 399 } | Popular Tags |