Search in sources :

Example 51 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testCollectingLinksAttachment.

@Test
public void testCollectingLinksAttachment() throws Exception {
    try {
        testEngine.saveText(PAGE_NAME, "content");
        Attachment att = new Attachment(testEngine, PAGE_NAME, "TestAtt.txt");
        att.setAuthor("FirstPost");
        testEngine.getAttachmentManager().storeAttachment(att, testEngine.makeAttachmentFile());
        LinkCollector coll = new LinkCollector();
        LinkCollector coll_others = new LinkCollector();
        String src = "[TestAtt.txt]";
        WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
        MarkupParser p = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
        p.addLocalLinkHook(coll_others);
        p.addExternalLinkHook(coll_others);
        p.addAttachmentLinkHook(coll);
        p.parse();
        Collection<String> links = coll.getLinks();
        Assert.assertEquals("no links found", 1, links.size());
        Assert.assertEquals("wrong link", PAGE_NAME + "/TestAtt.txt", links.iterator().next());
        Assert.assertEquals("wrong links found", 0, coll_others.getLinks().size());
    } finally {
        String files = testEngine.getWikiProperties().getProperty(BasicAttachmentProvider.PROP_STORAGEDIR);
        File storagedir = new File(files, PAGE_NAME + BasicAttachmentProvider.DIR_EXTENSION);
        if (storagedir.exists() && storagedir.isDirectory())
            TestEngine.deleteAll(storagedir);
    }
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Attachment(org.apache.wiki.attachment.Attachment) LinkCollector(org.apache.wiki.LinkCollector) File(java.io.File) Test(org.junit.Test)

Example 52 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testSet1.

/**
 * Used by the ACL tests.
 * @param array
 * @param key
 * @return
 */
/*
    private boolean inArray( Object[] array, Object key )
    {
        for( int i = 0; i < array.length; i++ )
        {
            if ( array[i].equals( key ) )
            {
                return true;
            }
        }
        return false;
    }
    */
/**
 * Used by the ACL tests.
 * @param array
 * @param key
 * @return
 */
/*
    private boolean inGroup( Object[] array, Principal key )
    {
        for( int i = 0; i < array.length; i++ )
        {
            if (array[i] instanceof Group)
            {
                if (((Group)array[i]).isMember(key))
                {
                    return true;
                }
            }
        }
        return false;
    }
    */
/**
 *  ACL tests.
 */
/*
    @Test
     public void testSimpleACL1()
     throws Exception
     {
     String src = "Foobar.[{ALLOW view JanneJalkanen}]";

     WikiPage p = new WikiPage( PAGE_NAME );

     String res = translate( p, src );

     Assert.assertEquals("Page text", "Foobar.", res);

     Acl acl = p.getAcl();

     Principal prof = new WikiPrincipal("JanneJalkanen");

     Assert.assertTrue( "has read", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
     Assert.assertFalse( "no edit", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
     }

    @Test
     public void testSimpleACL2()
     throws Exception
     {
     String src = "Foobar.[{ALLOW view JanneJalkanen}]\n"+
     "[{ALLOW edit JanneJalkanen, SuloVilen}]";

     WikiPage p = new WikiPage( PAGE_NAME );

     String res = translate( p, src );

     Assert.assertEquals("Page text", "Foobar.\n", res);

     Acl acl = p.getAcl();

     // ACL says Janne can read and edit
      Principal prof = new WikiPrincipal("JanneJalkanen");
      Assert.assertTrue( "read for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
      Assert.assertTrue( "edit for JJ", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );

      // ACL doesn't say Erik can read or edit
       prof = new WikiPrincipal("ErikBunn");
       Assert.assertFalse( "no read for BB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
       Assert.assertFalse( "no edit for EB", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );

       // ACL says Sulo can edit, but doens't say he can read (though the AuthMgr will tell us it's implied)
        prof = new WikiPrincipal("SuloVilen");
        Assert.assertFalse( "read for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "view") ), prof ) );
        Assert.assertTrue( "edit for SV", inArray( acl.findPrincipals( new PagePermission( PAGE_NAME, "edit") ), prof ) );
        }
        */
/*
    private boolean containsGroup( List l, String name )
    {
        for( Iterator i = l.iterator(); i.hasNext(); )
        {
            String group = (String) i.next();

            if( group.equals( name ) )
                return true;
        }

        return false;
    }
    */
/**
 *   Metadata tests
 */
@Test
public void testSet1() throws Exception {
    String src = "Foobar.[{SET name=foo}]";
    WikiPage p = new WikiPage(testEngine, PAGE_NAME);
    String res = translate(p, src);
    Assert.assertEquals("Page text", "Foobar.", res);
    Assert.assertEquals("foo", p.getAttribute("name"));
}
Also used : WikiPage(org.apache.wiki.WikiPage) Test(org.junit.Test)

Example 53 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class JSPWikiMarkupParserTest method translate_nofollow.

private String translate_nofollow(String src) throws IOException, NoRequiredPropertyException, ServletException, WikiException {
    props = TestEngine.getTestProperties();
    props.setProperty("jspwiki.translatorReader.useRelNofollow", "true");
    TestEngine testEngine2 = new TestEngine(props);
    WikiContext context = new WikiContext(testEngine2, new WikiPage(testEngine2, PAGE_NAME));
    JSPWikiMarkupParser r = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
    XHTMLRenderer conv = new XHTMLRenderer(context, r.parse());
    return conv.getString();
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) XHTMLRenderer(org.apache.wiki.render.XHTMLRenderer) TestEngine(org.apache.wiki.TestEngine)

Example 54 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testCollectingLinks2.

@Test
public void testCollectingLinks2() throws Exception {
    LinkCollector coll = new LinkCollector();
    String src = "[" + PAGE_NAME + "/Test.txt]";
    WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
    MarkupParser p = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
    p.addLocalLinkHook(coll);
    p.addExternalLinkHook(coll);
    p.addAttachmentLinkHook(coll);
    p.parse();
    Collection<String> links = coll.getLinks();
    Assert.assertEquals("no links found", 1, links.size());
    Assert.assertEquals("wrong link", PAGE_NAME + "/Test.txt", links.iterator().next());
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) LinkCollector(org.apache.wiki.LinkCollector) Test(org.junit.Test)

Example 55 with WikiPage

use of org.apache.wiki.WikiPage in project jspwiki by apache.

the class JSPWikiMarkupParserTest method testCollectingLinks.

/**
 *  Test collection of links.
 */
@Test
public void testCollectingLinks() throws Exception {
    LinkCollector coll = new LinkCollector();
    String src = "[Test]";
    WikiContext context = new WikiContext(testEngine, new WikiPage(testEngine, PAGE_NAME));
    MarkupParser p = new JSPWikiMarkupParser(context, new BufferedReader(new StringReader(src)));
    p.addLocalLinkHook(coll);
    p.addExternalLinkHook(coll);
    p.addAttachmentLinkHook(coll);
    p.parse();
    Collection<String> links = coll.getLinks();
    Assert.assertEquals("no links found", 1, links.size());
    Assert.assertEquals("wrong link", "Test", links.iterator().next());
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) LinkCollector(org.apache.wiki.LinkCollector) Test(org.junit.Test)

Aggregations

WikiPage (org.apache.wiki.WikiPage)186 Test (org.junit.Test)77 WikiContext (org.apache.wiki.WikiContext)63 WikiEngine (org.apache.wiki.WikiEngine)29 Attachment (org.apache.wiki.attachment.Attachment)26 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)17 File (java.io.File)16 Collection (java.util.Collection)16 TestEngine (org.apache.wiki.TestEngine)15 Iterator (java.util.Iterator)13 StringReader (java.io.StringReader)9 Hashtable (java.util.Hashtable)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 Calendar (java.util.Calendar)8 Vector (java.util.Vector)8 StringWriter (java.io.StringWriter)7 InternalWikiException (org.apache.wiki.InternalWikiException)7 PagePermission (org.apache.wiki.auth.permissions.PagePermission)7