use of org.apache.wiki.api.core.Command in project jspwiki by apache.
the class CommandResolverTest method testFindWikiActionWithParams.
@Test
public void testFindWikiActionWithParams() {
final Page page = m_engine.getManager(PageManager.class).getPage("SinglePage");
// Passing an EDIT request with page param yields a wrapped action
MockHttpServletRequest request = m_engine.newHttpRequest("/Edit.jsp?page=SinglePage");
request.getParameterMap().put("page", new String[] { "SinglePage" });
Command a = resolver.findCommand(request, ContextEnum.PAGE_EDIT.getRequestContext());
Assertions.assertNotSame(PageCommand.EDIT, a);
Assertions.assertEquals("EditContent.jsp", a.getContentTemplate());
Assertions.assertEquals("Edit.jsp", a.getJSP());
Assertions.assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
Assertions.assertEquals(page, a.getTarget());
// Passing an EDIT request with page=Search yields FIND action, *not* edit
request.setContextPath("/Edit.jsp?page=Search");
request.getParameterMap().put("page", new String[] { "Search" });
a = resolver.findCommand(request, ContextEnum.PAGE_EDIT.getRequestContext());
Assertions.assertEquals(WikiCommand.FIND, a);
Assertions.assertEquals("FindContent.jsp", a.getContentTemplate());
Assertions.assertEquals("Search.jsp", a.getJSP());
Assertions.assertEquals("%uSearch.jsp", a.getURLPattern());
Assertions.assertNull(a.getTarget());
// Passing an EDIT request with group="Foo" yields wrapped VIEW_GROUP
request = m_engine.newHttpRequest("/Group.jsp?group=Foo");
request.getParameterMap().put("group", new String[] { "Foo" });
a = resolver.findCommand(request, ContextEnum.PAGE_EDIT.getRequestContext());
Assertions.assertNotSame(GroupCommand.VIEW_GROUP, a);
Assertions.assertEquals("GroupContent.jsp", a.getContentTemplate());
Assertions.assertEquals("Group.jsp", a.getJSP());
Assertions.assertEquals("%uGroup.jsp?group=%n", a.getURLPattern());
Assertions.assertEquals(new GroupPrincipal("Foo"), a.getTarget());
}
use of org.apache.wiki.api.core.Command in project jspwiki by apache.
the class RedirectCommandTest method testTargetedCommand.
@Test
public void testTargetedCommand() {
final Command a = RedirectCommand.REDIRECT;
// Test with local JSP
Command b = a.targetedCommand("%uTestPage.jsp");
Assertions.assertEquals("", b.getRequestContext());
Assertions.assertEquals("TestPage.jsp", b.getJSP());
Assertions.assertEquals("%uTestPage.jsp", b.getURLPattern());
Assertions.assertNull(b.getContentTemplate());
Assertions.assertEquals("%uTestPage.jsp", b.getTarget());
Assertions.assertNotSame(RedirectCommand.REDIRECT, b);
// Test with non-local URL
b = a.targetedCommand("http://www.yahoo.com");
Assertions.assertEquals("", b.getRequestContext());
Assertions.assertEquals("http://www.yahoo.com", b.getJSP());
Assertions.assertEquals("http://www.yahoo.com", b.getURLPattern());
Assertions.assertNull(b.getContentTemplate());
Assertions.assertEquals("http://www.yahoo.com", b.getTarget());
Assertions.assertNotSame(RedirectCommand.REDIRECT, b);
}
use of org.apache.wiki.api.core.Command in project jspwiki by apache.
the class WikiCommandTest method testStaticCommand.
@Test
public void testStaticCommand() {
Command a = WikiCommand.CREATE_GROUP;
Assertions.assertEquals("createGroup", a.getRequestContext());
Assertions.assertEquals("NewGroup.jsp", a.getJSP());
Assertions.assertEquals("%uNewGroup.jsp", a.getURLPattern());
Assertions.assertEquals("NewGroupContent.jsp", a.getContentTemplate());
Assertions.assertNull(a.getTarget());
Assertions.assertNull(a.requiredPermission());
Assertions.assertEquals(a, WikiCommand.CREATE_GROUP);
a = WikiCommand.ERROR;
Assertions.assertEquals("error", a.getRequestContext());
Assertions.assertEquals("Error.jsp", a.getJSP());
Assertions.assertEquals("%uError.jsp", a.getURLPattern());
Assertions.assertEquals("DisplayMessage.jsp", a.getContentTemplate());
Assertions.assertNull(a.getTarget());
Assertions.assertNull(a.requiredPermission());
Assertions.assertEquals(a, WikiCommand.ERROR);
a = WikiCommand.FIND;
Assertions.assertEquals("find", a.getRequestContext());
Assertions.assertEquals("Search.jsp", a.getJSP());
Assertions.assertEquals("%uSearch.jsp", a.getURLPattern());
Assertions.assertEquals("FindContent.jsp", a.getContentTemplate());
Assertions.assertNull(a.getTarget());
Assertions.assertNull(a.requiredPermission());
Assertions.assertEquals(a, WikiCommand.FIND);
a = WikiCommand.INSTALL;
Assertions.assertEquals("install", a.getRequestContext());
Assertions.assertEquals("Install.jsp", a.getJSP());
Assertions.assertEquals("%uInstall.jsp", a.getURLPattern());
Assertions.assertNull(a.getContentTemplate());
Assertions.assertNull(a.getTarget());
Assertions.assertNull(a.requiredPermission());
Assertions.assertEquals(a, WikiCommand.INSTALL);
a = WikiCommand.LOGIN;
Assertions.assertEquals("login", a.getRequestContext());
Assertions.assertEquals("Login.jsp", a.getJSP());
Assertions.assertEquals("%uLogin.jsp?redirect=%n", a.getURLPattern());
Assertions.assertEquals("LoginContent.jsp", a.getContentTemplate());
Assertions.assertNull(a.getTarget());
Assertions.assertNull(a.requiredPermission());
Assertions.assertEquals(a, WikiCommand.LOGIN);
a = WikiCommand.LOGOUT;
Assertions.assertEquals("logout", a.getRequestContext());
Assertions.assertEquals("Logout.jsp", a.getJSP());
Assertions.assertEquals("%uLogout.jsp", a.getURLPattern());
Assertions.assertNull(a.getContentTemplate());
Assertions.assertNull(a.getTarget());
Assertions.assertNull(a.requiredPermission());
Assertions.assertEquals(a, WikiCommand.LOGOUT);
a = WikiCommand.PREFS;
Assertions.assertEquals("prefs", a.getRequestContext());
Assertions.assertEquals("UserPreferences.jsp", a.getJSP());
Assertions.assertEquals("%uUserPreferences.jsp", a.getURLPattern());
Assertions.assertEquals("PreferencesContent.jsp", a.getContentTemplate());
Assertions.assertNull(a.getTarget());
Assertions.assertNull(a.requiredPermission());
Assertions.assertEquals(a, WikiCommand.PREFS);
}
use of org.apache.wiki.api.core.Command in project jspwiki by apache.
the class WikiCommandTest method testTargetedCommand.
@Test
public void testTargetedCommand() {
// Get view command
Command a = WikiCommand.CREATE_GROUP;
// Combine with wiki; make sure it's not equal to old command
Command b = a.targetedCommand(wiki);
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(new WikiPermission(wiki, "createGroups"), b.requiredPermission());
Assertions.assertEquals(wiki, b.getTarget());
// Do the same with other commands
a = WikiCommand.ERROR;
b = a.targetedCommand(wiki);
Assertions.assertNotSame(a, b);
Assertions.assertNotNull(b.getTarget());
Assertions.assertNull(b.requiredPermission());
Assertions.assertEquals(wiki, b.getTarget());
a = WikiCommand.FIND;
b = a.targetedCommand(wiki);
Assertions.assertNotSame(a, b);
Assertions.assertNotNull(b.getTarget());
Assertions.assertNull(b.requiredPermission());
Assertions.assertEquals(wiki, b.getTarget());
a = WikiCommand.INSTALL;
b = a.targetedCommand(wiki);
Assertions.assertNotSame(a, b);
Assertions.assertNotNull(b.getTarget());
Assertions.assertNull(b.requiredPermission());
Assertions.assertEquals(wiki, b.getTarget());
a = WikiCommand.LOGIN;
b = a.targetedCommand(wiki);
Assertions.assertNotSame(a, b);
Assertions.assertNotNull(b.getTarget());
Assertions.assertNotNull(b.requiredPermission());
Assertions.assertEquals(new WikiPermission(wiki, "login"), b.requiredPermission());
Assertions.assertEquals(wiki, b.getTarget());
a = WikiCommand.LOGOUT;
b = a.targetedCommand(wiki);
Assertions.assertNotSame(a, b);
Assertions.assertNotNull(b.getTarget());
Assertions.assertNotNull(b.requiredPermission());
Assertions.assertEquals(new WikiPermission(wiki, "login"), b.requiredPermission());
Assertions.assertEquals(wiki, b.getTarget());
a = WikiCommand.PREFS;
b = a.targetedCommand(wiki);
Assertions.assertNotSame(a, b);
Assertions.assertNotNull(b.getTarget());
Assertions.assertNotNull(b.requiredPermission());
Assertions.assertEquals(new WikiPermission(wiki, "editProfile"), b.requiredPermission());
Assertions.assertEquals(wiki, b.getTarget());
}
use of org.apache.wiki.api.core.Command in project jspwiki by apache.
the class WikiContext method findCommand.
/**
* Looks up and returns a PageCommand based on a supplied WikiPage and HTTP request. First, the appropriate Command is obtained by
* examining the HTTP request; the default is {@link ContextEnum#PAGE_VIEW}. If the Command is a PageCommand (and it should be, in most
* cases), a targeted Command is created using the (non-<code>null</code>) WikiPage as target.
*
* @param engine the wiki engine
* @param request the HTTP request
* @param page the wiki page
* @return the correct command
*/
protected static Command findCommand(final Engine engine, final HttpServletRequest request, final Page page) {
final String defaultContext = ContextEnum.PAGE_VIEW.getRequestContext();
Command command = engine.getManager(CommandResolver.class).findCommand(request, defaultContext);
if (command instanceof PageCommand && page != null) {
command = command.targetedCommand(page);
}
return command;
}
Aggregations