KickJava   Java API By Example, From Geeks To Geeks.

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


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2003 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/tests/tagTests/HtmlTagTest.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/07/02 00:49:31 $
10
// $Revision: 1.2 $
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.Node;
30 import org.htmlparser.PrototypicalNodeFactory;
31 import org.htmlparser.Tag;
32 import org.htmlparser.filters.NodeClassFilter;
33 import org.htmlparser.tags.Html;
34 import org.htmlparser.tags.TitleTag;
35 import org.htmlparser.tests.ParserTestCase;
36 import org.htmlparser.util.NodeList;
37
38 public class HtmlTagTest extends ParserTestCase
39 {
40     static
41     {
42         System.setProperty ("org.htmlparser.tests.tagTests.HtmlTagTest", "HtmlTagTest");
43     }
44
45     public HtmlTagTest (String JavaDoc name)
46     {
47         super(name);
48     }
49     
50     public void testScan() throws Exception JavaDoc {
51         createParser(
52             "<html>" +
53             " <head>" +
54             " <title>Some Title</title>" +
55             " </head>" +
56             " <body>" +
57             " Some data" +
58             " </body>" +
59             "</html>");
60         parser.setNodeFactory (
61             new PrototypicalNodeFactory (
62                 new Tag[]
63                 {
64                     new TitleTag (),
65                     new Html (),
66                 }));
67         parseAndAssertNodeCount(1);
68         assertType("html tag",Html.class,node[0]);
69         Html html = (Html)node[0];
70         NodeList nodeList = new NodeList();
71         NodeClassFilter filter = new NodeClassFilter (TitleTag.class);
72         html.collectInto(nodeList, filter);
73         assertEquals("nodelist size",1,nodeList.size());
74         Node node = nodeList.elementAt(0);
75         assertType("expected title tag",TitleTag.class,node);
76         TitleTag titleTag = (TitleTag)node;
77         assertStringEquals("title","Some Title",titleTag.getTitle());
78     }
79 }
80
Free Books   Free Magazines  
Popular Tags