|
|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
Other links
The source code
package tests;
import java.util.*;
import org.stringtree.factory.memory.MapStringRepository;
import org.stringtree.util.ResourceUtils;
import com.efsol.friki.*;
public class ClassicFilterTest extends FilterTest
{
MapStringRepository context;
Map remoteNames;
public ClassicFilterTest(String name)
{
super(name);
}
public void setUp()
{
super.setUp();
context = new MapStringRepository();
remoteNames = new HashMap();
remoteNames.put("ALife", "http://news.alife.org/wiki/index.php?");
remoteNames.put("Wiki", "http://c2.com/cgi/wiki?");
setFilter(new ClassicToHTMLFilter(context, rep, remoteNames, ResourceUtils.readResource("wiki.transform")));
}
public void testPlainText()
{
check("ClassicFilterTest.plain text 1", "hello, there",
"hello, there");
check("ClassicFilterTest.plain text 2", "then run c:\\bin\\rsync.exe",
"then run c:\\bin\\rsync.exe");
}
public void testItalics()
{
check("ClassicFilterTest.italic 1", "uh<i>hello there",
"uh''hello'' there");
}
public void testBold()
{
check("ClassicFilterTest.bold 1", "uh<b>hello there",
"uh'''hello''' there");
}
public void testBoldItalic()
{
check("ClassicFilterTest.bolditalic 1", "uh<i>hello there",
"uh'''''hello''''' there");
check("ClassicFilterTest.bolditalic 2", "uh<i>humhello there",
"uh''hum'''hello''''' there");
}
public void testRuler()
{
check("ClassicFilterTest.ruler 1", "\n<hr/>",
"----");
check("ClassicFilterTest.ruler 2", "\n<hr/>",
"-----");
check("ClassicFilterTest.ruler 3", "\n<hr/>",
"------");
check("ClassicFilterTest.ruler 4", "---",
"---");
}
public void testExternalLinks()
{
check("ClassicFilterTest.ext 1",
"<a href='http://www.efsol.com/'>http://www.efsol.com/",
"http://www.efsol.com/");
check("ClassicFilterTest.ext 2",
"<a href='http://www.efsol.com/friki?JustLink'>http://www.efsol.com/friki?JustLink",
"http://www.efsol.com/friki?JustLink");
check("ClassicFilterTest.ext 3",
"<a href='mailto:test@efsol.com'>mailto:test@efsol.com",
"mailto:test@efsol.com");
check("ClassicFilterTest.ext 4",
"<a href='mailto:test@efsol.gif'>mailto:test@efsol.gif",
"mailto:test@efsol.gif");
check("ClassicFilterTest.ext 5",
"<a href='mailto:test@172.16.1.254'>mailto:test@172.16.1.254",
"mailto:test@172.16.1.254");
check("ClassicFilterTest.ext 6",
"<a href='http://www.efsol.com/friki?JustLink&x=2'>http://www.efsol.com/friki?JustLink&x=2.",
"http://www.efsol.com/friki?JustLink&x=2.");
check("ClassicFilterTest.ext 7",
"<b>http://www.efsol.com/friki?JustLink&x=2",
"'''http://www.efsol.com/friki?JustLink&x=2'''");
check("ClassicFilterTest.ext 8",
"<a href='http://www.efsol.com/FrankCarver.html'>http://www.efsol.com/FrankCarver.html",
"http://www.efsol.com/FrankCarver.html");
}
public void testInlinedLinks()
{
check("ClassicFilterTest.inlined 1",
"<img src='http://www.efsol.com/images/efsol-logo.gif'/>",
"http://www.efsol.com/images/efsol-logo.gif");
check("ClassicFilterTest.inlined 2",
"<img src='ftp://www.efsol.com/images/efsol-logo.jpg'/>",
"ftp://www.efsol.com/images/efsol-logo.jpg");
check("ClassicFilterTest.inlined 3",
"<img src='http://www.efsol.com/images/efsol-logo.gif?ugh=x'/>",
"http://www.efsol.com/images/efsol-logo.gif?ugh=x");
}
public void testUnorderedList()
{
check("ClassicFilterTest.unordered 1", "\n<ul>\nfirst\nsecond\n\n",
"\t* first\n\t*second\n");
check("ClassicFilterTest.unordered 2", "\n<ul>\nfirst\nsecond\n\nmore stuff",
"\t* first\n\t*second\nmore stuff");
check("ClassicFilterTest.unordered 3", "\n<ul>\nfirst\nsecond\n\nmore stuff",
"\t* first\r\n\t*second\r\nmore stuff");
check("ClassicFilterTest.unordered 4", "JustLink<a href='edit?JustLink'>?\n\n\nmore stuff",
"JustLink\n\t* first\r\n\t*second\r\nmore stuff");
check("ClassicFilterTest.unordered 5", "\n<ul>\nfirst\nsecond\n\nabc\ndef ",
"\t* first\n\t*second\n abc\n def");
check("ClassicFilterTest.unordered 6", "\n\t*\n<ul>\n \n\n",
"\t*\n\t* \n");
}
public void testOrderedList()
{
check("ClassicFilterTest.ordered 1", "\n<ol>\nfirst\nsecond\n\n",
"\t1 first\n\t1second\n");
check("ClassicFilterTest.ordered 1", "\n<ol>\nfirst\nsecond\n\n",
" 1 first\n 1second\n");
check("ClassicFilterTest.ordered 1", "\n<ol>\nfirst\nsecond\n\n",
" 1. first\n 1second\n");
check("ClassicFilterTest.ordered 2", "\n<ol>\nfirst\nsecond\n\nmore stuff",
"\t1 first\n\t1second\nmore stuff");
check("ClassicFilterTest.ordered 3", "\n<ol>\nfirst\nsecond\n\nmore stuff",
"\t1 first\r\n\t1second\r\nmore stuff");
}
public void testMixedList()
{
check("ClassicFilterTest.mixed 1", "\n<ol>\nfirst\n\n\n",
"\t1 first\n\t*second\n");
check("ClassicFilterTest.mixed 2", "\n<ul>\nfirst unordered element\nsecond unordered element\n\n\n- third ordered element
\n \n",
"\t* first unordered element\n\t* second unordered element\n\t1 third ordered element");
}
public void testMonospace()
{
check("ClassicFilterTest.monospace 1", "<pre>uhhello there",
" uh''hello'' there");
check("ClassicFilterTest.monospace 2", "<pre>uh\n there\n too",
" uh\n there\n too");
check("ClassicFilterTest.monospace 3", "<pre>uh\n there\n too",
" uh\r\n there\r\n too");
check("ClassicFilterTest.monospace 4", "\n<pre>uh\n there\n too",
"\n uh\r\n there\r\n too");
}
public void testISBN()
{
check("ClassicFilterTest.isbn 1",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"ISBN 047120708X");
check("ClassicFilterTest.isbn 2",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"[ISBN 047120708X]");
check("ClassicFilterTest.isbn 3",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"[ ISBN 047120708X]");
check("ClassicFilterTest.isbn 4",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"[ ISBN 047120708X ]");
check("ClassicFilterTest.isbn 5",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"ISBN: 047120708X");
check("ClassicFilterTest.isbn 6",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"[ISBN: 047120708X]");
check("ClassicFilterTest.isbn 7",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"[ ISBN: 047120708X]");
check("ClassicFilterTest.isbn 8",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047120708X",
"[ ISBN: 047120708X ]");
check("ClassicFilterTest.isbn 9",
"<a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047-120-708-X",
"ISBN 047-120-708-X");
check("ClassicFilterTest.isbn 10",
"prefix <a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047-120-708-X hello",
"prefix ISBN 047-120-708-X hello");
check("ClassicFilterTest.isbn 11",
"prefix <a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047-120-708-X hello",
"prefix [ISBN 047-120-708-X] hello");
check("ClassicFilterTest.isbn 12",
"prefix <a href='http://www.amazon.com/exec/obidos/ASIN/047120708X/efficacysolut-20'>ISBN 047-120-708-X hello",
"prefix [ ISBN 047-120-708-X ] hello");
}
public void testJustLink()
{
check("ClassicFilterTest.just link 1.1", "JustLink<a href='edit?JustLink'>?",
"JustLink");
check("ClassicFilterTest.just link 1.2", "Just<b>Link",
"Just''''''Link");
check("ClassicFilterTest.just link 1.3", "a JustLink<a href='edit?JustLink'>?",
"a JustLink");
check("ClassicFilterTest.just link 1.4", "a JustLink<a href='edit?JustLink'>? ",
"a JustLink ");
check("ClassicFilterTest.just link 1.5",
"JustLink<a href='edit?JustLink'>?\nAnotherLink?\nThirdLink?",
"JustLink\nAnotherLink\nThirdLink");
rep.put("JustLink", new Page("JustLink"));
check("ClassicFilterTest.just link 2", "<a href='view?JustLink'>JustLink",
"JustLink");
check("ClassicFilterTest.just link 3", "Just",
"Just");
check("ClassicFilterTest.just link 4", "JustL",
"JustL");
check("ClassicFilterTest.just link 5", "JustLI",
"JustLI");
check("ClassicFilterTest.just link 6", "JustLinkI",
"JustLinkI");
check("ClassicFilterTest.just link 7", "(<a href='view?JustLink'>JustLink)",
"(JustLink)");
}
public void testInterwikiLinks()
{
check("ClassicFilterTest.interwiki 1",
"<a href='http://news.alife.org/wiki/index.php?HoopyFrood'>ALife:HoopyFrood",
"ALife:HoopyFrood");
check("ClassicFilterTest.interwiki 2",
"<a href='http://c2.com/cgi/wiki?FrankCarver'>Wiki:FrankCarver",
"Wiki:FrankCarver");
check("ClassicFilterTest.interwiki 3",
"NotAnotherWiki:FrankCarver",
"NotAnotherWiki:FrankCarver");
}
public void testDefList()
{
check("ClassicFilterTest.deflist 1", "<dl>\n\tfirstsecond\n\n",
"\tfirst:\tsecond\n");
check("ClassicFilterTest.deflist 2",
"<dl>\n"+
"\t<dt>first termThis is first definition.\n" +
"\t<dt>second termThis is the second definition.\n" +
"</dl>\n",
"\tfirst term:\tThis is first definition.\n\tsecond term:\tThis is the second definition.\n");
check("ClassicFilterTest.deflist 3",
"<dl>\n"+
"\t<dt>first termThis is first definition.\n" +
"\t<dt>second termThis is the second definition.\n" +
"</dl>\n",
"\tfirst term:\tThis is first definition.\r\n\tsecond term:\tThis is the second definition.\r\n");
}
public void testIndents()
{
check("ClassicFilterTest.indent 1", "\n<ol>\n\n- first
\n \n\n",
"\t\t1 first\n");
check("ClassicFilterTest.indent 2", "\n<ul>\nhello\n\n- first
\n \n\n",
"\t*hello\n\t\t1 first\n");
check("ClassicFilterTest.indent 3", "\n<ul>\nhello\n\n\n",
"\t*hello\n\t\t*first\n");
check("ClassicFilterTest.indent 3", "\n<ul>\nhello\n\n\n",
" *hello\n *first\n");
}
public void testTable()
{
check("ClassicFilterTest.table 1", "<table BORDER CELLSPACING='0' CELLPADDING='3'>\n |