KickJava   Java API By Example, From Geeks To Geeks.

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


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/FrameTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/01/02 16:24:57 $
10
// $Revision: 1.36 $
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.tags.FrameTag;
31 import org.htmlparser.tests.ParserTestCase;
32 import org.htmlparser.util.ParserException;
33
34 public class FrameTagTest extends ParserTestCase {
35
36     static
37     {
38         System.setProperty ("org.htmlparser.tests.tagTests.FrameTagTest", "FrameTagTest");
39     }
40
41     public FrameTagTest(String JavaDoc name) {
42         super(name);
43     }
44
45     public void testToHTML() throws ParserException {
46         String JavaDoc frame1 = "<frame name=\"topFrame\" noresize SRC=\"demo_bc_top.html\" scrolling=\"NO\" frameborder=\"NO\">";
47         String JavaDoc frame2 = "<frame name=\"mainFrame\" SRC=\"http://www.kizna.com/web_e/\" scrolling=\"AUTO\">";
48         createParser(
49         "<frameset rows=\"115,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">\n"+
50             frame1 + "\n"+
51             frame2 + "\n"+
52         "</frameset>");
53         parser.setNodeFactory (new PrototypicalNodeFactory (new FrameTag ()));
54         parseAndAssertNodeCount(7);
55         assertTrue("Node 3 should be Frame Tag",node[2] instanceof FrameTag);
56         assertTrue("Node 5 should be Frame Tag",node[4] instanceof FrameTag);
57
58         FrameTag frameTag1 = (FrameTag)node[2];
59         FrameTag frameTag2 = (FrameTag)node[4];
60
61         assertStringEquals("Frame 1 toHTML()",frame1,frameTag1.toHtml());
62         assertStringEquals("Frame 2 toHTML()",frame2,frameTag2.toHtml());
63     }
64
65     public void testScan() throws ParserException {
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>","http://www.google.com/test/index.html");
71
72         parser.setNodeFactory (new PrototypicalNodeFactory (new FrameTag ()));
73         parseAndAssertNodeCount(7);
74
75         assertTrue("Node 2 should be Frame Tag",node[2] instanceof FrameTag);
76         assertTrue("Node 4 should be Frame Tag",node[4] instanceof FrameTag);
77
78         FrameTag frameTag1 = (FrameTag)node[2];
79         FrameTag frameTag2 = (FrameTag)node[4];
80         assertEquals("Frame 1 Locn","http://www.google.com/test/demo_bc_top.html",frameTag1.getFrameLocation());
81         assertEquals("Frame 1 Name","topFrame",frameTag1.getFrameName());
82         assertEquals("Frame 2 Locn","http://www.kizna.com/web_e/",frameTag2.getFrameLocation());
83         assertEquals("Frame 2 Name","mainFrame",frameTag2.getFrameName());
84         assertEquals("Frame 1 Scrolling","NO",frameTag1.getAttribute("scrolling"));
85         assertEquals("Frame 1 Border","NO",frameTag1.getAttribute("frameborder"));
86     }
87 }
88
89
Popular Tags