1 package de.fu_berlin.ties.xml;
2
3 import junit.framework.TestCase;
4
5 import java.io.StringReader;
6 import java.io.StringWriter;
7 import java.util.HashMap;
8 import java.util.Map;
9 import java.util.regex.Pattern;
10
11 import de.fu_berlin.ties.text.TextUtils;
12
13
14 /***
15 * Generated by JUnitDoclet, a tool provided by
16 * ObjectFab GmbH under LGPL.
17 * Please see www.junitdoclet.org, www.gnu.org
18 * and www.objectfab.de for informations about
19 * the tool, the licence and the authors.
20 */
21
22
23 public class TagIsolatorTest
24
25 extends TestCase
26
27 {
28
29 TagIsolator tagisolator = null;
30
31
32 public TagIsolatorTest(String name) {
33
34 super(name);
35
36 }
37
38 public de.fu_berlin.ties.xml.TagIsolator createInstance() throws Exception {
39
40 return new de.fu_berlin.ties.xml.TagIsolator();
41
42 }
43
44 protected void setUp() throws Exception {
45
46 super.setUp();
47 tagisolator = createInstance();
48
49 }
50
51 protected void tearDown() throws Exception {
52
53 tagisolator = null;
54 super.tearDown();
55
56 }
57
58 public void testIsolateTags() throws Exception {
59
60 final String nl = TextUtils.LINE_SEPARATOR;
61 final String[] input = new String[] {
62 "<html><head>\n<title>c't 16/2003, S. 28: Digitales Radio\n "
63 + "</title>\r\n",
64 "<meta name=\"description\" content=\"c't - \r\n"
65 + " Magazin für Computertechnik\"> \r\n",
66 "<meta name=\"keywords\" content=\"Computer, Magazin\" />\n"
67 + "\t<base TARGET=\"_top\"/> \n",
68 " <meta name=\"copyright\"\r\n\r\n\tcontent=\"Copyright Heise\">\r\n",
69 "Ende.<!-- NAVIGATION\r(UNTERBRECHUNG FUER TITEL DER MITTLEREN "
70 + "SPALTE) -->\rc't 16/2003",
71 "<h4><a href=\"mailto:roe@ct.de\">Peter R??bke-Doerr</a>\n"
72 + "</h4>\n<h2>Digital Radio Mondiale on air?\n </h2>\n",
73 "heiß begehrt.\r\n\r\n<cadv>\r\n<table border=\"0\" "
74 + "align=\"right\">\r\n <tr>\r\n <td align=\"right\"><img "
75 + "SRC=\"http://www.heise.de/adstream_lx.ads/3102e3134?_RM_EMPTY_\""
76 + "WIDTH=\"1\" HEIGHT=\"1\"></td>\r\n </tr>\r\n</table>\r\n"
77 + "</cadv></p>\r\n\r\n<p>In der Bundesrepublik",
78 "<a href=\"#anfang\"><font size=\"-2\">Seitenanfang</font></a>",
79 "\t<font size=\"-2\"> Zuletzt aktualisiert von \n"
80 + "<a HREF=\"mailto:www@ct.heise.de\">c't-WWW</a>,\n",
81 "<?xml version=\"1.0\"\r\n encoding=\"ISO-8859-1\"?> "
82 + "<?xml-stylesheet type=\"text/css\" href=\n \"augmented.css\"?>"
83 + "<!DOCTYPE html\r\nPUBLIC \"-//W3C//DTD XHTML 1.0"
84 + "Transitional//EN\"\r\n\t"
85 + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
86 + "<html><body> Text"
87 };
88
89 final String[] expectedOutput = new String[] {
90 "<html>" + nl + "<head>\n<title>" + nl
91 + "c't 16/2003, S. 28: Digitales Radio\n</title>\r\n",
92 "<meta name=\"description\" content=\"c't - Magazin für "
93 + "Computertechnik\">\r\n",
94 "<meta name=\"keywords\" content=\"Computer, Magazin\" />\n"
95 + "<base TARGET=\"_top\"/>\n",
96 "<meta name=\"copyright\" content=\"Copyright Heise\">\r\n",
97 "Ende." + nl + "<!-- NAVIGATION (UNTERBRECHUNG FUER TITEL DER MITTLEREN "
98 + "SPALTE) -->\rc't 16/2003",
99 "<h4>" + nl + "<a href=\"mailto:roe@ct.de\">" + nl
100 + "Peter R??bke-Doerr" + nl + "</a>\n" + "</h4>\n<h2>" + nl
101 + "Digital Radio Mondiale on air?\n</h2>\n",
102 "heiß begehrt.\r\n\r\n<cadv>\r\n<table border=\"0\" "
103 + "align=\"right\">\r\n<tr>\r\n<td align=\"right\">" + nl + "<img "
104 + "SRC=\"http://www.heise.de/adstream_lx.ads/3102e3134?_RM_EMPTY_\""
105 + "WIDTH=\"1\" HEIGHT=\"1\">" + nl + "</td>\r\n</tr>\r\n</table>\r\n"
106 + "</cadv>" + nl + "</p>\r\n\r\n<p>" + nl + "In der Bundesrepublik",
107 "<a href=\"#anfang\">" + nl + "<font size=\"-2\">" + nl +
108 "Seitenanfang" + nl + "</font>" + nl + "</a>" + nl,
109 "<font size=\"-2\">" + nl + " Zuletzt aktualisiert von \n"
110 + "<a HREF=\"mailto:www@ct.heise.de\">" + nl + "c't-WWW" + nl
111 + "</a>" + nl + ",\n",
112 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" + nl
113 + "<?xml-stylesheet type=\"text/css\" href= \"augmented.css\"?>"
114 + nl + "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0"
115 + "Transitional//EN\" "
116 + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
117 + "<html>" + nl + "<body>" + nl + "Text"
118 };
119
120 final Map<Pattern, String> replacements = new HashMap<Pattern, String>();
121 replacements.put(Pattern.compile("//s+"), "&;");
122 replacements.put(Pattern.compile("'"), "&';");
123
124 final String[] expectedReplacedOut = new String[] {
125 "<html>" + nl + "<head>\n<title>" + nl
126 + "c't 16/2003, S. 28: Digitales Radio\n</title>\r\n",
127 "<meta&;name=\"description\"&;content=\"c&';t&;-&;Magazin&;für&;"
128 + "Computertechnik\">\r\n",
129 "<meta&;name=\"keywords\"&;content=\"Computer,&;Magazin\"&;/>\n"
130 + "<base&;TARGET=\"_top\"/>\n",
131 "<meta&;name=\"copyright\"&;content=\"Copyright&;Heise\">\r\n",
132 "Ende." + nl + "<!--&;NAVIGATION&;(UNTERBRECHUNG&;FUER&;TITEL&;DER&;MITTLEREN&;"
133 + "SPALTE)&;-->\rc't 16/2003",
134 "<h4>" + nl + "<a&;href=\"mailto:roe@ct.de\">" + nl
135 + "Peter R??bke-Doerr" + nl + "</a>\n" + "</h4>\n<h2>" + nl
136 + "Digital Radio Mondiale on air?\n</h2>\n",
137 "heiß begehrt.\r\n\r\n<cadv>\r\n<table&;border=\"0\"&;"
138 + "align=\"right\">\r\n<tr>\r\n<td&;align=\"right\">" + nl + "<img&;"
139 + "SRC=\"http://www.heise.de/adstream_lx.ads/3102e3134?_RM_EMPTY_\""
140 + "WIDTH=\"1\"&;HEIGHT=\"1\">" + nl + "</td>\r\n</tr>\r\n</table>\r\n"
141 + "</cadv>" + nl + "</p>\r\n\r\n<p>" + nl + "In der Bundesrepublik",
142 "<a&;href=\"#anfang\">" + nl + "<font&;size=\"-2\">" + nl +
143 "Seitenanfang" + nl + "</font>" + nl + "</a>" + nl,
144 "<font&;size=\"-2\">" + nl + " Zuletzt aktualisiert von \n"
145 + "<a&;HREF=\"mailto:www@ct.heise.de\">" + nl + "c't-WWW" + nl
146 + "</a>" + nl + ",\n",
147 "<?xml&;version=\"1.0\"&;encoding=\"ISO-8859-1\"?>" + nl
148 + "<?xml-stylesheet&;type=\"text/css\"&;href=&;\"augmented.css\"?>"
149 + nl + "<!DOCTYPE&;html&;PUBLIC&;\"-//W3C//DTD&;XHTML&;1.0"
150 + "Transitional//EN\"&;"
151 + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
152 + "<html>" + nl + "<body>" + nl + "Text"
153 };
154
155 StringReader in;
156 StringWriter out;
157 for (int i = 0; i < input.length; i++) {
158 in = new StringReader(input[i]);
159 out = new StringWriter();
160 tagisolator.isolateTags(in, out);
161
162 assertEquals(out.toString(), expectedOutput[i]);
163 }
164
165 StringWriter replacedOut;
166 for (int i = 0; i < input.length; i++) {
167 in = new StringReader(input[i]);
168 replacedOut = new StringWriter();
169 tagisolator.isolateTags(in, replacedOut, replacements);
170
171 assertEquals(replacedOut.toString(), expectedReplacedOut[i]);
172 }
173
174 }
175
176 public void testToString() throws Exception {
177
178
179 }
180
181
182
183 /***
184 * JUnitDoclet moves marker to this method, if there is not match
185 * for them in the regenerated code and if the marker is not empty.
186 * This way, no test gets lost when regenerating after renaming.
187 * Method testVault is supposed to be empty.
188 */
189 public void testVault() throws Exception {
190
191
192 }
193
194 public static void main(String[] args) {
195
196 junit.textui.TestRunner.run(TagIsolatorTest.class);
197
198 }
199 }