Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/htmlparser/tests/visitorsTests/UrlModifyingVisitorTest.java


1   // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/visitorsTests/UrlModifyingVisitorTest.java,v 1.2 2004/02/11 02:16:59 woolfel Exp $
2   /*
3    * ====================================================================
4    * Copyright 2002-2004 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * 
18   */
19  
20  // The developers of JMeter and Apache are greatful to the developers
21  // of HTMLParser for giving Apache Software Foundation a non-exclusive
22  // license. The performance benefits of HTMLParser are clear and the
23  // users of JMeter will benefit from the hard work the HTMLParser
24  // team. For detailed information about HTMLParser, the project is
25  // hosted on sourceforge at http://htmlparser.sourceforge.net/.
26  //
27  // HTMLParser was originally created by Somik Raha in 2000. Since then
28  // a healthy community of users has formed and helped refine the
29  // design so that it is able to tackle the difficult task of parsing
30  // dirty HTML. Derrick Oswald is the current lead developer and was kind
31  // enough to assist JMeter.
32  
33  package org.htmlparser.tests.visitorsTests;
34  
35  import org.htmlparser.Parser;
36  import org.htmlparser.tests.ParserTestCase;
37  import org.htmlparser.visitors.UrlModifyingVisitor;
38  
39  public class UrlModifyingVisitorTest extends ParserTestCase
40  {
41      private static final String HTML_WITH_LINK =
42          "<HTML><BODY>"
43              + "<A HREF=\"mylink.html\"><IMG SRC=\"mypic.jpg\">"
44              + "</A><IMG SRC=\"mysecondimage.gif\">"
45              + "</BODY></HTML>";
46  
47      private static final String MODIFIED_HTML =
48          "<HTML><BODY>"
49              + "<A HREF=\"localhost://mylink.html\">"
50              + "<IMG SRC=\"localhost://mypic.jpg\"></A>"
51              + "<IMG SRC=\"localhost://mysecondimage.gif\">"
52              + "</BODY></HTML>";
53  
54      public UrlModifyingVisitorTest(String name)
55      {
56          super(name);
57      }
58  
59      public void testUrlModificationWithVisitor() throws Exception
60      {
61          Parser parser = Parser.createParser(HTML_WITH_LINK);
62          UrlModifyingVisitor visitor =
63              new UrlModifyingVisitor(parser, "localhost://");
64          parser.visitAllNodesWith(visitor);
65          assertStringEquals(
66              "Expected HTML",
67              MODIFIED_HTML,
68              visitor.getModifiedResult());
69      }
70  }