use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class IfPluginTest method getJanneBasedWikiContextFor.
/**
* Returns a {@link WikiContext} for the given page, with user {@link Users#JANNE} logged in.
*
* @param page given {@link WikiPage}.
* @return {@link WikiContext} associated to given {@link WikiPage}.
* @throws WikiException problems while logging in.
*/
WikiContext getJanneBasedWikiContextFor(WikiPage page) throws WikiException {
MockHttpServletRequest request = testEngine.newHttpRequest();
WikiSession session = WikiSession.getWikiSession(testEngine, request);
testEngine.getAuthenticationManager().login(session, request, Users.JANNE, Users.JANNE_PASS);
return new WikiContext(testEngine, request, page);
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class SearchManagerTest method testSimpleSearch3.
@Test
public void testSimpleSearch3() throws Exception {
String txt = "It was the dawn of the third age of mankind, ten years after the Earth-Minbari War.";
MockHttpServletRequest request = m_engine.newHttpRequest();
request.getParameterMap().put("page", new String[] { "TestPage" });
WikiContext ctx = m_engine.createContext(request, WikiContext.EDIT);
m_engine.saveText(ctx, txt);
m_engine.saveText(ctx, "The Babylon Project was a dream given form. Its goal: to prevent another war by creating a place where humans and aliens could work out their differences peacefully.");
Thread.yield();
// wait until 2nd m_engine.saveText() takes effect
Collection res = waitForIndex("Babylon", "testSimpleSearch3");
// check for text present in 1st m_engine.saveText() but not in 2nd
res = m_mgr.findPages("mankind", ctx);
Assert.assertNotNull("found results", res);
Assert.assertEquals("empty results", 0, res.size());
res = m_mgr.findPages("Babylon", ctx);
Assert.assertNotNull("null result", res);
Assert.assertEquals("no pages", 1, res.size());
Assert.assertEquals("page", "TestPage", ((SearchResult) res.iterator().next()).getPage().getName());
m_engine.deleteTestPage("TestPage");
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class CommandResolverTest method testFindWikiActionWithPath.
@Test
public void testFindWikiActionWithPath() {
MockHttpServletRequest request;
Command a;
// Passing an EDIT request with View JSP yields EDIT of the Front page
request = m_engine.newHttpRequest("/Wiki.jsp");
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertNotNull(a.getTarget());
Assert.assertEquals(((WikiPage) a.getTarget()).getName(), m_engine.getFrontPage());
// Passing an EDIT request with Group JSP yields VIEW_GROUP
request = m_engine.newHttpRequest("/Group.jsp");
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertEquals(GroupCommand.VIEW_GROUP, a);
Assert.assertNull(a.getTarget());
// Passing an EDIT request with UserPreferences JSP yields PREFS
request = m_engine.newHttpRequest("/UserPreferences.jsp");
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertEquals(WikiCommand.PREFS, a);
Assert.assertNull(a.getTarget());
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class CommandResolverTest method testFindWikiActionNoParams.
@Test
public void testFindWikiActionNoParams() {
Command a;
MockHttpServletRequest request = m_engine.newHttpRequest("");
// Passing an EDIT request with no explicit page params means the EDIT action
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertEquals(PageCommand.EDIT, a);
Assert.assertEquals("EditContent.jsp", a.getContentTemplate());
Assert.assertEquals("Edit.jsp", a.getJSP());
Assert.assertEquals("%uEdit.jsp?page=%n", a.getURLPattern());
Assert.assertNull(a.getTarget());
// Ditto for prefs context
a = resolver.findCommand(request, WikiContext.PREFS);
Assert.assertEquals(WikiCommand.PREFS, a);
Assert.assertNull(a.getTarget());
// Ditto for group view context
a = resolver.findCommand(request, WikiContext.VIEW_GROUP);
Assert.assertEquals(GroupCommand.VIEW_GROUP, a);
Assert.assertNull(a.getTarget());
// Looking for non-existent context; should result in exception
try {
a = resolver.findCommand(request, "nonExistentContext");
Assert.assertFalse("Context supported, strangely...", true);
} catch (IllegalArgumentException e) {
// Good; this is what we expect
}
// Request for "UserPreference.jsp" should resolve to PREFS action
request = m_engine.newHttpRequest("/UserPreferences.jsp");
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertEquals(WikiCommand.PREFS, a);
Assert.assertNull(a.getTarget());
// Request for "NewGroup.jsp" should resolve to CREATE_GROUP action
// but targeted at the wiki
request = m_engine.newHttpRequest("/NewGroup.jsp");
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertNotSame(WikiCommand.CREATE_GROUP, a);
Assert.assertEquals(WikiCommand.CREATE_GROUP.getRequestContext(), a.getRequestContext());
Assert.assertEquals(m_engine.getApplicationName(), a.getTarget());
// But request for JSP not mapped to action should get default
request = m_engine.newHttpRequest("/NonExistent.jsp");
a = resolver.findCommand(request, WikiContext.EDIT);
Assert.assertEquals(PageCommand.EDIT, a);
Assert.assertNull(a.getTarget());
}
use of net.sourceforge.stripes.mock.MockHttpServletRequest in project jspwiki by apache.
the class WikiSessionTest method anonymousSession.
/**
* Creates an anonymous user session.
* @param engine the wiki engine
* @return the new session
* @throws Exception
*/
public static WikiSession anonymousSession(TestEngine engine) throws Exception {
// Build anon session
MockHttpServletRequest request = engine.newHttpRequest();
// Log in
runSecurityFilter(engine, request);
// Make sure the user is actually anonymous
WikiSession session = WikiSession.getWikiSession(engine, request);
if (!session.isAnonymous()) {
throw new IllegalStateException("Session is not anonymous.");
}
return session;
}
Aggregations