Search in sources :

Example 16 with Command

use of org.apache.wiki.api.core.Command in project jspwiki by apache.

the class PageCommandTest method testStaticCommand.

@Test
public void testStaticCommand() {
    Command a = PageCommand.VIEW;
    Assertions.assertEquals("view", a.getRequestContext());
    Assertions.assertEquals("Wiki.jsp", a.getJSP());
    Assertions.assertEquals("%uWiki.jsp?page=%n", a.getURLPattern());
    Assertions.assertEquals("PageContent.jsp", a.getContentTemplate());
    Assertions.assertNull(a.getTarget());
    Assertions.assertNull(a.requiredPermission());
    Assertions.assertEquals(a, PageCommand.VIEW);
    a = PageCommand.EDIT;
    Assertions.assertEquals("edit", a.getRequestContext());
    Assertions.assertEquals("Edit.jsp", a.getJSP());
    Assertions.assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
    Assertions.assertEquals("EditContent.jsp", a.getContentTemplate());
    Assertions.assertNull(a.getTarget());
    Assertions.assertNull(a.requiredPermission());
    Assertions.assertEquals(a, PageCommand.EDIT);
    a = PageCommand.PREVIEW;
    Assertions.assertEquals("preview", a.getRequestContext());
    Assertions.assertEquals("Preview.jsp", a.getJSP());
    Assertions.assertEquals("%uPreview.jsp?page=%n", a.getURLPattern());
    Assertions.assertEquals("PreviewContent.jsp", a.getContentTemplate());
    Assertions.assertNull(a.getTarget());
    Assertions.assertNull(a.requiredPermission());
    Assertions.assertEquals(a, PageCommand.PREVIEW);
}
Also used : Command(org.apache.wiki.api.core.Command) Test(org.junit.jupiter.api.Test)

Example 17 with Command

use of org.apache.wiki.api.core.Command in project jspwiki by apache.

the class PageCommandTest method testTargetedCommand.

@Test
public void testTargetedCommand() throws Exception {
    final TestEngine testEngine = TestEngine.build();
    testEngine.saveText("TestPage", "This is a test.");
    final Page testPage = testEngine.getManager(PageManager.class).getPage("TestPage");
    // Get view command
    Command a = PageCommand.VIEW;
    // Combine with wiki page; make sure it's not equal to old command
    Command b = a.targetedCommand(testPage);
    Assertions.assertNotSame(a, b);
    Assertions.assertEquals(a.getRequestContext(), b.getRequestContext());
    Assertions.assertEquals(a.getJSP(), b.getJSP());
    Assertions.assertEquals(a.getURLPattern(), b.getURLPattern());
    Assertions.assertEquals(a.getContentTemplate(), b.getContentTemplate());
    Assertions.assertNotNull(b.getTarget());
    Assertions.assertNotNull(b.requiredPermission());
    Assertions.assertEquals(PermissionFactory.getPagePermission(testPage, "view"), b.requiredPermission());
    Assertions.assertEquals(testPage, b.getTarget());
    // Do the same with edit command
    a = PageCommand.EDIT;
    b = a.targetedCommand(testPage);
    Assertions.assertNotSame(a, b);
    Assertions.assertNotNull(b.getTarget());
    Assertions.assertNotNull(b.requiredPermission());
    Assertions.assertEquals(PermissionFactory.getPagePermission(testPage, "edit"), b.requiredPermission());
    Assertions.assertEquals(testPage, b.getTarget());
    // Do the same with delete command
    a = PageCommand.DELETE;
    b = a.targetedCommand(testPage);
    Assertions.assertNotSame(a, b);
    Assertions.assertNotNull(b.getTarget());
    Assertions.assertNotNull(b.requiredPermission());
    Assertions.assertEquals(PermissionFactory.getPagePermission(testPage, "delete"), b.requiredPermission());
    Assertions.assertEquals(testPage, b.getTarget());
    // Do the same with info command
    a = PageCommand.INFO;
    b = a.targetedCommand(testPage);
    Assertions.assertNotSame(a, b);
    Assertions.assertNotNull(b.getTarget());
    Assertions.assertNotNull(b.requiredPermission());
    Assertions.assertEquals(PermissionFactory.getPagePermission(testPage, "view"), b.requiredPermission());
    Assertions.assertEquals(testPage, b.getTarget());
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Command(org.apache.wiki.api.core.Command) Page(org.apache.wiki.api.core.Page) TestEngine(org.apache.wiki.TestEngine) Test(org.junit.jupiter.api.Test)

Aggregations

Command (org.apache.wiki.api.core.Command)17 Test (org.junit.jupiter.api.Test)12 Page (org.apache.wiki.api.core.Page)4 GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)4 MockHttpServletRequest (net.sourceforge.stripes.mock.MockHttpServletRequest)3 GroupPermission (org.apache.wiki.auth.permissions.GroupPermission)2 WikiPermission (org.apache.wiki.auth.permissions.WikiPermission)2 PageManager (org.apache.wiki.pages.PageManager)2 PageCommand (org.apache.wiki.ui.PageCommand)2 Permission (java.security.Permission)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PageContext (javax.servlet.jsp.PageContext)1 TestEngine (org.apache.wiki.TestEngine)1 Context (org.apache.wiki.api.core.Context)1 Engine (org.apache.wiki.api.core.Engine)1 Session (org.apache.wiki.api.core.Session)1 SearchResult (org.apache.wiki.api.search.SearchResult)1 AuthorizationManager (org.apache.wiki.auth.AuthorizationManager)1