📄 wikienginetest.java
字号:
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", -1, 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() ); try { // and check post-conditions Collection c = refMgr.findUncreated(); assertTrue("attachment exists: "+c, c==null || c.size()==0 ); c = refMgr.findUnreferenced(); assertEquals( "unreferenced count", 2, c.size() ); Iterator i = c.iterator(); String first = (String) i.next(); String second = (String) i.next(); assertTrue( "unreferenced", (first.equals( NAME1 ) && second.equals( NAME1+"/TestAtt.txt")) || (first.equals( NAME1+"/TestAtt.txt" ) && second.equals( NAME1 )) ); } finally { // do cleanup String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); m_engine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION ) ); } } /** * Is ReferenceManager updated properly if a page references * its own attachments? */ /* FIXME: This is a deep problem. The real problem is that the reference manager cannot know when it encounters a link like "testatt.txt" that it is really a link to an attachment IF the link is created before the attachment. This means that when the attachment is created, the link will stay in the "uncreated" list. There are two issues here: first of all, TranslatorReader should able to return the proper attachment references (which I think it does), and second, the ReferenceManager should be able to remove any links that are not referred to, nor they are created. However, doing this in a relatively sane timeframe can be a problem. */ public void testAttachmentRefs2() throws Exception { ReferenceManager refMgr = m_engine.getReferenceManager(); AttachmentManager attMgr = m_engine.getAttachmentManager(); m_engine.saveText( NAME1, "[TestAtt.txt]"); // check a few pre-conditions Collection c = refMgr.findReferrers( "TestAtt.txt" ); assertTrue( "normal, unexisting page", c!=null && ((String)c.iterator().next()).equals( NAME1 ) ); c = refMgr.findReferrers( NAME1+"/TestAtt.txt" ); assertTrue( "no attachment", c==null || c.size()==0 ); c = refMgr.findUncreated(); assertTrue( "unknown attachment", c!=null && c.size()==1 && ((String)c.iterator().next()).equals( "TestAtt.txt" ) ); // now we create the attachment Attachment att = new Attachment( NAME1, "TestAtt.txt" ); att.setAuthor( "FirstPost" ); attMgr.storeAttachment( att, m_engine.makeAttachmentFile() ); try { // and check post-conditions c = refMgr.findUncreated(); assertTrue( "attachment exists: ", c==null || c.size()==0 ); c = refMgr.findReferrers( "TestAtt.txt" ); assertTrue( "no normal page", c==null || c.size()==0 ); c = refMgr.findReferrers( NAME1+"/TestAtt.txt" ); assertTrue( "attachment exists now", c!=null && ((String)c.iterator().next()).equals( NAME1 ) ); c = refMgr.findUnreferenced(); assertTrue( "unreferenced", c.size()==1 && ((String)c.iterator().next()).equals( NAME1 )); } finally { // do cleanup String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); m_engine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION ) ); } } /** * Checks, if ReferenceManager is informed if a link to an attachment is added. */ public void testAttachmentRefs3() 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() ); m_engine.saveText( NAME1, " ["+NAME1+"/TestAtt.txt] "); try { // and check post-conditions Collection c = refMgr.findUncreated(); assertTrue( "attachment exists", c==null || c.size()==0 ); c = refMgr.findUnreferenced(); assertEquals( "unreferenced count", c.size(), 1 ); assertTrue( "unreferenced", ((String)c.iterator().next()).equals( NAME1 ) ); } finally { // do cleanup String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); m_engine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION ) ); } } /** * Checks, if ReferenceManager is informed if a third page references an attachment. */ public void testAttachmentRefs4() throws Exception { ReferenceManager refMgr = m_engine.getReferenceManager(); AttachmentManager attMgr = m_engine.getAttachmentManager(); m_engine.saveText( NAME1, "[TestPage2]"); Attachment att = new Attachment( NAME1, "TestAtt.txt" ); att.setAuthor( "FirstPost" ); attMgr.storeAttachment( att, m_engine.makeAttachmentFile() ); m_engine.saveText( "TestPage2", "["+NAME1+"/TestAtt.txt]"); try { // and check post-conditions Collection c = refMgr.findUncreated(); assertTrue( "attachment exists", c==null || c.size()==0 ); c = refMgr.findUnreferenced(); assertEquals( "unreferenced count", c.size(), 1 ); assertTrue( "unreferenced", ((String)c.iterator().next()).equals( NAME1 ) ); } finally { // do cleanup String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); m_engine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION ) ); new File( files, "TestPage2"+FileSystemProvider.FILE_EXT ).delete(); } } /** * Assumes that CachingProvider is in use. */ public void testExternalModification() throws Exception { m_engine.saveText( NAME1, "Foobar" ); m_engine.getText( NAME1 ); // Ensure that page is cached. Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT ); assertTrue( "No file!", saved.exists() ); FileWriter out = new FileWriter( saved ); FileUtil.copyContents( new StringReader("Puppaa"), out ); out.close(); // Wait for the caching provider to notice a refresh. Thread.sleep( 2L*PAGEPROVIDER_RESCAN_PERIOD ); // Trim - engine.saveText() may append a newline. String text = m_engine.getText( NAME1 ).trim(); assertEquals( "wrong contents", "Puppaa", text ); } /** * Assumes that CachingProvider is in use. */ public void testExternalModificationRefs() throws Exception { ReferenceManager refMgr = m_engine.getReferenceManager(); m_engine.saveText( NAME1, "[Foobar]" ); m_engine.getText( NAME1 ); // Ensure that page is cached. Collection c = refMgr.findUncreated(); assertTrue( "Non-existent reference not detected by ReferenceManager", Util.collectionContains( c, "Foobar" )); Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT ); assertTrue( "No file!", saved.exists() ); FileWriter out = new FileWriter( saved ); FileUtil.copyContents( new StringReader("[Puppaa]"), out ); out.close(); Thread.sleep( 5000L ); // Wait five seconds for CachingProvider to wake up. String text = m_engine.getText( NAME1 ); assertEquals( "wrong contents", "[Puppaa]", text ); c = refMgr.findUncreated(); assertTrue( "Non-existent reference after external page change " + "not detected by ReferenceManager", Util.collectionContains( c, "Puppaa" )); } /** * Assumes that CachingProvider is in use. */ public void testExternalModificationRefsDeleted() throws Exception { ReferenceManager refMgr = m_engine.getReferenceManager(); m_engine.saveText( NAME1, "[Foobar]" ); m_engine.getText( NAME1 ); // Ensure that page is cached. Collection c = refMgr.findUncreated(); assertEquals( "uncreated count", 1, c.size() ); assertEquals( "wrong referenced page", "Foobar", (String)c.iterator().next() ); Thread.sleep( 2000L ); // Wait two seconds for filesystem granularity String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT ); assertTrue( "No file!", saved.exists() ); saved.delete(); assertFalse( "File not deleted!", saved.exists() ); Thread.sleep( 5000L ); // Wait five seconds for CachingProvider to catch up. WikiPage p = m_engine.getPage( NAME1 ); assertNull( "Got page!", p ); String text = m_engine.getText( NAME1 ); assertEquals( "wrong contents", "", text ); c = refMgr.findUncreated(); assertEquals( "NEW: uncreated count", 0, c.size() ); } /* public void testDeletePage() throws Exception { m_engine.saveText( NAME1, "Test" ); String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR ); File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT ); assertTrue( "Didn't create it!", saved.exists() ); WikiPage page = m_engine.getPage( NAME1, WikiProvider.LATEST_VERSION ); m_engine.deletePage( page ); assertFalse( "Page has not been removed!", saved.exists() ); } */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -