Source Code Cross Referenced for JSPWikiMarkupParserTest.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » parser » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Wiki Engine » JSPWiki » com.ecyrd.jspwiki.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package com.ecyrd.jspwiki.parser;
0002:
0003:        import java.io.BufferedReader;
0004:        import java.io.File;
0005:        import java.io.IOException;
0006:        import java.io.StringReader;
0007:        import java.util.Collection;
0008:        import java.util.Iterator;
0009:        import java.util.Properties;
0010:        import java.util.Vector;
0011:
0012:        import javax.servlet.ServletException;
0013:
0014:        import junit.framework.Test;
0015:        import junit.framework.TestCase;
0016:        import junit.framework.TestSuite;
0017:        import stress.Benchmark;
0018:
0019:        import com.ecyrd.jspwiki.*;
0020:        import com.ecyrd.jspwiki.attachment.Attachment;
0021:        import com.ecyrd.jspwiki.providers.BasicAttachmentProvider;
0022:        import com.ecyrd.jspwiki.render.XHTMLRenderer;
0023:
0024:        public class JSPWikiMarkupParserTest extends TestCase {
0025:            Properties props = new Properties();
0026:            Vector created = new Vector();
0027:
0028:            static final String PAGE_NAME = "testpage";
0029:
0030:            TestEngine testEngine;
0031:
0032:            public JSPWikiMarkupParserTest(String s) {
0033:                super (s);
0034:            }
0035:
0036:            public void setUp() throws Exception {
0037:                props.load(TestEngine.findTestProperties());
0038:
0039:                props.setProperty(
0040:                        "jspwiki.translatorReader.matchEnglishPlurals", "true");
0041:                testEngine = new TestEngine(props);
0042:            }
0043:
0044:            public void tearDown() {
0045:                deleteCreatedPages();
0046:            }
0047:
0048:            private void newPage(String name) throws WikiException {
0049:                testEngine.saveText(name, "<test>");
0050:
0051:                created.addElement(name);
0052:            }
0053:
0054:            private void deleteCreatedPages() {
0055:                for (Iterator i = created.iterator(); i.hasNext();) {
0056:                    String name = (String) i.next();
0057:
0058:                    TestEngine.deleteTestPage(name);
0059:                    testEngine.deleteAttachments(name);
0060:                }
0061:
0062:                created.clear();
0063:            }
0064:
0065:            private String translate(String src) throws IOException,
0066:                    NoRequiredPropertyException, ServletException {
0067:                return translate(new WikiPage(testEngine, PAGE_NAME), src);
0068:            }
0069:
0070:            private String translate(WikiEngine e, String src)
0071:                    throws IOException, NoRequiredPropertyException,
0072:                    ServletException {
0073:                return translate(e, new WikiPage(testEngine, PAGE_NAME), src);
0074:            }
0075:
0076:            private String translate(WikiPage p, String src)
0077:                    throws IOException, NoRequiredPropertyException,
0078:                    ServletException {
0079:                return translate(testEngine, p, src);
0080:            }
0081:
0082:            private String translate(WikiEngine e, WikiPage p, String src)
0083:                    throws IOException, NoRequiredPropertyException,
0084:                    ServletException {
0085:                WikiContext context = new WikiContext(e, p);
0086:                JSPWikiMarkupParser tr = new JSPWikiMarkupParser(context,
0087:                        new BufferedReader(new StringReader(src)));
0088:
0089:                XHTMLRenderer conv = new XHTMLRenderer(context, tr.parse());
0090:
0091:                return conv.getString();
0092:            }
0093:
0094:            private String translate_nofollow(String src) throws IOException,
0095:                    NoRequiredPropertyException, ServletException,
0096:                    WikiException {
0097:                props.load(TestEngine.findTestProperties());
0098:
0099:                props.setProperty("jspwiki.translatorReader.useRelNofollow",
0100:                        "true");
0101:                TestEngine testEngine2 = new TestEngine(props);
0102:
0103:                WikiContext context = new WikiContext(testEngine2,
0104:                        new WikiPage(testEngine2, PAGE_NAME));
0105:                JSPWikiMarkupParser r = new JSPWikiMarkupParser(context,
0106:                        new BufferedReader(new StringReader(src)));
0107:
0108:                XHTMLRenderer conv = new XHTMLRenderer(context, r.parse());
0109:
0110:                return conv.getString();
0111:            }
0112:
0113:            public void testHyperlinks2() throws Exception {
0114:                newPage("Hyperlink");
0115:
0116:                String src = "This should be a [hyperlink]";
0117:
0118:                assertEquals(
0119:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=Hyperlink\">hyperlink</a>",
0120:                        translate(src));
0121:            }
0122:
0123:            public void testHyperlinks3() throws Exception {
0124:                newPage("HyperlinkToo");
0125:
0126:                String src = "This should be a [hyperlink too]";
0127:
0128:                assertEquals(
0129:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperlinkToo\">hyperlink too</a>",
0130:                        translate(src));
0131:            }
0132:
0133:            public void testHyperlinks4() throws Exception {
0134:                newPage("HyperLink");
0135:
0136:                String src = "This should be a [HyperLink]";
0137:
0138:                assertEquals(
0139:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>",
0140:                        translate(src));
0141:            }
0142:
0143:            public void testHyperlinks5() throws Exception {
0144:                newPage("HyperLink");
0145:
0146:                String src = "This should be a [here|HyperLink]";
0147:
0148:                assertEquals(
0149:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">here</a>",
0150:                        translate(src));
0151:            }
0152:
0153:            public void testHyperlinksNamed1() throws Exception {
0154:                newPage("HyperLink");
0155:
0156:                String src = "This should be a [here|HyperLink#heading]";
0157:
0158:                assertEquals(
0159:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink#section-HyperLink-Heading\">here</a>",
0160:                        translate(src));
0161:            }
0162:
0163:            public void testHyperlinksNamed2() throws Exception {
0164:                newPage("HyperLink");
0165:
0166:                String src = "This should be a [HyperLink#heading]";
0167:
0168:                assertEquals(
0169:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink#section-HyperLink-Heading\">HyperLink#heading</a>",
0170:                        translate(src));
0171:            }
0172:
0173:            public void testHyperlinksNamed3() throws Exception {
0174:                newPage("HyperLink");
0175:
0176:                String src = "!Heading Too\r\nThis should be a [HyperLink#heading too]";
0177:
0178:                assertEquals(
0179:                        "<h4 id=\"section-testpage-HeadingToo\">Heading Too</h4>\nThis should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink#section-HyperLink-HeadingToo\">HyperLink#heading too</a>",
0180:                        translate(src));
0181:            }
0182:
0183:            //
0184:            //  Testing CamelCase hyperlinks
0185:            //
0186:
0187:            public void testHyperLinks6() throws Exception {
0188:                newPage("DiscussionAboutWiki");
0189:                newPage("WikiMarkupDevelopment");
0190:
0191:                String src = "[DiscussionAboutWiki] [WikiMarkupDevelopment].";
0192:
0193:                assertEquals(
0194:                        "<a class=\"wikipage\" href=\"/Wiki.jsp?page=DiscussionAboutWiki\">DiscussionAboutWiki</a> <a class=\"wikipage\" href=\"/Wiki.jsp?page=WikiMarkupDevelopment\">WikiMarkupDevelopment</a>.",
0195:                        translate(src));
0196:            }
0197:
0198:            public void testHyperlinksCC() throws Exception {
0199:                newPage("HyperLink");
0200:
0201:                String src = "This should be a HyperLink.";
0202:
0203:                assertEquals(
0204:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>.",
0205:                        translate(src));
0206:            }
0207:
0208:            public void testHyperlinksCCNonExistant() throws Exception {
0209:                String src = "This should be a HyperLink.";
0210:
0211:                assertEquals(
0212:                        "This should be a <a class=\"createpage\" href=\"/Edit.jsp?page=HyperLink\" title=\"Create &quot;HyperLink&quot;\">HyperLink</a>.",
0213:                        translate(src));
0214:            }
0215:
0216:            /**
0217:             *  Check if the CC hyperlink translator gets confused with
0218:             *  unorthodox bracketed links.
0219:             */
0220:
0221:            public void testHyperlinksCC2() throws Exception {
0222:                newPage("HyperLink");
0223:
0224:                String src = "This should be a [  HyperLink  ].";
0225:
0226:                assertEquals(
0227:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">  HyperLink  </a>.",
0228:                        translate(src));
0229:            }
0230:
0231:            public void testHyperlinksCC3() throws Exception {
0232:                String src = "This should be a nonHyperLink.";
0233:
0234:                assertEquals("This should be a nonHyperLink.", translate(src));
0235:            }
0236:
0237:            /** Two links on same line. */
0238:
0239:            public void testHyperlinksCC4() throws Exception {
0240:                newPage("HyperLink");
0241:                newPage("ThisToo");
0242:
0243:                String src = "This should be a HyperLink, and ThisToo.";
0244:
0245:                assertEquals(
0246:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>, and <a class=\"wikipage\" href=\"/Wiki.jsp?page=ThisToo\">ThisToo</a>.",
0247:                        translate(src));
0248:            }
0249:
0250:            /** Two mixed links on same line. */
0251:
0252:            public void testHyperlinksCC5() throws Exception {
0253:                newPage("HyperLink");
0254:                newPage("ThisToo");
0255:
0256:                String src = "This should be a [HyperLink], and ThisToo.";
0257:
0258:                assertEquals(
0259:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>, and <a class=\"wikipage\" href=\"/Wiki.jsp?page=ThisToo\">ThisToo</a>.",
0260:                        translate(src));
0261:            }
0262:
0263:            /** Closing tags only. */
0264:
0265:            public void testHyperlinksCC6() throws Exception {
0266:                newPage("HyperLink");
0267:                newPage("ThisToo");
0268:
0269:                String src = "] This ] should be a HyperLink], and ThisToo.";
0270:
0271:                assertEquals(
0272:                        "] This ] should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>], and <a class=\"wikipage\" href=\"/Wiki.jsp?page=ThisToo\">ThisToo</a>.",
0273:                        translate(src));
0274:            }
0275:
0276:            /** First and last words on line. */
0277:            public void testHyperlinksCCFirstAndLast() throws Exception {
0278:                newPage("HyperLink");
0279:                newPage("ThisToo");
0280:
0281:                String src = "HyperLink, and ThisToo";
0282:
0283:                assertEquals(
0284:                        "<a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>, and <a class=\"wikipage\" href=\"/Wiki.jsp?page=ThisToo\">ThisToo</a>",
0285:                        translate(src));
0286:            }
0287:
0288:            /** Hyperlinks inside URIs. */
0289:
0290:            public void testHyperlinksCCURLs() throws Exception {
0291:                String src = "http://www.foo.bar/ANewHope/";
0292:
0293:                // System.out.println( "EX:"+translate(src) );
0294:                assertEquals(
0295:                        "<a class=\"external\" href=\"http://www.foo.bar/ANewHope/\">http://www.foo.bar/ANewHope/</a>",
0296:                        translate(src));
0297:            }
0298:
0299:            /** Hyperlinks inside URIs. */
0300:
0301:            public void testHyperlinksCCURLs2() throws Exception {
0302:                String src = "mailto:foo@bar.com";
0303:
0304:                // System.out.println( "EX:"+translate(src) );
0305:                assertEquals(
0306:                        "<a class=\"external\" href=\"mailto:foo@bar.com\">mailto:foo@bar.com</a>",
0307:                        translate(src));
0308:            }
0309:
0310:            /** Hyperlinks inside URIs. */
0311:
0312:            public void testHyperlinksCCURLs3() throws Exception {
0313:                String src = "This should be a link: http://www.foo.bar/ANewHope/.  Is it?";
0314:
0315:                // System.out.println( "EX:"+translate(src) );
0316:                assertEquals(
0317:                        "This should be a link: <a class=\"external\" href=\"http://www.foo.bar/ANewHope/\">http://www.foo.bar/ANewHope/</a>.  Is it?",
0318:                        translate(src));
0319:            }
0320:
0321:            /** Hyperlinks in brackets. */
0322:
0323:            public void testHyperlinksCCURLs4() throws Exception {
0324:                String src = "This should be a link: (http://www.foo.bar/ANewHope/)  Is it?";
0325:
0326:                // System.out.println( "EX:"+translate(src) );
0327:                assertEquals(
0328:                        "This should be a link: (<a class=\"external\" href=\"http://www.foo.bar/ANewHope/\">http://www.foo.bar/ANewHope/</a>)  Is it?",
0329:                        translate(src));
0330:            }
0331:
0332:            /** Hyperlinks end line. */
0333:
0334:            public void testHyperlinksCCURLs5() throws Exception {
0335:                String src = "This should be a link: http://www.foo.bar/ANewHope/\nIs it?";
0336:
0337:                // System.out.println( "EX:"+translate(src) );
0338:                assertEquals(
0339:                        "This should be a link: <a class=\"external\" href=\"http://www.foo.bar/ANewHope/\">http://www.foo.bar/ANewHope/</a>\nIs it?",
0340:                        translate(src));
0341:            }
0342:
0343:            /** Hyperlinks with odd chars. */
0344:
0345:            public void testHyperlinksCCURLs6() throws Exception {
0346:                String src = "This should not be a link: http://''some.server''/wiki//Wiki.jsp\nIs it?";
0347:
0348:                // System.out.println( "EX:"+translate(src) );
0349:                assertEquals(
0350:                        "This should not be a link: http://<i>some.server</i>/wiki//Wiki.jsp\nIs it?",
0351:                        translate(src));
0352:            }
0353:
0354:            public void testHyperlinksCCURLs7() throws Exception {
0355:                String src = "http://www.foo.bar/ANewHope?q=foobar&gobble=bobble+gnoo";
0356:
0357:                // System.out.println( "EX:"+translate(src) );
0358:                assertEquals(
0359:                        "<a class=\"external\" href=\"http://www.foo.bar/ANewHope?q=foobar&amp;gobble=bobble+gnoo\">http://www.foo.bar/ANewHope?q=foobar&amp;gobble=bobble+gnoo</a>",
0360:                        translate(src));
0361:            }
0362:
0363:            public void testHyperlinksCCURLs8() throws Exception {
0364:                String src = "http://www.foo.bar/~ANewHope/";
0365:
0366:                // System.out.println( "EX:"+translate(src) );
0367:                assertEquals(
0368:                        "<a class=\"external\" href=\"http://www.foo.bar/~ANewHope/\">http://www.foo.bar/~ANewHope/</a>",
0369:                        translate(src));
0370:            }
0371:
0372:            public void testHyperlinksCCURLs9() throws Exception {
0373:                String src = "http://www.foo.bar/%7EANewHope/";
0374:
0375:                // System.out.println( "EX:"+translate(src) );
0376:                assertEquals(
0377:                        "<a class=\"external\" href=\"http://www.foo.bar/%7EANewHope/\">http://www.foo.bar/%7EANewHope/</a>",
0378:                        translate(src));
0379:            }
0380:
0381:            public void testHyperlinksCCNegated() throws Exception {
0382:                String src = "This should not be a ~HyperLink.";
0383:
0384:                assertEquals("This should not be a HyperLink.", translate(src));
0385:            }
0386:
0387:            public void testHyperlinksCCNegated2() throws Exception {
0388:                String src = "~HyperLinks should not be matched.";
0389:
0390:                assertEquals("HyperLinks should not be matched.",
0391:                        translate(src));
0392:            }
0393:
0394:            public void testHyperlinksCCNegated3() throws Exception {
0395:                String src = "The page ~ASamplePage is not a hyperlink.";
0396:
0397:                assertEquals("The page ASamplePage is not a hyperlink.",
0398:                        translate(src));
0399:            }
0400:
0401:            public void testHyperlinksCCNegated4() throws Exception {
0402:                String src = "The page \"~ASamplePage\" is not a hyperlink.";
0403:
0404:                assertEquals(
0405:                        "The page &quot;ASamplePage&quot; is not a hyperlink.",
0406:                        translate(src));
0407:            }
0408:
0409:            public void testCCLinkInList() throws Exception {
0410:                newPage("HyperLink");
0411:
0412:                String src = "*HyperLink";
0413:
0414:                assertEquals(
0415:                        "<ul><li><a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a></li></ul>",
0416:                        translate(src));
0417:            }
0418:
0419:            public void testCCLinkBold() throws Exception {
0420:                newPage("BoldHyperLink");
0421:
0422:                String src = "__BoldHyperLink__";
0423:
0424:                assertEquals(
0425:                        "<b><a class=\"wikipage\" href=\"/Wiki.jsp?page=BoldHyperLink\">BoldHyperLink</a></b>",
0426:                        translate(src));
0427:            }
0428:
0429:            public void testCCLinkBold2() throws Exception {
0430:                newPage("HyperLink");
0431:
0432:                String src = "Let's see, if a bold __HyperLink__ is correct?";
0433:
0434:                assertEquals(
0435:                        "Let's see, if a bold <b><a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a></b> is correct?",
0436:                        translate(src));
0437:            }
0438:
0439:            public void testCCLinkItalic() throws Exception {
0440:                newPage("ItalicHyperLink");
0441:
0442:                String src = "''ItalicHyperLink''";
0443:
0444:                assertEquals(
0445:                        "<i><a class=\"wikipage\" href=\"/Wiki.jsp?page=ItalicHyperLink\">ItalicHyperLink</a></i>",
0446:                        translate(src));
0447:            }
0448:
0449:            public void testCCLinkWithPunctuation() throws Exception {
0450:                newPage("HyperLink");
0451:
0452:                String src = "Test. Punctuation. HyperLink.";
0453:
0454:                assertEquals(
0455:                        "Test. Punctuation. <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>.",
0456:                        translate(src));
0457:            }
0458:
0459:            public void testCCLinkWithPunctuation2() throws Exception {
0460:                newPage("HyperLink");
0461:                newPage("ThisToo");
0462:
0463:                String src = "Punctuations: HyperLink,ThisToo.";
0464:
0465:                assertEquals(
0466:                        "Punctuations: <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLink</a>,<a class=\"wikipage\" href=\"/Wiki.jsp?page=ThisToo\">ThisToo</a>.",
0467:                        translate(src));
0468:            }
0469:
0470:            public void testCCLinkWithScandics() throws Exception {
0471:                newPage("\u00c4itiSy\u00f6\u00d6ljy\u00e4");
0472:
0473:                String src = "Onko t\u00e4m\u00e4 hyperlinkki: \u00c4itiSy\u00f6\u00d6ljy\u00e4?";
0474:
0475:                assertEquals(
0476:                        "Onko t\u00e4m\u00e4 hyperlinkki: <a class=\"wikipage\" href=\"/Wiki.jsp?page=%C4itiSy%F6%D6ljy%E4\">\u00c4itiSy\u00f6\u00d6ljy\u00e4</a>?",
0477:                        translate(src));
0478:            }
0479:
0480:            public void testHyperlinksExt() throws Exception {
0481:                String src = "This should be a [http://www.regex.fi/]";
0482:
0483:                assertEquals(
0484:                        "This should be a <a class=\"external\" href=\"http://www.regex.fi/\">http://www.regex.fi/</a>",
0485:                        translate(src));
0486:            }
0487:
0488:            public void testHyperlinksExt2() throws Exception {
0489:                String src = "This should be a [link|http://www.regex.fi/]";
0490:
0491:                assertEquals(
0492:                        "This should be a <a class=\"external\" href=\"http://www.regex.fi/\">link</a>",
0493:                        translate(src));
0494:            }
0495:
0496:            public void testHyperlinksExtNofollow() throws Exception {
0497:                String src = "This should be a [link|http://www.regex.fi/]";
0498:
0499:                assertEquals(
0500:                        "This should be a <a class=\"external\" href=\"http://www.regex.fi/\" rel=\"nofollow\">link</a>",
0501:                        translate_nofollow(src));
0502:            }
0503:
0504:            //
0505:            //  Testing various odds and ends about hyperlink matching.
0506:            //
0507:
0508:            public void testHyperlinksPluralMatch() throws Exception {
0509:                String src = "This should be a [HyperLinks]";
0510:
0511:                newPage("HyperLink");
0512:
0513:                assertEquals(
0514:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">HyperLinks</a>",
0515:                        translate(src));
0516:            }
0517:
0518:            public void testHyperlinksPluralMatch2() throws Exception {
0519:                String src = "This should be a [HyperLinks]";
0520:
0521:                assertEquals(
0522:                        "This should be a <a class=\"createpage\" href=\"/Edit.jsp?page=HyperLinks\" title=\"Create &quot;HyperLinks&quot;\">HyperLinks</a>",
0523:                        translate(src));
0524:            }
0525:
0526:            public void testHyperlinksPluralMatch3() throws Exception {
0527:                String src = "This should be a [HyperLink]";
0528:
0529:                newPage("HyperLinks");
0530:
0531:                assertEquals(
0532:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLinks\">HyperLink</a>",
0533:                        translate(src));
0534:            }
0535:
0536:            public void testHyperlinksPluralMatch4() throws Exception {
0537:                String src = "This should be a [Hyper links]";
0538:
0539:                newPage("HyperLink");
0540:
0541:                assertEquals(
0542:                        "This should be a <a class=\"wikipage\" href=\"/Wiki.jsp?page=HyperLink\">Hyper links</a>",
0543:                        translate(src));
0544:            }
0545:
0546:            public void testHyperlinkJS1() throws Exception {
0547:                String src = "This should be a [link|http://www.haxored.com/\" onMouseOver=\"alert('Hahhaa');\"]";
0548:
0549:                assertEquals(
0550:                        "This should be a <a class=\"external\" href=\"http://www.haxored.com/&quot; onMouseOver=&quot;alert('Hahhaa');&quot;\">link</a>",
0551:                        translate(src));
0552:            }
0553:
0554:            public void testHyperlinksInterWiki1() throws Exception {
0555:                String src = "This should be a [link|JSPWiki:HyperLink]";
0556:
0557:                assertEquals(
0558:                        "This should be a <a class=\"interwiki\" href=\"http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=HyperLink\">link</a>",
0559:                        translate(src));
0560:            }
0561:
0562:            public void testHyperlinksInterWiki2() throws Exception {
0563:                String src = "This should be a [JSPWiki:HyperLink]";
0564:
0565:                assertEquals(
0566:                        "This should be a <a class=\"interwiki\" href=\"http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=HyperLink\">JSPWiki:HyperLink</a>",
0567:                        translate(src));
0568:            }
0569:
0570:            public void testAttachmentLink() throws Exception {
0571:                newPage("Test");
0572:
0573:                Attachment att = new Attachment(testEngine, "Test",
0574:                        "TestAtt.txt");
0575:                att.setAuthor("FirstPost");
0576:                testEngine.getAttachmentManager().storeAttachment(att,
0577:                        testEngine.makeAttachmentFile());
0578:
0579:                String src = "This should be an [attachment link|Test/TestAtt.txt]";
0580:
0581:                assertEquals(
0582:                        "This should be an <a class=\"attachment\" href=\"/attach/Test/TestAtt.txt\">attachment link</a>"
0583:                                + "<a href=\"/PageInfo.jsp?page=Test/TestAtt.txt\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>",
0584:                        translate(src));
0585:            }
0586:
0587:            public void testAttachmentLink2() throws Exception {
0588:                props.setProperty("jspwiki.encoding", "ISO-8859-1");
0589:
0590:                //TODO
0591:                TestEngine testEngine2 = new TestEngine(props);
0592:
0593:                testEngine2.saveText("Test", "foo ");
0594:                created.addElement("Test");
0595:
0596:                Attachment att = new Attachment(testEngine2, "Test",
0597:                        "TestAtt.txt");
0598:                att.setAuthor("FirstPost");
0599:
0600:                testEngine2.getAttachmentManager().storeAttachment(att,
0601:                        testEngine.makeAttachmentFile());
0602:
0603:                String src = "This should be an [attachment link|Test/TestAtt.txt]";
0604:
0605:                assertEquals(
0606:                        "This should be an <a class=\"attachment\" href=\"/attach/Test/TestAtt.txt\">attachment link</a>"
0607:                                + "<a href=\"/PageInfo.jsp?page=Test/TestAtt.txt\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>",
0608:                        translate(testEngine2, src));
0609:            }
0610:
0611:            /**
0612:             * Are attachments parsed correctly also when using gappy text?
0613:             */
0614:            public void testAttachmentLink3() throws Exception {
0615:                TestEngine testEngine2 = new TestEngine(props);
0616:
0617:                testEngine2.saveText("TestPage", "foo ");
0618:                created.addElement("TestPage");
0619:
0620:                Attachment att = new Attachment(testEngine2, "TestPage",
0621:                        "TestAtt.txt");
0622:                att.setAuthor("FirstPost");
0623:
0624:                testEngine2.getAttachmentManager().storeAttachment(att,
0625:                        testEngine.makeAttachmentFile());
0626:
0627:                String src = "[Test page/TestAtt.txt]";
0628:
0629:                assertEquals(
0630:                        "<a class=\"attachment\" href=\"/attach/TestPage/TestAtt.txt\">Test page/TestAtt.txt</a>"
0631:                                + "<a href=\"/PageInfo.jsp?page=TestPage/TestAtt.txt\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>",
0632:                        translate(testEngine2, src));
0633:            }
0634:
0635:            public void testAttachmentLink4() throws Exception {
0636:                TestEngine testEngine2 = new TestEngine(props);
0637:
0638:                testEngine2.saveText("TestPage", "foo ");
0639:                created.addElement("TestPage");
0640:
0641:                Attachment att = new Attachment(testEngine2, "TestPage",
0642:                        "TestAtt.txt");
0643:                att.setAuthor("FirstPost");
0644:
0645:                testEngine2.getAttachmentManager().storeAttachment(att,
0646:                        testEngine.makeAttachmentFile());
0647:
0648:                String src = "["
0649:                        + testEngine2.beautifyTitle("TestPage/TestAtt.txt")
0650:                        + "]";
0651:
0652:                assertEquals(
0653:                        "<a class=\"attachment\" href=\"/attach/TestPage/TestAtt.txt\">Test Page/TestAtt.txt</a>"
0654:                                + "<a href=\"/PageInfo.jsp?page=TestPage/TestAtt.txt\"><img src=\"/images/attachment_small.png\" border=\"0\" alt=\"(info)\" /></a>",
0655:                        translate(testEngine2, src));
0656:            }
0657:
0658:            public void testNoHyperlink() throws Exception {
0659:                newPage("HyperLink");
0660:
0661:                String src = "This should not be a [[HyperLink]";
0662:
0663:                assertEquals("This should not be a [HyperLink]", translate(src));
0664:            }
0665:
0666:            public void testNoHyperlink2() throws Exception {
0667:                String src = "This should not be a [[[[HyperLink]";
0668:
0669:                assertEquals("This should not be a [[[HyperLink]",
0670:                        translate(src));
0671:            }
0672:
0673:            public void testNoHyperlink3() throws Exception {
0674:                String src = "[[HyperLink], and this [[Neither].";
0675:
0676:                assertEquals("[HyperLink], and this [Neither].", translate(src));
0677:            }
0678:
0679:            public void testNoPlugin() throws Exception {
0680:                String src = "There is [[{NoPlugin}] here.";
0681:
0682:                assertEquals("There is [{NoPlugin}] here.", translate(src));
0683:            }
0684:
0685:            public void testErroneousHyperlink() throws Exception {
0686:                String src = "What if this is the last char [";
0687:
0688:                assertEquals("What if this is the last char ", translate(src));
0689:            }
0690:
0691:            public void testErroneousHyperlink2() throws Exception {
0692:                String src = "What if this is the last char [[";
0693:
0694:                assertEquals("What if this is the last char [", translate(src));
0695:            }
0696:
0697:            public void testExtraPagename1() throws Exception {
0698:                String src = "Link [test_page]";
0699:
0700:                newPage("Test_page");
0701:
0702:                assertEquals(
0703:                        "Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=Test_page\">test_page</a>",
0704:                        translate(src));
0705:            }
0706:
0707:            public void testExtraPagename2() throws Exception {
0708:                String src = "Link [test.page]";
0709:
0710:                newPage("Test.page");
0711:
0712:                assertEquals(
0713:                        "Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=Test.page\">test.page</a>",
0714:                        translate(src));
0715:            }
0716:
0717:            public void testExtraPagename3() throws Exception {
0718:                String src = "Link [.testpage_]";
0719:
0720:                newPage(".testpage_");
0721:
0722:                assertEquals(
0723:                        "Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=.testpage_\">.testpage_</a>",
0724:                        translate(src));
0725:            }
0726:
0727:            public void testInlineImages() throws Exception {
0728:                String src = "Link [test|http://www.ecyrd.com/test.png]";
0729:
0730:                assertEquals(
0731:                        "Link <img class=\"inline\" src=\"http://www.ecyrd.com/test.png\" alt=\"test\" />",
0732:                        translate(src));
0733:            }
0734:
0735:            public void testInlineImages2() throws Exception {
0736:                String src = "Link [test|http://www.ecyrd.com/test.ppm]";
0737:
0738:                assertEquals(
0739:                        "Link <a class=\"external\" href=\"http://www.ecyrd.com/test.ppm\">test</a>",
0740:                        translate(src));
0741:            }
0742:
0743:            public void testInlineImages3() throws Exception {
0744:                String src = "Link [test|http://images.com/testi]";
0745:
0746:                assertEquals(
0747:                        "Link <img class=\"inline\" src=\"http://images.com/testi\" alt=\"test\" />",
0748:                        translate(src));
0749:            }
0750:
0751:            public void testInlineImages4() throws Exception {
0752:                String src = "Link [test|http://foobar.jpg]";
0753:
0754:                assertEquals(
0755:                        "Link <img class=\"inline\" src=\"http://foobar.jpg\" alt=\"test\" />",
0756:                        translate(src));
0757:            }
0758:
0759:            // No link text should be just embedded link.
0760:            public void testInlineImagesLink2() throws Exception {
0761:                String src = "Link [http://foobar.jpg]";
0762:
0763:                assertEquals(
0764:                        "Link <img class=\"inline\" src=\"http://foobar.jpg\" alt=\"http://foobar.jpg\" />",
0765:                        translate(src));
0766:            }
0767:
0768:            public void testInlineImagesLink() throws Exception {
0769:                String src = "Link [http://link.to/|http://foobar.jpg]";
0770:
0771:                assertEquals(
0772:                        "Link <a class=\"external\" href=\"http://link.to/\"><img class=\"inline\" src=\"http://foobar.jpg\" alt=\"http://link.to/\" /></a>",
0773:                        translate(src));
0774:            }
0775:
0776:            public void testInlineImagesLink3() throws Exception {
0777:                String src = "Link [SandBox|http://foobar.jpg]";
0778:
0779:                newPage("SandBox");
0780:
0781:                assertEquals(
0782:                        "Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=SandBox\"><img class=\"inline\" src=\"http://foobar.jpg\" alt=\"SandBox\" /></a>",
0783:                        translate(src));
0784:            }
0785:
0786:            public void testScandicPagename1() throws Exception {
0787:                String src = "Link [\u00C5\u00E4Test]";
0788:
0789:                newPage("\u00C5\u00E4Test"); // FIXME: Should be capital
0790:
0791:                assertEquals(
0792:                        "Link <a class=\"wikipage\" href=\"/Wiki.jsp?page=%C5%E4Test\">\u00c5\u00e4Test</a>",
0793:                        translate(src));
0794:            }
0795:
0796:            public void testParagraph() throws Exception {
0797:                String src = "1\n\n2\n\n3";
0798:
0799:                assertEquals("<p>1\n</p><p>2\n</p>\n<p>3</p>", translate(src));
0800:            }
0801:
0802:            public void testParagraph2() throws Exception {
0803:                String src = "[WikiEtiquette]\r\n\r\n[Find page]";
0804:
0805:                newPage("WikiEtiquette");
0806:
0807:                assertEquals(
0808:                        "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=WikiEtiquette\">WikiEtiquette</a>\n</p>"
0809:                                + "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=FindPage\">Find page</a></p>",
0810:                        translate(src));
0811:            }
0812:
0813:            public void testParagraph3() throws Exception {
0814:                String src = "\r\n\r\n!Testi\r\n\r\nFoo.";
0815:
0816:                assertEquals(
0817:                        "<p />\n<h4 id=\"section-testpage-Testi\">Testi</h4>\n<p>Foo.</p>",
0818:                        translate(src));
0819:            }
0820:
0821:            public void testParagraph4() throws Exception {
0822:                String src = "\r\n[Recent Changes]\\\\\r\n[WikiEtiquette]\r\n\r\n[Find pages|FindPage]\\\\\r\n[Unused pages|UnusedPages]";
0823:
0824:                newPage("WikiEtiquette");
0825:                newPage("RecentChanges");
0826:                newPage("FindPage");
0827:                newPage("UnusedPages");
0828:
0829:                assertEquals(
0830:                        "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=RecentChanges\">Recent Changes</a><br />\n"
0831:                                + "<a class=\"wikipage\" href=\"/Wiki.jsp?page=WikiEtiquette\">WikiEtiquette</a>\n</p>\n"
0832:                                + "<p><a class=\"wikipage\" href=\"/Wiki.jsp?page=FindPage\">Find pages</a><br />\n"
0833:                                + "<a class=\"wikipage\" href=\"/Wiki.jsp?page=UnusedPages\">Unused pages</a></p>",
0834:                        translate(src));
0835:            }
0836:
0837:            public void testParagraph5() throws Exception {
0838:                String src = "__File type sniffing__ is a way of identifying the content type of a document.\n\n"
0839:                        + "In UNIX, the file(1) command can be used.";
0840:
0841:                assertEquals(
0842:                        "<p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>"
0843:                                + "<p>In UNIX, the file(1) command can be used.</p>",
0844:                        translate(src));
0845:            }
0846:
0847:            public void testParagraph6() throws Exception {
0848:                String src = "[{Counter}]\n\n__File type sniffing__ is a way of identifying the content type of a document.\n\n"
0849:                        + "In UNIX, the file(1) command can be used.";
0850:
0851:                assertEquals(
0852:                        "<p>1\n</p><p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"
0853:                                + "<p>In UNIX, the file(1) command can be used.</p>",
0854:                        translate(src));
0855:            }
0856:
0857:            public void testParagraph7() throws Exception {
0858:                String src = "[{$encoding}]\n\n__File type sniffing__ is a way of identifying the content type of a document.\n\n"
0859:                        + "In UNIX, the file(1) command can be used.";
0860:
0861:                assertEquals(
0862:                        "<p>ISO-8859-1\n</p><p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"
0863:                                + "<p>In UNIX, the file(1) command can be used.</p>",
0864:                        translate(src));
0865:            }
0866:
0867:            public void testParagraph8() throws Exception {
0868:                String src = "[{SET foo=bar}]\n\n__File type sniffing__ is a way of identifying the content type of a document.\n\n"
0869:                        + "In UNIX, the file(1) command can be used.";
0870:
0871:                assertEquals(
0872:                        "<p><b>File type sniffing</b> is a way of identifying the content type of a document.\n</p>\n"
0873:                                + "<p>In UNIX, the file(1) command can be used.</p>",
0874:                        translate(src));
0875:            }
0876:
0877:            public void testLinebreak() throws Exception {
0878:                String src = "1\\\\2";
0879:
0880:                assertEquals("1<br />2", translate(src));
0881:            }
0882:
0883:            public void testLinebreakEscape() throws Exception {
0884:                String src = "1~\\\\2";
0885:
0886:                assertEquals("1\\\\2", translate(src));
0887:            }
0888:
0889:            public void testLinebreakClear() throws Exception {
0890:                String src = "1\\\\\\2";
0891:
0892:                assertEquals("1<br clear=\"all\" />2", translate(src));
0893:            }
0894:
0895:            public void testTT() throws Exception {
0896:                String src = "1{{2345}}6";
0897:
0898:                assertEquals("1<tt>2345</tt>6", translate(src));
0899:            }
0900:
0901:            public void testTTAcrossLines() throws Exception {
0902:                String src = "1{{\n2345\n}}6";
0903:
0904:                assertEquals("1<tt>\n2345\n</tt>6", translate(src));
0905:            }
0906:
0907:            public void testTTLinks() throws Exception {
0908:                String src = "1{{\n2345\n[a link]\n}}6";
0909:
0910:                newPage("ALink");
0911:
0912:                assertEquals(
0913:                        "1<tt>\n2345\n<a class=\"wikipage\" href=\"/Wiki.jsp?page=ALink\">a link</a>\n</tt>6",
0914:                        translate(src));
0915:            }
0916:
0917:            public void testPre() throws Exception {
0918:                String src = "1{{{2345}}}6";
0919:
0920:                assertEquals(
0921:                        "1<span style=\"font-family:monospace; white-space:pre;\">2345</span>6",
0922:                        translate(src));
0923:            }
0924:
0925:            public void testPre2() throws Exception {
0926:                String src = "1 {{{ {{{ 2345 }}} }}} 6";
0927:
0928:                assertEquals(
0929:                        "1 <span style=\"font-family:monospace; white-space:pre;\"> {{{ 2345 </span> }}} 6",
0930:                        translate(src));
0931:            }
0932:
0933:            public void testPre3() throws Exception {
0934:                String src = "foo\n\nbar{{{2345}}}6";
0935:
0936:                assertEquals(
0937:                        "<p>foo\n</p><p>bar<span style=\"font-family:monospace; white-space:pre;\">2345</span>6</p>",
0938:                        translate(src));
0939:            }
0940:
0941:            public void testPreEscape() throws Exception {
0942:                String src = "1~{{{2345}}}6";
0943:
0944:                assertEquals("1{{{2345}}}6", translate(src));
0945:            }
0946:
0947:            public void testPreEscape2() throws Exception {
0948:                String src = "1{{{{{{2345~}}}}}}6";
0949:
0950:                assertEquals(
0951:                        "1<span style=\"font-family:monospace; white-space:pre;\">{{{2345}}}</span>6",
0952:                        translate(src));
0953:            }
0954:
0955:            public void testPreEscape3() throws Exception {
0956:                String src = "1 {{{ {{{ 2345 ~}}} }}} 6";
0957:
0958:                assertEquals(
0959:                        "1 <span style=\"font-family:monospace; white-space:pre;\"> {{{ 2345 }}} </span> 6",
0960:                        translate(src));
0961:            }
0962:
0963:            public void testPreEscape4() throws Exception {
0964:                String src = "1{{{ {{{2345~}} }}}6";
0965:
0966:                assertEquals(
0967:                        "1<span style=\"font-family:monospace; white-space:pre;\"> {{{2345~}} </span>6",
0968:                        translate(src));
0969:            }
0970:
0971:            public void testPreEscape5() throws Exception {
0972:                String src = "1{{{ ~ }}}6";
0973:
0974:                assertEquals(
0975:                        "1<span style=\"font-family:monospace; white-space:pre;\"> ~ </span>6",
0976:                        translate(src));
0977:            }
0978:
0979:            public void testHTMLInPre() throws Exception {
0980:                String src = "1\n{{{ <b> }}}";
0981:
0982:                assertEquals("1\n<pre> &lt;b&gt; </pre>", translate(src));
0983:            }
0984:
0985:            public void testCamelCaseInPre() throws Exception {
0986:                String src = "1\n{{{ CamelCase }}}";
0987:
0988:                assertEquals("1\n<pre> CamelCase </pre>", translate(src));
0989:            }
0990:
0991:            public void testPreWithLines() throws Exception {
0992:                String src = "1\r\n{{{\r\nZippadii\r\n}}}";
0993:
0994:                assertEquals("1\n<pre>\nZippadii\n</pre>", translate(src));
0995:            }
0996:
0997:            public void testList1() throws Exception {
0998:                String src = "A list:\n* One\n* Two\n* Three\n";
0999:
1000:                assertEquals(
1001:                        "A list:\n<ul><li>One\n</li><li>Two\n</li><li>Three\n</li></ul>",
1002:                        translate(src));
1003:            }
1004:
1005:            /** Plain multi line testing:
1006:             <pre>
1007:             * One
1008:             continuing
1009:             * Two
1010:             * Three
1011:             </pre>
1012:             */
1013:            public void testMultilineList1() throws Exception {
1014:                String src = "A list:\n* One\n continuing.\n* Two\n* Three\n";
1015:
1016:                assertEquals(
1017:                        "A list:\n<ul><li>One\n continuing.\n</li><li>Two\n</li><li>Three\n</li></ul>",
1018:                        translate(src));
1019:            }
1020:
1021:            public void testMultilineList2() throws Exception {
1022:                String src = "A list:\n* One\n continuing.\n* Two\n* Three\nShould be normal.";
1023:
1024:                assertEquals(
1025:                        "A list:\n<ul><li>One\n continuing.\n</li><li>Two\n</li><li>Three\n</li></ul>Should be normal.",
1026:                        translate(src));
1027:            }
1028:
1029:            public void testHTML() throws Exception {
1030:                String src = "<b>Test</b>";
1031:
1032:                assertEquals("&lt;b&gt;Test&lt;/b&gt;", translate(src));
1033:            }
1034:
1035:            public void testHTML2() throws Exception {
1036:                String src = "<p>";
1037:
1038:                assertEquals("&lt;p&gt;", translate(src));
1039:            }
1040:
1041:            public void testHTMLWhenAllowed() throws Exception {
1042:                String src = "<p>";
1043:
1044:                props.setProperty("jspwiki.translatorReader.allowHTML", "true");
1045:                testEngine = new TestEngine(props);
1046:
1047:                WikiPage page = new WikiPage(testEngine, PAGE_NAME);
1048:
1049:                String out = translate(testEngine, page, src);
1050:
1051:                assertEquals("<p>", out);
1052:            }
1053:
1054:            public void testHTMLWhenAllowedPre() throws Exception {
1055:                String src = "{{{ <br /> }}}";
1056:
1057:                props.setProperty("jspwiki.translatorReader.allowHTML", "true");
1058:                testEngine = new TestEngine(props);
1059:
1060:                WikiPage page = new WikiPage(testEngine, PAGE_NAME);
1061:
1062:                String out = translate(testEngine, page, src);
1063:
1064:                assertEquals("<pre> &lt;br /&gt; </pre>", out);
1065:            }
1066:
1067:            /*
1068:            // This test is not really needed anymore: the JDOM output mechanism
1069:            // handles attribute and element content escaping properly.
1070:            public void testQuotes()
1071:            throws Exception
1072:            {
1073:                String src = "\"Test\"\"";
1074:
1075:                assertEquals( "&quot;Test&quot;&quot;", translate(src) );
1076:            }
1077:             */
1078:            public void testHTMLEntities() throws Exception {
1079:                String src = "& &darr; foo&nbsp;bar &nbsp;&quot; &#2020;&";
1080:
1081:                assertEquals(
1082:                        "&amp; &darr; foo&nbsp;bar &nbsp;&quot; &#2020;&amp;",
1083:                        translate(src));
1084:            }
1085:
1086:            public void testItalicAcrossLinebreak() throws Exception {
1087:                String src = "''This is a\ntest.''";
1088:
1089:                assertEquals("<i>This is a\ntest.</i>", translate(src));
1090:            }
1091:
1092:            public void testBoldAcrossLinebreak() throws Exception {
1093:                String src = "__This is a\ntest.__";
1094:
1095:                assertEquals("<b>This is a\ntest.</b>", translate(src));
1096:            }
1097:
1098:            public void testBoldAcrossParagraph() throws Exception {
1099:                String src = "__This is a\n\ntest.__";
1100:
1101:                assertEquals("<p><b>This is a\n</b></p><p><b>test.</b></p>",
1102:                        translate(src));
1103:            }
1104:
1105:            public void testBoldItalic() throws Exception {
1106:                String src = "__This ''is'' a test.__";
1107:
1108:                assertEquals("<b>This <i>is</i> a test.</b>", translate(src));
1109:            }
1110:
1111:            public void testFootnote1() throws Exception {
1112:                String src = "Footnote[1]";
1113:
1114:                assertEquals(
1115:                        "Footnote<a class=\"footnoteref\" href=\"#ref-testpage-1\">[1]</a>",
1116:                        translate(src));
1117:            }
1118:
1119:            public void testFootnote2() throws Exception {
1120:                String src = "[#2356] Footnote.";
1121:
1122:                assertEquals(
1123:                        "<a class=\"footnote\" name=\"ref-testpage-2356\">[#2356]</a> Footnote.",
1124:                        translate(src));
1125:            }
1126:
1127:            /** Check an reported error condition where empty list items could cause crashes */
1128:
1129:            public void testEmptySecondLevelList() throws Exception {
1130:                String src = "A\n\n**\n\nB";
1131:
1132:                // System.out.println(translate(src));
1133:                assertEquals(
1134:                        "<p>A\n</p><ul><li><ul><li>\n</li></ul></li></ul><p>B</p>",
1135:                        translate(src));
1136:            }
1137:
1138:            public void testEmptySecondLevelList2() throws Exception {
1139:                String src = "A\n\n##\n\nB";
1140:
1141:                // System.out.println(translate(src));
1142:                assertEquals(
1143:                        "<p>A\n</p><ol><li><ol><li>\n</li></ol></li></ol><p>B</p>",
1144:                        translate(src));
1145:            }
1146:
1147:            /**
1148:             * <pre>
1149:             *   *Item A
1150:             *   ##Numbered 1
1151:             *   ##Numbered 2
1152:             *   *Item B
1153:             * </pre>
1154:             *
1155:             * would come out as:
1156:             *<ul>
1157:             * <li>Item A
1158:             * </ul>
1159:             * <ol>
1160:             * <ol>
1161:             * <li>Numbered 1
1162:             * <li>Numbered 2
1163:             * <ul>
1164:             * <li></ol>
1165:             * </ol>
1166:             * Item B
1167:             * </ul>
1168:             *
1169:             *  (by Mahlen Morris).
1170:             */
1171:
1172:            public void testMixedList() throws Exception {
1173:                String src = "*Item A\n##Numbered 1\n##Numbered 2\n*Item B\n";
1174:
1175:                String result = translate(src);
1176:
1177:                // Remove newlines for easier parsing.
1178:                result = TextUtil.replaceString(result, "\n", "");
1179:
1180:                assertEquals("<ul><li>Item A" + "<ol><li>Numbered 1</li>"
1181:                        + "<li>Numbered 2</li>" + "</ol></li>"
1182:                        + "<li>Item B</li>" + "</ul>", result);
1183:            }
1184:
1185:            /**
1186:             *  Like testMixedList() but the list types have been reversed.
1187:             */
1188:
1189:            public void testMixedList2() throws Exception {
1190:                String src = "#Item A\n**Numbered 1\n**Numbered 2\n#Item B\n";
1191:
1192:                String result = translate(src);
1193:
1194:                // Remove newlines for easier parsing.
1195:                result = TextUtil.replaceString(result, "\n", "");
1196:
1197:                assertEquals("<ol><li>Item A" + "<ul><li>Numbered 1</li>"
1198:                        + "<li>Numbered 2</li>" + "</ul></li>"
1199:                        + "<li>Item B</li>" + "</ol>", result);
1200:            }
1201:
1202:            public void testNestedList() throws Exception {
1203:                String src = "*Item A\n**Numbered 1\n**Numbered 2\n*Item B\n";
1204:
1205:                String result = translate(src);
1206:
1207:                // Remove newlines for easier parsing.
1208:                result = TextUtil.replaceString(result, "\n", "");
1209:
1210:                assertEquals("<ul><li>Item A" + "<ul><li>Numbered 1</li>"
1211:                        + "<li>Numbered 2</li>" + "</ul></li>"
1212:                        + "<li>Item B</li>" + "</ul>", result);
1213:            }
1214:
1215:            public void testNestedList2() throws Exception {
1216:                String src = "*Item A\n**Numbered 1\n**Numbered 2\n***Numbered3\n*Item B\n";
1217:
1218:                String result = translate(src);
1219:
1220:                // Remove newlines for easier parsing.
1221:                result = TextUtil.replaceString(result, "\n", "");
1222:
1223:                assertEquals("<ul><li>Item A" + "<ul><li>Numbered 1</li>"
1224:                        + "<li>Numbered 2" + "<ul><li>Numbered3</li>"
1225:                        + "</ul></li>" + "</ul></li>" + "<li>Item B</li>"
1226:                        + "</ul>", result);
1227:            }
1228:
1229:            public void testPluginInsert() throws Exception {
1230:                String src = "[{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text=test}]";
1231:
1232:                assertEquals("test", translate(src));
1233:            }
1234:
1235:            public void testPluginHTMLInsert() throws Exception {
1236:                String src = "[{INSERT com.ecyrd.jspwiki.plugin.SamplePlugin WHERE text='<b>Foo</b>'}]";
1237:
1238:                assertEquals("<b>Foo</b>", translate(src));
1239:            }
1240:
1241:            public void testPluginNoInsert() throws Exception {
1242:                String src = "[{SamplePlugin text=test}]";
1243:
1244:                assertEquals("test", translate(src));
1245:            }
1246:
1247:            public void testPluginInsertJS() throws Exception {
1248:                String src = "Today: [{INSERT JavaScriptPlugin}] ''day''.";
1249:
1250:                assertEquals(
1251:                        "Today: <script language=\"JavaScript\"><!--\nfoo='';\n--></script>\n <i>day</i>.",
1252:                        translate(src));
1253:            }
1254:
1255:            public void testShortPluginInsert() throws Exception {
1256:                String src = "[{INSERT SamplePlugin WHERE text=test}]";
1257:
1258:                assertEquals("test", translate(src));
1259:            }
1260:
1261:            /**
1262:             *  Test two plugins on same row.
1263:             */
1264:            public void testShortPluginInsert2() throws Exception {
1265:                String src = "[{INSERT SamplePlugin WHERE text=test}] [{INSERT SamplePlugin WHERE text=test2}]";
1266:
1267:                assertEquals("test test2", translate(src));
1268:            }
1269:
1270:            public void testPluginQuotedArgs() throws Exception {
1271:                String src = "[{INSERT SamplePlugin WHERE text='test me now'}]";
1272:
1273:                assertEquals("test me now", translate(src));
1274:            }
1275:
1276:            public void testPluginDoublyQuotedArgs() throws Exception {
1277:                String src = "[{INSERT SamplePlugin WHERE text='test \\'me too\\' now'}]";
1278:
1279:                assertEquals("test 'me too' now", translate(src));
1280:            }
1281:
1282:            public void testPluginQuotedArgs2() throws Exception {
1283:                String src = "[{INSERT SamplePlugin WHERE text=foo}] [{INSERT SamplePlugin WHERE text='test \\'me too\\' now'}]";
1284:
1285:                assertEquals("foo test 'me too' now", translate(src));
1286:            }
1287:
1288:            /**
1289:             *  Plugin output must not be parsed as Wiki text.
1290:             */
1291:            public void testPluginWikiText() throws Exception {
1292:                String src = "[{INSERT SamplePlugin WHERE text=PageContent}]";
1293:
1294:                assertEquals("PageContent", translate(src));
1295:            }
1296:
1297:            /**
1298:             *  Nor should plugin input be interpreted as wiki text.
1299:             */
1300:            public void testPluginWikiText2() throws Exception {
1301:                String src = "[{INSERT SamplePlugin WHERE text='----'}]";
1302:
1303:                assertEquals("----", translate(src));
1304:            }
1305:
1306:            public void testMultilinePlugin1() throws Exception {
1307:                String src = "Test [{INSERT SamplePlugin WHERE\n text=PageContent}]";
1308:
1309:                assertEquals("Test PageContent", translate(src));
1310:            }
1311:
1312:            public void testMultilinePluginBodyContent() throws Exception {
1313:                String src = "Test [{INSERT SamplePlugin\ntext=PageContent\n\n123\n456\n}]";
1314:
1315:                assertEquals("Test PageContent (123+456+)", translate(src));
1316:            }
1317:
1318:            public void testMultilinePluginBodyContent2() throws Exception {
1319:                String src = "Test [{INSERT SamplePlugin\ntext=PageContent\n\n\n123\n456\n}]";
1320:
1321:                assertEquals("Test PageContent (+123+456+)", translate(src));
1322:            }
1323:
1324:            public void testMultilinePluginBodyContent3() throws Exception {
1325:                String src = "Test [{INSERT SamplePlugin\n\n123\n456\n}]";
1326:
1327:                assertEquals("Test  (123+456+)", translate(src));
1328:            }
1329:
1330:            /**
1331:             *  Has an extra space after plugin name.
1332:             */
1333:            public void testMultilinePluginBodyContent4() throws Exception {
1334:                String src = "Test [{INSERT SamplePlugin \n\n123\n456\n}]";
1335:
1336:                assertEquals("Test  (123+456+)", translate(src));
1337:            }
1338:
1339:            /**
1340:             *  Check that plugin end is correctly recognized.
1341:             */
1342:            public void testPluginEnd() throws Exception {
1343:                String src = "Test [{INSERT SamplePlugin text=']'}]";
1344:
1345:                assertEquals("Test ]", translate(src));
1346:            }
1347:
1348:            public void testPluginEnd2() throws Exception {
1349:                String src = "Test [{INSERT SamplePlugin text='a[]+b'}]";
1350:
1351:                assertEquals("Test a[]+b", translate(src));
1352:            }
1353:
1354:            public void testPluginEnd3() throws Exception {
1355:                String src = "Test [{INSERT SamplePlugin\n\na[]+b\n}]";
1356:
1357:                assertEquals("Test  (a[]+b+)", translate(src));
1358:            }
1359:
1360:            public void testPluginEnd4() throws Exception {
1361:                String src = "Test [{INSERT SamplePlugin text='}'}]";
1362:
1363:                assertEquals("Test }", translate(src));
1364:            }
1365:
1366:            public void testPluginEnd5() throws Exception {
1367:                String src = "Test [{INSERT SamplePlugin\n\na[]+b{}\nGlob.\n}]";
1368:
1369:                assertEquals("Test  (a[]+b{}+Glob.+)", translate(src));
1370:            }
1371:
1372:            public void testPluginEnd6() throws Exception {
1373:                String src = "Test [{INSERT SamplePlugin\n\na[]+b{}\nGlob.\n}}]";
1374:
1375:                assertEquals("Test  (a[]+b{}+Glob.+})", translate(src));
1376:            }
1377:
1378:            public void testNestedPlugin1() throws Exception {
1379:                String src = "Test [{INSERT SamplePlugin\n\n[{SamplePlugin}]\nGlob.\n}}]";
1380:
1381:                assertEquals("Test  ([{SamplePlugin}]+Glob.+})", translate(src));
1382:            }
1383:
1384:            public void testNestedPlugin2() throws Exception {
1385:                String src = "[{SET foo='bar'}]Test [{INSERT SamplePlugin\n\n[{SamplePlugin text='[{$foo}]'}]\nGlob.\n}}]";
1386:
1387:                assertEquals("Test  ([{SamplePlugin text='[bar]'}]+Glob.+})",
1388:                        translate(src));
1389:            }
1390:
1391:            //  FIXME: I am not entirely certain if this is the right result
1392:            //  Perhaps some sort of an error should be checked?
1393:            public void testPluginNoEnd() throws Exception {
1394:                String src = "Test [{INSERT SamplePlugin\n\na+b{}\nGlob.\n}";
1395:
1396:                assertEquals("Test {INSERT SamplePlugin\n\na+b{}\nGlob.\n}",
1397:                        translate(src));
1398:            }
1399:
1400:            public void testVariableInsert() throws Exception {
1401:                String src = "[{$pagename}]";
1402:
1403:                assertEquals(PAGE_NAME + "", translate(src));
1404:            }
1405:
1406:            public void testTable1() throws Exception {
1407:                String src = "|| heading || heading2 \n| Cell 1 | Cell 2 \n| Cell 3 | Cell 4\n\n";
1408:
1409:                assertEquals(
1410:                        "<table class=\"wikitable\" border=\"1\">"
1411:                                + "<tr class=\"odd\"><th> heading </th><th> heading2 </th></tr>\n"
1412:                                + "<tr><td> Cell 1 </td><td> Cell 2 </td></tr>\n"
1413:                                + "<tr class=\"odd\"><td> Cell 3 </td><td> Cell 4</td></tr>\n"
1414:                                + "</table><p />", translate(src));
1415:            }
1416:
1417:            public void testTable2() throws Exception {
1418:                String src = "||heading||heading2\n|Cell 1| Cell 2\n| Cell 3 |Cell 4\n\n";
1419:
1420:                assertEquals(
1421:                        "<table class=\"wikitable\" border=\"1\">"
1422:                                + "<tr class=\"odd\"><th>heading</th><th>heading2</th></tr>\n"
1423:                                + "<tr><td>Cell 1</td><td> Cell 2</td></tr>\n"
1424:                                + "<tr class=\"odd\"><td> Cell 3 </td><td>Cell 4</td></tr>\n"
1425:                                + "</table><p />", translate(src));
1426:            }
1427:
1428:            public void testTable3() throws Exception {
1429:                String src = "|Cell 1| Cell 2\n| Cell 3 |Cell 4\n\n";
1430:
1431:                assertEquals(
1432:                        "<table class=\"wikitable\" border=\"1\">"
1433:                                + "<tr class=\"odd\"><td>Cell 1</td><td> Cell 2</td></tr>\n"
1434:                                + "<tr><td> Cell 3 </td><td>Cell 4</td></tr>\n"
1435:                                + "</table><p />", translate(src));
1436:            }
1437:
1438:            public void testTable4() throws Exception {
1439:                String src = "|a\nbc";
1440:
1441:                assertEquals("<table class=\"wikitable\" border=\"1\">"
1442:                        + "<tr class=\"odd\"><td>a</td></tr>\n" + "</table>"
1443:                        + "bc", translate(src));
1444:            }
1445:
1446:            /**
1447:             * Tests BugTableHeaderNotXHMTLCompliant
1448:             * @throws Exception
1449:             */
1450:            public void testTable5() throws Exception {
1451:                String src = "Testtable\n||header|cell\n\n|cell||header";
1452:
1453:                assertEquals(
1454:                        "<p>Testtable\n</p>"
1455:                                + "<table class=\"wikitable\" border=\"1\">"
1456:                                + "<tr class=\"odd\"><th>header</th><td>cell</td></tr>\n</table><p />\n"
1457:                                + "<table class=\"wikitable\" border=\"1\">"
1458:                                + "<tr class=\"odd\"><td>cell</td><th>header</th></tr>"
1459:                                + "</table>", translate(src));
1460:            }
1461:
1462:            public void testTableLink() throws Exception {
1463:                String src = "|Cell 1| Cell 2\n|[Cell 3|ReallyALink]|Cell 4\n\n";
1464:
1465:                newPage("ReallyALink");
1466:
1467:                assertEquals(
1468:                        "<table class=\"wikitable\" border=\"1\">"
1469:                                + "<tr class=\"odd\"><td>Cell 1</td><td> Cell 2</td></tr>\n"
1470:                                + "<tr><td><a class=\"wikipage\" href=\"/Wiki.jsp?page=ReallyALink\">Cell 3</a></td><td>Cell 4</td></tr>\n"
1471:                                + "</table><p />", translate(src));
1472:            }
1473:
1474:            public void testTableLinkEscapedBar() throws Exception {
1475:                String src = "|Cell 1| Cell~| 2\n|[Cell 3|ReallyALink]|Cell 4\n\n";
1476:
1477:                newPage("ReallyALink");
1478:
1479:                assertEquals(
1480:                        "<table class=\"wikitable\" border=\"1\">"
1481:                                + "<tr class=\"odd\"><td>Cell 1</td><td> Cell| 2</td></tr>\n"
1482:                                + "<tr><td><a class=\"wikipage\" href=\"/Wiki.jsp?page=ReallyALink\">Cell 3</a></td><td>Cell 4</td></tr>\n"
1483:                                + "</table><p />", translate(src));
1484:            }
1485:
1486:            public void testDescription() throws Exception {
1487:                String src = ";:Foo";
1488:
1489:                assertEquals("<dl><dt></dt><dd>Foo</dd></dl>", translate(src));
1490:            }
1491:
1492:            public void testDescription2() throws Exception {
1493:                String src = ";Bar:Foo";
1494:
1495:                assertEquals("<dl><dt>Bar</dt><dd>Foo</dd></dl>",
1496:                        translate(src));
1497:            }
1498:
1499:            public void testDescription3() throws Exception {
1500:                String src = ";:";
1501:
1502:                assertEquals("<dl><dt></dt><dd /></dl>", translate(src));
1503:            }
1504:
1505:            public void testDescription4() throws Exception {
1506:                String src = ";Bar:Foo :-)";
1507:
1508:                assertEquals("<dl><dt>Bar</dt><dd>Foo :-)</dd></dl>",
1509:                        translate(src));
1510:            }
1511:
1512:            public void testDescription5() throws Exception {
1513:                String src = ";Bar:Foo :-) ;-) :*]";
1514:
1515:                assertEquals("<dl><dt>Bar</dt><dd>Foo :-) ;-) :*]</dd></dl>",
1516:                        translate(src));
1517:            }
1518:
1519:            public void testRuler() throws Exception {
1520:                String src = "----";
1521:
1522:                assertEquals("<hr />", translate(src));
1523:            }
1524:
1525:            public void testRulerCombo() throws Exception {
1526:                String src = "----Foo";
1527:
1528:                assertEquals("<hr />Foo", translate(src));
1529:            }
1530:
1531:            public void testRulerCombo2() throws Exception {
1532:                String src = "Bar----Foo";
1533:
1534:                assertEquals("Bar----Foo", translate(src));
1535:            }
1536:
1537:            public void testShortRuler1() throws Exception {
1538:                String src = "-";
1539:
1540:                assertEquals("-", translate(src));
1541:            }
1542:
1543:            public void testShortRuler2() throws Exception {
1544:                String src = "--";
1545:
1546:                assertEquals("--", translate(src));
1547:            }
1548:
1549:            public void testShortRuler3() throws Exception {
1550:                String src = "---";
1551:
1552:                assertEquals("---", translate(src));
1553:            }
1554:
1555:            public void testLongRuler() throws Exception {
1556:                String src = "------";
1557:
1558:                assertEquals("<hr />", translate(src));
1559:            }
1560:
1561:            public void testHeading1() throws Exception {
1562:                String src = "!Hello\nThis is a test";
1563:
1564:                assertEquals(
1565:                        "<h4 id=\"section-testpage-Hello\">Hello</h4>\nThis is a test",
1566:                        translate(src));
1567:            }
1568:
1569:            public void testHeading2() throws Exception {
1570:                String src = "!!Hello, testing 1, 2, 3";
1571:
1572:                assertEquals(
1573:                        "<h3 id=\"section-testpage-HelloTesting123\">Hello, testing 1, 2, 3</h3>",
1574:                        translate(src));
1575:            }
1576:
1577:            public void testHeading3() throws Exception {
1578:                String src = "!!!Hello there, how are you doing?";
1579:
1580:                assertEquals(
1581:                        "<h2 id=\"section-testpage-HelloThereHowAreYouDoing\">Hello there, how are you doing?</h2>",
1582:                        translate(src));
1583:            }
1584:
1585:            public void testHeadingHyperlinks() throws Exception {
1586:                String src = "!!![Hello]";
1587:
1588:                assertEquals(
1589:                        "<h2 id=\"section-testpage-Hello\"><a class=\"createpage\" href=\"/Edit.jsp?page=Hello\" title=\"Create &quot;Hello&quot;\">Hello</a></h2>",
1590:                        translate(src));
1591:            }
1592:
1593:            public void testHeadingHyperlinks2() throws Exception {
1594:                String src = "!!![Hello|http://www.google.com/]";
1595:
1596:                assertEquals(
1597:                        "<h2 id=\"section-testpage-Hello\"><a class=\"external\" href=\"http://www.google.com/\">Hello</a></h2>",
1598:                        translate(src));
1599:            }
1600:
1601:            public void testHeadingHyperlinks3() throws Exception {
1602:                String src = "![Hello|http://www.google.com/?p=a&c=d]";
1603:
1604:                assertEquals(
1605:                        "<h4 id=\"section-testpage-Hello\"><a class=\"external\" href=\"http://www.google.com/?p=a&amp;c=d\">Hello</a></h4>",
1606:                        translate(src));
1607:            }
1608:
1609:            /**
1610:             *  in 2.0.0, this one throws OutofMemoryError.
1611:             */
1612:            public void testBrokenPageText() throws Exception {
1613:                String translation = translate(brokenPageText);
1614:
1615:                assertNotNull(translation);
1616:            }
1617:
1618:            /**
1619:             *  Shortened version of the previous one.
1620:             */
1621:            public void testBrokenPageTextShort() throws Exception {
1622:                String src = "{{{\ncode.}}\n";
1623:
1624:                assertEquals("<pre>\ncode.}}\n</pre>", translate(src));
1625:            }
1626:
1627:            /**
1628:             *  Shortened version of the previous one.
1629:             */
1630:            public void testBrokenPageTextShort2() throws Exception {
1631:                String src = "{{{\ncode.}\n";
1632:
1633:                assertEquals("<pre>\ncode.}\n</pre>", translate(src));
1634:            }
1635:
1636:            public void testExtraExclamation() throws Exception {
1637:                String src = "Hello!";
1638:
1639:                assertEquals("Hello!", translate(src));
1640:            }
1641:
1642:            /**
1643:             * Used by the ACL tests.
1644:             * @param array
1645:             * @param key
1646:             * @return
1647:             */
1648:            /*
1649:            private boolean inArray( Object[] array, Object key )
1650:            {
1651:                for( int i = 0; i < array.length; i++ )
1652:                {
1653:                    if ( array[i].equals( key ) )
1654:                    {
1655:                        return true;
1656:                    }
1657:                }
1658:                return false;
1659:            }
1660:             */
1661:            /**
1662:             * Used by the ACL tests.
1663:             * @param array
1664:             * @param key
1665:             * @return
1666:             */
1667:            /*
1668:            private boolean inGroup( Object[] array, Principal key )
1669:            {
1670:                for( int i = 0; i < array.length; i++ )
1671:                {
1672:                    if (array[i] instanceof Group)
1673:                    {
1674:                        if (((Group)array[i]).isMember(key))
1675:                        {
1676:                            return true;
1677:                        }
1678:                    }
1679:                }
1680:                return false;
1681:            }
1682:             */
1683:            /**
1684:             *  ACL tests.
1685:             */
1686:            /*
1687:             public void testSimpleACL1()
1688:             throws Exception
1689:             {
1690:             String src = "Foobar.[{ALLOW view JanneJalkanen}]";
1691:
1692:             WikiPage p = new WikiPage( PAGE_NAME );
1693:
1694:             String res = translate( p, src );
1695:
1696:             assertEquals("Page text", "Foobar.", res);
1697:
1698:             Acl acl = p.getAcl();
1699:
1700:             Principal prof = new WikiPrincipal("JanneJalkanen");
1701:
1702:             assertTrue( "has read", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
1703:             assertFalse( "no edit", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
1704:             }
1705:
1706:             public void testSimpleACL2()
1707:             throws Exception
1708:             {
1709:             String src = "Foobar.[{ALLOW view JanneJalkanen}]\n"+
1710:             "[{ALLOW edit JanneJalkanen, SuloVilen}]";
1711:
1712:             WikiPage p = new WikiPage( PAGE_NAME );
1713:
1714:             String res = translate( p, src );
1715:
1716:             assertEquals("Page text", "Foobar.\n", res);
1717:
1718:             Acl acl = p.getAcl();
1719:
1720:             // ACL says Janne can read and edit
1721:              Principal prof = new WikiPrincipal("JanneJalkanen");
1722:              assertTrue( "read for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
1723:              assertTrue( "edit for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
1724:
1725:              // ACL doesn't say Erik can read or edit
1726:               prof = new WikiPrincipal("ErikBunn");
1727:               assertFalse( "no read for BB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
1728:               assertFalse( "no edit for EB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
1729:
1730:               // ACL says Sulo can edit, but doens't say he can read (though the AuthMgr will tell us it's implied)
1731:                prof = new WikiPrincipal("SuloVilen");
1732:                assertFalse( "read for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
1733:                assertTrue( "edit for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
1734:                }
1735:             */
1736:            /*
1737:            private boolean containsGroup( List l, String name )
1738:            {
1739:                for( Iterator i = l.iterator(); i.hasNext(); )
1740:                {
1741:                    String group = (String) i.next();
1742:
1743:                    if( group.equals( name ) )
1744:                        return true;
1745:                }
1746:
1747:                return false;
1748:            }
1749:             */
1750:            /**
1751:             *   Metadata tests
1752:             */
1753:            public void testSet1() throws Exception {
1754:                String src = "Foobar.[{SET name=foo}]";
1755:
1756:                WikiPage p = new WikiPage(testEngine, PAGE_NAME);
1757:
1758:                String res = translate(p, src);
1759:
1760:                assertEquals("Page text", "Foobar.", res);
1761:
1762:                assertEquals("foo", p.getAttribute("name"));
1763:            }
1764:
1765:            public void testSet2() throws Exception {
1766:                String src = "Foobar.[{SET name = foo}]";
1767:
1768:                WikiPage p = new WikiPage(testEngine, PAGE_NAME);
1769:
1770:                String res = translate(p, src);
1771:
1772:                assertEquals("Page text", "Foobar.", res);
1773:
1774:                assertEquals("foo", p.getAttribute("name"));
1775:            }
1776:
1777:            public void testSet3() throws Exception {
1778:                String src = "Foobar.[{SET name= Janne Jalkanen}]";
1779:
1780:                WikiPage p = new WikiPage(testEngine, PAGE_NAME);
1781:
1782:                String res = translate(p, src);
1783:
1784:                assertEquals("Page text", "Foobar.", res);
1785:
1786:                assertEquals("Janne Jalkanen", p.getAttribute("name"));
1787:            }
1788:
1789:            public void testSet4() throws Exception {
1790:                String src = "Foobar.[{SET name='Janne Jalkanen'}][{SET too='{$name}'}]";
1791:
1792:                WikiPage p = new WikiPage(testEngine, PAGE_NAME);
1793:
1794:                String res = translate(p, src);
1795:
1796:                assertEquals("Page text", "Foobar.", res);
1797:
1798:                assertEquals("Janne Jalkanen", p.getAttribute("name"));
1799:                assertEquals("Janne Jalkanen", p.getAttribute("too"));
1800:            }
1801:
1802:            public void testSetHTML() throws Exception {
1803:                String src = "Foobar.[{SET name='<b>danger</b>'}] [{$name}]";
1804:
1805:                WikiPage p = new WikiPage(testEngine, PAGE_NAME);
1806:
1807:                String res = translate(p, src);
1808:
1809:                assertEquals("Page text", "Foobar. &lt;b&gt;danger&lt;/b&gt;",
1810:                        res);
1811:
1812:                assertEquals("<b>danger</b>", p.getAttribute("name"));
1813:            }
1814:
1815:            /**
1816:             *  Test collection of links.
1817:             */
1818:
1819:            public void testCollectingLinks() throws Exception {
1820:                LinkCollector coll = new LinkCollector();
1821:                String src = "[Test]";
1822:                WikiContext context = new WikiContext(testEngine, new WikiPage(
1823:                        testEngine, PAGE_NAME));
1824:
1825:                MarkupParser p = new JSPWikiMarkupParser(context,
1826:                        new BufferedReader(new StringReader(src)));
1827:                p.addLocalLinkHook(coll);
1828:                p.addExternalLinkHook(coll);
1829:                p.addAttachmentLinkHook(coll);
1830:
1831:                p.parse();
1832:
1833:                Collection links = coll.getLinks();
1834:
1835:                assertEquals("no links found", 1, links.size());
1836:                assertEquals("wrong link", "Test", links.iterator().next());
1837:            }
1838:
1839:            public void testCollectingLinks2() throws Exception {
1840:                LinkCollector coll = new LinkCollector();
1841:                String src = "[" + PAGE_NAME + "/Test.txt]";
1842:
1843:                WikiContext context = new WikiContext(testEngine, new WikiPage(
1844:                        testEngine, PAGE_NAME));
1845:
1846:                MarkupParser p = new JSPWikiMarkupParser(context,
1847:                        new BufferedReader(new StringReader(src)));
1848:                p.addLocalLinkHook(coll);
1849:                p.addExternalLinkHook(coll);
1850:                p.addAttachmentLinkHook(coll);
1851:
1852:                p.parse();
1853:
1854:                Collection links = coll.getLinks();
1855:
1856:                assertEquals("no links found", 1, links.size());
1857:                assertEquals("wrong link", PAGE_NAME + "/Test.txt", links
1858:                        .iterator().next());
1859:            }
1860:
1861:            public void testCollectingLinksAttachment() throws Exception {
1862:                // First, make an attachment.
1863:
1864:                try {
1865:                    Attachment att = new Attachment(testEngine, PAGE_NAME,
1866:                            "TestAtt.txt");
1867:                    att.setAuthor("FirstPost");
1868:                    testEngine.getAttachmentManager().storeAttachment(att,
1869:                            testEngine.makeAttachmentFile());
1870:
1871:                    LinkCollector coll = new LinkCollector();
1872:                    LinkCollector coll_others = new LinkCollector();
1873:
1874:                    String src = "[TestAtt.txt]";
1875:                    WikiContext context = new WikiContext(testEngine,
1876:                            new WikiPage(testEngine, PAGE_NAME));
1877:
1878:                    MarkupParser p = new JSPWikiMarkupParser(context,
1879:                            new BufferedReader(new StringReader(src)));
1880:                    p.addLocalLinkHook(coll_others);
1881:                    p.addExternalLinkHook(coll_others);
1882:                    p.addAttachmentLinkHook(coll);
1883:
1884:                    p.parse();
1885:
1886:                    Collection links = coll.getLinks();
1887:
1888:                    assertEquals("no links found", 1, links.size());
1889:                    assertEquals("wrong link", PAGE_NAME + "/TestAtt.txt",
1890:                            links.iterator().next());
1891:
1892:                    assertEquals("wrong links found", 0, coll_others.getLinks()
1893:                            .size());
1894:                } finally {
1895:                    String files = testEngine.getWikiProperties().getProperty(
1896:                            BasicAttachmentProvider.PROP_STORAGEDIR);
1897:                    File storagedir = new File(files, PAGE_NAME
1898:                            + BasicAttachmentProvider.DIR_EXTENSION);
1899:
1900:                    if (storagedir.exists() && storagedir.isDirectory())
1901:                        TestEngine.deleteAll(storagedir);
1902:                }
1903:            }
1904:
1905:            public void testDivStyle1() throws Exception {
1906:                String src = "%%foo\ntest\n%%\n";
1907:
1908:                assertEquals("<div class=\"foo\">\ntest\n</div>\n",
1909:                        translate(src));
1910:            }
1911:
1912:            public void testDivStyle2() throws Exception {
1913:                String src = "%%(foo:bar;)\ntest\n%%\n";
1914:
1915:                assertEquals("<div style=\"foo:bar;\">\ntest\n</div>\n",
1916:                        translate(src));
1917:            }
1918:
1919:            public void testSpanStyle1() throws Exception {
1920:                String src = "%%foo test%%\n";
1921:
1922:                assertEquals("<span class=\"foo\">test</span>\n",
1923:                        translate(src));
1924:            }
1925:
1926:            public void testSpanStyle2() throws Exception {
1927:                String src = "%%(foo:bar;)test%%\n";
1928:
1929:                assertEquals("<span style=\"foo:bar;\">test</span>\n",
1930:                        translate(src));
1931:            }
1932:
1933:            public void testSpanStyle3() throws Exception {
1934:                String src = "Johan %%(foo:bar;)test%%\n";
1935:
1936:                assertEquals("Johan <span style=\"foo:bar;\">test</span>\n",
1937:                        translate(src));
1938:            }
1939:
1940:            public void testSpanStyle4() throws Exception {
1941:                String src = "Johan %%(foo:bar;)test/%\n";
1942:
1943:                assertEquals("Johan <span style=\"foo:bar;\">test</span>\n",
1944:                        translate(src));
1945:            }
1946:
1947:            public void testSpanEscape() throws Exception {
1948:                String src = "~%%foo test~%%\n";
1949:
1950:                assertEquals("%%foo test%%\n", translate(src));
1951:            }
1952:
1953:            public void testSpanNested() throws Exception {
1954:                String src = "Johan %%(color: rgb(1,2,3);)test%%\n";
1955:
1956:                assertEquals(
1957:                        "Johan <span style=\"color: rgb(1,2,3);\">test</span>\n",
1958:                        translate(src));
1959:            }
1960:
1961:            public void testSpanStyleTable() throws Exception {
1962:                String src = "|%%(foo:bar;)test%%|no test\n";
1963:
1964:                assertEquals(
1965:                        "<table class=\"wikitable\" border=\"1\"><tr class=\"odd\"><td><span style=\"foo:bar;\">test</span></td><td>no test</td></tr>\n</table>",
1966:                        translate(src));
1967:            }
1968:
1969:            public void testSpanJavascript() throws Exception {
1970:                String src = "%%(visibility: hidden; background-image:url(javascript:alert('X')))%%\nTEST";
1971:
1972:                assertEquals(
1973:                        "<span class=\"error\">Attempt to output javascript!</span>\nTEST",
1974:                        translate(src));
1975:            }
1976:
1977:            // FIXME: This test must be enabled later on!
1978:            /*
1979:            public void testSpanJavascript2()
1980:            throws Exception
1981:            {
1982:                String src = "%%(visibility: hidden; background&#09;-image:url(j&#000013;avas&#99;ript:'url()';alert('X');)%%\nTEST";
1983:
1984:                assertEquals( "<span class=\"error\">Attempt to output javascript!</span>\nTEST", translate(src) );
1985:            }
1986:             */
1987:            public void testHTMLEntities1() throws Exception {
1988:                String src = "Janne&apos;s test";
1989:
1990:                assertEquals("Janne&apos;s test", translate(src));
1991:            }
1992:
1993:            public void testHTMLEntities2() throws Exception {
1994:                String src = "&Auml;";
1995:
1996:                assertEquals("&Auml;", translate(src));
1997:            }
1998:
1999:            public void testBlankEscape() throws Exception {
2000:                String src = "H2%%sub 2%%~ O";
2001:
2002:                assertEquals("H2<span class=\"sub\">2</span>O", translate(src));
2003:            }
2004:
2005:            public void testEmptyBold() throws Exception {
2006:                String src = "____";
2007:
2008:                assertEquals("<b></b>", translate(src));
2009:            }
2010:
2011:            public void testEmptyItalic() throws Exception {
2012:                String src = "''''";
2013:
2014:                assertEquals("<i></i>", translate(src));
2015:            }
2016:
2017:            public void testRenderingSpeed1() throws Exception {
2018:                Benchmark sw = new Benchmark();
2019:                sw.start();
2020:
2021:                for (int i = 0; i < 100; i++) {
2022:                    translate(brokenPageText);
2023:                }
2024:
2025:                sw.stop();
2026:                System.out.println("100 page renderings: " + sw + " ("
2027:                        + sw.toString(100) + " renderings/second)");
2028:            }
2029:
2030:            public void testPunctuatedWikiNames() throws Exception {
2031:                String src = "[-phobous]";
2032:
2033:                assertEquals(
2034:                        "<a class=\"createpage\" href=\"/Edit.jsp?page=-phobous\" title=\"Create &quot;-phobous&quot;\">-phobous</a>",
2035:                        translate(src));
2036:            }
2037:
2038:            public void testPunctuatedWikiNames2() throws Exception {
2039:                String src = "[?phobous]";
2040:
2041:                assertEquals(
2042:                        "<a class=\"createpage\" href=\"/Edit.jsp?page=Phobous\" title=\"Create &quot;Phobous&quot;\">?phobous</a>",
2043:                        translate(src));
2044:            }
2045:
2046:            public void testPunctuatedWikiNames3() throws Exception {
2047:                String src = "[Brightness (apical)]";
2048:
2049:                assertEquals(
2050:                        "<a class=\"createpage\" href=\"/Edit.jsp?page=Brightness%20%28apical%29\" title=\"Create &quot;Brightness (apical)&quot;\">Brightness (apical)</a>",
2051:                        translate(src));
2052:            }
2053:
2054:            public void testDeadlySpammer() throws Exception {
2055:                String deadlySpammerText = "zzz <a href=\"http://ring1.gmum.net/frog-ringtone.html\">frogringtone</a> zzz http://ring1.gmum.net/frog-ringtone.html[URL=http://ring1.gmum.net/frog-ringtone.html]frog ringtone[/URL] frogringtone<br>";
2056:
2057:                StringBuffer death = new StringBuffer(20000);
2058:
2059:                for (int i = 0; i < 1000; i++) {
2060:                    death.append(deadlySpammerText);
2061:                }
2062:
2063:                death.append("\n\n");
2064:
2065:                System.out
2066:                        .println("Trying to crash parser with a line which is "
2067:                                + death.length() + " chars in size");
2068:                //  This should not fail
2069:                String res = translate(death.toString());
2070:
2071:                assertTrue(res.length() > 0);
2072:            }
2073:
2074:            public void testSpacesInLinks1() throws Exception {
2075:                newPage("Foo bar");
2076:                String src = "[Foo bar]";
2077:
2078:                assertEquals(
2079:                        "<a class=\"wikipage\" href=\"/Wiki.jsp?page=Foo%20bar\">Foo bar</a>",
2080:                        translate(src));
2081:            }
2082:
2083:            /** Too many spaces */
2084:            public void testSpacesInLinks2() throws Exception {
2085:                newPage("Foo bar");
2086:                String src = "[Foo        bar]";
2087:
2088:                assertEquals(
2089:                        "<a class=\"wikipage\" href=\"/Wiki.jsp?page=Foo%20bar\">Foo        bar</a>",
2090:                        translate(src));
2091:            }
2092:
2093:            public void testIllegalXML() throws Exception {
2094:                String src = "Test \u001d foo";
2095:
2096:                String dst = translate(src);
2097:
2098:                assertTrue("No error", dst.indexOf("JDOM") != -1);
2099:            }
2100:
2101:            public void testXSS1() throws Exception {
2102:                String src = "[http://www.host.com/du=\"> <img src=\"foobar\" onerror=\"alert(document.cookie)\"/>]";
2103:
2104:                String dst = translate(src);
2105:
2106:                assertEquals(
2107:                        "<a class=\"external\" href=\"http://www.host.com/du=&quot;&gt; &lt;img src=&quot;foobar&quot; onerror=&quot;alert(document.cookie)&quot;/&gt;\">http://www.host.com/du=&quot;&gt; &lt;img src=&quot;foobar&quot; onerror=&quot;alert(document.cookie)&quot;/&gt;</a>",
2108:                        dst);
2109:            }
2110:
2111:            // This is a random find: the following page text caused an eternal loop in V2.0.x.
2112:            private static final String brokenPageText = "Please ''check [RecentChanges].\n"
2113:                    + "\n"
2114:                    + "Testing. fewfwefe\n"
2115:                    + "\n"
2116:                    + "CHeck [testpage]\n"
2117:                    + "\n"
2118:                    + "More testing.\n"
2119:                    + "dsadsadsa''\n"
2120:                    + "Is this {{truetype}} or not?\n"
2121:                    + "What about {{{This}}}?\n"
2122:                    + "How about {{this?\n"
2123:                    + "\n"
2124:                    + "{{{\n"
2125:                    + "{{text}}\n"
2126:                    + "}}}\n"
2127:                    + "goo\n"
2128:                    + "\n"
2129:                    + "<b>Not bold</b>\n"
2130:                    + "\n"
2131:                    + "motto\n"
2132:                    + "\n"
2133:                    + "* This is a list which we\n"
2134:                    + "shall continue on a other line.\n"
2135:                    + "* There is a list item here.\n"
2136:                    + "*  Another item.\n"
2137:                    + "* More stuff, which continues\n"
2138:                    + "on a second line.  And on\n"
2139:                    + "a third line as well.\n"
2140:                    + "And a fourth line.\n"
2141:                    + "* Third item.\n"
2142:                    + "\n"
2143:                    + "Foobar.\n"
2144:                    + "\n"
2145:                    + "----\n"
2146:                    + "\n"
2147:                    + "!!!Really big heading\n"
2148:                    + "Text.\n"
2149:                    + "!! Just a normal heading [with a hyperlink|Main]\n"
2150:                    + "More text.\n"
2151:                    + "!Just a small heading.\n"
2152:                    + "\n"
2153:                    + "This should be __bold__ text.\n"
2154:                    + "\n"
2155:                    + "__more bold text continuing\n"
2156:                    + "on the next line.__\n"
2157:                    + "\n"
2158:                    + "__more bold text continuing\n"
2159:                    + "\n"
2160:                    + "on the next paragraph.__\n"
2161:                    + "\n"
2162:                    + "\n"
2163:                    + "This should be normal.\n"
2164:                    + "\n"
2165:                    + "Now, let's try ''italic text''.\n"
2166:                    + "\n"
2167:                    + "Bulleted lists:\n"
2168:                    + "* One\n"
2169:                    + "Or more.\n"
2170:                    + "* Two\n"
2171:                    + "\n"
2172:                    + "** Two.One\n"
2173:                    + "\n"
2174:                    + "*** Two.One.One\n"
2175:                    + "\n"
2176:                    + "* Three\n"
2177:                    + "\n"
2178:                    + "Numbered lists.\n"
2179:                    + "# One\n"
2180:                    + "# Two\n"
2181:                    + "# Three\n"
2182:                    + "## Three.One\n"
2183:                    + "## Three.Two\n"
2184:                    + "## Three.Three\n"
2185:                    + "### Three.Three.One\n"
2186:                    + "# Four\n"
2187:                    + "\n"
2188:                    + "End?\n"
2189:                    + "\n"
2190:                    + "No, let's {{break}} things.\\ {{{ {{{ {{text}} }}} }}}\n"
2191:                    + "\n"
2192:                    + "More breaking.\n"
2193:                    + "\n"
2194:                    + "{{{\n"
2195:                    + "code.}}\n"
2196:                    + "----\n"
2197:                    + "author: [Asser], [Ebu], [JanneJalkanen], [Jarmo|mailto:jarmo@regex.com.au]\n";
2198:
2199:            public static Test suite() {
2200:                return new TestSuite(JSPWikiMarkupParserTest.class);
2201:            }
2202:
2203:            public static Test suiteSingle(String test) {
2204:                return new TestSuite(JSPWikiMarkupParserTest.class, test);
2205:            }
2206:
2207:            public static void main(String[] argv) {
2208:                if (argv.length > 0)
2209:                    junit.textui.TestRunner.run(suiteSingle(argv[0]));
2210:                else
2211:                    junit.textui.TestRunner.run(suite());
2212:            }
2213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.