1 package org.apache.maven.doxia.module.xhtml;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.Iterator;
24 import java.util.List;
25
26 import org.apache.maven.doxia.parser.AbstractParserTest;
27 import org.apache.maven.doxia.parser.Parser;
28 import org.apache.maven.doxia.sink.SinkEventElement;
29 import org.apache.maven.doxia.sink.SinkEventTestingSink;
30 import org.codehaus.plexus.util.FileUtils;
31
32
33
34
35
36 public class XhtmlParserTest
37 extends AbstractParserTest
38 {
39 private XhtmlParser parser;
40
41
42 protected void setUp()
43 throws Exception
44 {
45 super.setUp();
46
47 parser = (XhtmlParser) lookup( Parser.ROLE, "xhtml" );
48
49
50
51 String tmpDir = System.getProperty( "java.io.tmpdir" );
52 String excludes = "xhtml-lat1.ent, xhtml1-transitional.dtd, xhtml-special.ent, xhtml-symbol.ent";
53 @SuppressWarnings( "unchecked" )
54 List<String> tmpFiles = FileUtils.getFileNames( new File( tmpDir ), excludes, null, true );
55 for ( String filename : tmpFiles )
56 {
57 File tmpFile = new File( filename );
58 tmpFile.delete();
59 }
60 }
61
62
63 protected Parser createParser()
64 {
65 return parser;
66 }
67
68
69 protected String outputExtension()
70 {
71 return "xhtml";
72 }
73
74
75 public void testDocumentBodyEventsList()
76 throws Exception
77 {
78 String text = "<html><body></body></html>";
79
80 SinkEventTestingSink sink = new SinkEventTestingSink();
81
82 ( (XhtmlParser) createParser() ).parse( text, sink );
83
84 Iterator<SinkEventElement> it = sink.getEventList().iterator();
85
86 assertEquals( "body", it.next().getName() );
87 assertEquals( "body_", it.next().getName() );
88 assertFalse( it.hasNext() );
89 }
90
91
92 public void testHeadEventsList()
93 throws Exception
94 {
95 String text = "<head><title>Title</title><meta name=\"author\" content=\"Author\" />"
96 + "<meta name=\"date\" content=\"Date\" /><meta name=\"security\" content=\"low\"/></head>";
97
98 SinkEventTestingSink sink = new SinkEventTestingSink();
99
100 ( (XhtmlParser) createParser() ).parse( text, sink );
101
102 Iterator<SinkEventElement> it = sink.getEventList().iterator();
103
104 assertEquals( "head", it.next().getName() );
105 assertEquals( "title", it.next().getName() );
106 assertEquals( "text", it.next().getName() );
107 assertEquals( "title_", it.next().getName() );
108 assertEquals( "author", it.next().getName() );
109 assertEquals( "text", it.next().getName() );
110 assertEquals( "author_", it.next().getName() );
111 assertEquals( "date", it.next().getName() );
112 assertEquals( "text", it.next().getName() );
113 assertEquals( "date_", it.next().getName() );
114 assertEquals( "unknown", it.next().getName() );
115 assertEquals( "head_", it.next().getName() );
116 assertFalse( it.hasNext() );
117 }
118
119
120 public void testPreEventsList()
121 throws Exception
122 {
123 String text = "<pre></pre>";
124
125 SinkEventTestingSink sink = new SinkEventTestingSink();
126
127 ( (XhtmlParser) createParser() ).parse( text, sink );
128
129 Iterator<SinkEventElement> it = sink.getEventList().iterator();
130
131 assertEquals( "verbatim", it.next().getName() );
132 assertEquals( "verbatim_", it.next().getName() );
133 assertFalse( it.hasNext() );
134 }
135
136
137
138
139
140
141 public void testUnknown()
142 throws Exception
143 {
144 String text = "<applet><param name=\"name\" value=\"value\"/><unknown/></applet>";
145
146 SinkEventTestingSink sink = new SinkEventTestingSink();
147
148 ( (XhtmlParser) createParser() ).parse( text, sink );
149
150 Iterator<SinkEventElement> it = sink.getEventList().iterator();
151 assertEquals( "unknown", it.next().getName() );
152 assertEquals( "unknown", it.next().getName() );
153 assertEquals( "unknown", it.next().getName() );
154 assertEquals( "unknown", it.next().getName() );
155 assertFalse( it.hasNext() );
156 }
157 }