1 17 package org.apache.sandesha.intergratedtest; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.client.Call; 21 import org.apache.axis.client.Service; 22 import org.apache.axis.components.uuid.UUIDGen; 23 import org.apache.axis.components.uuid.UUIDGenFactory; 24 import org.apache.axis.deployment.wsdd.WSDDDeployment; 25 import org.apache.axis.deployment.wsdd.WSDDDocument; 26 import org.apache.axis.encoding.XMLType; 27 import org.apache.axis.transport.http.SimpleAxisServer; 28 import org.apache.sandesha.Constants; 29 import org.apache.sandesha.RMReport; 30 import org.apache.sandesha.SandeshaContext; 31 import org.w3c.dom.Document ; 32 33 import javax.xml.namespace.QName ; 34 import javax.xml.parsers.DocumentBuilder ; 35 import javax.xml.parsers.DocumentBuilderFactory ; 36 import javax.xml.rpc.ParameterMode ; 37 import java.io.File ; 38 import java.net.ServerSocket ; 39 40 46 public class TCScenarioTest extends TestCase { 47 private static SimpleAxisServer sas = null; 48 49 private static String defaultServerPort = "5555"; 50 private static String defaultClientPort = "9090"; 51 private static boolean serverStarted = false; 52 private static int testCount = 5; 53 54 private static String targetURL = "http://127.0.0.1:" + defaultServerPort + 55 "/axis/services/RMTestService"; 56 57 58 public void setUp() throws Exception { 59 if (!serverStarted) { 60 sas = new SimpleAxisServer(); 61 62 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 63 dbf.setNamespaceAware(true); 64 DocumentBuilder db = dbf.newDocumentBuilder(); 65 66 Document doc = db.parse(new File ("test-resources/server-config.wsdd")); 67 WSDDDocument wsdddoc = new WSDDDocument(doc); 68 WSDDDeployment wsdddep = wsdddoc.getDeployment(); 69 sas.setMyConfig(wsdddep); 70 71 sas.setServerSocket(new ServerSocket ((new Integer (defaultServerPort)).intValue())); 72 sas.start(); 73 serverStarted = true; 74 } 75 } 76 77 public void tearDown() throws InterruptedException { 78 if (testCount == 0) { 79 Thread.sleep(5000); 80 sas.stop(); 81 } 82 } 83 84 90 public void testPingSync() throws Exception { 91 System.out.println(" Synchronous Ping Test Started"); 92 93 Service service = new Service(); 94 Call call = (Call) service.createCall(); 95 96 SandeshaContext ctx = new SandeshaContext(Constants.SYNCHRONOUS); 97 ctx.initCall(call, targetURL, "urn:wsrm:Ping", Constants.ClientProperties.IN_ONLY); 98 99 call.setOperationName(new QName ("http://tempuri.org/", "Ping")); 100 call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN); 101 102 103 call.invoke(new Object []{"Ping One"}); 104 ctx.setLastMessage(call); 105 call.invoke(new Object []{"Ping Two"}); 106 107 RMReport report = ctx.endSequence(); 108 109 assertEquals(report.isAllAcked(), true); 110 assertEquals(report.getNumberOfReturnMessages(), 0); 111 testCount--; 112 System.out.println(" Synchronous Ping Test Finished"); 113 } 114 115 121 public void testPingAsync() throws Exception { 122 System.out.println(" Asynchronous Ping Test Started"); 123 124 Service service = new Service(); 125 Call call = (Call) service.createCall(); 126 127 SandeshaContext ctx = new SandeshaContext(); 128 129 ctx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 130 ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 131 ctx.initCall(call, targetURL, "urn:wsrm:ping", Constants.ClientProperties.IN_ONLY); 132 133 call.setOperationName(new QName ("http://tempuri.org", "Ping")); 134 call.addParameter("Text", XMLType.XSD_STRING, ParameterMode.IN); 135 136 call.invoke(new Object []{"Ping One"}); 137 ctx.setLastMessage(call); 138 call.invoke(new Object []{"Ping Two"}); 139 140 RMReport report = ctx.endSequence(); 141 142 assertEquals(report.isAllAcked(), true); 143 assertEquals(report.getNumberOfReturnMessages(), 0); 144 testCount--; 145 System.out.println(" Asynchronous Ping Test Finished"); 146 147 } 148 149 157 158 public void testEchoSyncAck() throws Exception { 159 System.out.println(" Echo(Sync Ack) Test Started"); 160 161 UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); String str = uuidGen.nextUUID(); 163 164 Service service = new Service(); 165 Call call = (Call) service.createCall(); 166 167 SandeshaContext ctx = new SandeshaContext(); 168 169 ctx.setAcksToURL(Constants.WSA.NS_ADDRESSING_ANONYMOUS); 170 ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 171 ctx.setSendOffer(true); 172 173 ctx.initCall(call, targetURL, "urn:wsrm:echoString", Constants.ClientProperties.IN_OUT); 174 175 call.setOperationName(new QName ("http://tempuri.org/", "echoString")); 176 177 call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN); 178 call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN); 179 call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); 180 181 String ret = (String ) call.invoke(new Object []{" Echo 1 ", str}); 182 System.out.println(" The Response for First Messsage is :" + ret); 183 184 ctx.setLastMessage(call); 185 ret = (String ) call.invoke(new Object []{" Echo 2 ", str}); 186 System.out.println(" The Response for Second Messsage is :" + ret); 187 188 RMReport report = ctx.endSequence(); 189 190 assertEquals(report.isAllAcked(), true); 191 assertEquals(report.getNumberOfReturnMessages(), 2); 192 testCount--; 193 System.out.println(" Echo(Sync Ack) Test Finished"); 194 } 195 196 203 public void testEchoAsyncAck() throws Exception { 204 System.out.println(" Echo(Aync Ack) Test Started"); 205 206 UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); String str = uuidGen.nextUUID(); 208 209 Service service = new Service(); 210 Call call = (Call) service.createCall(); 211 212 SandeshaContext ctx = new SandeshaContext(); 213 214 ctx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 215 ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 216 ctx.setSendOffer(true); 217 218 ctx.initCall(call, targetURL, "urn:wsrm:echoString", Constants.ClientProperties.IN_OUT); 219 220 call.setOperationName(new QName ("http://tempuri.org/", "echoString")); 221 222 call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN); 223 call.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN); 224 call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); 225 226 String ret = (String ) call.invoke(new Object []{" Echo 1 ", str}); 227 System.out.println(" The Response for First Messsage is :" + ret); 228 229 ctx.setLastMessage(call); 230 ret = (String ) call.invoke(new Object []{" Echo 2 ", str}); 231 System.out.println(" The Response for Second Messsage is :" + ret); 232 233 RMReport report = ctx.endSequence(); 234 235 assertEquals(report.isAllAcked(), true); 236 assertEquals(report.getNumberOfReturnMessages(), 2); 237 testCount--; 238 System.out.println(" Echo(Async Ack) Test Finished"); 239 } 240 241 249 public void testEchoPing() throws Exception { 250 System.out.println(" Echo and Ping Combined Test Started"); 251 UUIDGen uuidGen = UUIDGenFactory.getUUIDGen(); String str = uuidGen.nextUUID(); 253 254 Service service = new Service(); 255 Call echoCall = (Call) service.createCall(); 256 257 SandeshaContext ctx = new SandeshaContext(); 258 260 ctx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 261 ctx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 262 ctx.setSendOffer(true); 263 ctx.initCall(echoCall, targetURL, "urn:wsrm:echoString", Constants.ClientProperties.IN_OUT); 264 265 echoCall.setOperationName(new QName ("http://tempuri.org/", "echoString")); 266 267 echoCall.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN); 268 echoCall.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN); 269 echoCall.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING); 270 272 Service pingService = new Service(); 274 Call pingCall = (Call) pingService.createCall(); 275 SandeshaContext pingCtx = new SandeshaContext(); 276 pingCtx.setAcksToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 277 pingCtx.setReplyToURL("http://127.0.0.1:" + defaultClientPort + "/axis/services/RMService"); 278 279 pingCtx.initCall(pingCall, targetURL, "urn:wsrm:Ping", Constants.ClientProperties.IN_ONLY); 280 281 pingCall.setOperationName(new QName ("http://tempuri.org/", "ping")); 282 pingCall.addParameter("arg2", XMLType.XSD_STRING, ParameterMode.IN); 283 285 286 String ret = (String ) echoCall.invoke(new Object []{" Echo 1 ", str}); 287 System.out.println(" The Response for First Messsage is :" + ret); 288 pingCall.invoke(new Object []{ret}); 289 290 ctx.setLastMessage(echoCall); 291 ret = (String ) echoCall.invoke(new Object []{" Echo 2 ", str}); 292 System.out.println(" The Response for Second Messsage is :" + ret); 293 pingCall.invoke(new Object []{ret}); 294 295 pingCtx.setLastMessage(pingCall); 296 pingCall.invoke(new Object []{ret}); 297 298 RMReport echoReport = ctx.endSequence(); 299 RMReport pingReport = pingCtx.endSequence(); 300 301 assertEquals(echoReport.isAllAcked(), true); 302 assertEquals(echoReport.getNumberOfReturnMessages(), 2); 303 304 assertEquals(pingReport.isAllAcked(), true); 305 assertEquals(pingReport.getNumberOfReturnMessages(), 0); 306 testCount--; 307 System.out.println(" Echo and Ping Combined Test Finished"); 308 309 } 310 311 } 312 | Popular Tags |