[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit WebConversation.java,1.12,1.13 WebLink.ja
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2000-10-05 14:45:18
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv20163/src/com/meterware/httpunit Modified Files: WebConversation.java WebLink.java WebResponse.java package.html Log Message: Corrected handling of blank frames Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- WebConversation.java 2000/10/04 15:45:47 1.12 +++ WebConversation.java 2000/10/05 14:45:14 1.13 @@ -98,10 +98,18 @@ WebResponse result = new WebResponse( this, request.getTarget(), request.getURL(), connection ); removeSubFrames( request.getTarget() ); _frameContents.put( request.getTarget(), result ); - _subFrames.put( request.getTarget(), result.getFrameNames() ); + createSubFrames( request.getTarget(), result.getFrameNames() ); WebRequest[] requests = result.getFrameRequests(); for (int i = 0; i < requests.length; i++) getResponse( requests[i] ); return result; + } + } + + + private void createSubFrames( String targetName, String[] frameNames ) { + _subFrames.put( targetName, frameNames ); + for (int i = 0; i < frameNames.length; i++) { + _frameContents.put( frameNames[i], WebResponse.BLANK_RESPONSE ); } } Index: WebLink.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebLink.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- WebLink.java 2000/10/02 16:32:10 1.4 +++ WebLink.java 2000/10/05 14:45:14 1.5 @@ -36,11 +36,18 @@ * Returns the target for this link. **/ public String getTarget() { - if (_node.getAttributes().getNamedItem( "target" ) == null) { + if (getSpecifiedTarget().length() == 0) { return _parentTarget; + } else if (getSpecifiedTarget().equalsIgnoreCase( "_self" )) { + return _parentTarget; } else { - return getValue( _node.getAttributes().getNamedItem( "target" ) ); + return getSpecifiedTarget(); } + } + + + private String getSpecifiedTarget() { + return NodeUtils.getNodeAttribute( _node, "target" ); } Index: WebResponse.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebResponse.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- WebResponse.java 2000/10/04 15:45:47 1.16 +++ WebResponse.java 2000/10/05 14:45:14 1.17 @@ -22,7 +22,7 @@ import java.io.*; import java.net.*; -import java.util.StringTokenizer; +import java.util.*; import org.xml.sax.*; import org.w3c.dom.*; @@ -91,13 +91,17 @@ **/ public WebRequest[] getFrameRequests() throws SAXException { NodeList frames = NodeUtils.getElementsByTagName( getReceivedPage().getDOM(), "frame" ); - WebRequest[] result = new WebRequest[ frames.getLength() ]; - for (int i = 0; i < result.length; i++) { - result[i] = new GetMethodWebRequest( this.getURL(), - NodeUtils.getNodeAttribute( frames.item(i), "src" ), - NodeUtils.getNodeAttribute( frames.item(i), "name" ) ); + Vector requests = new Vector(); + for (int i = 0; i < frames.getLength(); i++) { + if (NodeUtils.getNodeAttribute( frames.item(i), "src" ).length() > 0) { + requests.addElement( new GetMethodWebRequest( this.getURL(), + NodeUtils.getNodeAttribute( frames.item(i), "src" ), + NodeUtils.getNodeAttribute( frames.item(i), "name" ) ) ); + } } + WebRequest[] result = new WebRequest[ requests.size() ]; + requests.copyInto( result ); return result; } @@ -196,6 +200,9 @@ //---------------------------------- package members -------------------------------- + final static WebResponse BLANK_RESPONSE = new WebResponse( "<html><head></head><body></body></html>" ); + + /** * Constructs a response object from an input stream. * @param conversation the web conversation which received the response @@ -203,23 +210,8 @@ * @param inputStream the input stream from which the response can be read **/ WebResponse( WebConversation conversation, String target, URL url, URLConnection connection ) { - _conversation = conversation; - _url = url; - _target = target; - StringBuffer sb = new StringBuffer(); - try { - BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); - - String str; - while (null != ((str = input.readLine()))) { - sb.append( str ).append( endOfLine ); - } - input.close (); - _responseText = sb.toString(); - readHeaders( connection ); - } catch (IOException e) { - throw new RuntimeException( "Unable to retrieve data from URL: " + _url.toExternalForm() + " (" + e + ")" ); - } + this( conversation, target, url, getResponseText( url, connection ) ); + readHeaders( connection ); } @@ -235,6 +227,7 @@ //--------------------------------- private members -------------------------------------- + final private static String endOfLine = System.getProperty( "line.separator" ); private ReceivedPage _page; @@ -250,6 +243,46 @@ final private WebConversation _conversation; final private String _target; + + + /** + * Constructs a response object from a text response. + **/ + private WebResponse( String responseText ) { + this( null, "", null, responseText ); + _contentType = "text/html"; + } + + + /** + * Constructs a response object. + * @param conversation the web conversation which received the response + * @param url the url from which the response was received + * @param inputStream the input stream from which the response can be read + **/ + private WebResponse( WebConversation conversation, String target, URL url, String responseText ) { + _conversation = conversation; + _url = url; + _target = target; + _responseText = responseText; + } + + + private static String getResponseText( URL url, URLConnection connection ) { + StringBuffer sb = new StringBuffer(); + try { + BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream() ) ); + + String str; + while (null != ((str = input.readLine()))) { + sb.append( str ).append( endOfLine ); + } + input.close (); + return sb.toString(); + } catch (IOException e) { + throw new RuntimeException( "Unable to retrieve data from URL: " + url.toExternalForm() + " (" + e + ")" ); + } + } private ReceivedPage getReceivedPage() throws SAXException { Index: package.html =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/package.html,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- package.html 2000/06/12 13:09:26 1.1.1.1 +++ package.html 2000/10/05 14:45:14 1.2 @@ -8,7 +8,7 @@ requests based on either submitting a form or clicking on a link. <H2>Installation</H2> -The package depends on <A HREF="http://www3.sympatico.ca/ac.quick/jtidy.html">JTidy</A> by Andy Quick. +The package depends on <A HREF="http://httpunit.sourceforge.net/Tidy.jar.zip">JTidy</A> by Andy Quick. The jtidy.jar must be in the class path ahead of any other implementation of the DOM classes. In addition, unit tests will require <A HREF=http://www.xprogramming.com/ftp/TestingFramework/JUnit/junit32.zip>JUnit</A> as well. |