1 16 17 18 package org.apache.xmlrpc; 19 20 import java.io.BufferedInputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 26 34 abstract public class XmlRpcTransportTest 35 extends LocalServerRpcTest 36 { 37 40 public XmlRpcTransportTest(String testName) 41 { 42 super(testName); 43 } 44 45 48 abstract protected XmlRpcTransport getTransport(URL url); 49 50 57 public void testSendXmlRpc() { 58 59 try { 60 setUpWebServer(); 61 startWebServer(); 62 URL testUrl = buildURL("localhost", SERVER_PORT); 63 XmlRpcTransport controlTransport = new DefaultXmlRpcTransport(testUrl); 64 XmlRpcTransport testTransport = getTransport(testUrl); 65 InputStream controlResponse = controlTransport.sendXmlRpc(RPC_REQUEST.getBytes()); 66 InputStream testResponse = testTransport.sendXmlRpc(RPC_REQUEST.getBytes()); 67 assertTrue( 68 "Response from XmlRpcTransport does not match that of DefaultXmlRpcTransport.", 69 equalsInputStream(controlResponse, testResponse)); 70 stopWebServer(); 71 } 72 catch (MalformedURLException e) { 73 e.printStackTrace(); 74 fail(e.getMessage()); 75 } 76 catch (IOException e) { 77 e.printStackTrace(); 78 fail(e.getMessage()); 79 } 80 catch (XmlRpcClientException e) { 81 e.printStackTrace(); 82 fail(e.getMessage()); 83 } 84 } 85 86 private URL buildURL(String hostname, int port) throws MalformedURLException { 87 return new URL ("http://" + hostname + ':' + port + "/RPC2"); 88 } 89 90 protected boolean equalsInputStream(InputStream is1, InputStream is2) throws IOException { 91 BufferedInputStream stream1 = new BufferedInputStream (is1); 92 BufferedInputStream stream2 = new BufferedInputStream (is2); 93 int char1 = is1.read(); 94 int char2 = is2.read(); 95 while ((char1 != -1) && (char2 != -1) && (char1 == char2)) { 96 char1 = is1.read(); 97 char2 = is2.read(); 98 } 99 return char1 == char2; 100 } 101 } 102 | Popular Tags |