1 package org.objectweb.celtix.systest.ws.addressing.jms; 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.hello_world_jms.HelloWorldPortType; 23 import org.objectweb.celtix.hello_world_jms.JMSSOAPServiceAddressing; 24 import org.objectweb.celtix.systest.common.ClientServerSetupBase; 25 import org.objectweb.celtix.systest.common.ClientServerTestBase; 26 import org.objectweb.celtix.systest.jms.EmbeddedJMSBrokerLauncher; 27 import org.objectweb.celtix.systest.ws.addressing.HeaderVerifier; 28 import org.objectweb.celtix.systest.ws.addressing.MAPVerifier; 29 import org.objectweb.celtix.systest.ws.addressing.VerificationCache; 30 import org.objectweb.celtix.ws.addressing.AddressingProperties; 31 import org.objectweb.celtix.ws.addressing.AttributedURIType; 32 33 34 import static org.objectweb.celtix.ws.addressing.JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES; 35 36 37 40 public class MAPTest extends ClientServerTestBase implements VerificationCache { 41 42 static final String INBOUND_KEY = "inbound"; 43 static final String OUTBOUND_KEY = "outbound"; 44 private static final QName SERVICE_NAME = 45 new QName ("http://celtix.objectweb.org/hello_world_jms", "JMSSOAPServiceAddressing"); 46 private static final QName PORT_NAME = 47 new QName ("http://celtix.objectweb.org/hello_world_jms", "HWJMSAddressingPort"); 48 private static Map <Object , Map <String , String >> messageIDs = 49 new HashMap <Object , Map <String , String >>(); 50 private HelloWorldPortType greeter; 51 private String verified; 52 private MAPVerifier mapVerifier; 53 54 public static void main(String [] args) { 55 junit.textui.TestRunner.run(MAPTest.class); 56 } 57 58 public static Test suite() throws Exception { 59 TestSuite suite = new TestSuite(MAPTest.class); 60 return new ClientServerSetupBase(suite) { 61 public void startServers() throws Exception { 62 Map <String , String > props = new HashMap <String , String >(); 63 if (System.getProperty("activemq.store.dir") != null) { 64 props.put("activemq.store.dir", System.getProperty("activemq.store.dir")); 65 } 66 props.put("java.util.logging.config.file", 67 System.getProperty("java.util.logging.config.file")); 68 69 assertTrue("server did not launch correctly", 70 launchServer(EmbeddedJMSBrokerLauncher.class, props, null)); 71 boolean inProcess = "Windows 2000".equals(System.getProperty("os.name")); 75 assertTrue("server did not launch correctly", 76 launchServer(Server.class, inProcess)); 77 } 78 79 public void setUp() throws Exception { 80 URL url = getClass().getResource("client.xml"); 83 assertNotNull("cannot find test resource", url); 84 configFileName = url.toString(); 85 super.setUp(); 86 } 87 }; 88 } 89 90 public void setUp() throws Exception { 91 super.setUp(); 92 URL wsdl = getClass().getResource("/wsdl/jms_test.wsdl"); 93 JMSSOAPServiceAddressing service = new JMSSOAPServiceAddressing(wsdl, SERVICE_NAME); 94 greeter = (HelloWorldPortType)service.getPort(PORT_NAME, HelloWorldPortType.class); 95 BindingProvider provider = (BindingProvider)greeter; 96 97 List <Handler> handlerChain = provider.getBinding().getHandlerChain(); 98 for (Object h : handlerChain) { 99 if (h instanceof MAPVerifier) { 100 mapVerifier = (MAPVerifier)h; 101 mapVerifier.setVerificationCache(this); 102 } else if (h instanceof HeaderVerifier) { 103 ((HeaderVerifier)h).setVerificationCache(this); 104 } 105 } 106 } 107 108 public void tearDown() { 109 verified = null; 110 } 111 112 114 public void testImplicitMAPs() throws Exception { 115 try { 116 String greeting = greeter.greetMe("implicit1"); 117 assertEquals("unexpected response received from service", 118 "Hello implicit1", 119 greeting); 120 checkVerification(); 121 greeting = greeter.greetMe("implicit2"); 122 assertEquals("unexpected response received from service", 123 "Hello implicit2", 124 greeting); 125 checkVerification(); 126 } catch (UndeclaredThrowableException ex) { 127 throw (Exception )ex.getCause(); 128 } 129 } 130 131 public void testExplicitMAPs() throws Exception { 132 try { 133 Map <String , Object > requestContext = 134 ((BindingProvider)greeter).getRequestContext(); 135 AddressingProperties maps = new AddressingPropertiesImpl(); 136 AttributedURIType id = 137 ContextUtils.getAttributedURI("urn:uuid:12345"); 138 maps.setMessageID(id); 139 requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps); 140 String greeting = greeter.greetMe("explicit1"); 141 assertEquals("unexpected response received from service", 142 "Hello explicit1", 143 greeting); 144 checkVerification(); 145 146 try { 150 greeter.greetMe("explicit2"); 151 fail("expected ProtocolException on duplicate message ID"); 152 } catch (ProtocolException pe) { 153 assertTrue("expected duplicate message ID failure", 154 "Duplicate Message ID urn:uuid:12345".equals(pe.getMessage())); 155 checkVerification(); 156 } 157 158 maps.setMessageID(null); 160 maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue())); 161 greeting = greeter.greetMe("explicit3"); 162 assertEquals("unexpected response received from service", 163 "Hello explicit3", 164 greeting); 165 } catch (UndeclaredThrowableException ex) { 166 throw (Exception )ex.getCause(); 167 } 168 } 169 170 public void testOneway() throws Exception { 171 try { 172 greeter.greetMeOneWay("implicit_oneway1"); 173 checkVerification(); 174 } catch (UndeclaredThrowableException ex) { 175 throw (Exception )ex.getCause(); 176 } 177 } 178 179 180 public void testVersioning() throws Exception { 181 try { 182 mapVerifier.addToExpectedExposedAs(VersionTransformer.Names200408.WSA_NAMESPACE_NAME); 185 mapVerifier.addToExpectedExposedAs(VersionTransformer.Names200408.WSA_NAMESPACE_NAME); 186 String greeting = greeter.greetMe("versioning1"); 187 assertEquals("unexpected response received from service", 188 "Hello versioning1", 189 greeting); 190 checkVerification(); 191 greeting = greeter.greetMe("versioning2"); 192 assertEquals("unexpected response received from service", 193 "Hello versioning2", 194 greeting); 195 checkVerification(); 196 } catch (UndeclaredThrowableException ex) { 197 throw (Exception )ex.getCause(); 198 } 199 } 200 201 203 public void put(String verification) { 204 if (verification != null) { 205 verified = verified == null 206 ? verification 207 : verified + "; " + verification; 208 } 209 } 210 211 213 220 protected static String verifyMAPs(AddressingProperties maps, 221 Object checkPoint) { 222 if (maps == null) { 223 return "expected MAPs"; 224 } 225 String id = maps.getMessageID().getValue(); 232 if (id == null) { 233 return "expected MessageID MAP"; 234 } 235 if (!id.startsWith("urn:uuid")) { 236 return "bad URN format in MessageID MAP: " + id; 237 } 238 Map <String , String > checkPointMessageIDs = messageIDs.get(checkPoint); 240 if (checkPointMessageIDs != null) { 241 if (checkPointMessageIDs.containsKey(id)) { 242 return null; 244 } 245 } else { 246 checkPointMessageIDs = new HashMap <String , String >(); 247 messageIDs.put(checkPoint, checkPointMessageIDs); 248 } 249 checkPointMessageIDs.put(id, id); 250 if (maps.getTo() == null) { 252 return "expected To MAP"; 253 } 254 return null; 255 } 256 257 265 protected static String verifyHeaders(List <String > wsaHeaders, boolean partial) { 266 if (!wsaHeaders.contains(Names.WSA_MESSAGEID_NAME)) { 268 return "expected MessageID header"; 269 } 270 if (!wsaHeaders.contains(Names.WSA_TO_NAME)) { 271 return "expected To header"; 272 } 273 if (!(wsaHeaders.contains(Names.WSA_REPLYTO_NAME) 274 || wsaHeaders.contains(Names.WSA_RELATESTO_NAME))) { 275 return "expected ReplyTo or RelatesTo header"; 276 } 277 if (partial) { 278 if (!wsaHeaders.contains(Names.WSA_FROM_NAME)) { 279 return "expected From header"; 280 } 281 } else { 282 if (!wsaHeaders.contains(Names.WSA_ACTION_NAME)) { 283 return "expected Action header"; 284 } 285 } 286 return null; 287 } 288 289 private void checkVerification() { 290 assertNull("MAP/Header verification failed: " + verified, verified); 291 } 292 } 293 294 | Popular Tags |