01: /**
02: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the latest version of the GNU Lesser General
06: * Public License as published by the Free Software Foundation;
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program (LICENSE.txt); if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: */package org.jamwiki.parser;
17:
18: import junit.framework.TestCase;
19: import org.apache.commons.lang.LocaleUtils;
20: import org.apache.commons.lang.StringUtils;
21: import org.jamwiki.TestFileUtil;
22: import org.jamwiki.utils.WikiLogger;
23:
24: /**
25: *
26: */
27: public abstract class TestParser extends TestCase {
28:
29: private static final WikiLogger logger = WikiLogger
30: .getLogger(TestParser.class.getName());
31:
32: /**
33: *
34: */
35: public TestParser(String name) {
36: super (name);
37: }
38:
39: /**
40: *
41: */
42: private String parse(String topicName, String raw) throws Exception {
43: // set dummy values for parser input
44: ParserInput parserInput = new ParserInput();
45: parserInput.setContext("/wiki");
46: parserInput.setLocale(LocaleUtils.toLocale("en_US"));
47: parserInput.setWikiUser(null);
48: parserInput.setTopicName(topicName);
49: parserInput.setUserIpAddress("0.0.0.0");
50: parserInput.setVirtualWiki("en");
51: parserInput.setAllowSectionEdit(true);
52: ParserOutput parserOutput = new ParserOutput();
53: return ParserUtil.parse(parserInput, parserOutput, raw);
54: }
55:
56: /**
57: *
58: */
59: protected void executeParserTest(String topicName) throws Exception {
60: String parserResult = this .parserResult(topicName);
61: String expectedResult = this .expectedResult(topicName);
62: assertEquals(parserResult, expectedResult);
63: }
64:
65: /**
66: *
67: */
68: private String expectedResult(String topicName) throws Exception {
69: String raw = TestFileUtil.retrieveFileContent(
70: TestFileUtil.TEST_TOPICS_DIR, topicName);
71: String output = this .parse(topicName, raw);
72: // FIXME - the sanitize should be unnecessary
73: return this .sanitize(output);
74: }
75:
76: /**
77: *
78: */
79: private String parserResult(String topicName) throws Exception {
80: String result = TestFileUtil.retrieveFileContent(
81: TestFileUtil.TEST_RESULTS_DIR, topicName);
82: // FIXME - the sanitize should be unnecessary
83: return this .sanitize(result);
84: }
85:
86: /**
87: *
88: */
89: private String sanitize(String value) {
90: return StringUtils.remove(value, '\r').trim();
91: }
92: }
|