1 package org.objectweb.celtix.systest.ws.addressing; 2 3 4 import java.lang.reflect.UndeclaredThrowableException ; 5 import java.net.URL ; 6 import java.util.HashMap ; 7 import java.util.List ; 8 import java.util.Map ; 9 10 import javax.xml.namespace.QName ; 11 import javax.xml.ws.BindingProvider; 12 import javax.xml.ws.ProtocolException; 13 import javax.xml.ws.handler.Handler; 14 15 import junit.framework.Test; 16 import junit.framework.TestSuite; 17 18 import org.objectweb.celtix.bus.ws.addressing.AddressingPropertiesImpl; 19 import org.objectweb.celtix.bus.ws.addressing.ContextUtils; 20 import org.objectweb.celtix.bus.ws.addressing.Names; 21 import org.objectweb.celtix.bus.ws.addressing.soap.VersionTransformer; 22 import org.objectweb.celtix.systest.common.ClientServerSetupBase; 23 import org.objectweb.celtix.systest.common.ClientServerTestBase; 24 import org.objectweb.celtix.ws.addressing.AddressingProperties; 25 import org.objectweb.celtix.ws.addressing.AttributedURIType; 26 27 import org.objectweb.hello_world_soap_http.BadRecordLitFault; 28 import org.objectweb.hello_world_soap_http.Greeter; 29 import org.objectweb.hello_world_soap_http.NoSuchCodeLitFault; 30 import org.objectweb.hello_world_soap_http.SOAPService; 31 import org.objectweb.hello_world_soap_http.types.BareDocumentResponse; 32 33 import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES; 34 35 36 39 public class MAPTest extends ClientServerTestBase implements VerificationCache { 40 41 static final String INBOUND_KEY = "inbound"; 42 static final String OUTBOUND_KEY = "outbound"; 43 private static final QName SERVICE_NAME = 44 new QName ("http://objectweb.org/hello_world_soap_http", "SOAPServiceAddressing"); 45 private static final QName PORT_NAME = 46 new QName ("http://objectweb.org/hello_world_soap_http", "SoapPort"); 47 private static Map <Object , Map <String , String >> messageIDs = 48 new HashMap <Object , Map <String , String >>(); 49 private Greeter greeter; 50 private String verified; 51 private MAPVerifier mapVerifier; 52 53 public static void main(String [] args) { 54 junit.textui.TestRunner.run(MAPTest.class); 55 } 56 57 public static Test suite() throws Exception { 58 TestSuite suite = new TestSuite(MAPTest.class); 59 return new ClientServerSetupBase(suite) { 60 public void startServers() throws Exception { 61 boolean inProcess = "Windows 2000".equals(System.getProperty("os.name")); 65 assertTrue("server did not launch correctly", 66 launchServer(Server.class, inProcess)); 67 } 68 69 public void setUp() throws Exception { 70 URL url = getClass().getResource("client.xml"); 73 assertNotNull("cannot find test resource", url); 74 configFileName = url.toString(); 75 super.setUp(); 76 } 77 }; 78 } 79 80 public void setUp() throws Exception { 81 super.setUp(); 82 URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl"); 83 SOAPService service = new SOAPService(wsdl, SERVICE_NAME); 84 greeter = (Greeter)service.getPort(PORT_NAME, Greeter.class); 85 BindingProvider provider = (BindingProvider)greeter; 86 List <Handler> handlerChain = provider.getBinding().getHandlerChain(); 87 for (Object h : handlerChain) { 88 if (h instanceof MAPVerifier) { 89 mapVerifier = (MAPVerifier)h; 90 mapVerifier.verificationCache = this; 91 } else if (h instanceof HeaderVerifier) { 92 ((HeaderVerifier)h).verificationCache = this; 93 } 94 } 95 } 96 97 public void tearDown() { 98 verified = null; 99 } 100 101 103 public void testImplicitMAPs() throws Exception { 104 try { 105 String greeting = greeter.greetMe("implicit1"); 106 assertEquals("unexpected response received from service", 107 "Hello implicit1", 108 greeting); 109 checkVerification(); 110 greeting = greeter.greetMe("implicit2"); 111 assertEquals("unexpected response received from service", 112 "Hello implicit2", 113 greeting); 114 checkVerification(); 115 } catch (UndeclaredThrowableException ex) { 116 throw (Exception )ex.getCause(); 117 } 118 } 119 120 public void testExplicitMAPs() throws Exception { 121 try { 122 Map <String , Object > requestContext = 123 ((BindingProvider)greeter).getRequestContext(); 124 AddressingProperties maps = new AddressingPropertiesImpl(); 125 AttributedURIType id = 126 ContextUtils.getAttributedURI("urn:uuid:12345"); 127 maps.setMessageID(id); 128 requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps); 129 String greeting = greeter.greetMe("explicit1"); 130 assertEquals("unexpected response received from service", 131 "Hello explicit1", 132 greeting); 133 checkVerification(); 134 135 try { 139 greeter.greetMe("explicit2"); 140 fail("expected ProtocolException on duplicate message ID"); 141 } catch (ProtocolException pe) { 142 assertTrue("expected duplicate message ID failure", 143 "Duplicate Message ID urn:uuid:12345".equals(pe.getMessage())); 144 checkVerification(); 145 } 146 147 maps.setMessageID(null); 149 maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue())); 150 greeting = greeter.greetMe("explicit3"); 151 assertEquals("unexpected response received from service", 152 "Hello explicit3", 153 greeting); 154 } catch (UndeclaredThrowableException ex) { 155 throw (Exception )ex.getCause(); 156 } 157 } 158 159 public void testOneway() throws Exception { 160 try { 161 greeter.greetMeOneWay("implicit_oneway1"); 162 checkVerification(); 163 } catch (UndeclaredThrowableException ex) { 164 throw (Exception )ex.getCause(); 165 } 166 } 167 168 public void testApplicationFault() throws Exception { 169 try { 170 greeter.testDocLitFault("BadRecordLitFault"); 171 fail("expected fault from service"); 172 } catch (BadRecordLitFault brlf) { 173 checkVerification(); 174 } catch (UndeclaredThrowableException ex) { 175 throw (Exception )ex.getCause(); 176 } 177 String greeting = greeter.greetMe("intra-fault"); 178 assertEquals("unexpected response received from service", 179 "Hello intra-fault", 180 greeting); 181 try { 182 greeter.testDocLitFault("NoSuchCodeLitFault"); 183 fail("expected NoSuchCodeLitFault"); 184 } catch (NoSuchCodeLitFault nsclf) { 185 checkVerification(); 186 } catch (UndeclaredThrowableException ex) { 187 throw (Exception )ex.getCause(); 188 } 189 } 190 191 public void testVersioning() throws Exception { 192 try { 193 mapVerifier.expectedExposedAs.add(VersionTransformer.Names200408.WSA_NAMESPACE_NAME); 196 mapVerifier.expectedExposedAs.add(VersionTransformer.Names200408.WSA_NAMESPACE_NAME); 197 String greeting = greeter.greetMe("versioning1"); 198 assertEquals("unexpected response received from service", 199 "Hello versioning1", 200 greeting); 201 checkVerification(); 202 greeting = greeter.greetMe("versioning2"); 203 assertEquals("unexpected response received from service", 204 "Hello versioning2", 205 greeting); 206 checkVerification(); 207 } catch (UndeclaredThrowableException ex) { 208 throw (Exception )ex.getCause(); 209 } 210 } 211 212 public void xtestAction() throws Exception { 213 try { 214 BareDocumentResponse bareResponse = 217 greeter.testDocLitBare("MySimpleDocument"); 218 assertNotNull("no response for testDocLitBare", bareResponse); 219 assertEquals("Celtix", bareResponse.getCompany()); 220 assertTrue(bareResponse.getId() == 1); 221 checkVerification(); 222 } catch (UndeclaredThrowableException ex) { 223 throw (Exception )ex.getCause(); 224 } 225 } 226 227 229 public void put(String verification) { 230 if (verification != null) { 231 verified = verified == null 232 ? verification 233 : verified + "; " + verification; 234 } 235 } 236 237 239 246 protected static String verifyMAPs(AddressingProperties maps, 247 Object checkPoint) { 248 if (maps == null) { 249 return "expected MAPs"; 250 } 251 String id = maps.getMessageID().getValue(); 258 if (id == null) { 259 return "expected MessageID MAP"; 260 } 261 if (!id.startsWith("urn:uuid")) { 262 return "bad URN format in MessageID MAP: " + id; 263 } 264 Map <String , String > checkPointMessageIDs = messageIDs.get(checkPoint); 266 if (checkPointMessageIDs != null) { 267 if (checkPointMessageIDs.containsKey(id)) { 268 return null; 270 } 271 } else { 272 checkPointMessageIDs = new HashMap <String , String >(); 273 messageIDs.put(checkPoint, checkPointMessageIDs); 274 } 275 checkPointMessageIDs.put(id, id); 276 if (maps.getTo() == null) { 278 return "expected To MAP"; 279 } 280 return null; 281 } 282 283 291 protected static String verifyHeaders(List <String > wsaHeaders, boolean partial) { 292 String ret = null; 294 if (!wsaHeaders.contains(Names.WSA_MESSAGEID_NAME)) { 295 ret = "expected MessageID header"; 296 } 297 if (!wsaHeaders.contains(Names.WSA_TO_NAME)) { 298 ret = "expected To header"; 299 } 300 301 if (!(wsaHeaders.contains(Names.WSA_REPLYTO_NAME) 302 || wsaHeaders.contains(Names.WSA_RELATESTO_NAME))) { 303 ret = "expected ReplyTo or RelatesTo header"; 304 } 305 if (partial) { 306 if (!wsaHeaders.contains(Names.WSA_FROM_NAME)) { 307 ret = "expected From header"; 308 } 309 } else { 310 if (!wsaHeaders.contains(Names.WSA_ACTION_NAME)) { 311 ret = "expected Action header"; 312 } 313 } 314 return ret; 315 } 316 317 private void checkVerification() { 318 assertNull("MAP/Header verification failed: " + verified, verified); 319 } 320 } 321 322 | Popular Tags |