KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > tests > tagTests > FrameSetTagTest


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Somik Raha
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/FrameSetTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/02 00:49:31 $
10
// $Revision: 1.37 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.tests.tagTests;
28
29 import org.htmlparser.PrototypicalNodeFactory;
30 import org.htmlparser.Tag;
31 import org.htmlparser.tags.FrameSetTag;
32 import org.htmlparser.tags.FrameTag;
33 import org.htmlparser.tests.ParserTestCase;
34 import org.htmlparser.util.ParserException;
35
36 public class FrameSetTagTest extends ParserTestCase {
37
38     static
39     {
40         System.setProperty ("org.htmlparser.tests.tagTests.FrameSetTagTest", "FrameSetTagTest");
41     }
42
43     public FrameSetTagTest(String JavaDoc name) {
44         super(name);
45     }
46
47     public void testToHTML() throws ParserException{
48         String JavaDoc html = "<frameset rows=\"115,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">\n"+
49             "<frame name=\"topFrame\" noresize SRC=\"demo_bc_top.html\" scrolling=\"NO\" frameborder=\"NO\">\n"+
50             "<frame name=\"mainFrame\" SRC=\"http://www.kizna.com/web_e/\" scrolling=\"AUTO\">\n"+
51         "</frameset>";
52         createParser(html);
53         parseAndAssertNodeCount(1);
54         assertTrue("Node 0 should be a FrameSetTag",node[0] instanceof FrameSetTag);
55         FrameSetTag frameSetTag = (FrameSetTag)node[0];
56         assertStringEquals("HTML Contents", html, frameSetTag.toHtml());
57     }
58
59     public void testScan() throws ParserException {
60         createParser(
61         "<frameset rows=\"115,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">\n"+
62             "<frame name=\"topFrame\" noresize SRC=\"demo_bc_top.html\" scrolling=\"NO\" frameborder=\"NO\">\n"+
63             "<frame name=\"mainFrame\" SRC=\"http://www.kizna.com/web_e/\" scrolling=\"AUTO\">\n"+
64         "</frameset>","http://www.google.com/test/index.html");
65
66         parser.setNodeFactory (
67             new PrototypicalNodeFactory (
68                 new Tag[]
69                 {
70                     new FrameSetTag (),
71                     new FrameTag (),
72                 }));
73         parseAndAssertNodeCount(1);
74         assertTrue("Node 0 should be End Tag",node[0] instanceof FrameSetTag);
75         FrameSetTag frameSetTag = (FrameSetTag)node[0];
76         // Find the details of the frameset itself
77
assertEquals("Rows","115,*",frameSetTag.getAttribute("rows"));
78         assertEquals("FrameBorder","NO",frameSetTag.getAttribute("FrameBorder"));
79         assertEquals("FrameSpacing","0",frameSetTag.getAttribute("FrameSpacing"));
80         assertEquals("Border","0",frameSetTag.getAttribute("Border"));
81         // Now check the frames
82
FrameTag topFrame = frameSetTag.getFrame("topFrame");
83         FrameTag mainFrame = frameSetTag.getFrame("mainFrame");
84         assertNotNull("Top Frame should not be null",topFrame);
85         assertNotNull("Main Frame should not be null",mainFrame);
86         assertEquals("Top Frame Name","topFrame",topFrame.getFrameName());
87         assertEquals("Top Frame Location","http://www.google.com/test/demo_bc_top.html",topFrame.getFrameLocation());
88         assertEquals("Main Frame Name","mainFrame",mainFrame.getFrameName());
89         assertEquals("Main Frame Location","http://www.kizna.com/web_e/",mainFrame.getFrameLocation());
90         assertEquals("Scrolling in Main Frame","AUTO",mainFrame.getAttribute("Scrolling"));
91     }
92 }
93
94
Popular Tags