⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wikienginetest.java

📁 wiki建站资源 java编写的 很好用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        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 );            TestEngine.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 );            TestEngine.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 );            TestEngine.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 );            TestEngine.deleteAll( new File( files, NAME1+BasicAttachmentProvider.DIR_EXTENSION ) );            new File( files, "TestPage2"+FileSystemProvider.FILE_EXT ).delete();        }    }            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.getName() );        assertFalse( "Page has not been removed!", saved.exists() );    }    public void testDeletePageAndAttachments()        throws Exception    {        m_engine.saveText( NAME1, "Test" );        Attachment att = new Attachment( NAME1, "TestAtt.txt" );        att.setAuthor( "FirstPost" );        m_engine.getAttachmentManager().storeAttachment( att, m_engine.makeAttachmentFile() );                String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );        File saved = new File( files, NAME1+FileSystemProvider.FILE_EXT );        String atts = props.getProperty( BasicAttachmentProvider.PROP_STORAGEDIR );        File attfile = new File( atts, NAME1+"-att/TestAtt.txt-dir" );                assertTrue( "Didn't create it!", saved.exists() );        assertTrue( "Attachment dir does not exist", attfile.exists() );                WikiPage page = m_engine.getPage( NAME1, WikiProvider.LATEST_VERSION );        m_engine.deletePage( page.getName() );        assertFalse( "Page has not been removed!", saved.exists() );        assertFalse( "Attachment has not been removed", attfile.exists() );    }    public void testDeleteVersion()        throws Exception    {        props.setProperty( "jspwiki.pageProvider", "VersioningFileProvider" );                TestEngine engine = new TestEngine( props );        engine.saveText( NAME1, "Test1" );        engine.saveText( NAME1, "Test2" );        engine.saveText( NAME1, "Test3" );        WikiPage page = engine.getPage( NAME1, 3 );        engine.deleteVersion( page );                assertNull( "got page", engine.getPage( NAME1, 3 ) );                String content = engine.getText( NAME1, WikiProvider.LATEST_VERSION );                assertEquals( "content", "Test2", content.trim() );    }    public void testDeleteVersion2()        throws Exception    {        props.setProperty( "jspwiki.pageProvider", "VersioningFileProvider" );            TestEngine engine = new TestEngine( props );        engine.saveText( NAME1, "Test1" );        engine.saveText( NAME1, "Test2" );        engine.saveText( NAME1, "Test3" );        WikiPage page = engine.getPage( NAME1, 1 );                engine.deleteVersion( page );                assertNull( "got page", engine.getPage( NAME1, 1 ) );                String content = engine.getText( NAME1, WikiProvider.LATEST_VERSION );                assertEquals( "content", "Test3", content.trim() );                assertEquals( "content1", "", engine.getText(NAME1, 1).trim() );    }        /**     *  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( 2000L*PAGEPROVIDER_RESCAN_PERIOD ); // 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( 2000L*PAGEPROVIDER_RESCAN_PERIOD ); // 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() );    }    /**     *  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( 2000L*PAGEPROVIDER_RESCAN_PERIOD );        // Trim - engine.saveText() may append a newline.        String text = m_engine.getText( NAME1 ).trim();        assertEquals( "wrong contents", "Puppaa", text );    }    /**     *  Tests BugReadingOfVariableNotWorkingForOlderVersions     * @throws Exception     */    public void testOldVersionVars()        throws Exception    {           Properties props = new Properties();        props.load( TestEngine.findTestProperties("/jspwiki_vers.properties"));                props.setProperty( PageManager.PROP_USECACHE, "true" );                TestEngine engine = new TestEngine( props );                engine.saveText( NAME1, "[{SET foo=bar}]" );            engine.saveText( NAME1, "[{SET foo=notbar}]");            WikiPage v1 = engine.getPage( NAME1, 1 );                WikiPage v2 = engine.getPage( NAME1, 2 );                assertEquals( "V1", "bar", v1.getAttribute("foo") );                // FIXME: The following must run as well        //assertEquals( "V2", "notbar", v2.getAttribute("foo") );                engine.deletePage( NAME1 );    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -