?? wikienginetest.java
字號:
package com.ecyrd.jspwiki;import junit.framework.*;import java.io.*;import java.util.*;import com.ecyrd.jspwiki.providers.*;import com.ecyrd.jspwiki.attachment.*;public class WikiEngineTest extends TestCase{ public static final String NAME1 = "Test1"; public static final long PAGEPROVIDER_RESCAN_PERIOD = 2; Properties props = new Properties(); TestEngine m_engine; public WikiEngineTest( String s ) { super( s ); } public static Test suite() { return new TestSuite( WikiEngineTest.class ); } public static void main(String[] args) { junit.textui.TestRunner.main(new String[] { WikiEngineTest.class.getName() } ); } public void setUp() throws Exception { props.load( TestEngine.findTestProperties() ); props.setProperty( WikiEngine.PROP_MATCHPLURALS, "true" ); // We'll need a shorter-than-default consistency check for // the page-changed checks. This will cause additional load // to the file system, though. props.setProperty( CachingProvider.PROP_CACHECHECKINTERVAL, Long.toString(PAGEPROVIDER_RESCAN_PERIOD) ); TestEngine.emptyWorkDir(); m_engine = new TestEngine(props); } public void tearDown() { String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); if( files != null ) { File f = new File( files ); TestEngine.deleteAll( f ); } TestEngine.emptyWorkDir(); } public void testNonExistantDirectory() throws Exception { String tmpdir = System.getProperties().getProperty("java.io.tmpdir"); String dirname = "non-existant-directory"; String newdir = tmpdir + File.separator + dirname; props.setProperty( FileSystemProvider.PROP_PAGEDIR, newdir ); WikiEngine test = new TestEngine( props ); File f = new File( newdir ); assertTrue( "didn't create it", f.exists() ); assertTrue( "isn't a dir", f.isDirectory() ); f.delete(); } public void testNonExistantDirProperty() throws Exception { props.remove( FileSystemProvider.PROP_PAGEDIR ); try { WikiEngine test = new TestEngine( props ); fail( "Wiki did not warn about missing property." ); } catch( WikiException e ) { // This is okay. } } /** * Check that calling pageExists( String ) works. */ public void testNonExistantPage() throws Exception { String pagename = "Test1"; assertEquals( "Page already exists", false, m_engine.pageExists( pagename ) ); } /** * Check that calling pageExists( WikiPage ) works. */ public void testNonExistantPage2() throws Exception { WikiPage page = new WikiPage("Test1"); assertEquals( "Page already exists", false, m_engine.pageExists( page ) ); } public void testFinalPageName() throws Exception { m_engine.saveText( "Foobar", "1" ); m_engine.saveText( "Foobars", "2" ); assertEquals( "plural mistake", "Foobars", m_engine.getFinalPageName( "Foobars" ) ); assertEquals( "singular mistake", "Foobar", m_engine.getFinalPageName( "Foobar" ) ); } public void testFinalPageNameSingular() throws Exception { m_engine.saveText( "Foobar", "1" ); assertEquals( "plural mistake", "Foobar", m_engine.getFinalPageName( "Foobars" ) ); assertEquals( "singular mistake", "Foobar", m_engine.getFinalPageName( "Foobar" ) ); } public void testFinalPageNamePlural() throws Exception { m_engine.saveText( "Foobars", "1" ); assertEquals( "plural mistake", "Foobars", m_engine.getFinalPageName( "Foobars" ) ); assertEquals( "singular mistake", "Foobars", m_engine.getFinalPageName( "Foobar" ) ); } public void testPutPage() throws Exception { String text = "Foobar.\r\n"; String name = NAME1; m_engine.saveText( name, text ); assertEquals( "page does not exist", true, m_engine.pageExists( name ) ); assertEquals( "wrong content", text, m_engine.getText( name ) ); } public void testPutPageEntities() throws Exception { String text = "Foobar. "\r\n"; String name = NAME1; m_engine.saveText( name, text ); assertEquals( "page does not exist", true, m_engine.pageExists( name ) ); assertEquals( "wrong content", "Foobar. &quot;\r\n", m_engine.getText( name ) ); } /** * Cgeck that basic " is changed. */ public void testPutPageEntities2() throws Exception { String text = "Foobar. \"\r\n"; String name = NAME1; m_engine.saveText( name, text ); assertEquals( "page does not exist", true, m_engine.pageExists( name ) ); assertEquals( "wrong content", "Foobar. "\r\n", m_engine.getText( name ) ); } public void testGetHTML() throws Exception { String text = "''Foobar.''"; String name = NAME1; m_engine.saveText( name, text ); String data = m_engine.getHTML( name ); assertEquals( "<i>Foobar.</i>\n", data ); } public void testEncodeNameLatin1() { String name = "abc\u00e5\u00e4\u00f6"; assertEquals( "abc%E5%E4%F6", m_engine.encodeName(name) ); } public void testEncodeNameUTF8() throws Exception { String name = "\u0041\u2262\u0391\u002E"; props.setProperty( WikiEngine.PROP_ENCODING, "UTF-8" ); WikiEngine engine = new TestEngine( props ); assertEquals( "A%E2%89%A2%CE%91.", engine.encodeName(name) ); } public void testReadLinks() throws Exception { String src="Foobar. [Foobar]. Frobozz. [This is a link]."; Object[] result = m_engine.scanWikiLinks( new WikiPage("Test"), src ).toArray(); assertEquals( "item 0", result[0], "Foobar" ); assertEquals( "item 1", result[1], "ThisIsALink" ); } public void testBeautifyTitle() { String src = "WikiNameThingy"; assertEquals("Wiki Name Thingy", m_engine.beautifyTitle( src ) ); } /** * Acronyms should be treated wisely. */ public void testBeautifyTitleAcronym() { String src = "JSPWikiPage"; assertEquals("JSP Wiki Page", m_engine.beautifyTitle( src ) ); } /** * Acronyms should be treated wisely. */ public void testBeautifyTitleAcronym2() { String src = "DELETEME"; assertEquals("DELETEME", m_engine.beautifyTitle( src ) ); } public void testBeautifyTitleAcronym3() { String src = "JSPWikiFAQ"; assertEquals("JSP Wiki FAQ", m_engine.beautifyTitle( src ) ); } public void testBeautifyTitleNumbers() { String src = "TestPage12"; assertEquals("Test Page 12", m_engine.beautifyTitle( src ) ); } /** * English articles too. */ public void testBeautifyTitleArticle() { String src = "ThisIsAPage"; assertEquals("This Is A Page", m_engine.beautifyTitle( src ) ); } /** * English articles too, pathological case... */ /* public void testBeautifyTitleArticle2() { String src = "ThisIsAJSPWikiPage"; assertEquals("This Is A JSP Wiki Page", m_engine.beautifyTitle( src ) ); } */ public void testLatestGet() throws Exception { props.setProperty( "jspwiki.pageProvider", "com.ecyrd.jspwiki.providers.VerySimpleProvider" ); props.setProperty( "jspwiki.usePageCache", "false" ); WikiEngine engine = new TestEngine( props ); WikiPage p = engine.getPage( "test", -1 ); VerySimpleProvider vsp = (VerySimpleProvider) engine.getPageManager().getProvider(); assertEquals( "wrong page", "test", vsp.m_latestReq ); assertEquals( "wrong version", -1, vsp.m_latestVers ); } public void testLatestGet2() throws Exception { props.setProperty( "jspwiki.pageProvider", "com.ecyrd.jspwiki.providers.VerySimpleProvider" ); props.setProperty( "jspwiki.usePageCache", "false" ); WikiEngine engine = new TestEngine( props ); String p = engine.getText( "test", -1 ); VerySimpleProvider vsp = (VerySimpleProvider) engine.getPageManager().getProvider(); assertEquals( "wrong page", "test", vsp.m_latestReq ); assertEquals( "wrong version", -1, vsp.m_latestVers ); } public void testLatestGet3() throws Exception { props.setProperty( "jspwiki.pageProvider", "com.ecyrd.jspwiki.providers.VerySimpleProvider" ); props.setProperty( "jspwiki.usePageCache", "false" ); WikiEngine engine = new TestEngine( props ); String p = engine.getHTML( "test", -1 ); VerySimpleProvider vsp = (VerySimpleProvider) engine.getPageManager().getProvider(); assertEquals( "wrong page", "test", vsp.m_latestReq ); assertEquals( "wrong version", 5, vsp.m_latestVers ); } public void testLatestGet4() throws Exception { props.setProperty( "jspwiki.pageProvider", "com.ecyrd.jspwiki.providers.VerySimpleProvider" ); props.setProperty( "jspwiki.usePageCache", "true" ); WikiEngine engine = new TestEngine( props ); String p = engine.getHTML( VerySimpleProvider.PAGENAME, -1 ); CachingProvider cp = (CachingProvider)engine.getPageManager().getProvider(); VerySimpleProvider vsp = (VerySimpleProvider) cp.getRealProvider(); assertEquals( "wrong page", VerySimpleProvider.PAGENAME, vsp.m_latestReq ); assertEquals( "wrong version", -1, vsp.m_latestVers ); } /** * Checks, if ReferenceManager is informed of new attachments. */ public void testAttachmentRefs() throws Exception { ReferenceManager refMgr = m_engine.getReferenceManager(); AttachmentManager attMgr = m_engine.getAttachmentManager(); m_engine.saveText( NAME1, "fooBar"); Attachment att = new Attachment( NAME1, "TestAtt.txt" ); att.setAuthor( "FirstPost" ); attMgr.storeAttachment( att, m_engine.makeAttachmentFile() );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -