001: /**
002: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003: *
004: * This program is free software; you can redistribute it and/or modify
005: * it under the terms of the latest version of the GNU Lesser General
006: * Public License as published by the Free Software Foundation;
007: *
008: * This program is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public License
014: * along with this program (LICENSE.txt); if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
016: *
017: * Based on code generated by Agitar build: Agitator Version 1.0.2.000071 (Build date: Jan 12, 2007) [1.0.2.000071]
018: */package org.jamwiki.utils;
019:
020: import java.io.FileNotFoundException;
021: import java.util.Locale;
022: import junit.framework.TestCase;
023: import org.jamwiki.WikiException;
024: import org.jamwiki.WikiMessage; /* FIXME - re-enable
025: import org.jamwiki.db.DatabaseUserHandler;
026: */
027: import org.jamwiki.model.Topic;
028:
029: public class WikiUtilTest extends TestCase {
030:
031: /**
032: *
033: */
034: public void testExtractCommentsLink() throws Throwable {
035: // FIXME
036: // String result = WikiUtil.extractCommentsLink("testWikiUtilName");
037: // assertEquals("result", "null:testWikiUtilName", result);
038: }
039:
040: /**
041: *
042: */
043: public void testExtractTopicLink() throws Throwable {
044: //TODO
045: String result = WikiUtil.extractTopicLink("testWikiUtilName");
046: assertSame("result", "testWikiUtilName", result);
047: }
048:
049: /**
050: *
051: */
052: /* FIXME - re-enable
053: public void testFindRedirectedTopic() throws Throwable {
054: Topic parent = new Topic();
055: parent.setRedirectTo("testWikiUtilRedirectTo");
056: parent.setTopicType(2);
057: Topic result = WikiUtil.findRedirectedTopic(parent, 8);
058: assertSame("result", parent, result);
059: }
060: */
061:
062: /**
063: *
064: */
065: public void testFindRedirectedTopic1() throws Throwable {
066: Topic parent = new Topic();
067: parent.setTopicType(2);
068: Topic result = WikiUtil.findRedirectedTopic(parent, 100);
069: assertSame("result", parent, result);
070: }
071:
072: /**
073: *
074: */
075: /* FIXME - re-enable
076: public void testUserHandlerInstance() throws Throwable {
077: DatabaseUserHandler result = (DatabaseUserHandler) WikiUtil.userHandlerInstance();
078: assertTrue("result.isWriteable()", result.isWriteable());
079: }
080: */
081:
082: /**
083: *
084: */
085: public void testValidateDirectory1() throws Throwable {
086: WikiMessage result = WikiUtil
087: .validateDirectory("testUtilitiesName");
088: assertEquals("result.getKey()", "error.directoryinvalid",
089: result.getKey());
090: }
091:
092: /**
093: *
094: */
095: public void testExtractCommentsLinkThrowsException()
096: throws Throwable {
097: try {
098: WikiUtil.extractCommentsLink("");
099: fail("Expected Exception to be thrown");
100: } catch (Exception ex) {
101: assertEquals("ex.getMessage()", "Empty topic name ", ex
102: .getMessage());
103: }
104: }
105:
106: /**
107: *
108: */
109: public void testExtractTopicLinkThrowsException() throws Throwable {
110: try {
111: WikiUtil.extractTopicLink("");
112: fail("Expected Exception to be thrown");
113: } catch (Exception ex) {
114: assertEquals("ex.getMessage()", "Empty topic name ", ex
115: .getMessage());
116: }
117: }
118:
119: /**
120: *
121: */
122: /* FIXME - re-enable
123: public void testFindRedirectedTopicThrowsClassNotFoundException() throws Throwable {
124: Topic parent = new Topic();
125: parent.setRedirectTo("testWikiUtilRedirectTo");
126: parent.setTopicType(2);
127: parent.setVirtualWiki("testWikiUtilVirtualWiki");
128: try {
129: WikiUtil.findRedirectedTopic(parent, 8);
130: fail("Expected ClassNotFoundException to be thrown");
131: } catch (ClassNotFoundException ex) {
132: assertTrue("Test completed without Exception", true);
133: // dependencies on static and environment state led to removal of 3 assertion(s)
134: }
135: }
136: */
137:
138: /**
139: *
140: */
141: public void testReadSpecialPageThrowsFileNotFoundException()
142: throws Throwable {
143: try {
144: WikiUtil.readSpecialPage(null, "testWikiUtilPageName");
145: fail("Expected FileNotFoundException to be thrown");
146: } catch (FileNotFoundException ex) {
147: assertEquals("ex.getClass()", FileNotFoundException.class,
148: ex.getClass());
149: }
150: }
151:
152: /**
153: *
154: */
155: public void testReadSpecialPageThrowsFileNotFoundException1()
156: throws Throwable {
157: try {
158: WikiUtil.readSpecialPage(Locale.GERMAN,
159: "testWikiUtilPageName");
160: fail("Expected FileNotFoundException to be thrown");
161: } catch (FileNotFoundException ex) {
162: assertEquals("ex.getClass()", FileNotFoundException.class,
163: ex.getClass());
164: }
165: }
166:
167: /**
168: *
169: */
170: public void testReadSpecialPageThrowsFileNotFoundException2()
171: throws Throwable {
172: try {
173: WikiUtil.readSpecialPage(Locale.SIMPLIFIED_CHINESE,
174: "testWikiUtilPageName");
175: fail("Expected FileNotFoundException to be thrown");
176: } catch (FileNotFoundException ex) {
177: assertEquals("ex.getClass()", FileNotFoundException.class,
178: ex.getClass());
179: }
180: }
181:
182: /**
183: *
184: */
185: public void testValidateDirectoryThrowsNullPointerException()
186: throws Throwable {
187: try {
188: WikiUtil.validateDirectory(null);
189: fail("Expected NullPointerException to be thrown");
190: } catch (NullPointerException ex) {
191: assertNull("ex.getMessage()", ex.getMessage());
192: }
193: }
194:
195: /**
196: *
197: */
198: public void testValidateTopicNameThrowsNullPointerException()
199: throws Throwable {
200: try {
201: WikiUtil.validateTopicName(null);
202: fail("Expected NullPointerException to be thrown");
203: } catch (WikiException ex) {
204: assertNull("ex.getMessage()", ex.getMessage());
205: }
206: }
207:
208: /**
209: *
210: */
211: public void testValidateTopicNameThrowsWikiException()
212: throws Throwable {
213: try {
214: WikiUtil.validateTopicName("");
215: fail("Expected WikiException to be thrown");
216: } catch (WikiException ex) {
217: assertNull("ex.getMessage()", ex.getMessage());
218: assertEquals("ex.getWikiMessage().getKey()",
219: "common.exception.notopic", ex.getWikiMessage()
220: .getKey());
221: }
222: }
223:
224: /**
225: *
226: */
227: /*
228: public void testValidateTopicNameThrowsWikiException1() throws Throwable {
229: try {
230: WikiUtil.validateTopicName("testWikiUtil\rName");
231: fail("Expected WikiException to be thrown");
232: } catch (WikiException ex) {
233: assertNull("ex.getMessage()", ex.getMessage());
234: assertEquals("ex.getWikiMessage().getKey()", "common.exception.name", ex.getWikiMessage().getKey());
235: }
236: }
237: */
238:
239: /**
240: *
241: */
242: public void testValidateUserNameThrowsWikiException()
243: throws Throwable {
244: try {
245: WikiUtil.validateUserName("testWikiUtil\rName");
246: fail("Expected WikiException to be thrown");
247: } catch (WikiException ex) {
248: assertNull("ex.getMessage()", ex.getMessage());
249: assertEquals("ex.getWikiMessage().getKey()",
250: "common.exception.name", ex.getWikiMessage()
251: .getKey());
252: }
253: }
254:
255: /**
256: *
257: */
258: public void testValidateUserNameThrowsWikiException1()
259: throws Throwable {
260: try {
261: WikiUtil.validateUserName("");
262: fail("Expected WikiException to be thrown");
263: } catch (WikiException ex) {
264: assertNull("ex.getMessage()", ex.getMessage());
265: assertEquals("ex.getWikiMessage().getKey()",
266: "error.loginempty", ex.getWikiMessage().getKey());
267: }
268: }
269: }
|