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: *
17: * Based on code generated by Agitar build: Agitator Version 1.0.2.000071 (Build date: Jan 12, 2007) [1.0.2.000071]
18: */package org.jamwiki.utils;
19:
20: import java.io.BufferedReader;
21: import java.io.ByteArrayInputStream;
22: import java.io.InputStreamReader;
23: import java.sql.Timestamp;
24: import java.text.SimpleDateFormat;
25: import java.util.ArrayList;
26: import java.util.LinkedHashMap;
27: import java.util.Vector;
28: import java.util.logging.Handler;
29: import java.util.logging.Level;
30: import java.util.logging.Logger;
31: import junit.framework.TestCase;
32: import org.jamwiki.model.Topic;
33: import org.jamwiki.model.TopicVersion;
34:
35: public class TiddlyWikiParserTest extends TestCase {
36:
37: private static final String NAME = "MyTopic";
38: private static final String DATUM = "200701020304";
39: private static final String CONTENT = "Content";
40:
41: public void testParse() throws Exception {
42: Handler[] h = Logger.getLogger("").getHandlers();
43: for (int i = 0; i < h.length; i++) {
44: h[i].setLevel(Level.ALL);
45: }
46: Logger.getLogger("").setLevel(Level.ALL);
47: WikiBaseMock mock = new WikiBaseMock();
48: TiddlyWikiParser parser = new TiddlyWikiParser("myvirtual",
49: null, "", mock);
50: String testLine = "<div tiddler=\"" + NAME + "\" modified=\""
51: + DATUM + "\">" + CONTENT + "</div>";
52: parser.parse(new BufferedReader(new InputStreamReader(
53: new ByteArrayInputStream(testLine.getBytes()))));
54: assertEquals(1, mock.topics.size());
55: Topic result = (Topic) mock.topics.get(0);
56: assertEquals(NAME, result.getName());
57: assertEquals(CONTENT, result.getTopicContent());
58: assertEquals(1, mock.versions.size());
59: TopicVersion version = (TopicVersion) mock.versions.get(0);
60: SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmm");
61: Timestamp t = new Timestamp(fmt.parse(DATUM).getTime());
62: assertEquals(t, version.getEditDate());
63: }
64:
65: private class WikiBaseMock implements
66: TiddlyWikiParser.WikiBaseFascade {
67: public ArrayList topics = new ArrayList();
68: public ArrayList versions = new ArrayList();
69:
70: public void writeTopic(Topic topic, TopicVersion topicVersion,
71: LinkedHashMap categories, Vector links,
72: boolean userVisible, Object transactionObject)
73: throws Exception {
74: topics.add(topic);
75: versions.add(topicVersion);
76: }
77: }
78: }
|