KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > scannersTests > FrameSetScannerTest


1 // $Header: /home/cvs/jakarta-jmeter/src/htmlparser/org/htmlparser/tests/scannersTests/FrameSetScannerTest.java,v 1.2 2004/02/11 02:16:58 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.scannersTests;
34
35 import org.htmlparser.scanners.FrameScanner;
36 import org.htmlparser.scanners.FrameSetScanner;
37 import org.htmlparser.tags.FrameSetTag;
38 import org.htmlparser.tags.FrameTag;
39 import org.htmlparser.tests.ParserTestCase;
40 import org.htmlparser.util.ParserException;
41
42 public class FrameSetScannerTest extends ParserTestCase
43 {
44
45     public FrameSetScannerTest(String JavaDoc name)
46     {
47         super(name);
48     }
49
50     public void testEvaluate()
51     {
52         String JavaDoc line1 =
53             "frameset rows=\"115,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\"";
54         String JavaDoc line2 =
55             "FRAMESET rows=\"115,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\"";
56         String JavaDoc line3 =
57             "Frameset rows=\"115,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\"";
58         FrameSetScanner frameSetScanner = new FrameSetScanner("");
59         assertTrue("Line 1", frameSetScanner.evaluate(line1, null));
60         assertTrue("Line 2", frameSetScanner.evaluate(line2, null));
61         assertTrue("Line 3", frameSetScanner.evaluate(line3, null));
62     }
63
64     public void testScan() throws ParserException
65     {
66         createParser(
67             "<frameset rows=\"115,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">\n"
68                 + "<frame name=\"topFrame\" noresize SRC=\"demo_bc_top.html\" scrolling=\"NO\" frameborder=\"NO\">\n"
69                 + "<frame name=\"mainFrame\" SRC=\"http://www.kizna.com/web_e/\" scrolling=\"AUTO\">\n"
70                 + "</frameset>",
71             "http://www.google.com/test/index.html");
72
73         parser.addScanner(new FrameSetScanner(""));
74         parser.addScanner(new FrameScanner());
75
76         parseAndAssertNodeCount(1);
77         assertTrue("Node 0 should be End Tag", node[0] instanceof FrameSetTag);
78         FrameSetTag frameSetTag = (FrameSetTag) node[0];
79         // Find the details of the frameset itself
80
assertEquals("Rows", "115,*", frameSetTag.getAttribute("rows"));
81         assertEquals(
82             "FrameBorder",
83             "NO",
84             frameSetTag.getAttribute("FrameBorder"));
85         assertEquals(
86             "FrameSpacing",
87             "0",
88             frameSetTag.getAttribute("FrameSpacing"));
89         assertEquals("Border", "0", frameSetTag.getAttribute("Border"));
90         // Now check the frames
91
FrameTag topFrame = frameSetTag.getFrame("topFrame");
92         FrameTag mainFrame = frameSetTag.getFrame("mainFrame");
93         assertNotNull("Top Frame should not be null", topFrame);
94         assertNotNull("Main Frame should not be null", mainFrame);
95         assertEquals("Top Frame Name", "topFrame", topFrame.getFrameName());
96         assertEquals(
97             "Top Frame Location",
98             "http://www.google.com/test/demo_bc_top.html",
99             topFrame.getFrameLocation());
100         assertEquals("Main Frame Name", "mainFrame", mainFrame.getFrameName());
101         assertEquals(
102             "Main Frame Location",
103             "http://www.kizna.com/web_e/",
104             mainFrame.getFrameLocation());
105         assertEquals(
106             "Scrolling in Main Frame",
107             "AUTO",
108             mainFrame.getAttribute("Scrolling"));
109     }
110 }
111
Popular Tags