Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/RfcDateParser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/RfcDateParser.java?rev=762039&view=auto ============================================================================== --- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/RfcDateParser.java (added) +++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/RfcDateParser.java Sun Apr 5 01:36:27 2009 @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.test.watchdog; + +import java.util.Date; +import java.util.Locale; +import java.util.TimeZone; + +/** + * A parser for date strings commonly found in http and email headers that + * follow various RFC conventions. Given a date-string, the parser will + * attempt to parse it by trying matches with a set of patterns, returning + * null on failure, a Date object on success. + * + * @author Ramesh.Mandava + */ +public class RfcDateParser { + + private boolean isGMT = false; + + static final String[] standardFormats = { + "EEEE', 'dd-MMM-yy HH:mm:ss z", // RFC 850 (obsoleted by 1036) + "EEEE', 'dd-MMM-yy HH:mm:ss", // ditto but no tz. Happens too often + "EEE', 'dd-MMM-yyyy HH:mm:ss z", // RFC 822/1123 + "EEE', 'dd MMM yyyy HH:mm:ss z", // REMIND what rfc? Apache/1.1 + "EEEE', 'dd MMM yyyy HH:mm:ss z", // REMIND what rfc? Apache/1.1 + "EEE', 'dd MMM yyyy hh:mm:ss z", // REMIND what rfc? Apache/1.1 + "EEEE', 'dd MMM yyyy hh:mm:ss z", // REMIND what rfc? Apache/1.1 + "EEE MMM dd HH:mm:ss z yyyy", // Date's string output format + "EEE MMM dd HH:mm:ss yyyy", // ANSI C asctime format() + "EEE', 'dd-MMM-yy HH:mm:ss", // No time zone 2 digit year RFC 1123 + "EEE', 'dd-MMM-yyyy HH:mm:ss" // No time zone RFC 822/1123 + }; + + /* because there are problems with JDK1.1.6/SimpleDateFormat with + * recognizing GMT, we have to create this workaround with the following + * hardcoded strings */ + static final String[] gmtStandardFormats = { + "EEEE',' dd-MMM-yy HH:mm:ss 'GMT'", // RFC 850 (obsoleted by 1036) + "EEE',' dd-MMM-yyyy HH:mm:ss 'GMT'", // RFC 822/1123 + "EEE',' dd MMM yyyy HH:mm:ss 'GMT'", // REMIND what rfc? Apache/1.1 + "EEEE',' dd MMM yyyy HH:mm:ss 'GMT'", // REMIND what rfc? Apache/1.1 + "EEE',' dd MMM yyyy hh:mm:ss 'GMT'", // REMIND what rfc? Apache/1.1 + "EEEE',' dd MMM yyyy hh:mm:ss 'GMT'", // REMIND what rfc? Apache/1.1 + "EEE MMM dd HH:mm:ss 'GMT' yyyy" // Date's string output format + }; + + String dateString; + + public RfcDateParser(String dateString) { + this.dateString = dateString.trim(); + if (this.dateString.indexOf("GMT") != -1) { + isGMT = true; + } + } + + public Date getDate() { + + int arrayLen = isGMT ? gmtStandardFormats.length : standardFormats.length; + for (int i = 0; i < arrayLen; i++) { + Date d = null; + + if (isGMT) { + d = tryParsing(gmtStandardFormats[i]); + } else { + d = tryParsing(standardFormats[i]); + } + if (d != null) { + return d; + } + + } + + return null; + } + + private Date tryParsing(String format) { + + java.text.SimpleDateFormat df = new java.text.SimpleDateFormat(format, Locale.US); + if (isGMT) { + df.setTimeZone(TimeZone.getTimeZone("GMT")); + } + try { + return df.parse(dateString); + } catch (Exception e) { + return null; + } + } +} /* class RfcDateParser */
Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/RfcDateParser.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/RfcDateParser.java ------------------------------------------------------------------------------ svn:executable = * Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java?rev=762039&view=auto ============================================================================== --- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java (added) +++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java Sun Apr 5 01:36:27 2009 @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.test.watchdog; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +import javax.xml.parsers.ParserConfigurationException; + +import junit.framework.Test; +import junit.framework.TestResult; +import junit.framework.TestSuite; + +import org.apache.tomcat.util.DomUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class WatchdogClient { + + protected String base = "../watchdog"; + + protected String goldenDir; + protected String testMatch; + protected String file; + protected String[] exclude = null; + protected String[] slow = + { + "SingleModelTest" // slow + }; + + protected String targetMatch; + + + Properties props = new Properties(); + + protected void beforeSuite() { + + } + + protected void afterSuite(TestResult res) { + + } + + /** + * Return a test suite for running a watchdog-like + * test file. + * + * @param base base dir for the watchdog dir + * @param testMatch Prefix of tests to be run + * @return + */ + public Test getSuite() { + TestSuite tests = new WatchdogTests(); + tests.setName(this.getClass().getSimpleName()); + + props.setProperty("port", "8080"); + props.setProperty("host", "localhost"); + props.setProperty("wgdir", + goldenDir); + + + try { + Document doc = DomUtil.readXml(new FileInputStream(file)); + Element docE = doc.getDocumentElement(); + NodeList targetsL = docE.getElementsByTagName("target"); + for (int i = 0; i < targetsL.getLength(); i++) { + Element target = (Element) targetsL.item(i); + String targetName = target.getAttribute("name"); + if (targetMatch != null && !targetName.equals(targetMatch)) { + continue; + } + + // Tests are duplicated + //TestSuite targetSuite = new TestSuite(targetName); + + NodeList watchDogL = target.getElementsByTagName("watchdog"); + for (int j = 0; j < watchDogL.getLength(); j++) { + Element watchE = (Element) watchDogL.item(j); + String testName = watchE.getAttribute("testName"); + if (testMatch != null) { + if (!testName.startsWith(testMatch)) { + continue; + } + } + if (exclude != null) { + boolean found = false; + for (String e: exclude) { + if (e.equals(testName)) { + found = true; + break; + } + } + if (found) { + continue; + } + } + testName = testName + ";" + this.getClass().getName(); + WatchdogTest test = new WatchdogTest(watchE, props, testName); + tests.addTest(test); + } + + // if (targetSuite.countTestCases() > 0) { + // tests.addTest(targetSuite); + // } + } + + } catch (IOException e) { + e.printStackTrace(); + } catch (SAXException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return tests; + } + + // --------- Inner classes ------------- + + public class WatchdogTests extends TestSuite { + public void run(TestResult res) { + beforeSuite(); + super.run(res); + afterSuite(res); + } + } + +} Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogClient.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java?rev=762039&view=auto ============================================================================== --- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java (added) +++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogHttpClient.java Sun Apr 5 01:36:27 2009 @@ -0,0 +1,406 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tomcat.test.watchdog; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.Socket; +import java.net.SocketException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + + + +public class WatchdogHttpClient { + private static final String CRLF = "\r\n"; + private static final int LINE_FEED = 10; + + static int debug = 0; + + public static void dispatch(GTest client) throws Exception { + HashMap requestHeaders = client.requestHeaders; + String host = client.host; + int port = client.port; + String content = client.content; + String request = client.request; + + // XXX headers are ignored + Socket socket = new Socket( host, port ); + + //socket obtained, rebuild the request. + rebuildRequest(client, client.request, socket); + + InputStream in = new CRBufferedInputStream( socket.getInputStream() ); + + // Write the request + socket.setSoLinger( true, 1000 ); + + OutputStream out = new BufferedOutputStream( + socket.getOutputStream() ); + StringBuffer reqbuf = new StringBuffer( 128 ); + + // set the Host header + client.setHeaderDetails( "Host:" + host + ":" + port, requestHeaders, true ); + + // set the Content-Length header + if ( content != null ) { + client.setHeaderDetails( "Content-Length:" + content.length(), + requestHeaders, true ); + } + + // set the Cookie header + if ( client.testSession != null ) { + client.cookieController = ( CookieController ) client.sessionHash.get( client.testSession ); + + if ( client.cookieController != null ) { + + String releventCookieString = client.cookieController.applyRelevantCookies( client.requestURL ); + + if ( ( releventCookieString != null ) && ( !releventCookieString.trim().equals( "" ) ) ) { + client.setHeaderDetails( "Cookie:" + releventCookieString, requestHeaders, true ); + } + } + } + + if ( debug > 0 ) { + System.out.println( " REQUEST: " + request ); + } + reqbuf.append( client.request ).append( CRLF ); + + // append all request headers + if ( !requestHeaders.isEmpty() ) { + Iterator iter = requestHeaders.keySet().iterator(); + + while ( iter.hasNext() ) { + StringBuffer tmpBuf = new StringBuffer(32); + String headerKey = ( String ) iter.next(); + ArrayList values = (ArrayList) requestHeaders.get( headerKey ); + String[] value = (String[]) values.toArray( new String[ values.size() ] ); + tmpBuf.append( headerKey ).append(": "); + for ( int i = 0; i < value.length; i++ ) { + if ((i + 1) == value.length) { + tmpBuf.append( value[ i ] ); + } else { + tmpBuf.append( value[ i ] ).append(", "); + } + } + if ( debug > 0 ) { + System.out.println( " REQUEST HEADER: " + tmpBuf.toString()); + } + tmpBuf.append( CRLF ); + reqbuf.append(tmpBuf.toString()); + } + } + + /* + + if ( ( testSession != null ) && ( sessionHash.get( testSession ) != null ) ) { + System.out.println("Sending Session Id : " + (String)sessionHash.get( testSession ) ); + pw.println("JSESSIONID:" + (String)sessionHash.get( testSession) ); + } + + */ + + if ( request.indexOf( "HTTP/1." ) > -1 ) { + reqbuf.append( "" ).append( CRLF ); + } + + // append request content + if ( content != null ) { + reqbuf.append( content ); + // XXX no CRLF at the end -see HTTP specs! + } + + byte[] reqbytes = reqbuf.toString().getBytes(); + + try { + // write the request + out.write( reqbytes, 0, reqbytes.length ); + out.flush(); + reqbuf = null; + } catch ( Exception ex1 ) { + System.out.println( " Error writing request " + ex1 ); + if ( debug > 0 ) { + System.out.println( "Message: " + ex1.getMessage() ); + ex1.printStackTrace(); + } + } + + // read the response + try { + + client.responseLine = read( in ); + + if ( debug > 0 ) { + System.out.println( " RESPONSE STATUS-LINE: " + client.responseLine ); + } + + client.headers = parseHeaders( client, in ); + + byte[] result = readBody( in ); + + if ( result != null ) { + client.responseBody = result; + if ( debug > 0 ) { + System.out.println( " RESPONSE BODY:\n" + new String( client.responseBody ) ); + } + } + + } catch ( SocketException ex ) { + System.out.println( " Socket Exception: " + ex ); + ex.printStackTrace(); + } finally { + if ( debug > 0 ) { + System.out.println( " closing socket" ); + } + socket.close(); + socket = null; + } + + } + + /** + * <code>readBody</code> reads the body of the response + * from the InputStream. + * + * @param input an <code>InputStream</code> + * @return a <code>byte[]</code> representation of the response + */ + private static byte[] readBody( InputStream input ) { + StringBuffer sb = new StringBuffer( 255 ); + while ( true ) { + try { + int ch = input.read(); + + if ( ch < 0 ) { + if ( sb.length() == 0 ) { + return ( null ); + } else { + break; + } + } + sb.append( ( char ) ch ); + + } catch ( IOException ex ) { + return null; + } + } + return sb.toString().getBytes(); + } + + + + /** + * Read a line from the specified servlet input stream, and strip off + * the trailing carriage return and newline (if any). Return the remaining + * characters that were read as a string.7 + * + * @returns The line that was read, or <code>null</code> if end of file + * was encountered + * + * @exception IOException if an input/output error occurred + */ + private static String read( InputStream input ) throws IOException { + // Read the next line from the input stream + StringBuffer sb = new StringBuffer(); + + while ( true ) { + try { + int ch = input.read(); + // System.out.println("XXX " + (char)ch ); + if ( ch < 0 ) { + if ( sb.length() == 0 ) { + if ( debug > 0 ) + System.out.println( " Error reading line " + ch + " " + sb.toString() ); + return ""; + } else { + break; + } + } else if ( ch == LINE_FEED ) { + break; + } + + sb.append( ( char ) ch ); + } catch ( IOException ex ) { + System.out.println( " Error reading : " + ex ); + debug = 1; + + if ( debug > 0 ) { + System.out.println( "Partial read: " + sb.toString() ); + ex.printStackTrace(); + } + } + } + return sb.toString(); + } + + + // ==================== Code from JSERV !!! ==================== + /** + * Parse the incoming HTTP request headers, and set the corresponding + * request properties. + * + * + * @exception IOException if an input/output error occurs + */ + private static HashMap parseHeaders( GTest client, InputStream is ) throws IOException { + HashMap headers = new HashMap(); + client.cookieVector = new Vector(); + + while ( true ) { + // Read the next header line + String line = read( is ); + + if ( ( line == null ) || ( line.length() < 1 ) ) { + break; + } + + client.parseHeader( line, headers, false ); + + if ( debug > 0 ) { + System.out.println( " RESPONSE HEADER: " + line ); + } + + } + + if ( client.testSession != null ) { + client.cookieController = ( CookieController ) client.sessionHash.get( client.testSession ); + + if ( client.cookieController != null ) { + client.cookieController.recordAnyCookies( client.cookieVector, client.requestURL ); + } + } + + return headers; + } + + + + /** + * Private utility method to 'massage' a request string that + * may or may not have replacement markers for the request parameters. + * + * @param req the request to manipulate + * @param socket local socket. Used to rebuild specified query strings. + * + * @exception Exception if an error occurs + */ + private static void rebuildRequest(GTest client, String req, Socket socket) throws Exception { + client.request = client.replaceMarkers(req, socket ); + String addressString = client.request.substring( client.request.indexOf( "/" ), client.request.indexOf( "HTTP" ) ).trim(); + + if ( addressString.indexOf( "?" ) > -1 ) { + addressString = addressString.substring( 0, addressString.indexOf( "?" ) ) ; + } + + client.requestURL = new URL( "http", client.host, client.port, addressString ); + } + + + + /** + * <code>CRBufferedInputStream</code> is a modified version of + * the java.io.BufferedInputStream class. The fill code is + * the same, but the read is modified in that if a carriage return + * is found in the response stream from the target server, + * it will skip that byte and return the next in the stream. + */ + private static class CRBufferedInputStream extends BufferedInputStream { + private static final int CARRIAGE_RETURN = 13; + + private static final int DEFAULT_BUFFER = 2048; + + /** + * Creates a new <code>CRBufferedInputStream</code> instance. + * + * @param in an <code>InputStream</code> value + */ + public CRBufferedInputStream( InputStream in ) { + super( in, DEFAULT_BUFFER ); + } + + /** + * <code>read</code> reads a single byte value per call. + * If, the byte read, is a carriage return, the next byte + * in the stream in returned instead. + * + * @return an <code>int</code> value + * @exception IOException if an error occurs + */ + public int read() throws IOException { + if ( in == null ) { + throw new IOException ( "Stream closed" ); + } + if ( pos >= count ) { + fill(); + if ( pos >= count ) { + return -1; + } + } + int val = buf[pos++] & 0xff; + if ( val == CARRIAGE_RETURN ) { + if (pos >= count) { + fill(); + if (pos >= count) { + return -1; + } + } + return buf[pos++] & 0xff; + } + return val; + } + + /** + * <code>fill</code> is used to fill the internal + * buffer used by this BufferedInputStream class. + * + * @exception IOException if an error occurs + */ + private void fill() throws IOException { + if (markpos < 0) + pos = 0; /* no mark: throw away the buffer */ + else if (pos >= buf.length) /* no room left in buffer */ + if (markpos > 0) { /* can throw away early part of the buffer */ + int sz = pos - markpos; + System.arraycopy(buf, markpos, buf, 0, sz); + pos = sz; + markpos = 0; + } else if (buf.length >= marklimit) { + markpos = -1; /* buffer got too big, invalidate mark */ + pos = 0; /* drop buffer contents */ + } else { /* grow buffer */ + int nsz = pos * 2; + if (nsz > marklimit) + nsz = marklimit; + byte nbuf[] = new byte[nsz]; + System.arraycopy(buf, 0, nbuf, 0, pos); + buf = nbuf; + } + count = pos; + int n = in.read(buf, pos, buf.length - pos); + if (n > 0) + count = n + pos; + } + } + +} Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTest.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTest.java?rev=762039&view=auto ============================================================================== --- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTest.java (added) +++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTest.java Sun Apr 5 01:36:27 2009 @@ -0,0 +1,105 @@ +/* + */ +package org.apache.tomcat.test.watchdog; + +import java.util.Properties; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; +import junit.framework.TestResult; +import junit.framework.TestSuite; + +import org.apache.tomcat.util.IntrospectionUtils; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +public class WatchdogTest extends TestCase { + String testName; + + Element watchE; + + private Properties props; + + private WatchdogTest delegate; + private WatchdogClient wc; + + public WatchdogTest(String s) throws Throwable { + String[] comp = s.split(";"); + Class c = Class.forName(comp[1]); + wc = (WatchdogClient) c.newInstance(); + TestSuite suite = (TestSuite) wc.getSuite(); + // need to encode the base, file, etc in the test name + + System.err.println(s); + + for (int i = 0; i < suite.testCount(); i++) { + WatchdogTest t = (WatchdogTest) suite.testAt(i); + if (s.equals(t.getName())) { + delegate = t; + return; + } + } + } + + public WatchdogTest(Element watchE, Properties props, String testName) { + this.testName = testName; + this.watchE = watchE; + this.props = props; + } + + public int countTestCases() { + return 1; + } + + public String getName() { + return testName; + } + + public void run(TestResult res) { + if (delegate != null) { + // Single method run + wc.beforeSuite(); + delegate.run(res); + wc.afterSuite(res); + return; + } + GTest test = new GTest(); + NamedNodeMap attrs = watchE.getAttributes(); + + for (int i = 0; i < attrs.getLength(); i++) { + Node n = attrs.item(i); + String name = n.getNodeName(); + String value = n.getNodeValue(); + value = IntrospectionUtils.replaceProperties(value, props, null); + try { + IntrospectionUtils.setProperty(test, name, value); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + try { + res.startTest(this); + IntrospectionUtils.execute(test, "execute"); + } catch (Throwable e) { + res.addError(this, e); + // res.stop(); + } + + if (test.passCount == 1) { + res.endTest(this); + return; + } else { + if (test.lastError == null) { + res.addFailure(this, new AssertionFailedError(test.request + + " " + test.description + "\n" + test.resultOut)); + } else { + res.addError(this, test.lastError); + } + } + res.endTest(this); + } + +} Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/test/watchdog/WatchdogTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java?rev=762039&view=auto ============================================================================== --- tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java (added) +++ tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java Sun Apr 5 01:36:27 2009 @@ -0,0 +1,36 @@ +/* + */ +package org.apache.tomcat.util.buf; + +import junit.framework.TestCase; + +public class UEncoderTest extends TestCase { + UEncoder enc=new UEncoder(); + + /* + * + * Test method for 'org.apache.tomcat.util.buf.UEncoder.encodeURL(String)' + * TODO: find the relevant rfc and apache tests and add more + */ + public void testEncodeURL() { + + String eurl1=enc.encodeURL("test"); + assertEquals("test", eurl1); + + eurl1=enc.encodeURL("/test"); + assertEquals("%2ftest", eurl1); + + // safe ranges + eurl1=enc.encodeURL("test$-_."); + assertEquals("test$-_.", eurl1); + + eurl1=enc.encodeURL("test$-_.!*'(),"); + assertEquals("test$-_.!*'(),", eurl1); + + eurl1=enc.encodeURL("//test"); + assertEquals("%2f%2ftest", eurl1); + + + } + +} Propchange: tomcat/trunk/modules/tomcat-lite/test/org/apache/tomcat/util/buf/UEncoderTest.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org